Bug#17478 mysqlslap not issuing any queries

 - Add more printouts it depending on verbose level
 - New common function 'run_query' to be used when executing a query
parent c8c80418
...@@ -254,10 +254,6 @@ int main(int argc, char **argv) ...@@ -254,10 +254,6 @@ int main(int argc, char **argv)
MY_INIT(argv[0]); MY_INIT(argv[0]);
/* Seed the random number generator if we will be using it. */
if (auto_generate_sql)
srandom((uint)time(NULL));
load_defaults("my",load_default_groups,&argc,&argv); load_defaults("my",load_default_groups,&argc,&argv);
defaults_argv=argv; defaults_argv=argv;
if (get_options(&argc,&argv)) if (get_options(&argc,&argv))
...@@ -267,6 +263,10 @@ int main(int argc, char **argv) ...@@ -267,6 +263,10 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
/* Seed the random number generator if we will be using it. */
if (auto_generate_sql)
srandom((uint)time(NULL));
/* globals? Yes, so we only have to run strlen once */ /* globals? Yes, so we only have to run strlen once */
delimiter_length= strlen(delimiter); delimiter_length= strlen(delimiter);
...@@ -300,7 +300,8 @@ int main(int argc, char **argv) ...@@ -300,7 +300,8 @@ int main(int argc, char **argv)
NULL, opt_mysql_port, NULL, opt_mysql_port,
opt_mysql_unix_port, client_flag))) opt_mysql_unix_port, client_flag)))
{ {
fprintf(stderr,"%s: %s\n",my_progname,mysql_error(&mysql)); fprintf(stderr,"%s: Error when connecting to server: %s\n",
my_progname,mysql_error(&mysql));
free_defaults(defaults_argv); free_defaults(defaults_argv);
my_end(0); my_end(0);
exit(1); exit(1);
...@@ -752,8 +753,13 @@ get_options(int *argc,char ***argv) ...@@ -752,8 +753,13 @@ get_options(int *argc,char ***argv)
if (!user) if (!user)
user= (char *)"root"; user= (char *)"root";
if (create_string || auto_generate_sql ) if (create_string || auto_generate_sql)
{
if (verbose >= 1)
fprintf(stderr,
"%s: Turning off preserve-schema!\n");
opt_preserve= FALSE; opt_preserve= FALSE;
}
if (auto_generate_sql && (create_string || user_supplied_query)) if (auto_generate_sql && (create_string || user_supplied_query))
{ {
...@@ -800,6 +806,14 @@ get_options(int *argc,char ***argv) ...@@ -800,6 +806,14 @@ get_options(int *argc,char ***argv)
DBUG_PRINT("info", ("auto-generated insert is %s", query_statements->string)); DBUG_PRINT("info", ("auto-generated insert is %s", query_statements->string));
query_statements->next= build_query_string(); query_statements->next= build_query_string();
DBUG_PRINT("info", ("auto-generated is %s", query_statements->next->string)); DBUG_PRINT("info", ("auto-generated is %s", query_statements->next->string));
if (verbose >= 1)
{
fprintf(stderr, "auto-generated insert is:\n");
fprintf(stderr, "%s\n", query_statements->string);
fprintf(stderr, "auto-generated is:\n");
fprintf(stderr, "%s\n", query_statements->next->string);
}
} }
else else
{ {
...@@ -868,30 +882,39 @@ get_options(int *argc,char ***argv) ...@@ -868,30 +882,39 @@ get_options(int *argc,char ***argv)
} }
static int run_query(MYSQL *mysql, const char *query, int len)
{
if (opt_only_print)
{
printf("%.*s;\n", len, query);
return 0;
}
if (verbose >= 2)
printf("%.*s;\n", len, query);
return mysql_real_query(mysql, query, len);
}
static int static int
create_schema(MYSQL *mysql, const char *db, statement *stmt, create_schema(MYSQL *mysql, const char *db, statement *stmt,
statement *engine_stmt) statement *engine_stmt)
{ {
char query[HUGE_STRING_LENGTH]; char query[HUGE_STRING_LENGTH];
statement *ptr; statement *ptr;
int len;
DBUG_ENTER("create_schema"); DBUG_ENTER("create_schema");
snprintf(query, HUGE_STRING_LENGTH, "CREATE SCHEMA `%s`", db); len= snprintf(query, HUGE_STRING_LENGTH, "CREATE SCHEMA `%s`", db);
DBUG_PRINT("info", ("query %s", query)); DBUG_PRINT("info", ("query %s", query));
if (opt_only_print)
{ if (run_query(mysql, query, len))
printf("%s;\n", query);
}
else
{
if (mysql_query(mysql, query))
{ {
fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db, fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
mysql_error(mysql)); mysql_error(mysql));
exit(1); exit(1);
} }
}
if (opt_only_print) if (opt_only_print)
{ {
...@@ -899,6 +922,8 @@ create_schema(MYSQL *mysql, const char *db, statement *stmt, ...@@ -899,6 +922,8 @@ create_schema(MYSQL *mysql, const char *db, statement *stmt,
} }
else else
{ {
if (verbose >= 2)
printf("%s;\n", query);
if (mysql_select_db(mysql, db)) if (mysql_select_db(mysql, db))
{ {
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db, fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
...@@ -909,64 +934,45 @@ create_schema(MYSQL *mysql, const char *db, statement *stmt, ...@@ -909,64 +934,45 @@ create_schema(MYSQL *mysql, const char *db, statement *stmt,
if (engine_stmt) if (engine_stmt)
{ {
snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`", len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
engine_stmt->string); engine_stmt->string);
if (opt_only_print) if (run_query(mysql, query, len))
{
printf("%s;\n", query);
}
else
{
if (mysql_query(mysql, query))
{ {
fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname, fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
mysql_error(mysql)); mysql_error(mysql));
exit(1); exit(1);
} }
} }
}
for (ptr= stmt; ptr && ptr->length; ptr= ptr->next) for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
{ {
if (opt_only_print) if (run_query(mysql, ptr->string, ptr->length))
{
printf("%.*s;\n", (uint)ptr->length, ptr->string);
}
else
{
if (mysql_real_query(mysql, ptr->string, ptr->length))
{ {
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n", fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql)); my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
exit(1); exit(1);
} }
} }
}
DBUG_RETURN(0); DBUG_RETURN(0);
} }
static int static int
drop_schema(MYSQL *mysql, const char *db) drop_schema(MYSQL *mysql, const char *db)
{ {
char query[HUGE_STRING_LENGTH]; char query[HUGE_STRING_LENGTH];
int len;
DBUG_ENTER("drop_schema"); DBUG_ENTER("drop_schema");
snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db); len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
if (opt_only_print)
{ if (run_query(mysql, query, len))
printf("%s;\n", query);
}
else
{
if (mysql_query(mysql, query))
{ {
fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n", fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
my_progname, db, mysql_error(mysql)); my_progname, db, mysql_error(mysql));
exit(1); exit(1);
} }
}
DBUG_RETURN(0); DBUG_RETURN(0);
} }
...@@ -1143,19 +1149,14 @@ run_task(thread_context *con) ...@@ -1143,19 +1149,14 @@ run_task(thread_context *con)
} }
} }
DBUG_PRINT("info", ("connected.")); DBUG_PRINT("info", ("connected."));
if (verbose >= 3)
fprintf(stderr, "connected!\n");
queries= 0; queries= 0;
limit_not_met: limit_not_met:
for (ptr= con->stmt; ptr && ptr->length; ptr= ptr->next) for (ptr= con->stmt; ptr && ptr->length; ptr= ptr->next)
{ {
if (opt_only_print) if (run_query(mysql, ptr->string, ptr->length))
{
printf("%.*s;\n", (uint)ptr->length, ptr->string);
}
else
{
if (mysql_real_query(mysql, ptr->string, ptr->length))
{ {
fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n", fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql)); my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
...@@ -1168,7 +1169,6 @@ limit_not_met: ...@@ -1168,7 +1169,6 @@ limit_not_met:
counter++; counter++;
mysql_free_result(result); mysql_free_result(result);
} }
}
queries++; queries++;
if (con->limit && queries == con->limit) if (con->limit && queries == con->limit)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment