From eeb7709897f077fd55f65b9844826136753efedb Mon Sep 17 00:00:00 2001 From: dolphinsboy Date: Mon, 13 Mar 2017 16:21:04 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=E4=BF=AE=E5=A4=8D-q=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E5=90=8E=E9=9D=A2=E8=B7=9F=E5=A4=9A=E4=B8=AASQL=E6=97=A0?= =?UTF-8?q?=E6=B3=95=E6=AD=A3=E7=A1=AE=E8=A7=A3=E6=9E=90=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82(issue:#7)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sqladvisor/main.cc | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sqladvisor/main.cc b/sqladvisor/main.cc index 36882a7..fee085c 100644 --- a/sqladvisor/main.cc +++ b/sqladvisor/main.cc @@ -22,6 +22,7 @@ #define CHUNK_SIZE 10000 #define DBNAME "information_schema" #define GROUT_NAME "sqladvisor" +//设置SQL语句的分隔符 #define SEP ';' #define EXPLAIN_ROWS 8 #define INDEX_NON_UNIQUE 1 @@ -31,6 +32,7 @@ #define INDEX_CARDINALITY 6 #define SHOW_ROWS 4 #define AFFECT_ROWS 0 +#define SQL_NUM_ONE_LINE 10 using std::set; using std::queue; @@ -1262,6 +1264,7 @@ static GOptionEntry entries[] = { { "defaults-file", 'f', 0, "sqls", 'q', 0, G_OPTION_ARG_STRING_ARRAY, &(options.query), "sqls", NULL }, { "verbose", 'v', 0, G_OPTION_ARG_INT, &(options.verbose), "1:output logs 0:output nothing", NULL }, { NULL } }; + int g_option_keyfile_parse(GKeyFile *keyfile, const char *ini_group_name, GOptionEntry *entries) { GError *gerr = NULL; @@ -1369,8 +1372,14 @@ int main(int argc, char **argv) { g_key_file_free(keyfile); sql_print_error("read config file failed:%s\n", error->message); } + }else if(options.query != NULL){ + gchar *delimiter = g_strnfill(1, SEP); + gchar ** query = g_strsplit(options.query[0], delimiter,SQL_NUM_ONE_LINE); + g_strfreev(options.query); + options.query = query; } + if (options.username == NULL || options.password == NULL || options.host == NULL || options.dbname == NULL || options.query[0] == NULL) { @@ -1378,6 +1387,7 @@ int main(int argc, char **argv) { return -1; } while ((query = options.query[i]) != NULL) { + sql_print_information("Query %d %s\n", i, query); sql_lex = sql_parser(query, options.dbname); if (sql_lex == NULL) {