Created
October 18, 2008 05:42
-
-
Save rdp/17607 to your computer and use it in GitHub Desktop.
This file contains 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
diff --git a/ext/mysql.c b/ext/mysql.c | |
index b14cae1..cead7c3 100644 | |
--- a/ext/mysql.c | |
+++ b/ext/mysql.c | |
@@ -893,6 +893,30 @@ static VALUE simulate_disconnect( VALUE obj ) | |
return Qnil; | |
} | |
+static int begins_with_insensitive(char *candidate, char *check_for_in_upper_case) | |
+{ | |
+ /* skip opening whitespace --tab is 11, newline is 12, cr is 15, space 32 */ | |
+ char *where_at = candidate; | |
+ while( ((*where_at >= 11 && *where_at <= 15) || (*where_at == 32)) && (where_at != 0)) | |
+ where_at++; | |
+ | |
+ char *where_at_in_test = check_for_in_upper_case; | |
+ while(*where_at_in_test) | |
+ { | |
+ int candidate_char = *where_at; | |
+ if(candidate_char == 0) | |
+ return 0; /* end of line */ | |
+ if(candidate_char >= 97 && candidate_char < 122) /* then it's upper case --lower case ify it */ | |
+ candidate_char -= 32; | |
+ if(candidate_char != *where_at_in_test) | |
+ return 0; | |
+ where_at_in_test++; | |
+ where_at++; | |
+ | |
+ } | |
+ return 1; | |
+} | |
+ | |
/* send_query(sql) */ | |
static VALUE send_query(VALUE obj, VALUE sql) | |
{ | |
@@ -905,12 +929,24 @@ static VALUE send_query(VALUE obj, VALUE sql) | |
} | |
validate_async_query(obj); | |
- | |
+ | |
if (mysql_send_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0){ | |
mysql_raise(m); | |
} | |
- | |
- async_in_progress_set( obj, Qtrue ); | |
+ /* what about http://dev.mysql.com/doc/refman/5.0/en/implicit-commit.html and more? */ | |
+ if( | |
+ begins_with_insensitive(RSTRING_PTR(sql), "SET ") || | |
+ begins_with_insensitive(RSTRING_PTR(sql), "BEGIN") || | |
+ begins_with_insensitive(RSTRING_PTR(sql), "START TRANSACTION") || | |
+ begins_with_insensitive(RSTRING_PTR(sql), "ROLLBACK") || | |
+ begins_with_insensitive(RSTRING_PTR(sql), "LOCK ") || | |
+ begins_with_insensitive(RSTRING_PTR(sql), "UNLOCK ") || | |
+ begins_with_insensitive(RSTRING_PTR(sql), "USE ") || | |
+ begins_with_insensitive(RSTRING_PTR(sql), "COMMIT")) | |
+ { | |
+ /* do not mark an async in progress --they used send_query for something that doesn't necessarily have a result--is this allowable? */ | |
+ } else | |
+ async_in_progress_set( obj, Qtrue ); | |
return Qnil; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment