diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-24 14:53:33 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-24 14:53:33 +0300 |
commit | 9f46ca3e0f3062dd6e9848f6bfd97926144ccbd7 (patch) | |
tree | cadc6ef1ab1c68b22cd85b3c6d03e095a45a37c8 | |
parent | c2fef3f238087c8be9d8ac25fbd4b7fe19370f0b (diff) | |
download | gamma-9f46ca3e0f3062dd6e9848f6bfd97926144ccbd7.tar.gz gamma-9f46ca3e0f3062dd6e9848f6bfd97926144ccbd7.tar.bz2 |
Improve handling of multi-result sets.
* src/mysql.c (s_mysql_query): Consume any additional results
to avoid 'out of sequence' errors.
-rw-r--r-- | src/mysql.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mysql.c b/src/mysql.c index 81364b4..1310212 100644 --- a/src/mysql.c +++ b/src/mysql.c @@ -128,12 +128,26 @@ s_mysql_connect (SCM parmlist, const char *func_name) conn->username = user; conn->database = dbname; conn->data = mysql; return smob; } +static void +flush_result(MYSQL *mysql) +{ + while (mysql_next_result(mysql) == 0) { + MYSQL_RES *result = mysql_store_result(mysql); + if (!result) + break; + if (mysql_field_count(mysql)) + while (mysql_fetch_row(result)) + ; + mysql_free_result(result); + } +} + static SCM s_mysql_query(struct sql_connect *conn, const char *query) { MYSQL *mysql = conn->data; MYSQL_RES *result; SCM cell = SCM_EOL; @@ -183,12 +197,13 @@ s_mysql_query(struct sql_connect *conn, const char *query) else SCM_SETCDR(row_tail, new_row); row_tail = new_row; } cell = row_head; mysql_free_result(result); + flush_result(mysql); } else { /* should it have returned something? */ if (mysql_field_count(mysql) == 0) { cell = scm_from_ulong(mysql_affected_rows(mysql)); } else { /* mysql_store_result() should have returned data */ scm_error(gamma_sql_error, "sql-query", "~A", |