Skip to content

Commit

Permalink
Merge branch 'iznogod'
Browse files Browse the repository at this point in the history
  • Loading branch information
kungfooman committed May 22, 2014
2 parents 9498365 + 7c63e98 commit 94ace07
Show file tree
Hide file tree
Showing 4 changed files with 408 additions and 12 deletions.
4 changes: 4 additions & 0 deletions gsc.cpp
Expand Up @@ -206,6 +206,10 @@ Scr_Function scriptFunctions[] = {
{"fwrite" , gsc_utils_fwrite , 0},
{"fclose" , gsc_utils_fclose , 0},
{"sprintf" , gsc_utils_sprintf , 0},
{"add_language" , gsc_add_language , 0},
{"load_languages" , gsc_load_languages , 0},
{"get_language_item" , gsc_get_language_item , 0},
{"free_slot" , gsc_free_slot , 0},
#endif

#if COMPILE_TCC == 1
Expand Down
41 changes: 31 additions & 10 deletions gsc_mysql.cpp
Expand Up @@ -39,19 +39,40 @@ MYSQL *cod_mysql_connection = NULL;

void mysql_async_execute_query(mysql_async_task *q, mysql_async_connection *c) //cannot be called from gsc, is threaded.
{
int res = mysql_query(c->connection, q->query);
if(res)
printf("scriptengine> Error in MySQL connection for async query. Cannot recover\n"); //keep mysql connection available for now, might recover in the future?
else
int i = 0;
int lastquery = 0;
bool goodquery = false;
while(q->query[i] != '\0')
{
if(q->save)
if(q->query[i] == ';' && i > 0 && q->query[i - 1] != '\\')
{
MYSQL_RES *result = mysql_store_result(c->connection);
q->result = result;
//subquery
q->query[i] = '\0';
int res = mysql_query(c->connection, &(q->query[lastquery]));
q->query[i] = ';';
if(res)
goodquery = false;
else
goodquery = true;
lastquery = i + 1;
while(q->query[lastquery] != '\0' && (q->query[lastquery] == ' ' || q->query[lastquery] == '\t'))
lastquery++;
}
c->in_use = false;
q->done = true;
i++;
}
if(i - lastquery > 5)
{
//this is a query
int res = mysql_query(c->connection, &(q->query[lastquery]));
if(res)
goodquery = false;
else
goodquery = true;
}
if(goodquery && q->save)
q->result = mysql_store_result(c->connection);
c->in_use = false;
q->done = true;
}

void mysql_async_query_handler() //is threaded after initialize
Expand Down Expand Up @@ -526,7 +547,7 @@ void gsc_mysql_free_result() {
#if DEBUG_MYSQL
printf("gsc_mysql_free_result(result=%d)\n", result);
#endif
if(result == NULL)
if(result == 0)
{
printf("scriptengine> Error in mysql_free_result: input is a NULL-pointer\n");
stackPushUndefined();
Expand Down

0 comments on commit 94ace07

Please sign in to comment.