summaryrefslogtreecommitdiff
path: root/client/mysqlslap.c
diff options
context:
space:
mode:
authorunknown <msvensson@neptunus.(none)>2006-04-11 22:04:08 +0200
committerunknown <msvensson@neptunus.(none)>2006-04-11 22:04:08 +0200
commitfaac43dfb91dd90fb41dcb58b09511c534dab092 (patch)
tree47bf1972fe26fea35ec4d104d274f90355b6ec54 /client/mysqlslap.c
parent6c09775a043f934bb9a9a9a3538a0a4fbc579d97 (diff)
downloadmariadb-git-faac43dfb91dd90fb41dcb58b09511c534dab092.tar.gz
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 client/mysqlslap.c: Seed random number generator after options handling Make common function 'run_query' to take care of "opt_print_only" and "opt_verbose" level Better error message when failing to connect to MySQL Server Message when turning off "preserve-schema" Print auto generated statmements Print queries if verbose >= 2 Print "connected" if verbose >= 3
Diffstat (limited to 'client/mysqlslap.c')
-rw-r--r--client/mysqlslap.c150
1 files changed, 75 insertions, 75 deletions
diff --git a/client/mysqlslap.c b/client/mysqlslap.c
index 0f91d28cd0b..b016d5f3538 100644
--- a/client/mysqlslap.c
+++ b/client/mysqlslap.c
@@ -254,10 +254,6 @@ int main(int argc, char **argv)
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);
defaults_argv=argv;
if (get_options(&argc,&argv))
@@ -267,6 +263,10 @@ int main(int argc, char **argv)
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 */
delimiter_length= strlen(delimiter);
@@ -300,7 +300,8 @@ int main(int argc, char **argv)
NULL, opt_mysql_port,
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);
my_end(0);
exit(1);
@@ -752,8 +753,13 @@ get_options(int *argc,char ***argv)
if (!user)
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;
+ }
if (auto_generate_sql && (create_string || user_supplied_query))
{
@@ -800,6 +806,14 @@ get_options(int *argc,char ***argv)
DBUG_PRINT("info", ("auto-generated insert is %s", query_statements->string));
query_statements->next= build_query_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
{
@@ -868,37 +882,48 @@ 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
create_schema(MYSQL *mysql, const char *db, statement *stmt,
statement *engine_stmt)
{
char query[HUGE_STRING_LENGTH];
statement *ptr;
-
+ int len;
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));
- if (opt_only_print)
- {
- printf("%s;\n", query);
- }
- else
+
+ if (run_query(mysql, query, len))
{
- if (mysql_query(mysql, query))
- {
- fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
- mysql_error(mysql));
- exit(1);
- }
+ fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
+ mysql_error(mysql));
+ exit(1);
}
- if (opt_only_print)
+ if (opt_only_print)
{
printf("use %s;\n", db);
}
else
{
+ if (verbose >= 2)
+ printf("%s;\n", query);
if (mysql_select_db(mysql, db))
{
fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
@@ -909,65 +934,46 @@ create_schema(MYSQL *mysql, const char *db, statement *stmt,
if (engine_stmt)
{
- snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
- engine_stmt->string);
- if (opt_only_print)
+ len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
+ engine_stmt->string);
+ 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,
- mysql_error(mysql));
- exit(1);
- }
+ fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
+ mysql_error(mysql));
+ exit(1);
}
}
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",
- my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
- exit(1);
- }
+ fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
+ my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
+ exit(1);
}
}
DBUG_RETURN(0);
}
-
static int
drop_schema(MYSQL *mysql, const char *db)
{
char query[HUGE_STRING_LENGTH];
-
+ int len;
DBUG_ENTER("drop_schema");
- snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
- if (opt_only_print)
- {
- printf("%s;\n", query);
- }
- else
+ len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
+
+ if (run_query(mysql, query, len))
{
- if (mysql_query(mysql, query))
- {
- fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
- my_progname, db, mysql_error(mysql));
- exit(1);
- }
+ fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
+ my_progname, db, mysql_error(mysql));
+ exit(1);
}
+
+
DBUG_RETURN(0);
}
@@ -1143,31 +1149,25 @@ run_task(thread_context *con)
}
}
DBUG_PRINT("info", ("connected."));
-
+ if (verbose >= 3)
+ fprintf(stderr, "connected!\n");
queries= 0;
limit_not_met:
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);
+ fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
+ my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
+ goto end;
}
- else
+ if (mysql_field_count(mysql))
{
- if (mysql_real_query(mysql, ptr->string, ptr->length))
- {
- fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
- my_progname, (uint)ptr->length, ptr->string, mysql_error(mysql));
- goto end;
- }
- if (mysql_field_count(mysql))
- {
- result= mysql_store_result(mysql);
- while ((row = mysql_fetch_row(result)))
- counter++;
- mysql_free_result(result);
- }
+ result= mysql_store_result(mysql);
+ while ((row = mysql_fetch_row(result)))
+ counter++;
+ mysql_free_result(result);
}
queries++;