Created
September 14, 2008 02:19
-
-
Save methodmissing/10689 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.dirname(__FILE__) + '/test_helper' | |
c = Mysql.real_connect('localhost','root') | |
c.send_query('select sleep(1)') | |
c.send_query('select sleep(1)') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macbook-pros-computer:mysqlplus lourens$ git diff | |
diff --git a/ext/mysql.c b/ext/mysql.c | |
index b804723..89bdfb3 100644 | |
--- a/ext/mysql.c | |
+++ b/ext/mysql.c | |
@@ -61,6 +61,7 @@ struct mysql { | |
char connection; | |
char query_with_result; | |
char blocking; | |
+ char query_sent; | |
}; | |
struct mysql_res { | |
@@ -278,6 +279,7 @@ static VALUE real_connect(int argc, VALUE* argv, VALUE klass) | |
vio_fastsend( myp->handler.net.vio ); | |
myp->query_with_result = Qtrue; | |
+ myp->query_sent = Qfalse; | |
rb_obj_call_init(obj, argc, argv); | |
return obj; | |
@@ -797,14 +799,21 @@ static VALUE readable( int argc, VALUE* argv, VALUE obj ) | |
static VALUE send_query(VALUE obj, VALUE sql) | |
{ | |
MYSQL* m = GetHandler(obj); | |
+ | |
+ /*free_old_query(m);*/ | |
+ | |
+ if( GetMysqlStruct(obj)->query_sent == Qtrue ){ | |
+ rb_raise(eMysql, "Query out of sequence: Each call to Mysql#send_query requires a successive Mysql#get_result."); | |
+ } | |
Check_Type(sql, T_STRING); | |
if (GetMysqlStruct(obj)->connection == Qfalse) { | |
rb_raise(eMysql, "query: not connected"); | |
} | |
- if (mysql_send_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) | |
- mysql_raise(m); | |
- return Qnil; | |
+ if (mysql_send_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0) | |
+ mysql_raise(m); | |
+ GetMysqlStruct(obj)->query_sent = Qtrue; | |
+ return Qnil; | |
} | |
/* get_result */ | |
@@ -814,12 +823,13 @@ static VALUE get_result(VALUE obj) | |
if (GetMysqlStruct(obj)->connection == Qfalse) { | |
rb_raise(eMysql, "query: not connected"); | |
} | |
- if (mysql_read_query_result(m) != 0) | |
- mysql_raise(m); | |
+ if (mysql_read_query_result(m) != 0) | |
+ mysql_raise(m); | |
if (GetMysqlStruct(obj)->query_with_result == Qfalse) | |
return obj; | |
if (mysql_field_count(m) == 0) | |
return Qnil; | |
+ GetMysqlStruct(obj)->query_sent = Qfalse; | |
return store_result(obj); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment