Skip to content

Commit

Permalink
Possible fix for issue #1062
Browse files Browse the repository at this point in the history
Forward to backend SET commands with prepared statements
  • Loading branch information
renecannao committed Jul 19, 2017
1 parent 1ba8c64 commit 02432b2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions include/MySQL_Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class MySQL_Protocol {

// prepared statements
bool generate_STMT_PREPARE_RESPONSE(uint8_t sequence_id, MySQL_STMT_Global_info *stmt_info, uint32_t _stmt_id=0);
void generate_STMT_PREPARE_RESPONSE_OK(uint8_t sequence_id, uint32_t stmt_id);

stmt_execute_metadata_t * get_binds_from_pkt(void *ptr, unsigned int size, MySQL_STMT_Global_info *stmt_info, stmt_execute_metadata_t **stmt_meta);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL_PreparedStatement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void MySQL_STMTs_local::insert(uint32_t global_statement_id, MYSQL_STMT *stmt) {
MySQL_STMT_Manager::MySQL_STMT_Manager() {
spinlock_rwlock_init(&rwlock);
next_statement_id =
1; // we initialize this as 1 because we 0 is not allowed
33; // we initialize this as 33, leaving the first 32 reserved for special prepared statements (future use)
}

MySQL_STMT_Manager::~MySQL_STMT_Manager() {
Expand Down
2 changes: 1 addition & 1 deletion lib/MySQL_Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ bool MySQL_Protocol::generate_STMT_PREPARE_RESPONSE(uint8_t sequence_id, MySQL_S
hdr.pkt_length=12;
memcpy(okpack,&hdr,sizeof(mysql_hdr)); // copy header
okpack[4]=0;
okpack[13]=0;
okpack[15]=0;
if (_stmt_id) {
memcpy(okpack+5,&_stmt_id,sizeof(uint32_t));
} else {
Expand Down
61 changes: 34 additions & 27 deletions lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3266,6 +3266,7 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
}

bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_COM_QUERY_qpo(PtrSize_t *pkt, bool prepared) {
unsigned char command_type=*((unsigned char *)pkt->ptr+sizeof(mysql_hdr));
if (qpo->new_query) {
// the query was rewritten
l_free(pkt->size,pkt->ptr); // free old pkt
Expand Down Expand Up @@ -3342,16 +3343,18 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
delete opt2;
if (rc && ( i==0 || i==1) ) {
//fprintf(stderr,"sql_log_bin=%d\n", i);
client_myds->DSS=STATE_QUERY_SENT_NET;
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
if (autocommit) setStatus += SERVER_STATUS_AUTOCOMMIT;
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,setStatus,0,NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
l_free(pkt->size,pkt->ptr);
RequestEnd(NULL);
client_myds->myconn->options.sql_log_bin=i;
return true;
if (command_type == _MYSQL_COM_QUERY) {
client_myds->DSS=STATE_QUERY_SENT_NET;
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
if (autocommit) setStatus= SERVER_STATUS_AUTOCOMMIT;
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,setStatus,0,NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
l_free(pkt->size,pkt->ptr);
RequestEnd(NULL);
return true;
}
} else {
proxy_error("Unable to parse query. If correct, report it as a bug: %s\n", nq.c_str());
return false;
Expand All @@ -3369,14 +3372,6 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
delete opt2;
if (rc) {
//fprintf(stderr,"sql_mode='%s'\n", s.c_str());
client_myds->DSS=STATE_QUERY_SENT_NET;
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
if (autocommit) setStatus += SERVER_STATUS_AUTOCOMMIT;
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,setStatus,0,NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
l_free(pkt->size,pkt->ptr);
RequestEnd(NULL);
uint32_t sql_mode_int=SpookyHash::Hash32(s.c_str(),s.length(),10);
if (client_myds->myconn->options.sql_mode_int != sql_mode_int) {
//fprintf(stderr,"sql_mode_int='%u'\n", sql_mode_int);
Expand All @@ -3386,7 +3381,17 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
}
client_myds->myconn->options.sql_mode=strdup(s.c_str());
}
return true;
if (command_type == _MYSQL_COM_QUERY) {
client_myds->DSS=STATE_QUERY_SENT_NET;
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
if (autocommit) setStatus= SERVER_STATUS_AUTOCOMMIT;
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,setStatus,0,NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
l_free(pkt->size,pkt->ptr);
RequestEnd(NULL);
return true;
}
} else {
proxy_error("Unable to parse query. If correct, report it as a bug: %s\n", nq.c_str());
return false;
Expand All @@ -3404,14 +3409,6 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
delete opt2;
if (rc) {
//fprintf(stderr,"time_zone='%s'\n", s.c_str());
client_myds->DSS=STATE_QUERY_SENT_NET;
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
if (autocommit) setStatus += SERVER_STATUS_AUTOCOMMIT;
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,setStatus,0,NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
l_free(pkt->size,pkt->ptr);
RequestEnd(NULL);
uint32_t time_zone_int=SpookyHash::Hash32(s.c_str(),s.length(),10);
if (client_myds->myconn->options.time_zone_int != time_zone_int) {
//fprintf(stderr,"time_zone_int='%u'\n", time_zone_int);
Expand All @@ -3421,7 +3418,17 @@ bool MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
}
client_myds->myconn->options.time_zone=strdup(s.c_str());
}
return true;
if (command_type == _MYSQL_COM_QUERY) {
client_myds->DSS=STATE_QUERY_SENT_NET;
uint16_t setStatus = (nTrx ? SERVER_STATUS_IN_TRANS : 0 );
if (autocommit) setStatus += SERVER_STATUS_AUTOCOMMIT;
client_myds->myprot.generate_pkt_OK(true,NULL,NULL,1,0,0,setStatus,0,NULL);
client_myds->DSS=STATE_SLEEP;
status=WAITING_CLIENT_DATA;
l_free(pkt->size,pkt->ptr);
RequestEnd(NULL);
return true;
}
} else {
proxy_error("Unable to parse query. If correct, report it as a bug: %s\n", nq.c_str());
return false;
Expand Down

0 comments on commit 02432b2

Please sign in to comment.