Skip to content

Commit

Permalink
Handle backquote in USE command #857
Browse files Browse the repository at this point in the history
Ported from 1.3.2

Conflicts:
	lib/MySQL_Session.cpp
  • Loading branch information
renecannao committed Dec 29, 2016
1 parent ee5158a commit ce61341
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/MySQL_Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2950,7 +2950,17 @@ void MySQL_Session::handler___status_WAITING_CLIENT_DATA___STATE_SLEEP___MYSQL_C
proxy_debug(PROXY_DEBUG_MYSQL_COM, 5, "Got COM_QUERY with USE dbname\n");
if (admin==false) {
__sync_fetch_and_add(&MyHGM->status.frontend_use_db, 1);
client_myds->myconn->userinfo->set_schemaname((char *)pkt->ptr+sizeof(mysql_hdr)+5,pkt->size-sizeof(mysql_hdr)-5);
char *schemaname=strndup((char *)pkt->ptr+sizeof(mysql_hdr)+5,pkt->size-sizeof(mysql_hdr)-5);
char *schemanameptr=schemaname;
//remove leading spaces
while(isspace((unsigned char)*schemanameptr)) schemanameptr++;
// handle cases like "USE `schemaname`
if(schemanameptr[0]=='`' && schemanameptr[strlen(schemanameptr)-1]=='`') {
schemanameptr[strlen(schemanameptr)-1]='\0';
schemanameptr++;
}
client_myds->myconn->userinfo->set_schemaname(schemanameptr,strlen(schemanameptr));
free(schemaname);
l_free(pkt->size,pkt->ptr);
client_myds->setDSS_STATE_QUERY_SENT_NET();
unsigned int nTrx=NumActiveTransactions();
Expand Down

0 comments on commit ce61341

Please sign in to comment.