MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:msvensson Date:April 11 2006 8:04pm
Subject:bk commit into 5.1 tree (msvensson:1.2325) BUG#17478
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of msvensson. When msvensson does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2325 06/04/11 22:04:08 msvensson@neptunus.(none) +1 -0
  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
    1.29 06/04/11 22:04:02 msvensson@neptunus.(none) +75 -75
    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  

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	msvensson
# Host:	neptunus.(none)
# Root:	/home/msvensson/mysql/mysql-5.1

--- 1.28/client/mysqlslap.c	2006-04-11 20:49:27 +02:00
+++ 1.29/client/mysqlslap.c	2006-04-11 22:04:02 +02:00
@@ -254,10 +254,6 @@
 
   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 @@
     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 @@
                              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 @@
   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 @@
       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 @@
 }
 
 
+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 @@
 
   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 @@
     }
   }
   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++;
 
Thread
bk commit into 5.1 tree (msvensson:1.2325) BUG#17478msvensson11 Apr