Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix:修复-q参数后面跟多个SQL无法正确解析的问题。(issue:#7) #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions sqladvisor/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1369,15 +1372,22 @@ 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) {
mysqld_cleanup();
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) {
Expand Down