From e0cefa327a2d308c925820958f994fd63edf7cb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Mon, 12 Jan 2015 09:06:41 +0000 Subject: [PATCH] Implemented SHOW CREATE TABLE for tables in other databases (issue #144) --- lib/Standard_ProxySQL_Admin.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/Standard_ProxySQL_Admin.cpp b/lib/Standard_ProxySQL_Admin.cpp index 9f4a82131..a433afc10 100644 --- a/lib/Standard_ProxySQL_Admin.cpp +++ b/lib/Standard_ProxySQL_Admin.cpp @@ -939,15 +939,26 @@ void admin_session_handler(MySQL_Session *sess, ProxySQL_Admin *pa, PtrSize_t *p } strA=(char *)"SHOW CREATE TABLE "; - strB=(char *)"SELECT name AS 'table' , sql AS 'Create Table' FROM sqlite_master WHERE type='table' AND name='%s'"; + strB=(char *)"SELECT name AS 'table' , sql AS 'Create Table' FROM %s.sqlite_master WHERE type='table' AND name='%s'"; strAl=strlen(strA); - if (strncasecmp("SHOW CREATE TABLE ", query_no_space, strAl)==0) { + if (strncasecmp("SHOW CREATE TABLE ", query_no_space, strAl)==0) { strBl=strlen(strB); - int tblnamelen=query_no_space_length-strAl; - int l=strBl+tblnamelen-2; + char *dbh=NULL; + char *tbh=NULL; + //int tblnamelen=query_no_space_length-strAl; + c_split_2(query_no_space+strAl,".",&dbh,&tbh); + + if (strlen(tbh)==0) { + free(tbh); + tbh=dbh; + dbh=strdup("main"); + } + int l=strBl+strlen(tbh)+strlen(dbh)-4; char *buff=(char *)l_alloc(l+1); - snprintf(buff,l+1,strB,query_no_space+strAl); + snprintf(buff,l+1,strB,dbh,tbh); buff[l]=0; + free(tbh); + free(dbh); l_free(query_length,query); query=buff; query_length=l+1;