diff --git a/include/MySQL_PreparedStatement.h b/include/MySQL_PreparedStatement.h index 960ebb9c1..a1f7c7657 100644 --- a/include/MySQL_PreparedStatement.h +++ b/include/MySQL_PreparedStatement.h @@ -62,6 +62,7 @@ class MySQL_STMT_Global_info { int timeout; int delay; } properties; + bool is_select_NOT_for_update; MYSQL_BIND **params; // seems unused (?) MySQL_STMT_Global_info(uint32_t id, unsigned int h, char *u, char *s, char *q, unsigned int ql, MYSQL_STMT *stmt, uint64_t _h); ~MySQL_STMT_Global_info(); diff --git a/lib/MySQL_PreparedStatement.cpp b/lib/MySQL_PreparedStatement.cpp index 6aecca908..0538bf01b 100644 --- a/lib/MySQL_PreparedStatement.cpp +++ b/lib/MySQL_PreparedStatement.cpp @@ -322,6 +322,22 @@ MySQL_STMT_Global_info::MySQL_STMT_Global_info(uint32_t id, unsigned int h, char compute_hash(); } + is_select_NOT_for_update=false; + { // see bug #899 . Most of the code is borrowed from Query_Info::is_select_NOT_for_update() + if (ql>=7) { + if (strncasecmp(q,(char *)"SELECT ",7)==0) { // is a SELECT + is_select_NOT_for_update=true; + if (ql>=17) { + char *p=(char *)q; + p+=ql-11; + if (strncasecmp(p," FOR UPDATE",11)==0) { // is a SELECT FOR UPDATE + is_select_NOT_for_update=false; + } + } + } + } + } + // set default properties: properties.cache_ttl=-1; properties.timeout=-1; diff --git a/lib/MySQL_Session.cpp b/lib/MySQL_Session.cpp index 89f00f9ee..e75d2a8c0 100644 --- a/lib/MySQL_Session.cpp +++ b/lib/MySQL_Session.cpp @@ -187,6 +187,9 @@ char * Query_Info::get_digest_text() { } bool Query_Info::is_select_NOT_for_update() { + if (stmt_info) { // we are processing a prepared statement. We already have the information + return stmt_info->is_select_NOT_for_update; + } // to avoid an expensive strlen() on the digest_text, we consider only the real query if (QueryPointer==NULL) { return false;