~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzleslap.cc

  • Committer: Brian Aker
  • Date: 2009-12-29 01:38:38 UTC
  • mfrom: (1251.1.1 drizzle)
  • Revision ID: brian@gaz-20091229013838-03kb2z5xbqw03ddt
Merge of Diego fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 Drizzle Open Source Development Team
2
 
 
3
 
   This program is free software; you can redistribute it and/or modify
4
 
   it under the terms of the GNU General Public License as published by
5
 
   the Free Software Foundation; version 2 of the License.
6
 
 
7
 
   This program is distributed in the hope that it will be useful,
8
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 
   GNU General Public License for more details.
11
 
 
12
 
   You should have received a copy of the GNU General Public License
13
 
   along with this program; if not, write to the Free Software
14
 
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
 
 
16
 
   original idea: Brian Aker via playing with ab for too many years
17
 
   coded by: Patrick Galbraith
18
 
*/
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 MySQL
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
19
20
 
20
21
 
21
22
/*
26
27
 
27
28
  Drizzle slap runs three stages:
28
29
  1) Create schema,table, and optionally any SP or data you want to beign
29
 
     the test with. (single client)
 
30
  the test with. (single client)
30
31
  2) Load test (many clients)
31
32
  3) Cleanup (disconnection, drop table if specified, single client)
32
33
 
35
36
  Supply your own create and query SQL statements, with 50 clients
36
37
  querying (200 selects for each):
37
38
 
38
 
    drizzleslap --delimiter=";" \
39
 
              --create="CREATE TABLE A (a int);INSERT INTO A VALUES (23)" \
40
 
              --query="SELECT * FROM A" --concurrency=50 --iterations=200
 
39
  drizzleslap --delimiter=";" \
 
40
  --create="CREATE TABLE A (a int);INSERT INTO A VALUES (23)" \
 
41
  --query="SELECT * FROM A" --concurrency=50 --iterations=200
41
42
 
42
43
  Let the program build the query SQL statement with a table of two int
43
44
  columns, three varchar columns, five clients querying (20 times each),
44
45
  don't create the table or insert the data (using the previous test's
45
46
  schema and data):
46
47
 
47
 
    drizzleslap --concurrency=5 --iterations=20 \
48
 
              --number-int-cols=2 --number-char-cols=3 \
49
 
              --auto-generate-sql
 
48
  drizzleslap --concurrency=5 --iterations=20 \
 
49
  --number-int-cols=2 --number-char-cols=3 \
 
50
  --auto-generate-sql
50
51
 
51
52
  Tell the program to load the create, insert and query SQL statements from
52
53
  the specified files, where the create.sql file has multiple table creation
55
56
  load statements, and then run all the queries in the query file
56
57
  with five clients (five times each):
57
58
 
58
 
    drizzleslap --concurrency=5 \
59
 
              --iterations=5 --query=query.sql --create=create.sql \
60
 
              --delimiter=";"
 
59
  drizzleslap --concurrency=5 \
 
60
  --iterations=5 --query=query.sql --create=create.sql \
 
61
  --delimiter=";"
61
62
 
62
 
TODO:
 
63
  TODO:
63
64
  Add language for better tests
64
65
  String length for files and those put on the command line are not
65
 
    setup to handle binary data.
 
66
  setup to handle binary data.
66
67
  More stats
67
68
  Break up tests and run them on multiple hosts at once.
68
69
  Allow output to be fed into a database directly.
80
81
#include <stdarg.h>
81
82
#include <sys/types.h>
82
83
#include <sys/wait.h>
 
84
#ifdef HAVE_SYS_STAT_H
 
85
# include <sys/stat.h>
 
86
#endif
 
87
#include <fcntl.h>
 
88
#include <math.h>
83
89
#include <ctype.h>
 
90
#include <cassert>
 
91
#include <cstdlib>
 
92
#include <string>
 
93
 
 
94
#include <pthread.h>
 
95
 
 
96
/* Added this for string translation. */
 
97
#include <drizzled/gettext.h>
 
98
 
 
99
using namespace std;
84
100
 
85
101
#ifdef HAVE_SMEM
86
102
static char *shared_memory_base_name=0;
87
103
#endif
88
104
 
 
105
extern "C"
 
106
bool get_one_option(int optid, const struct my_option *, char *argument);
 
107
 
89
108
/* Global Thread counter */
90
 
uint thread_counter;
 
109
uint32_t thread_counter;
91
110
pthread_mutex_t counter_mutex;
92
111
pthread_cond_t count_threshhold;
93
 
uint master_wakeup;
 
112
uint32_t master_wakeup;
94
113
pthread_mutex_t sleeper_mutex;
95
114
pthread_cond_t sleep_threshhold;
96
115
 
102
121
static char **defaults_argv;
103
122
 
104
123
char **primary_keys;
105
 
unsigned long long primary_keys_number_of;
 
124
/* This gets passed to malloc, so lets set it to an arch-dependant size */
 
125
size_t primary_keys_number_of;
106
126
 
107
127
static char *host= NULL, *opt_password= NULL, *user= NULL,
108
 
            *user_supplied_query= NULL,
109
 
            *user_supplied_pre_statements= NULL,
110
 
            *user_supplied_post_statements= NULL,
111
 
            *default_engine= NULL,
112
 
            *pre_system= NULL,
113
 
            *post_system= NULL,
114
 
            *opt_drizzle_unix_port= NULL;
 
128
  *user_supplied_query= NULL,
 
129
  *user_supplied_pre_statements= NULL,
 
130
  *user_supplied_post_statements= NULL,
 
131
  *default_engine= NULL,
 
132
  *pre_system= NULL,
 
133
  *post_system= NULL,
 
134
  *opt_drizzle_unix_port= NULL;
115
135
 
116
136
const char *delimiter= "\n";
117
137
 
118
 
const char *create_schema_string= "mysqlslap";
 
138
const char *create_schema_string= "drizzleslap";
119
139
 
120
140
static bool opt_preserve= true;
121
 
static bool debug_info_flag= 0, debug_check_flag= 0;
122
141
static bool opt_only_print= false;
123
142
static bool opt_burnin= false;
124
143
static bool opt_ignore_sql_errors= false;
125
 
static bool opt_compress= false, tty_password= false,
126
 
               opt_silent= false,
127
 
               auto_generate_sql_autoincrement= false,
128
 
               auto_generate_sql_guid_primary= false,
129
 
               auto_generate_sql= false;
 
144
static bool tty_password= false,
 
145
  opt_silent= false,
 
146
  auto_generate_sql_autoincrement= false,
 
147
  auto_generate_sql_guid_primary= false,
 
148
  auto_generate_sql= false;
130
149
const char *opt_auto_generate_sql_type= "mixed";
131
150
 
132
 
static unsigned long connect_flags= CLIENT_MULTI_RESULTS |
133
 
                                    CLIENT_MULTI_STATEMENTS;
134
 
 
135
151
static int verbose, delimiter_length;
136
 
static uint commit_rate;
137
 
static uint detach_rate;
138
 
static uint opt_timer_length;
139
 
static uint opt_delayed_start;
 
152
static uint32_t commit_rate;
 
153
static uint32_t detach_rate;
 
154
static uint32_t opt_timer_length;
 
155
static uint32_t opt_delayed_start;
140
156
const char *num_int_cols_opt;
141
157
const char *num_char_cols_opt;
142
158
const char *num_blob_cols_opt;
154
170
static unsigned int num_int_cols_index= 0;
155
171
static unsigned int num_char_cols_index= 0;
156
172
static unsigned int iterations;
157
 
static uint my_end_arg= 0;
158
 
static char *default_charset= (char*) DRIZZLE_DEFAULT_CHARSET_NAME;
159
173
static uint64_t actual_queries= 0;
160
174
static uint64_t auto_actual_queries;
161
175
static uint64_t auto_generate_sql_unique_write_number;
165
179
static uint64_t auto_generate_sql_number;
166
180
const char *concurrency_str= NULL;
167
181
static char *create_string;
168
 
uint *concurrency;
 
182
uint32_t *concurrency;
169
183
 
170
 
const char *default_dbug_option="d:t:o,/tmp/mysqlslap.trace";
 
184
const char *default_dbug_option= "d:t:o,/tmp/drizzleslap.trace";
171
185
const char *opt_csv_str;
172
 
File csv_file;
173
 
 
174
 
static uint opt_protocol= DRIZZLE_PROTOCOL_TCP;
 
186
int csv_file;
175
187
 
176
188
static int get_options(int *argc,char ***argv);
177
 
static uint opt_drizzle_port= 0;
 
189
static uint32_t opt_drizzle_port= 0;
178
190
 
179
 
static const char *load_default_groups[]= { "mysqlslap","client",0 };
 
191
static const char *load_default_groups[]= { "drizzleslap","client",0 };
180
192
 
181
193
/* Types */
182
194
typedef enum {
214
226
 
215
227
struct stats {
216
228
  long int timing;
217
 
  uint users;
218
 
  uint real_users;
219
 
  unsigned long long rows;
 
229
  uint32_t users;
 
230
  uint32_t real_users;
 
231
  uint64_t rows;
220
232
  long int create_timing;
221
 
  unsigned long long create_count;
 
233
  uint64_t create_count;
222
234
};
223
235
 
224
236
typedef struct thread_context thread_context;
235
247
  long int avg_timing;
236
248
  long int max_timing;
237
249
  long int min_timing;
238
 
  uint users;
239
 
  uint real_users;
240
 
  unsigned long long avg_rows;
 
250
  uint32_t users;
 
251
  uint32_t real_users;
 
252
  uint64_t avg_rows;
241
253
  long int sum_of_time;
242
254
  long int std_dev;
243
255
  /* These are just for create time stats */
244
256
  long int create_avg_timing;
245
257
  long int create_max_timing;
246
258
  long int create_min_timing;
247
 
  unsigned long long create_count;
 
259
  uint64_t create_count;
248
260
  /* The following are not used yet */
249
 
  unsigned long long max_rows;
250
 
  unsigned long long min_rows;
 
261
  uint64_t max_rows;
 
262
  uint64_t min_rows;
251
263
};
252
264
 
253
265
static option_string *engine_options= NULL;
264
276
void print_conclusions(conclusions *con);
265
277
void print_conclusions_csv(conclusions *con);
266
278
void generate_stats(conclusions *con, option_string *eng, stats *sptr);
267
 
uint parse_comma(const char *string, uint **range);
268
 
uint parse_delimiter(const char *script, statement **stmt, char delm);
269
 
uint parse_option(const char *origin, option_string **stmt, char delm);
270
 
static int drop_schema(DRIZZLE *drizzle, const char *db);
271
 
uint get_random_string(char *buf, size_t size);
 
279
uint32_t parse_comma(const char *string, uint32_t **range);
 
280
uint32_t parse_delimiter(const char *script, statement **stmt, char delm);
 
281
uint32_t parse_option(const char *origin, option_string **stmt, char delm);
 
282
static int drop_schema(drizzle_con_st *con, const char *db);
 
283
uint32_t get_random_string(char *buf, size_t size);
272
284
static statement *build_table_string(void);
273
285
static statement *build_insert_string(void);
274
286
static statement *build_update_string(void);
275
287
static statement * build_select_string(bool key);
276
 
static int generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt);
 
288
static int generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt);
277
289
static int drop_primary_key_list(void);
278
 
static int create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
 
290
static int create_schema(drizzle_con_st *con, const char *db, statement *stmt,
279
291
                         option_string *engine_stmt, stats *sptr);
280
 
static int run_scheduler(stats *sptr, statement **stmts, uint concur,
 
292
static int run_scheduler(stats *sptr, statement **stmts, uint32_t concur,
281
293
                         uint64_t limit);
282
 
pthread_handler_t run_task(void *p);
283
 
pthread_handler_t timer_thread(void *p);
 
294
extern "C" pthread_handler_t run_task(void *p);
 
295
extern "C" pthread_handler_t timer_thread(void *p);
284
296
void statement_cleanup(statement *stmt);
285
297
void option_cleanup(option_string *stmt);
286
 
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr);
287
 
static int run_statements(DRIZZLE *drizzle, statement *stmt);
288
 
void slap_connect(DRIZZLE *drizzle, bool connect_to_schema);
289
 
void slap_close(DRIZZLE *drizzle);
290
 
static int run_query(DRIZZLE *drizzle, const char *query, int len);
 
298
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr);
 
299
static int run_statements(drizzle_con_st *con, statement *stmt);
 
300
void slap_connect(drizzle_con_st *con, bool connect_to_schema);
 
301
void slap_close(drizzle_con_st *con);
 
302
static int run_query(drizzle_con_st *con, drizzle_result_st *result, const char *query, int len);
291
303
void standard_deviation (conclusions *con, stats *sptr);
292
304
 
293
305
static const char ALPHANUMERICS[]=
294
 
  "0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
 
306
"0123456789ABCDEFGHIJKLMNOPQRSTWXYZabcdefghijklmnopqrstuvwxyz";
295
307
 
296
308
#define ALPHANUMERICS_SIZE (sizeof(ALPHANUMERICS)-1)
297
309
 
298
310
 
299
311
static long int timedif(struct timeval a, struct timeval b)
300
312
{
301
 
    register int us, s;
 
313
  register int us, s;
302
314
 
303
 
    us = a.tv_usec - b.tv_usec;
304
 
    us /= 1000;
305
 
    s = a.tv_sec - b.tv_sec;
306
 
    s *= 1000;
307
 
    return s + us;
 
315
  us = a.tv_usec - b.tv_usec;
 
316
  us /= 1000;
 
317
  s = a.tv_sec - b.tv_sec;
 
318
  s *= 1000;
 
319
  return s + us;
308
320
}
309
321
 
310
322
int main(int argc, char **argv)
311
323
{
312
 
  DRIZZLE drizzle;
 
324
  drizzle_con_st con;
313
325
  option_string *eptr;
314
326
  unsigned int x;
315
327
 
317
329
 
318
330
  MY_INIT(argv[0]);
319
331
 
320
 
  if (!(drizzle_thread_safe()))
321
 
      fprintf(stderr, "This application was compiled incorrectly. Please recompile with thread support.\n");
322
 
 
323
 
  load_defaults("my",load_default_groups,&argc,&argv);
 
332
  load_defaults("drizzle",load_default_groups,&argc,&argv);
324
333
  defaults_argv=argv;
325
334
  if (get_options(&argc,&argv))
326
335
  {
327
336
    free_defaults(defaults_argv);
328
 
    my_end(0);
 
337
    my_end();
329
338
    exit(1);
330
339
  }
331
340
 
344
353
  {
345
354
    fprintf(stderr,"%s: Too many arguments\n",my_progname);
346
355
    free_defaults(defaults_argv);
347
 
    my_end(0);
 
356
    my_end();
348
357
    exit(1);
349
358
  }
350
359
 
351
 
  slap_connect(&drizzle, false);
 
360
  slap_connect(&con, false);
352
361
 
353
 
  VOID(pthread_mutex_init(&counter_mutex, NULL));
354
 
  VOID(pthread_cond_init(&count_threshhold, NULL));
355
 
  VOID(pthread_mutex_init(&sleeper_mutex, NULL));
356
 
  VOID(pthread_cond_init(&sleep_threshhold, NULL));
357
 
  VOID(pthread_mutex_init(&timer_alarm_mutex, NULL));
358
 
  VOID(pthread_cond_init(&timer_alarm_threshold, NULL));
 
362
  pthread_mutex_init(&counter_mutex, NULL);
 
363
  pthread_cond_init(&count_threshhold, NULL);
 
364
  pthread_mutex_init(&sleeper_mutex, NULL);
 
365
  pthread_cond_init(&sleep_threshhold, NULL);
 
366
  pthread_mutex_init(&timer_alarm_mutex, NULL);
 
367
  pthread_cond_init(&timer_alarm_threshold, NULL);
359
368
 
360
369
 
361
370
  /* Main iterations loop */
364
373
  do
365
374
  {
366
375
    /* For the final stage we run whatever queries we were asked to run */
367
 
    uint *current;
 
376
    uint32_t *current;
368
377
 
369
378
    if (verbose >= 2)
370
379
      printf("Starting Concurrency Test\n");
372
381
    if (*concurrency)
373
382
    {
374
383
      for (current= concurrency; current && *current; current++)
375
 
        concurrency_loop(&drizzle, *current, eptr);
 
384
        concurrency_loop(&con, *current, eptr);
376
385
    }
377
386
    else
378
387
    {
379
 
      uint infinite= 1;
 
388
      uint32_t infinite= 1;
380
389
      do {
381
 
        concurrency_loop(&drizzle, infinite, eptr);
 
390
        concurrency_loop(&con, infinite, eptr);
382
391
      }
383
392
      while (infinite++);
384
393
    }
385
394
 
386
395
    if (!opt_preserve)
387
 
      drop_schema(&drizzle, create_schema_string);
 
396
      drop_schema(&con, create_schema_string);
388
397
 
389
398
  } while (eptr ? (eptr= eptr->next) : 0);
390
 
 
 
399
 
391
400
  if (opt_burnin)
392
401
    goto burnin;
393
402
 
394
 
  VOID(pthread_mutex_destroy(&counter_mutex));
395
 
  VOID(pthread_cond_destroy(&count_threshhold));
396
 
  VOID(pthread_mutex_destroy(&sleeper_mutex));
397
 
  VOID(pthread_cond_destroy(&sleep_threshhold));
398
 
  VOID(pthread_mutex_destroy(&timer_alarm_mutex));
399
 
  VOID(pthread_cond_destroy(&timer_alarm_threshold));
 
403
  pthread_mutex_destroy(&counter_mutex);
 
404
  pthread_cond_destroy(&count_threshhold);
 
405
  pthread_mutex_destroy(&sleeper_mutex);
 
406
  pthread_cond_destroy(&sleep_threshhold);
 
407
  pthread_mutex_destroy(&timer_alarm_mutex);
 
408
  pthread_cond_destroy(&timer_alarm_threshold);
400
409
 
401
 
  slap_close(&drizzle);
 
410
  slap_close(&con);
402
411
 
403
412
  /* now free all the strings we created */
404
413
  if (opt_password)
405
 
    my_free(opt_password, MYF(0));
 
414
    free(opt_password);
406
415
 
407
 
  my_free(concurrency, MYF(0));
 
416
  free(concurrency);
408
417
 
409
418
  statement_cleanup(create_statements);
410
419
  for (x= 0; x < query_statements_count; x++)
411
420
    statement_cleanup(query_statements[x]);
412
 
  my_free(query_statements, MYF(0));
 
421
  free(query_statements);
413
422
  statement_cleanup(pre_statements);
414
423
  statement_cleanup(post_statements);
415
424
  option_cleanup(engine_options);
417
426
 
418
427
#ifdef HAVE_SMEM
419
428
  if (shared_memory_base_name)
420
 
    my_free(shared_memory_base_name, MYF(MY_ALLOW_ZERO_PTR));
 
429
    free(shared_memory_base_name);
421
430
#endif
422
431
  free_defaults(defaults_argv);
423
 
  my_end(my_end_arg);
 
432
  my_end();
424
433
 
425
434
  return 0;
426
435
}
427
436
 
428
 
void concurrency_loop(DRIZZLE *drizzle, uint current, option_string *eptr)
 
437
void concurrency_loop(drizzle_con_st *con, uint32_t current, option_string *eptr)
429
438
{
430
439
  unsigned int x;
431
440
  stats *head_sptr;
432
441
  stats *sptr;
433
442
  conclusions conclusion;
434
 
  unsigned long long client_limit;
 
443
  uint64_t client_limit;
435
444
 
436
 
  head_sptr= (stats *)my_malloc(sizeof(stats) * iterations,
437
 
                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
445
  head_sptr= (stats *)malloc(sizeof(stats) * iterations);
 
446
  if (head_sptr == NULL)
 
447
  {
 
448
    fprintf(stderr,"Error allocating memory in concurrency_loop\n");
 
449
    exit(1);
 
450
  }
 
451
  memset(head_sptr, 0, sizeof(stats) * iterations);
438
452
 
439
453
  memset(&conclusion, 0, sizeof(conclusions));
440
454
 
453
467
      data in the table.
454
468
    */
455
469
    if (opt_preserve == false)
456
 
      drop_schema(drizzle, create_schema_string);
 
470
      drop_schema(con, create_schema_string);
457
471
 
458
472
    /* First we create */
459
473
    if (create_statements)
460
 
      create_schema(drizzle, create_schema_string, create_statements, eptr, sptr);
 
474
      create_schema(con, create_schema_string, create_statements, eptr, sptr);
461
475
 
462
476
    /*
463
477
      If we generated GUID we need to build a list of them from creation that
466
480
    if (verbose >= 2)
467
481
      printf("Generating primary key list\n");
468
482
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
469
 
      generate_primary_key_list(drizzle, eptr);
 
483
      generate_primary_key_list(con, eptr);
470
484
 
471
485
    if (commit_rate)
472
 
      run_query(drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
486
      run_query(con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
473
487
 
474
488
    if (pre_system)
475
 
      system(pre_system);
 
489
    {
 
490
      int ret= system(pre_system);
 
491
      assert(ret != -1);
 
492
    }
 
493
       
476
494
 
477
495
    /*
478
496
      Pre statements are always run after all other logic so they can
479
497
      correct/adjust any item that they want.
480
498
    */
481
499
    if (pre_statements)
482
 
      run_statements(drizzle, pre_statements);
 
500
      run_statements(con, pre_statements);
483
501
 
484
502
    run_scheduler(sptr, query_statements, current, client_limit);
485
 
   
 
503
 
486
504
    if (post_statements)
487
 
      run_statements(drizzle, post_statements);
 
505
      run_statements(con, post_statements);
488
506
 
489
507
    if (post_system)
490
 
      system(post_system);
 
508
    {
 
509
      int ret=  system(post_system);
 
510
      assert(ret !=-1);
 
511
    }
491
512
 
492
513
    /* We are finished with this run */
493
514
    if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
504
525
  if (opt_csv_str)
505
526
    print_conclusions_csv(&conclusion);
506
527
 
507
 
  my_free(head_sptr, MYF(0));
 
528
  free(head_sptr);
508
529
 
509
530
}
510
531
 
512
533
static struct my_option my_long_options[] =
513
534
{
514
535
  {"help", '?', "Display this help and exit.", 0, 0, 0, GET_NO_ARG, NO_ARG,
515
 
    0, 0, 0, 0, 0, 0},
 
536
   0, 0, 0, 0, 0, 0},
516
537
  {"auto-generate-sql-select-columns", OPT_SLAP_AUTO_GENERATE_SELECT_COLUMNS,
517
 
    "Provide a string to use for the select fields used in auto tests.",
518
 
    (char**) &auto_generate_selected_columns_opt,
519
 
    (char**) &auto_generate_selected_columns_opt,
520
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
538
   "Provide a string to use for the select fields used in auto tests.",
 
539
   (char**) &auto_generate_selected_columns_opt,
 
540
   (char**) &auto_generate_selected_columns_opt,
 
541
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
521
542
  {"auto-generate-sql", 'a',
522
 
    "Generate SQL where not supplied by file or command line.",
523
 
    (char**) &auto_generate_sql, (char**) &auto_generate_sql,
524
 
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
543
   "Generate SQL where not supplied by file or command line.",
 
544
   (char**) &auto_generate_sql, (char**) &auto_generate_sql,
 
545
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
525
546
  {"auto-generate-sql-add-autoincrement", OPT_SLAP_AUTO_GENERATE_ADD_AUTO,
526
 
    "Add an AUTO_INCREMENT column to auto-generated tables.",
527
 
    (char**) &auto_generate_sql_autoincrement,
528
 
    (char**) &auto_generate_sql_autoincrement,
529
 
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
547
   "Add an AUTO_INCREMENT column to auto-generated tables.",
 
548
   (char**) &auto_generate_sql_autoincrement,
 
549
   (char**) &auto_generate_sql_autoincrement,
 
550
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
530
551
  {"auto-generate-sql-execute-number", OPT_SLAP_AUTO_GENERATE_EXECUTE_QUERIES,
531
 
    "Set this number to generate a set number of queries to run.",
532
 
    (char**) &auto_actual_queries, (char**) &auto_actual_queries,
533
 
    0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
552
   "Set this number to generate a set number of queries to run.",
 
553
   (char**) &auto_actual_queries, (char**) &auto_actual_queries,
 
554
   0, GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
534
555
  {"auto-generate-sql-guid-primary", OPT_SLAP_AUTO_GENERATE_GUID_PRIMARY,
535
 
    "Add GUID based primary keys to auto-generated tables.",
536
 
    (char**) &auto_generate_sql_guid_primary,
537
 
    (char**) &auto_generate_sql_guid_primary,
538
 
    0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
556
   "Add GUID based primary keys to auto-generated tables.",
 
557
   (char**) &auto_generate_sql_guid_primary,
 
558
   (char**) &auto_generate_sql_guid_primary,
 
559
   0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
539
560
  {"auto-generate-sql-load-type", OPT_SLAP_AUTO_GENERATE_SQL_LOAD_TYPE,
540
 
    "Specify test load type: mixed, update, write, key, or read; default is mixed.",
541
 
    (char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
542
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
561
   "Specify test load type: mixed, update, write, key, or read; default is mixed.",
 
562
   (char**) &opt_auto_generate_sql_type, (char**) &opt_auto_generate_sql_type,
 
563
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
543
564
  {"auto-generate-sql-secondary-indexes",
544
 
    OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
545
 
    "Number of secondary indexes to add to auto-generated tables.",
546
 
    (char**) &auto_generate_sql_secondary_indexes,
547
 
    (char**) &auto_generate_sql_secondary_indexes, 0,
548
 
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
565
   OPT_SLAP_AUTO_GENERATE_SECONDARY_INDEXES,
 
566
   "Number of secondary indexes to add to auto-generated tables.",
 
567
   (char**) &auto_generate_sql_secondary_indexes,
 
568
   (char**) &auto_generate_sql_secondary_indexes, 0,
 
569
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
549
570
  {"auto-generate-sql-unique-query-number",
550
 
    OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
551
 
    "Number of unique queries to generate for automatic tests.",
552
 
    (char**) &auto_generate_sql_unique_query_number,
553
 
    (char**) &auto_generate_sql_unique_query_number,
554
 
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
 
571
   OPT_SLAP_AUTO_GENERATE_UNIQUE_QUERY_NUM,
 
572
   "Number of unique queries to generate for automatic tests.",
 
573
   (char**) &auto_generate_sql_unique_query_number,
 
574
   (char**) &auto_generate_sql_unique_query_number,
 
575
   0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
555
576
  {"auto-generate-sql-unique-write-number",
556
 
    OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
557
 
    "Number of unique queries to generate for auto-generate-sql-write-number.",
558
 
    (char**) &auto_generate_sql_unique_write_number,
559
 
    (char**) &auto_generate_sql_unique_write_number,
560
 
    0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
 
577
   OPT_SLAP_AUTO_GENERATE_UNIQUE_WRITE_NUM,
 
578
   "Number of unique queries to generate for auto-generate-sql-write-number.",
 
579
   (char**) &auto_generate_sql_unique_write_number,
 
580
   (char**) &auto_generate_sql_unique_write_number,
 
581
   0, GET_ULL, REQUIRED_ARG, 10, 0, 0, 0, 0, 0},
561
582
  {"auto-generate-sql-write-number", OPT_SLAP_AUTO_GENERATE_WRITE_NUM,
562
 
    "Number of row inserts to perform for each thread (default is 100).",
563
 
    (char**) &auto_generate_sql_number, (char**) &auto_generate_sql_number,
564
 
    0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
 
583
   "Number of row inserts to perform for each thread (default is 100).",
 
584
   (char**) &auto_generate_sql_number, (char**) &auto_generate_sql_number,
 
585
   0, GET_ULL, REQUIRED_ARG, 100, 0, 0, 0, 0, 0},
565
586
  {"burnin", OPT_SLAP_BURNIN, "Run full test case in infinite loop.",
566
 
    (char**) &opt_burnin, (char**) &opt_burnin, 0, GET_BOOL, NO_ARG, 0, 0, 0,
567
 
    0, 0, 0},
 
587
   (char**) &opt_burnin, (char**) &opt_burnin, 0, GET_BOOL, NO_ARG, 0, 0, 0,
 
588
   0, 0, 0},
568
589
  {"ignore-sql-errors", OPT_SLAP_IGNORE_SQL_ERRORS,
569
 
    "Ignore SQL erros in query run.",
570
 
    (char**) &opt_ignore_sql_errors,
571
 
    (char**) &opt_ignore_sql_errors,
572
 
    0, GET_BOOL, NO_ARG, 0, 0, 0,
573
 
    0, 0, 0},
 
590
   "Ignore SQL erros in query run.",
 
591
   (char**) &opt_ignore_sql_errors,
 
592
   (char**) &opt_ignore_sql_errors,
 
593
   0, GET_BOOL, NO_ARG, 0, 0, 0,
 
594
   0, 0, 0},
574
595
  {"commit", OPT_SLAP_COMMIT, "Commit records every X number of statements.",
575
 
    (char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
576
 
    0, 0, 0, 0, 0, 0},
577
 
  {"compress", 'C', "Use compression in server/client protocol.",
578
 
    (char**) &opt_compress, (char**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
579
 
    0, 0, 0},
 
596
   (char**) &commit_rate, (char**) &commit_rate, 0, GET_UINT, REQUIRED_ARG,
 
597
   0, 0, 0, 0, 0, 0},
580
598
  {"concurrency", 'c', "Number of clients to simulate for query to run.",
581
 
    (char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
582
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
599
   (char**) &concurrency_str, (char**) &concurrency_str, 0, GET_STR,
 
600
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
583
601
  {"create", OPT_SLAP_CREATE_STRING, "File or string to use create tables.",
584
 
    (char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
585
 
    0, 0, 0, 0, 0, 0},
 
602
   (char**) &create_string, (char**) &create_string, 0, GET_STR, REQUIRED_ARG,
 
603
   0, 0, 0, 0, 0, 0},
586
604
  {"create-schema", OPT_CREATE_SLAP_SCHEMA, "Schema to run tests in.",
587
 
    (char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
588
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
605
   (char**) &create_schema_string, (char**) &create_schema_string, 0, GET_STR,
 
606
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
589
607
  {"csv", OPT_SLAP_CSV,
590
 
  "Generate CSV output to named file or to stdout if no file is named.",
591
 
    (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
592
 
    OPT_ARG, 0, 0, 0, 0, 0, 0},
593
 
  {"debug-check", OPT_DEBUG_CHECK, "Check memory and open file usage at exit.",
594
 
   (char**) &debug_check_flag, (char**) &debug_check_flag, 0,
595
 
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
596
 
  {"debug-info", 'T', "Print some debug info at exit.", (char**) &debug_info_flag,
597
 
   (char**) &debug_info_flag, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
 
608
   "Generate CSV output to named file or to stdout if no file is named.",
 
609
   (char**) &opt_csv_str, (char**) &opt_csv_str, 0, GET_STR,
 
610
   OPT_ARG, 0, 0, 0, 0, 0, 0},
598
611
  {"delayed-start", OPT_SLAP_DELAYED_START,
599
 
    "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
600
 
    (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
601
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
612
   "Delay the startup of threads by a random number of microsends (the maximum of the delay)",
 
613
   (char**) &opt_delayed_start, (char**) &opt_delayed_start, 0, GET_UINT,
 
614
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
602
615
  {"delimiter", 'F',
603
 
    "Delimiter to use in SQL statements supplied in file or command line.",
604
 
    (char**) &delimiter, (char**) &delimiter, 0, GET_STR, REQUIRED_ARG,
605
 
    0, 0, 0, 0, 0, 0},
 
616
   "Delimiter to use in SQL statements supplied in file or command line.",
 
617
   (char**) &delimiter, (char**) &delimiter, 0, GET_STR, REQUIRED_ARG,
 
618
   0, 0, 0, 0, 0, 0},
606
619
  {"detach", OPT_SLAP_DETACH,
607
 
    "Detach (close and reopen) connections after X number of requests.",
608
 
    (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG,
609
 
    0, 0, 0, 0, 0, 0},
 
620
   "Detach (close and reopen) connections after X number of requests.",
 
621
   (char**) &detach_rate, (char**) &detach_rate, 0, GET_UINT, REQUIRED_ARG,
 
622
   0, 0, 0, 0, 0, 0},
610
623
  {"engine", 'e', "Storage engine to use for creating the table.",
611
 
    (char**) &default_engine, (char**) &default_engine, 0,
612
 
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
624
   (char**) &default_engine, (char**) &default_engine, 0,
 
625
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
613
626
  {"host", 'h', "Connect to host.", (char**) &host, (char**) &host, 0, GET_STR,
614
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
627
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
615
628
  {"iterations", 'i', "Number of times to run the tests.", (char**) &iterations,
616
 
    (char**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
 
629
   (char**) &iterations, 0, GET_UINT, REQUIRED_ARG, 1, 0, 0, 0, 0, 0},
617
630
  {"label", OPT_SLAP_LABEL, "Label to use for print and csv output.",
618
 
    (char**) &opt_label, (char**) &opt_label, 0,
619
 
    GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
631
   (char**) &opt_label, (char**) &opt_label, 0,
 
632
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
620
633
  {"number-blob-cols", OPT_SLAP_BLOB_COL,
621
 
    "Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ",
622
 
    (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
623
 
    0, 0, 0, 0, 0, 0},
 
634
   "Number of BLOB columns to create table with if specifying --auto-generate-sql. Example --number-blob-cols=3:1024/2048 would give you 3 blobs with a random size between 1024 and 2048. ",
 
635
   (char**) &num_blob_cols_opt, (char**) &num_blob_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
636
   0, 0, 0, 0, 0, 0},
624
637
  {"number-char-cols", 'x',
625
 
    "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
626
 
    (char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
627
 
    0, 0, 0, 0, 0, 0},
 
638
   "Number of VARCHAR columns to create in table if specifying --auto-generate-sql.",
 
639
   (char**) &num_char_cols_opt, (char**) &num_char_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
640
   0, 0, 0, 0, 0, 0},
628
641
  {"number-int-cols", 'y',
629
 
    "Number of INT columns to create in table if specifying --auto-generate-sql.",
630
 
    (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
631
 
    0, 0, 0, 0, 0, 0},
 
642
   "Number of INT columns to create in table if specifying --auto-generate-sql.",
 
643
   (char**) &num_int_cols_opt, (char**) &num_int_cols_opt, 0, GET_STR, REQUIRED_ARG,
 
644
   0, 0, 0, 0, 0, 0},
632
645
  {"number-of-queries", OPT_DRIZZLE_NUMBER_OF_QUERY,
633
 
    "Limit each client to this number of queries (this is not exact).",
634
 
    (char**) &num_of_query, (char**) &num_of_query, 0,
635
 
    GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
646
   "Limit each client to this number of queries (this is not exact).",
 
647
   (char**) &num_of_query, (char**) &num_of_query, 0,
 
648
   GET_ULL, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
636
649
  {"only-print", OPT_DRIZZLE_ONLY_PRINT,
637
 
    "This causes drizzleslap to not connect to the databases, but instead print "
638
 
      "out what it would have done instead.",
639
 
    (char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
640
 
    0, 0, 0, 0, 0, 0},
641
 
  {"password", 'p',
642
 
    "Password to use when connecting to server. If password is not given it's "
643
 
      "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
644
 
  {"port", 'P', "Port number to use for connection.", (char**) &opt_drizzle_port,
645
 
    (char**) &opt_drizzle_port, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0,
646
 
    0},
 
650
   "This causes drizzleslap to not connect to the databases, but instead print "
 
651
   "out what it would have done instead.",
 
652
   (char**) &opt_only_print, (char**) &opt_only_print, 0, GET_BOOL,  NO_ARG,
 
653
   0, 0, 0, 0, 0, 0},
 
654
  {"password", 'P',
 
655
   "Password to use when connecting to server. If password is not given it's "
 
656
   "asked from the tty.", 0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
 
657
  {"port", 'p', "Port number to use for connection.",
 
658
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
647
659
  {"post-query", OPT_SLAP_POST_QUERY,
648
 
    "Query to run or file containing query to execute after tests have completed.",
649
 
    (char**) &user_supplied_post_statements,
650
 
    (char**) &user_supplied_post_statements,
651
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
660
   "Query to run or file containing query to execute after tests have completed.",
 
661
   (char**) &user_supplied_post_statements,
 
662
   (char**) &user_supplied_post_statements,
 
663
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
652
664
  {"post-system", OPT_SLAP_POST_SYSTEM,
653
 
    "system() string to execute after tests have completed.",
654
 
    (char**) &post_system,
655
 
    (char**) &post_system,
656
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
665
   "system() string to execute after tests have completed.",
 
666
   (char**) &post_system,
 
667
   (char**) &post_system,
 
668
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
657
669
  {"pre-query", OPT_SLAP_PRE_QUERY,
658
 
    "Query to run or file containing query to execute before running tests.",
659
 
    (char**) &user_supplied_pre_statements,
660
 
    (char**) &user_supplied_pre_statements,
661
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
670
   "Query to run or file containing query to execute before running tests.",
 
671
   (char**) &user_supplied_pre_statements,
 
672
   (char**) &user_supplied_pre_statements,
 
673
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
662
674
  {"pre-system", OPT_SLAP_PRE_SYSTEM,
663
 
    "system() string to execute before running tests.",
664
 
    (char**) &pre_system,
665
 
    (char**) &pre_system,
666
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
675
   "system() string to execute before running tests.",
 
676
   (char**) &pre_system,
 
677
   (char**) &pre_system,
 
678
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
667
679
  {"protocol", OPT_DRIZZLE_PROTOCOL,
668
 
    "The protocol of connection (tcp,socket,pipe,memory).",
669
 
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
680
   "The protocol of connection (tcp,socket,pipe,memory).",
 
681
   0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
670
682
  {"query", 'q', "Query to run or file containing query to run.",
671
 
    (char**) &user_supplied_query, (char**) &user_supplied_query,
672
 
    0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
683
   (char**) &user_supplied_query, (char**) &user_supplied_query,
 
684
   0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
673
685
  {"set-random-seed", OPT_SLAP_SET_RANDOM_SEED,
674
 
    "Seed for random number generator (srandom(3))",
675
 
    (char**)&opt_set_random_seed,
676
 
    (char**)&opt_set_random_seed,0,
677
 
    GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
686
   "Seed for random number generator (srandom(3))",
 
687
   (char**)&opt_set_random_seed,
 
688
   (char**)&opt_set_random_seed,0,
 
689
   GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
678
690
  {"silent", 's', "Run program in silent mode - no output.",
679
 
    (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
680
 
    0, 0, 0, 0, 0, 0},
 
691
   (char**) &opt_silent, (char**) &opt_silent, 0, GET_BOOL,  NO_ARG,
 
692
   0, 0, 0, 0, 0, 0},
681
693
  {"socket", 'S', "Socket file to use for connection.",
682
 
    (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
683
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
694
   (char**) &opt_drizzle_unix_port, (char**) &opt_drizzle_unix_port, 0, GET_STR,
 
695
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
684
696
  {"timer-length", OPT_SLAP_TIMER_LENGTH,
685
 
    "Require drizzleslap to run each specific test a certain amount of time in seconds.",
686
 
    (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
687
 
    REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
688
 
#ifndef DONT_ALLOW_USER_CHANGE
 
697
   "Require drizzleslap to run each specific test a certain amount of time in seconds.",
 
698
   (char**) &opt_timer_length, (char**) &opt_timer_length, 0, GET_UINT,
 
699
   REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
689
700
  {"user", 'u', "User for login if not current user.", (char**) &user,
690
 
    (char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
691
 
#endif
 
701
   (char**) &user, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
692
702
  {"verbose", 'v',
693
 
    "More verbose output; you can use this multiple times to get even more "
694
 
      "verbose output.", (char**) &verbose, (char**) &verbose, 0,
695
 
      GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
 
703
   "More verbose output; you can use this multiple times to get even more "
 
704
   "verbose output.", (char**) &verbose, (char**) &verbose, 0,
 
705
   GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
696
706
  {"version", 'V', "Output version information and exit.", 0, 0, 0, GET_NO_ARG,
697
 
    NO_ARG, 0, 0, 0, 0, 0, 0},
 
707
   NO_ARG, 0, 0, 0, 0, 0, 0},
698
708
  {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
699
709
};
700
710
 
701
711
 
702
712
static void print_version(void)
703
713
{
704
 
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname, SLAP_VERSION,
705
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
714
  printf("%s  Ver %s Distrib %s, for %s-%s (%s)\n",my_progname, SLAP_VERSION,
 
715
         drizzle_version(),HOST_VENDOR,HOST_OS,HOST_CPU);
706
716
}
707
717
 
708
718
 
709
719
static void usage(void)
710
720
{
711
721
  print_version();
712
 
  puts("Copyright (C) 2005 DRIZZLE AB");
 
722
  puts("Copyright (C) 2008 Sun Microsystems");
713
723
  puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\
714
724
       \nand you are welcome to modify and redistribute it under the GPL \
715
725
       license\n");
716
726
  puts("Run a query multiple times against the server\n");
717
727
  printf("Usage: %s [OPTIONS]\n",my_progname);
718
 
  print_defaults("my",load_default_groups);
 
728
  print_defaults("drizzle",load_default_groups);
719
729
  my_print_help(my_long_options);
720
730
}
721
731
 
722
 
static bool
723
 
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
724
 
               char *argument)
 
732
bool get_one_option(int optid, const struct my_option *, char *argument)
725
733
{
 
734
  char *endchar= NULL;
 
735
  uint64_t temp_drizzle_port= 0;
726
736
 
727
737
  switch(optid) {
728
738
  case 'v':
729
739
    verbose++;
730
740
    break;
731
741
  case 'p':
 
742
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
743
    /* if there is an alpha character this is not a valid port */
 
744
    if (strlen(endchar) != 0)
 
745
    {
 
746
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
 
747
      exit(1);
 
748
    }
 
749
    /* If the port number is > 65535 it is not a valid port
 
750
       This also helps with potential data loss casting unsigned long to a
 
751
       uint32_t. */
 
752
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
753
    {
 
754
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
 
755
      exit(1);
 
756
    }
 
757
    else
 
758
    {
 
759
      opt_drizzle_port= (uint32_t) temp_drizzle_port;
 
760
    }
 
761
    break;
 
762
  case 'P':
732
763
    if (argument)
733
764
    {
734
765
      char *start= argument;
735
 
      my_free(opt_password, MYF(MY_ALLOW_ZERO_PTR));
736
 
      opt_password= my_strdup(argument,MYF(MY_FAE));
737
 
      while (*argument) *argument++= 'x';    /* Destroy argument */
 
766
      if (opt_password)
 
767
        free(opt_password);
 
768
      opt_password = strdup(argument);
 
769
      if (opt_password == NULL)
 
770
      {
 
771
        fprintf(stderr, "Memory allocation error while copying password. "
 
772
                        "Aborting.\n");
 
773
        exit(ENOMEM);
 
774
      }
 
775
      while (*argument)
 
776
      {
 
777
        /* Overwriting password with 'x' */
 
778
        *argument++= 'x';
 
779
      }
738
780
      if (*start)
739
 
        start[1]= 0;        /* Cut length of argument */
 
781
      {
 
782
        /* Cut length of argument */
 
783
        start[1]= 0;
 
784
      }
740
785
      tty_password= 0;
741
786
    }
742
787
    else
745
790
  case 'V':
746
791
    print_version();
747
792
    exit(0);
748
 
    break;
749
793
  case '?':
750
794
  case 'I':          /* Info */
751
795
    usage();
779
823
  char       buf[HUGE_STRING_LENGTH];
780
824
  unsigned int        col_count;
781
825
  statement *ptr;
782
 
  DYNAMIC_STRING table_string;
783
 
 
784
 
  init_dynamic_string(&table_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
785
 
 
786
 
  dynstr_append(&table_string, "CREATE TABLE `t1` (");
 
826
  string table_string;
 
827
 
 
828
  table_string.reserve(HUGE_STRING_LENGTH);
 
829
 
 
830
  table_string= "CREATE TABLE `t1` (";
787
831
 
788
832
  if (auto_generate_sql_autoincrement)
789
833
  {
790
 
    dynstr_append(&table_string, "id serial");
 
834
    table_string.append("id serial");
791
835
 
792
836
    if (num_int_cols || num_char_cols)
793
 
      dynstr_append(&table_string, ",");
 
837
      table_string.append(",");
794
838
  }
795
839
 
796
840
  if (auto_generate_sql_guid_primary)
797
841
  {
798
 
    dynstr_append(&table_string, "id varchar(128) primary key");
 
842
    table_string.append("id varchar(128) primary key");
799
843
 
800
844
    if (num_int_cols || num_char_cols || auto_generate_sql_guid_primary)
801
 
      dynstr_append(&table_string, ",");
 
845
      table_string.append(",");
802
846
  }
803
847
 
804
848
  if (auto_generate_sql_secondary_indexes)
808
852
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
809
853
    {
810
854
      if (count) /* Except for the first pass we add a comma */
811
 
        dynstr_append(&table_string, ",");
 
855
        table_string.append(",");
812
856
 
813
857
      if (snprintf(buf, HUGE_STRING_LENGTH, "id%d varchar(32) unique key", count)
814
858
          > HUGE_STRING_LENGTH)
816
860
        fprintf(stderr, "Memory Allocation error in create table\n");
817
861
        exit(1);
818
862
      }
819
 
      dynstr_append(&table_string, buf);
 
863
      table_string.append(buf);
820
864
    }
821
865
 
822
866
    if (num_int_cols || num_char_cols)
823
 
      dynstr_append(&table_string, ",");
 
867
      table_string.append(",");
824
868
  }
825
869
 
826
870
  if (num_int_cols)
844
888
          exit(1);
845
889
        }
846
890
      }
847
 
      dynstr_append(&table_string, buf);
 
891
      table_string.append(buf);
848
892
 
849
893
      if (col_count < num_int_cols || num_char_cols > 0)
850
 
        dynstr_append(&table_string, ",");
 
894
        table_string.append(",");
851
895
    }
852
896
 
853
897
  if (num_char_cols)
872
916
          exit(1);
873
917
        }
874
918
      }
875
 
      dynstr_append(&table_string, buf);
 
919
      table_string.append(buf);
876
920
 
877
921
      if (col_count < num_char_cols || num_blob_cols > 0)
878
 
        dynstr_append(&table_string, ",");
 
922
        table_string.append(",");
879
923
    }
880
924
 
881
925
  if (num_blob_cols)
887
931
        fprintf(stderr, "Memory Allocation error in creating table\n");
888
932
        exit(1);
889
933
      }
890
 
      dynstr_append(&table_string, buf);
 
934
      table_string.append(buf);
891
935
 
892
936
      if (col_count < num_blob_cols)
893
 
        dynstr_append(&table_string, ",");
 
937
        table_string.append(",");
894
938
    }
895
939
 
896
 
  dynstr_append(&table_string, ")");
897
 
  ptr= (statement *)my_malloc(sizeof(statement),
898
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
899
 
  ptr->string = (char *)my_malloc(table_string.length+1,
900
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
901
 
  ptr->length= table_string.length+1;
 
940
  table_string.append(")");
 
941
  ptr= (statement *)malloc(sizeof(statement));
 
942
  if (ptr == NULL)
 
943
  {
 
944
    fprintf(stderr, "Memory Allocation error in creating table\n");
 
945
    exit(1);
 
946
  }
 
947
  memset(ptr, 0, sizeof(statement));
 
948
  ptr->string = (char *)malloc(table_string.length()+1);
 
949
  if (ptr->string == NULL)
 
950
  {
 
951
    fprintf(stderr, "Memory Allocation error in creating table\n");
 
952
    exit(1);
 
953
  }
 
954
  memset(ptr->string, 0, table_string.length()+1);
 
955
  ptr->length= table_string.length()+1;
902
956
  ptr->type= CREATE_TABLE_TYPE;
903
 
  stpcpy(ptr->string, table_string.str);
904
 
  dynstr_free(&table_string);
 
957
  strcpy(ptr->string, table_string.c_str());
905
958
  return(ptr);
906
959
}
907
960
 
917
970
  char       buf[HUGE_STRING_LENGTH];
918
971
  unsigned int        col_count;
919
972
  statement *ptr;
920
 
  DYNAMIC_STRING update_string;
921
 
 
922
 
 
923
 
  init_dynamic_string(&update_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
924
 
 
925
 
  dynstr_append(&update_string, "UPDATE t1 SET ");
 
973
  string update_string;
 
974
 
 
975
  update_string.reserve(HUGE_STRING_LENGTH);
 
976
 
 
977
  update_string= "UPDATE t1 SET ";
926
978
 
927
979
  if (num_int_cols)
928
980
    for (col_count= 1; col_count <= num_int_cols; col_count++)
933
985
        fprintf(stderr, "Memory Allocation error in creating update\n");
934
986
        exit(1);
935
987
      }
936
 
      dynstr_append(&update_string, buf);
 
988
      update_string.append(buf);
937
989
 
938
990
      if (col_count < num_int_cols || num_char_cols > 0)
939
 
        dynstr_append_mem(&update_string, ",", 1);
 
991
        update_string.append(",", 1);
940
992
    }
941
993
 
942
994
  if (num_char_cols)
952
1004
        fprintf(stderr, "Memory Allocation error in creating update\n");
953
1005
        exit(1);
954
1006
      }
955
 
      dynstr_append(&update_string, buf);
 
1007
      update_string.append(buf);
956
1008
 
957
1009
      if (col_count < num_char_cols)
958
 
        dynstr_append_mem(&update_string, ",", 1);
 
1010
        update_string.append(",", 1);
959
1011
    }
960
1012
 
961
1013
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
962
 
    dynstr_append(&update_string, " WHERE id = ");
963
 
 
964
 
 
965
 
  ptr= (statement *)my_malloc(sizeof(statement),
966
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
967
 
 
968
 
  ptr->string= (char *)my_malloc(update_string.length + 1,
969
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
970
 
  ptr->length= update_string.length+1;
 
1014
    update_string.append(" WHERE id = ");
 
1015
 
 
1016
 
 
1017
  ptr= (statement *)malloc(sizeof(statement));
 
1018
  if (ptr == NULL)
 
1019
  {
 
1020
    fprintf(stderr, "Memory Allocation error in creating update\n");
 
1021
    exit(1);
 
1022
  }
 
1023
  memset(ptr, 0, sizeof(statement));
 
1024
 
 
1025
  ptr->length= update_string.length()+1;
 
1026
  ptr->string= (char *)malloc(ptr->length);
 
1027
  if (ptr->string == NULL)
 
1028
  {
 
1029
    fprintf(stderr, "Memory Allocation error in creating update\n");
 
1030
    exit(1);
 
1031
  }
 
1032
  memset(ptr->string, 0, ptr->length);
971
1033
  if (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary)
972
1034
    ptr->type= UPDATE_TYPE_REQUIRES_PREFIX ;
973
1035
  else
974
1036
    ptr->type= UPDATE_TYPE;
975
 
  stpcpy(ptr->string, update_string.str);
976
 
  dynstr_free(&update_string);
 
1037
  strncpy(ptr->string, update_string.c_str(), ptr->length);
977
1038
  return(ptr);
978
1039
}
979
1040
 
990
1051
  char       buf[HUGE_STRING_LENGTH];
991
1052
  unsigned int        col_count;
992
1053
  statement *ptr;
993
 
  DYNAMIC_STRING insert_string;
994
 
 
995
 
 
996
 
  init_dynamic_string(&insert_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
997
 
 
998
 
  dynstr_append(&insert_string, "INSERT INTO t1 VALUES (");
 
1054
  string insert_string;
 
1055
 
 
1056
  insert_string.reserve(HUGE_STRING_LENGTH);
 
1057
 
 
1058
  insert_string= "INSERT INTO t1 VALUES (";
999
1059
 
1000
1060
  if (auto_generate_sql_autoincrement)
1001
1061
  {
1002
 
    dynstr_append(&insert_string, "NULL");
 
1062
    insert_string.append("NULL");
1003
1063
 
1004
1064
    if (num_int_cols || num_char_cols)
1005
 
      dynstr_append(&insert_string, ",");
 
1065
      insert_string.append(",");
1006
1066
  }
1007
1067
 
1008
1068
  if (auto_generate_sql_guid_primary)
1009
1069
  {
1010
 
    dynstr_append(&insert_string, "uuid()");
 
1070
    insert_string.append("uuid()");
1011
1071
 
1012
1072
    if (num_int_cols || num_char_cols)
1013
 
      dynstr_append(&insert_string, ",");
 
1073
      insert_string.append(",");
1014
1074
  }
1015
1075
 
1016
1076
  if (auto_generate_sql_secondary_indexes)
1020
1080
    for (count= 0; count < auto_generate_sql_secondary_indexes; count++)
1021
1081
    {
1022
1082
      if (count) /* Except for the first pass we add a comma */
1023
 
        dynstr_append(&insert_string, ",");
 
1083
        insert_string.append(",");
1024
1084
 
1025
 
      dynstr_append(&insert_string, "uuid()");
 
1085
      insert_string.append("uuid()");
1026
1086
    }
1027
1087
 
1028
1088
    if (num_int_cols || num_char_cols)
1029
 
      dynstr_append(&insert_string, ",");
 
1089
      insert_string.append(",");
1030
1090
  }
1031
1091
 
1032
1092
  if (num_int_cols)
1037
1097
        fprintf(stderr, "Memory Allocation error in creating insert\n");
1038
1098
        exit(1);
1039
1099
      }
1040
 
      dynstr_append(&insert_string, buf);
 
1100
      insert_string.append(buf);
1041
1101
 
1042
1102
      if (col_count < num_int_cols || num_char_cols > 0)
1043
 
        dynstr_append_mem(&insert_string, ",", 1);
 
1103
        insert_string.append(",");
1044
1104
    }
1045
1105
 
1046
1106
  if (num_char_cols)
1047
1107
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1048
1108
    {
1049
1109
      int buf_len= get_random_string(buf, RAND_STRING_SIZE);
1050
 
      dynstr_append_mem(&insert_string, "'", 1);
1051
 
      dynstr_append_mem(&insert_string, buf, buf_len);
1052
 
      dynstr_append_mem(&insert_string, "'", 1);
 
1110
      insert_string.append("'", 1);
 
1111
      insert_string.append(buf, buf_len);
 
1112
      insert_string.append("'", 1);
1053
1113
 
1054
1114
      if (col_count < num_char_cols || num_blob_cols > 0)
1055
 
        dynstr_append_mem(&insert_string, ",", 1);
 
1115
        insert_string.append(",", 1);
1056
1116
    }
1057
1117
 
1058
1118
  if (num_blob_cols)
1061
1121
 
1062
1122
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1063
1123
    {
1064
 
      blob_ptr= (char *)my_malloc(sizeof(char)*num_blob_cols_size,
1065
 
                             MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1124
      blob_ptr= (char *)malloc(sizeof(char)*num_blob_cols_size);
1066
1125
      if (!blob_ptr)
1067
1126
      {
1068
1127
        fprintf(stderr, "Memory Allocation error in creating select\n");
1069
1128
        exit(1);
1070
1129
      }
 
1130
      memset(blob_ptr, 0, sizeof(char)*num_blob_cols_size);
1071
1131
    }
1072
1132
    else
1073
1133
    {
1081
1141
      unsigned int difference= num_blob_cols_size - num_blob_cols_size_min;
1082
1142
 
1083
1143
      size= difference ? (num_blob_cols_size_min + (random() % difference)) :
1084
 
                          num_blob_cols_size;
 
1144
        num_blob_cols_size;
1085
1145
 
1086
1146
      buf_len= get_random_string(blob_ptr, size);
1087
1147
 
1088
 
      dynstr_append_mem(&insert_string, "'", 1);
1089
 
      dynstr_append_mem(&insert_string, blob_ptr, buf_len);
1090
 
      dynstr_append_mem(&insert_string, "'", 1);
 
1148
      insert_string.append("'", 1);
 
1149
      insert_string.append(blob_ptr, buf_len);
 
1150
      insert_string.append("'", 1);
1091
1151
 
1092
1152
      if (col_count < num_blob_cols)
1093
 
        dynstr_append_mem(&insert_string, ",", 1);
 
1153
        insert_string.append(",", 1);
1094
1154
    }
1095
1155
 
1096
1156
    if (num_blob_cols_size > HUGE_STRING_LENGTH)
1097
 
      my_free(blob_ptr, MYF(0));
1098
 
  }
1099
 
 
1100
 
  dynstr_append_mem(&insert_string, ")", 1);
1101
 
 
1102
 
  if (!(ptr= (statement *)my_malloc(sizeof(statement), MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1103
 
  {
1104
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1105
 
    exit(1);
1106
 
  }
1107
 
  if (!(ptr->string= (char *)my_malloc(insert_string.length + 1, MYF(MY_ZEROFILL|MY_FAE|MY_WME))))
1108
 
  {
1109
 
    fprintf(stderr, "Memory Allocation error in creating select\n");
1110
 
    exit(1);
1111
 
  }
1112
 
  ptr->length= insert_string.length+1;
 
1157
      free(blob_ptr);
 
1158
  }
 
1159
 
 
1160
  insert_string.append(")", 1);
 
1161
 
 
1162
  if (!(ptr= (statement *)malloc(sizeof(statement))))
 
1163
  {
 
1164
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1165
    exit(1);
 
1166
  }
 
1167
  memset(ptr, 0, sizeof(statement));
 
1168
  ptr->length= insert_string.length()+1;
 
1169
  if (!(ptr->string= (char *)malloc(ptr->length)))
 
1170
  {
 
1171
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1172
    exit(1);
 
1173
  }
 
1174
  memset(ptr->string, 0, ptr->length);
1113
1175
  ptr->type= INSERT_TYPE;
1114
 
  stpcpy(ptr->string, insert_string.str);
1115
 
  dynstr_free(&insert_string);
1116
 
 
 
1176
  strcpy(ptr->string, insert_string.c_str());
1117
1177
  return(ptr);
1118
1178
}
1119
1179
 
1130
1190
  char       buf[HUGE_STRING_LENGTH];
1131
1191
  unsigned int        col_count;
1132
1192
  statement *ptr;
1133
 
  static DYNAMIC_STRING query_string;
1134
 
 
1135
 
 
1136
 
  init_dynamic_string(&query_string, "", HUGE_STRING_LENGTH, HUGE_STRING_LENGTH);
1137
 
 
1138
 
  dynstr_append_mem(&query_string, "SELECT ", 7);
 
1193
  string query_string;
 
1194
 
 
1195
  query_string.reserve(HUGE_STRING_LENGTH);
 
1196
 
 
1197
  query_string.append("SELECT ", 7);
1139
1198
  if (auto_generate_selected_columns_opt)
1140
1199
  {
1141
 
    dynstr_append(&query_string, auto_generate_selected_columns_opt);
 
1200
    query_string.append(auto_generate_selected_columns_opt);
1142
1201
  }
1143
1202
  else
1144
1203
  {
1150
1209
        fprintf(stderr, "Memory Allocation error in creating select\n");
1151
1210
        exit(1);
1152
1211
      }
1153
 
      dynstr_append(&query_string, buf);
 
1212
      query_string.append(buf);
1154
1213
 
1155
1214
      if (col_count < num_int_cols || num_char_cols > 0)
1156
 
        dynstr_append_mem(&query_string, ",", 1);
 
1215
        query_string.append(",", 1);
1157
1216
 
1158
1217
    }
1159
1218
    for (col_count= 1; col_count <= num_char_cols; col_count++)
1164
1223
        fprintf(stderr, "Memory Allocation error in creating select\n");
1165
1224
        exit(1);
1166
1225
      }
1167
 
      dynstr_append(&query_string, buf);
 
1226
      query_string.append(buf);
1168
1227
 
1169
1228
      if (col_count < num_char_cols || num_blob_cols > 0)
1170
 
        dynstr_append_mem(&query_string, ",", 1);
 
1229
        query_string.append(",", 1);
1171
1230
 
1172
1231
    }
1173
1232
    for (col_count= 1; col_count <= num_blob_cols; col_count++)
1178
1237
        fprintf(stderr, "Memory Allocation error in creating select\n");
1179
1238
        exit(1);
1180
1239
      }
1181
 
      dynstr_append(&query_string, buf);
 
1240
      query_string.append(buf);
1182
1241
 
1183
1242
      if (col_count < num_blob_cols)
1184
 
        dynstr_append_mem(&query_string, ",", 1);
 
1243
        query_string.append(",", 1);
1185
1244
    }
1186
1245
  }
1187
 
  dynstr_append(&query_string, " FROM t1");
 
1246
  query_string.append(" FROM t1");
1188
1247
 
1189
1248
  if ((key) &&
1190
1249
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1191
 
    dynstr_append(&query_string, " WHERE id = ");
 
1250
    query_string.append(" WHERE id = ");
1192
1251
 
1193
 
  ptr= (statement *)my_malloc(sizeof(statement),
1194
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1195
 
  ptr->string= (char *)my_malloc(query_string.length + 1,
1196
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1197
 
  ptr->length= query_string.length+1;
 
1252
  ptr= (statement *)malloc(sizeof(statement));
 
1253
  if (ptr == NULL)
 
1254
  {
 
1255
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1256
    exit(1);
 
1257
  }
 
1258
  memset(ptr, 0, sizeof(statement));
 
1259
  ptr->length= query_string.length()+1;
 
1260
  ptr->string= (char *)malloc(ptr->length);
 
1261
  if (ptr->string == NULL)
 
1262
  {
 
1263
    fprintf(stderr, "Memory Allocation error in creating select\n");
 
1264
    exit(1);
 
1265
  }
 
1266
  memset(ptr->string, 0, ptr->length);
1198
1267
  if ((key) &&
1199
1268
      (auto_generate_sql_autoincrement || auto_generate_sql_guid_primary))
1200
1269
    ptr->type= SELECT_TYPE_REQUIRES_PREFIX;
1201
1270
  else
1202
1271
    ptr->type= SELECT_TYPE;
1203
 
  stpcpy(ptr->string, query_string.str);
1204
 
  dynstr_free(&query_string);
 
1272
  strcpy(ptr->string, query_string.c_str());
1205
1273
  return(ptr);
1206
1274
}
1207
1275
 
1213
1281
  struct stat sbuf;
1214
1282
  option_string *sql_type;
1215
1283
  unsigned int sql_type_count= 0;
 
1284
  ssize_t bytes_read= 0;
1216
1285
 
1217
1286
 
1218
1287
  if ((ho_error= handle_options(argc, argv, my_long_options, get_one_option)))
1219
1288
    exit(ho_error);
1220
 
  if (debug_info_flag)
1221
 
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
1222
 
  if (debug_check_flag)
1223
 
    my_end_arg= MY_CHECK_ERROR;
1224
1289
 
1225
1290
  if (!user)
1226
1291
    user= (char *)"root";
1231
1296
 
1232
1297
  if (auto_generate_sql && (create_string || user_supplied_query))
1233
1298
  {
1234
 
      fprintf(stderr,
1235
 
              "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
1236
 
              my_progname);
1237
 
      exit(1);
 
1299
    fprintf(stderr,
 
1300
            "%s: Can't use --auto-generate-sql when create and query strings are specified!\n",
 
1301
            my_progname);
 
1302
    exit(1);
1238
1303
  }
1239
1304
 
1240
1305
  if (auto_generate_sql && auto_generate_sql_guid_primary &&
1241
1306
      auto_generate_sql_autoincrement)
1242
1307
  {
1243
 
      fprintf(stderr,
1244
 
              "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
1245
 
              my_progname);
1246
 
      exit(1);
 
1308
    fprintf(stderr,
 
1309
            "%s: Either auto-generate-sql-guid-primary or auto-generate-sql-add-autoincrement can be used!\n",
 
1310
            my_progname);
 
1311
    exit(1);
1247
1312
  }
1248
1313
 
1249
1314
  if (auto_generate_sql && num_of_query && auto_actual_queries)
1250
1315
  {
1251
 
      fprintf(stderr,
1252
 
              "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
1253
 
              my_progname);
1254
 
      exit(1);
 
1316
    fprintf(stderr,
 
1317
            "%s: Either auto-generate-sql-execute-number or number-of-queries can be used!\n",
 
1318
            my_progname);
 
1319
    exit(1);
1255
1320
  }
1256
1321
 
1257
1322
  parse_comma(concurrency_str ? concurrency_str : "1", &concurrency);
1259
1324
  if (opt_csv_str)
1260
1325
  {
1261
1326
    opt_silent= true;
1262
 
   
 
1327
 
1263
1328
    if (opt_csv_str[0] == '-')
1264
1329
    {
1265
1330
      csv_file= fileno(stdout);
1266
1331
    }
1267
1332
    else
1268
1333
    {
1269
 
      if ((csv_file= my_open(opt_csv_str, O_CREAT|O_WRONLY|O_APPEND, MYF(0)))
1270
 
          == -1)
 
1334
      if ((csv_file= open(opt_csv_str, O_CREAT|O_WRONLY|O_APPEND, 
 
1335
                          S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)) == -1)
1271
1336
      {
1272
1337
        fprintf(stderr,"%s: Could not open csv file: %sn\n",
1273
1338
                my_progname, opt_csv_str);
1331
1396
 
1332
1397
  if (auto_generate_sql)
1333
1398
  {
1334
 
    unsigned long long x= 0;
 
1399
    uint64_t x= 0;
1335
1400
    statement *ptr_statement;
1336
1401
 
1337
1402
    if (verbose >= 2)
1357
1422
    query_statements_count=
1358
1423
      parse_option(opt_auto_generate_sql_type, &query_options, ',');
1359
1424
 
1360
 
    query_statements= (statement **)my_malloc(sizeof(statement *) * query_statements_count,
1361
 
                                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1425
    query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
 
1426
    if (query_statements == NULL)
 
1427
    {
 
1428
      fprintf(stderr, "Memory Allocation error in Building Query Statements\n");
 
1429
      exit(1);
 
1430
    }
 
1431
    memset(query_statements, 0, sizeof(statement *) * query_statements_count);
1362
1432
 
1363
1433
    sql_type= query_options;
1364
1434
    do
1466
1536
  {
1467
1537
    if (create_string && !stat(create_string, &sbuf))
1468
1538
    {
1469
 
      File data_file;
 
1539
      int data_file;
1470
1540
      if (!S_ISREG(sbuf.st_mode))
1471
1541
      {
1472
1542
        fprintf(stderr,"%s: Create file was not a regular file\n",
1473
1543
                my_progname);
1474
1544
        exit(1);
1475
1545
      }
1476
 
      if ((data_file= my_open(create_string, O_RDWR, MYF(0))) == -1)
 
1546
      if ((data_file= open(create_string, O_RDWR)) == -1)
1477
1547
      {
1478
1548
        fprintf(stderr,"%s: Could not open create file\n", my_progname);
1479
1549
        exit(1);
1480
1550
      }
1481
 
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1482
 
                              MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1483
 
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
 
1551
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1552
      {
 
1553
        fprintf(stderr, "Request for more memory than architecture supports\n");
 
1554
        exit(1);
 
1555
      }
 
1556
      tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
 
1557
      if (tmp_string == NULL)
 
1558
      {
 
1559
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1560
        exit(1);
 
1561
      }
 
1562
      memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
 
1563
      bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1564
                       (size_t)sbuf.st_size);
1484
1565
      tmp_string[sbuf.st_size]= '\0';
1485
 
      my_close(data_file,MYF(0));
 
1566
      close(data_file);
 
1567
      if (bytes_read != sbuf.st_size)
 
1568
      {
 
1569
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1570
      }
1486
1571
      parse_delimiter(tmp_string, &create_statements, delimiter[0]);
1487
 
      my_free(tmp_string, MYF(0));
 
1572
      free(tmp_string);
1488
1573
    }
1489
1574
    else if (create_string)
1490
1575
    {
1491
 
        parse_delimiter(create_string, &create_statements, delimiter[0]);
 
1576
      parse_delimiter(create_string, &create_statements, delimiter[0]);
1492
1577
    }
1493
1578
 
1494
1579
    /* Set this up till we fully support options on user generated queries */
1497
1582
      query_statements_count=
1498
1583
        parse_option("default", &query_options, ',');
1499
1584
 
1500
 
      query_statements= (statement **)my_malloc(sizeof(statement *),
1501
 
                                                MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1585
      query_statements= (statement **)malloc(sizeof(statement *) * query_statements_count);
 
1586
      if (query_statements == NULL)
 
1587
      {
 
1588
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1589
        exit(1);
 
1590
      }
 
1591
      memset(query_statements, 0, sizeof(statement *) * query_statements_count); 
1502
1592
    }
1503
1593
 
1504
1594
    if (user_supplied_query && !stat(user_supplied_query, &sbuf))
1505
1595
    {
1506
 
      File data_file;
 
1596
      int data_file;
1507
1597
      if (!S_ISREG(sbuf.st_mode))
1508
1598
      {
1509
1599
        fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1510
1600
                my_progname);
1511
1601
        exit(1);
1512
1602
      }
1513
 
      if ((data_file= my_open(user_supplied_query, O_RDWR, MYF(0))) == -1)
 
1603
      if ((data_file= open(user_supplied_query, O_RDWR)) == -1)
1514
1604
      {
1515
1605
        fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1516
1606
        exit(1);
1517
1607
      }
1518
 
      tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1519
 
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1520
 
      my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
 
1608
      if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1609
      {
 
1610
        fprintf(stderr, "Request for more memory than architecture supports\n");
 
1611
        exit(1);
 
1612
      }
 
1613
      tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
 
1614
      if (tmp_string == NULL)
 
1615
      {
 
1616
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1617
        exit(1);
 
1618
      }
 
1619
      memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
 
1620
      bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1621
                       (size_t)sbuf.st_size);
1521
1622
      tmp_string[sbuf.st_size]= '\0';
1522
 
      my_close(data_file,MYF(0));
 
1623
      close(data_file);
 
1624
      if (bytes_read != sbuf.st_size)
 
1625
      {
 
1626
        fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1627
      }
1523
1628
      if (user_supplied_query)
1524
1629
        actual_queries= parse_delimiter(tmp_string, &query_statements[0],
1525
1630
                                        delimiter[0]);
1526
 
      my_free(tmp_string, MYF(0));
 
1631
      free(tmp_string);
1527
1632
    }
1528
1633
    else if (user_supplied_query)
1529
1634
    {
1535
1640
  if (user_supplied_pre_statements
1536
1641
      && !stat(user_supplied_pre_statements, &sbuf))
1537
1642
  {
1538
 
    File data_file;
 
1643
    int data_file;
1539
1644
    if (!S_ISREG(sbuf.st_mode))
1540
1645
    {
1541
1646
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1542
1647
              my_progname);
1543
1648
      exit(1);
1544
1649
    }
1545
 
    if ((data_file= my_open(user_supplied_pre_statements, O_RDWR, MYF(0))) == -1)
 
1650
    if ((data_file= open(user_supplied_pre_statements, O_RDWR)) == -1)
1546
1651
    {
1547
1652
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1548
1653
      exit(1);
1549
1654
    }
1550
 
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1551
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1552
 
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
 
1655
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1656
    {
 
1657
      fprintf(stderr, "Request for more memory than architecture supports\n");
 
1658
      exit(1);
 
1659
    }
 
1660
    tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
 
1661
    if (tmp_string == NULL)
 
1662
    {
 
1663
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1664
      exit(1);
 
1665
    }
 
1666
    memset(tmp_string, 0, (size_t)(sbuf.st_size + 1));
 
1667
    bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1668
                     (size_t)sbuf.st_size);
1553
1669
    tmp_string[sbuf.st_size]= '\0';
1554
 
    my_close(data_file,MYF(0));
 
1670
    close(data_file);
 
1671
    if (bytes_read != sbuf.st_size)
 
1672
    {
 
1673
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1674
    }
1555
1675
    if (user_supplied_pre_statements)
1556
1676
      (void)parse_delimiter(tmp_string, &pre_statements,
1557
1677
                            delimiter[0]);
1558
 
    my_free(tmp_string, MYF(0));
 
1678
    free(tmp_string);
1559
1679
  }
1560
1680
  else if (user_supplied_pre_statements)
1561
1681
  {
1567
1687
  if (user_supplied_post_statements
1568
1688
      && !stat(user_supplied_post_statements, &sbuf))
1569
1689
  {
1570
 
    File data_file;
 
1690
    int data_file;
1571
1691
    if (!S_ISREG(sbuf.st_mode))
1572
1692
    {
1573
1693
      fprintf(stderr,"%s: User query supplied file was not a regular file\n",
1574
1694
              my_progname);
1575
1695
      exit(1);
1576
1696
    }
1577
 
    if ((data_file= my_open(user_supplied_post_statements, O_RDWR, MYF(0))) == -1)
 
1697
    if ((data_file= open(user_supplied_post_statements, O_RDWR)) == -1)
1578
1698
    {
1579
1699
      fprintf(stderr,"%s: Could not open query supplied file\n", my_progname);
1580
1700
      exit(1);
1581
1701
    }
1582
 
    tmp_string= (char *)my_malloc(sbuf.st_size + 1,
1583
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1584
 
    my_read(data_file, (uchar*) tmp_string, sbuf.st_size, MYF(0));
 
1702
 
 
1703
    if ((uint64_t)(sbuf.st_size + 1) > SIZE_MAX)
 
1704
    {
 
1705
      fprintf(stderr, "Request for more memory than architecture supports\n");
 
1706
      exit(1);
 
1707
    }
 
1708
    tmp_string= (char *)malloc((size_t)(sbuf.st_size + 1));
 
1709
    if (tmp_string == NULL)
 
1710
    {
 
1711
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1712
      exit(1);
 
1713
    }
 
1714
    memset(tmp_string, 0, (size_t)(sbuf.st_size+1));
 
1715
 
 
1716
    bytes_read= read(data_file, (unsigned char*) tmp_string,
 
1717
                     (size_t)(sbuf.st_size));
1585
1718
    tmp_string[sbuf.st_size]= '\0';
1586
 
    my_close(data_file,MYF(0));
 
1719
    close(data_file);
 
1720
    if (bytes_read != sbuf.st_size)
 
1721
    {
 
1722
      fprintf(stderr, "Problem reading file: read less bytes than requested\n");
 
1723
    }
1587
1724
    if (user_supplied_post_statements)
1588
1725
      (void)parse_delimiter(tmp_string, &post_statements,
1589
1726
                            delimiter[0]);
1590
 
    my_free(tmp_string, MYF(0));
 
1727
    free(tmp_string);
1591
1728
  }
1592
1729
  else if (user_supplied_post_statements)
1593
1730
  {
1602
1739
    parse_option(default_engine, &engine_options, ',');
1603
1740
 
1604
1741
  if (tty_password)
1605
 
    opt_password= get_tty_password(NullS);
 
1742
    opt_password= client_get_tty_password(NULL);
1606
1743
  return(0);
1607
1744
}
1608
1745
 
1609
1746
 
1610
 
static int run_query(DRIZZLE *drizzle, const char *query, int len)
 
1747
static int run_query(drizzle_con_st *con, drizzle_result_st *result,
 
1748
                     const char *query, int len)
1611
1749
{
 
1750
  drizzle_return_t ret;
 
1751
  drizzle_result_st result_buffer;
 
1752
 
1612
1753
  if (opt_only_print)
1613
1754
  {
1614
1755
    printf("%.*s;\n", len, query);
1617
1758
 
1618
1759
  if (verbose >= 3)
1619
1760
    printf("%.*s;\n", len, query);
1620
 
  return drizzle_real_query(drizzle, query, len);
 
1761
 
 
1762
  if (result == NULL)
 
1763
    result= &result_buffer;
 
1764
 
 
1765
  result= drizzle_query(con, result, query, len, &ret);
 
1766
 
 
1767
  if (ret == DRIZZLE_RETURN_OK)
 
1768
    ret= drizzle_result_buffer(result);
 
1769
 
 
1770
  if (result == &result_buffer)
 
1771
    drizzle_result_free(result);
 
1772
    
 
1773
  return ret;
1621
1774
}
1622
1775
 
1623
1776
 
1624
1777
static int
1625
 
generate_primary_key_list(DRIZZLE *drizzle, option_string *engine_stmt)
 
1778
generate_primary_key_list(drizzle_con_st *con, option_string *engine_stmt)
1626
1779
{
1627
 
  DRIZZLE_RES *result;
1628
 
  DRIZZLE_ROW row;
1629
 
  unsigned long long counter;
 
1780
  drizzle_result_st result;
 
1781
  drizzle_row_t row;
 
1782
  uint64_t counter;
1630
1783
 
1631
1784
 
1632
1785
  /*
1637
1790
                         strstr(engine_stmt->string, "blackhole")))
1638
1791
  {
1639
1792
    primary_keys_number_of= 1;
1640
 
    primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1641
 
                                            primary_keys_number_of),
1642
 
                                    MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
1793
    primary_keys= (char **)malloc((sizeof(char *) *
 
1794
                                  primary_keys_number_of));
 
1795
    if (primary_keys == NULL)
 
1796
    {
 
1797
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1798
      exit(1);
 
1799
    }
 
1800
    
 
1801
    memset(primary_keys, 0, (sizeof(char *) * primary_keys_number_of));
1643
1802
    /* Yes, we strdup a const string to simplify the interface */
1644
 
    primary_keys[0]= my_strdup("796c4422-1d94-102a-9d6d-00e0812d", MYF(0));
 
1803
    primary_keys[0]= strdup("796c4422-1d94-102a-9d6d-00e0812d");
 
1804
    if (primary_keys[0] == NULL)
 
1805
    {
 
1806
      fprintf(stderr, "Memory Allocation error in option processing\n");
 
1807
      exit(1);
 
1808
    }
1645
1809
  }
1646
1810
  else
1647
1811
  {
1648
 
    if (run_query(drizzle, "SELECT id from t1", strlen("SELECT id from t1")))
 
1812
    if (run_query(con, &result, "SELECT id from t1", strlen("SELECT id from t1")))
1649
1813
    {
1650
1814
      fprintf(stderr,"%s: Cannot select GUID primary keys. (%s)\n", my_progname,
1651
 
              drizzle_error(drizzle));
 
1815
              drizzle_con_error(con));
1652
1816
      exit(1);
1653
1817
    }
1654
1818
 
1655
 
    result= drizzle_store_result(drizzle);
1656
 
    primary_keys_number_of= drizzle_num_rows(result);
 
1819
    uint64_t num_rows_ret= drizzle_result_row_count(&result);
 
1820
    if (num_rows_ret > SIZE_MAX)
 
1821
    {
 
1822
      fprintf(stderr, "More primary keys than than architecture supports\n");
 
1823
      exit(1);
 
1824
    }
 
1825
    primary_keys_number_of= (size_t)num_rows_ret;
1657
1826
 
1658
1827
    /* So why check this? Blackhole :) */
1659
1828
    if (primary_keys_number_of)
1661
1830
      /*
1662
1831
        We create the structure and loop and create the items.
1663
1832
      */
1664
 
      primary_keys= (char **)my_malloc((uint)(sizeof(char *) *
1665
 
                                              primary_keys_number_of),
1666
 
                                       MYF(MY_ZEROFILL|MY_FAE|MY_WME));
1667
 
      row= drizzle_fetch_row(result);
 
1833
      primary_keys= (char **)malloc(sizeof(char *) *
 
1834
                                    primary_keys_number_of);
 
1835
      if (primary_keys == NULL)
 
1836
      {
 
1837
        fprintf(stderr, "Memory Allocation error in option processing\n");
 
1838
        exit(1);
 
1839
      }
 
1840
      memset(primary_keys, 0, (size_t)(sizeof(char *) * primary_keys_number_of));
 
1841
      row= drizzle_row_next(&result);
1668
1842
      for (counter= 0; counter < primary_keys_number_of;
1669
 
           counter++, row= drizzle_fetch_row(result))
1670
 
        primary_keys[counter]= my_strdup(row[0], MYF(0));
 
1843
           counter++, row= drizzle_row_next(&result))
 
1844
      {
 
1845
        primary_keys[counter]= strdup(row[0]);
 
1846
        if (primary_keys[counter] == NULL)
 
1847
        {
 
1848
          fprintf(stderr, "Memory Allocation error in option processing\n");
 
1849
          exit(1);
 
1850
        }
 
1851
      }
1671
1852
    }
1672
1853
 
1673
 
    drizzle_free_result(result);
 
1854
    drizzle_result_free(&result);
1674
1855
  }
1675
1856
 
1676
1857
  return(0);
1679
1860
static int
1680
1861
drop_primary_key_list(void)
1681
1862
{
1682
 
  unsigned long long counter;
 
1863
  uint64_t counter;
1683
1864
 
1684
1865
  if (primary_keys_number_of)
1685
1866
  {
1686
1867
    for (counter= 0; counter < primary_keys_number_of; counter++)
1687
 
      my_free(primary_keys[counter], MYF(0));
 
1868
      free(primary_keys[counter]);
1688
1869
 
1689
 
    my_free(primary_keys, MYF(0));
 
1870
    free(primary_keys);
1690
1871
  }
1691
1872
 
1692
1873
  return 0;
1693
1874
}
1694
1875
 
1695
1876
static int
1696
 
create_schema(DRIZZLE *drizzle, const char *db, statement *stmt,
 
1877
create_schema(drizzle_con_st *con, const char *db, statement *stmt,
1697
1878
              option_string *engine_stmt, stats *sptr)
1698
1879
{
1699
1880
  char query[HUGE_STRING_LENGTH];
1711
1892
  if (verbose >= 2)
1712
1893
    printf("Loading Pre-data\n");
1713
1894
 
1714
 
  if (run_query(drizzle, query, len))
 
1895
  if (run_query(con, NULL, query, len))
1715
1896
  {
1716
1897
    fprintf(stderr,"%s: Cannot create schema %s : %s\n", my_progname, db,
1717
 
            drizzle_error(drizzle));
 
1898
            drizzle_con_error(con));
1718
1899
    exit(1);
1719
1900
  }
1720
1901
  else
1728
1909
  }
1729
1910
  else
1730
1911
  {
 
1912
    drizzle_result_st result;
 
1913
    drizzle_return_t ret;
 
1914
 
1731
1915
    if (verbose >= 3)
1732
1916
      printf("%s;\n", query);
1733
1917
 
1734
 
    if (drizzle_select_db(drizzle,  db))
 
1918
    if (drizzle_select_db(con,  &result, db, &ret) == NULL ||
 
1919
        ret != DRIZZLE_RETURN_OK)
1735
1920
    {
1736
1921
      fprintf(stderr,"%s: Cannot select schema '%s': %s\n",my_progname, db,
1737
 
              drizzle_error(drizzle));
 
1922
              ret == DRIZZLE_RETURN_ERROR_CODE ?
 
1923
              drizzle_result_error(&result) : drizzle_con_error(con));
1738
1924
      exit(1);
1739
1925
    }
 
1926
    drizzle_result_free(&result);
1740
1927
    sptr->create_count++;
1741
1928
  }
1742
1929
 
1744
1931
  {
1745
1932
    len= snprintf(query, HUGE_STRING_LENGTH, "set storage_engine=`%s`",
1746
1933
                  engine_stmt->string);
1747
 
    if (run_query(drizzle, query, len))
 
1934
    if (run_query(con, NULL, query, len))
1748
1935
    {
1749
1936
      fprintf(stderr,"%s: Cannot set default engine: %s\n", my_progname,
1750
 
              drizzle_error(drizzle));
 
1937
              drizzle_con_error(con));
1751
1938
      exit(1);
1752
1939
    }
1753
1940
    sptr->create_count++;
1768
1955
 
1769
1956
      snprintf(buffer, HUGE_STRING_LENGTH, "%s %s", ptr->string,
1770
1957
               engine_stmt->option);
1771
 
      if (run_query(drizzle, buffer, strlen(buffer)))
 
1958
      if (run_query(con, NULL, buffer, strlen(buffer)))
1772
1959
      {
1773
1960
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1774
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1961
                my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1775
1962
        if (!opt_ignore_sql_errors)
1776
1963
          exit(1);
1777
1964
      }
1779
1966
    }
1780
1967
    else
1781
1968
    {
1782
 
      if (run_query(drizzle, ptr->string, ptr->length))
 
1969
      if (run_query(con, NULL, ptr->string, ptr->length))
1783
1970
      {
1784
1971
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1785
 
                my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
1972
                my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1786
1973
        if (!opt_ignore_sql_errors)
1787
1974
          exit(1);
1788
1975
      }
1805
1992
}
1806
1993
 
1807
1994
static int
1808
 
drop_schema(DRIZZLE *drizzle, const char *db)
 
1995
drop_schema(drizzle_con_st *con, const char *db)
1809
1996
{
1810
1997
  char query[HUGE_STRING_LENGTH];
1811
1998
  int len;
1812
1999
 
1813
2000
  len= snprintf(query, HUGE_STRING_LENGTH, "DROP SCHEMA IF EXISTS `%s`", db);
1814
2001
 
1815
 
  if (run_query(drizzle, query, len))
 
2002
  if (run_query(con, NULL, query, len))
1816
2003
  {
1817
2004
    fprintf(stderr,"%s: Cannot drop database '%s' ERROR : %s\n",
1818
 
            my_progname, db, drizzle_error(drizzle));
 
2005
            my_progname, db, drizzle_con_error(con));
1819
2006
    exit(1);
1820
2007
  }
1821
2008
 
1825
2012
}
1826
2013
 
1827
2014
static int
1828
 
run_statements(DRIZZLE *drizzle, statement *stmt)
 
2015
run_statements(drizzle_con_st *con, statement *stmt)
1829
2016
{
1830
2017
  statement *ptr;
1831
 
  DRIZZLE_RES *result;
1832
 
 
1833
2018
 
1834
2019
  for (ptr= stmt; ptr && ptr->length; ptr= ptr->next)
1835
2020
  {
1836
 
    if (run_query(drizzle, ptr->string, ptr->length))
 
2021
    if (run_query(con, NULL, ptr->string, ptr->length))
1837
2022
    {
1838
2023
      fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
1839
 
              my_progname, (uint)ptr->length, ptr->string, drizzle_error(drizzle));
 
2024
              my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(con));
1840
2025
      exit(1);
1841
2026
    }
1842
 
    if (!opt_only_print)
1843
 
    {
1844
 
      if (drizzle_field_count(drizzle))
1845
 
      {
1846
 
        result= drizzle_store_result(drizzle);
1847
 
        drizzle_free_result(result);
1848
 
      }
1849
 
    }
1850
2027
  }
1851
2028
 
1852
2029
  return(0);
1853
2030
}
1854
2031
 
1855
2032
static int
1856
 
run_scheduler(stats *sptr, statement **stmts, uint concur, uint64_t limit)
 
2033
run_scheduler(stats *sptr, statement **stmts, uint32_t concur, uint64_t limit)
1857
2034
{
1858
 
  uint x;
1859
 
  uint y;
 
2035
  uint32_t x;
 
2036
  uint32_t y;
1860
2037
  unsigned int real_concurrency;
1861
2038
  struct timeval start_time, end_time;
1862
2039
  option_string *sql_type;
1867
2044
 
1868
2045
  pthread_attr_init(&attr);
1869
2046
  pthread_attr_setdetachstate(&attr,
1870
 
      PTHREAD_CREATE_DETACHED);
 
2047
                              PTHREAD_CREATE_DETACHED);
1871
2048
 
1872
2049
  pthread_mutex_lock(&counter_mutex);
1873
2050
  thread_counter= 0;
1894
2071
    while (options_loop--)
1895
2072
      for (x= 0; x < concur; x++)
1896
2073
      {
1897
 
        con= (thread_context *)my_malloc(sizeof(thread_context), MYF(0));
 
2074
        con= (thread_context *)malloc(sizeof(thread_context));
 
2075
        if (con == NULL)
 
2076
        {
 
2077
          fprintf(stderr, "Memory Allocation error in scheduler\n");
 
2078
          exit(1);
 
2079
        }
1898
2080
        con->stmt= stmts[y];
1899
2081
        con->limit= limit;
1900
2082
 
1965
2147
 
1966
2148
pthread_handler_t timer_thread(void *p)
1967
2149
{
1968
 
  uint *timer_length= (uint *)p;
 
2150
  uint32_t *timer_length= (uint32_t *)p;
1969
2151
  struct timespec abstime;
1970
2152
 
1971
2153
 
1972
 
 
1973
 
  if (drizzle_thread_init())
1974
 
  {
1975
 
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n",
1976
 
            my_progname);
1977
 
    exit(1);
1978
 
  }
1979
 
 
1980
2154
  /*
1981
2155
    We lock around the initial call in case were we in a loop. This
1982
2156
    also keeps the value properly syncronized across call threads.
1998
2172
  timer_alarm= false;
1999
2173
  pthread_mutex_unlock(&timer_alarm_mutex);
2000
2174
 
2001
 
  drizzle_thread_end();
2002
2175
  return(0);
2003
2176
}
2004
2177
 
2007
2180
  uint64_t counter= 0, queries;
2008
2181
  uint64_t detach_counter;
2009
2182
  unsigned int commit_counter;
2010
 
  DRIZZLE drizzle;
2011
 
  DRIZZLE_RES *result;
2012
 
  DRIZZLE_ROW row;
 
2183
  drizzle_con_st con;
 
2184
  drizzle_result_st result;
 
2185
  drizzle_row_t row;
2013
2186
  statement *ptr;
2014
 
  thread_context *con= (thread_context *)p;
2015
 
 
2016
 
  if (drizzle_thread_init())
2017
 
  {
2018
 
    fprintf(stderr,"%s: drizzle_thread_init() failed.\n",
2019
 
            my_progname);
2020
 
    exit(1);
2021
 
  }
 
2187
  thread_context *ctx= (thread_context *)p;
2022
2188
 
2023
2189
  pthread_mutex_lock(&sleeper_mutex);
2024
2190
  while (master_wakeup)
2027
2193
  }
2028
2194
  pthread_mutex_unlock(&sleeper_mutex);
2029
2195
 
2030
 
  slap_connect(&drizzle, true);
 
2196
  slap_connect(&con, true);
2031
2197
 
2032
2198
  if (verbose >= 3)
2033
2199
    printf("connected!\n");
2035
2201
 
2036
2202
  commit_counter= 0;
2037
2203
  if (commit_rate)
2038
 
    run_query(&drizzle, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
 
2204
    run_query(&con, NULL, "SET AUTOCOMMIT=0", strlen("SET AUTOCOMMIT=0"));
2039
2205
 
2040
2206
limit_not_met:
2041
 
    for (ptr= con->stmt, detach_counter= 0;
2042
 
         ptr && ptr->length;
2043
 
         ptr= ptr->next, detach_counter++)
2044
 
    {
2045
 
      if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
2046
 
      {
2047
 
        slap_close(&drizzle);
2048
 
        slap_connect(&drizzle, true);
2049
 
      }
 
2207
  for (ptr= ctx->stmt, detach_counter= 0;
 
2208
       ptr && ptr->length;
 
2209
       ptr= ptr->next, detach_counter++)
 
2210
  {
 
2211
    if (!opt_only_print && detach_rate && !(detach_counter % detach_rate))
 
2212
    {
 
2213
      slap_close(&con);
 
2214
      slap_connect(&con, true);
 
2215
    }
 
2216
 
 
2217
    /*
 
2218
      We have to execute differently based on query type. This should become a function.
 
2219
    */
 
2220
    if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
 
2221
        (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
 
2222
    {
 
2223
      int length;
 
2224
      unsigned int key_val;
 
2225
      char *key;
 
2226
      char buffer[HUGE_STRING_LENGTH];
2050
2227
 
2051
2228
      /*
2052
 
        We have to execute differently based on query type. This should become a function.
 
2229
        This should only happen if some sort of new engine was
 
2230
        implemented that didn't properly handle UPDATEs.
 
2231
 
 
2232
        Just in case someone runs this under an experimental engine we don't
 
2233
        want a crash so the if() is placed here.
2053
2234
      */
2054
 
      if ((ptr->type == UPDATE_TYPE_REQUIRES_PREFIX) ||
2055
 
          (ptr->type == SELECT_TYPE_REQUIRES_PREFIX))
2056
 
      {
2057
 
        int length;
2058
 
        unsigned int key_val;
2059
 
        char *key;
2060
 
        char buffer[HUGE_STRING_LENGTH];
2061
 
 
2062
 
        /*
2063
 
          This should only happen if some sort of new engine was
2064
 
          implemented that didn't properly handle UPDATEs.
2065
 
 
2066
 
          Just in case someone runs this under an experimental engine we don't
2067
 
          want a crash so the if() is placed here.
2068
 
        */
2069
 
        assert(primary_keys_number_of);
2070
 
        if (primary_keys_number_of)
2071
 
        {
2072
 
          key_val= (unsigned int)(random() % primary_keys_number_of);
2073
 
          key= primary_keys[key_val];
2074
 
 
2075
 
          assert(key);
2076
 
 
2077
 
          length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
2078
 
                           (int)ptr->length, ptr->string, key);
2079
 
 
2080
 
          if (run_query(&drizzle, buffer, length))
2081
 
          {
2082
 
            fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2083
 
                    my_progname, (uint)length, buffer, drizzle_error(&drizzle));
2084
 
            exit(1);
2085
 
          }
2086
 
        }
2087
 
      }
2088
 
      else
2089
 
      {
2090
 
        if (run_query(&drizzle, ptr->string, ptr->length))
 
2235
      assert(primary_keys_number_of);
 
2236
      if (primary_keys_number_of)
 
2237
      {
 
2238
        key_val= (unsigned int)(random() % primary_keys_number_of);
 
2239
        key= primary_keys[key_val];
 
2240
 
 
2241
        assert(key);
 
2242
 
 
2243
        length= snprintf(buffer, HUGE_STRING_LENGTH, "%.*s '%s'",
 
2244
                         (int)ptr->length, ptr->string, key);
 
2245
 
 
2246
        if (run_query(&con, &result, buffer, length))
2091
2247
        {
2092
2248
          fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
2093
 
                  my_progname, (uint)ptr->length, ptr->string, drizzle_error(&drizzle));
 
2249
                  my_progname, (uint32_t)length, buffer, drizzle_con_error(&con));
2094
2250
          exit(1);
2095
2251
        }
2096
2252
      }
2097
 
 
2098
 
      if (!opt_only_print)
2099
 
      {
2100
 
        do
2101
 
        {
2102
 
          if (drizzle_field_count(&drizzle))
2103
 
          {
2104
 
            result= drizzle_store_result(&drizzle);
2105
 
            while ((row = drizzle_fetch_row(result)))
2106
 
              counter++;
2107
 
            drizzle_free_result(result);
2108
 
          }
2109
 
        } while(drizzle_next_result(&drizzle) == 0);
2110
 
      }
2111
 
      queries++;
2112
 
 
2113
 
      if (commit_rate && (++commit_counter == commit_rate))
2114
 
      {
2115
 
        commit_counter= 0;
2116
 
        run_query(&drizzle, "COMMIT", strlen("COMMIT"));
2117
 
      }
2118
 
 
2119
 
      /* If the timer is set, and the alarm is not active then end */
2120
 
      if (opt_timer_length && timer_alarm == false)
2121
 
        goto end;
2122
 
 
2123
 
      /* If limit has been reached, and we are not in a timer_alarm just end */
2124
 
      if (con->limit && queries == con->limit && timer_alarm == false)
2125
 
        goto end;
2126
 
    }
2127
 
 
2128
 
    if (opt_timer_length && timer_alarm == true)
2129
 
      goto limit_not_met;
2130
 
 
2131
 
    if (con->limit && queries < con->limit)
2132
 
      goto limit_not_met;
 
2253
    }
 
2254
    else
 
2255
    {
 
2256
      if (run_query(&con, &result, ptr->string, ptr->length))
 
2257
      {
 
2258
        fprintf(stderr,"%s: Cannot run query %.*s ERROR : %s\n",
 
2259
                my_progname, (uint32_t)ptr->length, ptr->string, drizzle_con_error(&con));
 
2260
        exit(1);
 
2261
      }
 
2262
    }
 
2263
 
 
2264
    if (!opt_only_print)
 
2265
    {
 
2266
      while ((row = drizzle_row_next(&result)))
 
2267
        counter++;
 
2268
      drizzle_result_free(&result);
 
2269
    }
 
2270
    queries++;
 
2271
 
 
2272
    if (commit_rate && (++commit_counter == commit_rate))
 
2273
    {
 
2274
      commit_counter= 0;
 
2275
      run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
 
2276
    }
 
2277
 
 
2278
    /* If the timer is set, and the alarm is not active then end */
 
2279
    if (opt_timer_length && timer_alarm == false)
 
2280
      goto end;
 
2281
 
 
2282
    /* If limit has been reached, and we are not in a timer_alarm just end */
 
2283
    if (ctx->limit && queries == ctx->limit && timer_alarm == false)
 
2284
      goto end;
 
2285
  }
 
2286
 
 
2287
  if (opt_timer_length && timer_alarm == true)
 
2288
    goto limit_not_met;
 
2289
 
 
2290
  if (ctx->limit && queries < ctx->limit)
 
2291
    goto limit_not_met;
2133
2292
 
2134
2293
 
2135
2294
end:
2136
2295
  if (commit_rate)
2137
 
    run_query(&drizzle, "COMMIT", strlen("COMMIT"));
 
2296
    run_query(&con, NULL, "COMMIT", strlen("COMMIT"));
2138
2297
 
2139
 
  slap_close(&drizzle);
 
2298
  slap_close(&con);
2140
2299
 
2141
2300
  pthread_mutex_lock(&counter_mutex);
2142
2301
  thread_counter--;
2143
2302
  pthread_cond_signal(&count_threshhold);
2144
2303
  pthread_mutex_unlock(&counter_mutex);
2145
2304
 
2146
 
  my_free(con, MYF(0));
 
2305
  free(ctx);
2147
2306
 
2148
 
  drizzle_thread_end();
2149
2307
  return(0);
2150
2308
}
2151
2309
 
2161
2319
  char *end_ptr;
2162
2320
  option_string **sptr= stmt;
2163
2321
  option_string *tmp;
2164
 
  uint length= strlen(origin);
2165
 
  uint count= 0; /* We know that there is always one */
 
2322
  uint32_t length= strlen(origin);
 
2323
  uint32_t count= 0; /* We know that there is always one */
2166
2324
 
2167
2325
  end_ptr= (char *)origin + length;
2168
2326
 
2169
 
  tmp= *sptr= (option_string *)my_malloc(sizeof(option_string),
2170
 
                                         MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2327
  tmp= *sptr= (option_string *)malloc(sizeof(option_string));
 
2328
  if (tmp == NULL)
 
2329
  {
 
2330
    fprintf(stderr,"Error allocating memory while parsing options\n");
 
2331
    exit(1);
 
2332
  }
 
2333
  memset(tmp, 0, sizeof(option_string));
2171
2334
 
2172
2335
  for (begin_ptr= (char *)origin;
2173
2336
       begin_ptr != end_ptr;
2187
2350
    }
2188
2351
    else
2189
2352
    {
2190
 
      size_t length= strlen(begin_ptr);
2191
 
      memcpy(buffer, begin_ptr, length);
 
2353
      size_t begin_len= strlen(begin_ptr);
 
2354
      memcpy(buffer, begin_ptr, begin_len);
2192
2355
      begin_ptr= end_ptr;
2193
2356
    }
2194
2357
 
2200
2363
 
2201
2364
      /* Move past the : and the first string */
2202
2365
      tmp->option_length= strlen(buffer_ptr);
2203
 
      tmp->option= my_strndup(buffer_ptr, (uint)tmp->option_length,
2204
 
                              MYF(MY_FAE));
 
2366
      tmp->option= (char *)malloc(tmp->option_length + 1);
 
2367
      if (tmp->option == NULL)
 
2368
      {
 
2369
        fprintf(stderr,"Error allocating memory while parsing options\n");
 
2370
        exit(1);
 
2371
      }
 
2372
      memcpy(tmp->option, buffer_ptr, tmp->option_length);
 
2373
      tmp->option[tmp->option_length]= 0; 
2205
2374
    }
2206
2375
 
2207
 
    tmp->string= my_strndup(buffer, strlen(buffer), MYF(MY_FAE));
2208
2376
    tmp->length= strlen(buffer);
 
2377
    tmp->string= strdup(buffer);
 
2378
    if (tmp->string == NULL)
 
2379
    {
 
2380
      fprintf(stderr,"Error allocating memory while parsing options\n");
 
2381
      exit(1);
 
2382
    }
2209
2383
 
2210
2384
    if (isspace(*begin_ptr))
2211
2385
      begin_ptr++;
2213
2387
    count++;
2214
2388
 
2215
2389
    if (begin_ptr != end_ptr)
2216
 
      tmp->next= (option_string *)my_malloc(sizeof(option_string),
2217
 
                                            MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2390
    {
 
2391
      tmp->next= (option_string *)malloc(sizeof(option_string));
 
2392
      if (tmp->next == NULL)
 
2393
      {
 
2394
        fprintf(stderr,"Error allocating memory while parsing options\n");
 
2395
        exit(1);
 
2396
      }
 
2397
      memset(tmp->next, 0, sizeof(option_string));
 
2398
    }
 
2399
    
2218
2400
  }
2219
2401
 
2220
2402
  return count;
2232
2414
  char *ptr= (char *)script;
2233
2415
  statement **sptr= stmt;
2234
2416
  statement *tmp;
2235
 
  uint length= strlen(script);
2236
 
  uint count= 0; /* We know that there is always one */
 
2417
  uint32_t length= strlen(script);
 
2418
  uint32_t count= 0; /* We know that there is always one */
2237
2419
 
2238
 
  for (tmp= *sptr= (statement *)my_malloc(sizeof(statement),
2239
 
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2420
  for (tmp= *sptr= (statement *)calloc(1, sizeof(statement));
2240
2421
       (retstr= strchr(ptr, delm));
2241
 
       tmp->next=  (statement *)my_malloc(sizeof(statement),
2242
 
                                          MYF(MY_ZEROFILL|MY_FAE|MY_WME)),
 
2422
       tmp->next=  (statement *)calloc(1, sizeof(statement)),
2243
2423
       tmp= tmp->next)
2244
2424
  {
 
2425
    if (tmp == NULL)
 
2426
    {
 
2427
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
 
2428
      exit(1);
 
2429
    }
 
2430
 
2245
2431
    count++;
2246
 
    tmp->string= my_strndup(ptr, (uint)(retstr - ptr), MYF(MY_FAE));
2247
2432
    tmp->length= (size_t)(retstr - ptr);
 
2433
    tmp->string= (char *)malloc(tmp->length + 1);
 
2434
 
 
2435
    if (tmp->string == NULL)
 
2436
    {
 
2437
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
 
2438
      exit(1);
 
2439
    }
 
2440
 
 
2441
    memcpy(tmp->string, ptr, tmp->length);
 
2442
    tmp->string[tmp->length]= 0;
2248
2443
    ptr+= retstr - ptr + 1;
2249
2444
    if (isspace(*ptr))
2250
2445
      ptr++;
2252
2447
 
2253
2448
  if (ptr != script+length)
2254
2449
  {
2255
 
    tmp->string= my_strndup(ptr, (uint)((script + length) - ptr),
2256
 
                                       MYF(MY_FAE));
2257
2450
    tmp->length= (size_t)((script + length) - ptr);
 
2451
    tmp->string= (char *)malloc(tmp->length + 1);
 
2452
    if (tmp->string == NULL)
 
2453
    {
 
2454
      fprintf(stderr,"Error allocating memory while parsing delimiter\n");
 
2455
      exit(1);
 
2456
    }
 
2457
    memcpy(tmp->string, ptr, tmp->length);
 
2458
    tmp->string[tmp->length]= 0;
2258
2459
    count++;
2259
2460
  }
2260
2461
 
2268
2469
  In restrospect, this is a lousy name from this function.
2269
2470
*/
2270
2471
uint
2271
 
parse_comma(const char *string, uint **range)
 
2472
parse_comma(const char *string, uint32_t **range)
2272
2473
{
2273
 
  uint count= 1,x; /* We know that there is always one */
 
2474
  unsigned int count= 1,x; /* We know that there is always one */
2274
2475
  char *retstr;
2275
2476
  char *ptr= (char *)string;
2276
 
  uint *nptr;
 
2477
  unsigned int *nptr;
2277
2478
 
2278
2479
  for (;*ptr; ptr++)
2279
2480
    if (*ptr == ',') count++;
2280
 
 
 
2481
 
2281
2482
  /* One extra spot for the NULL */
2282
 
  nptr= *range= (uint *)my_malloc(sizeof(uint) * (count + 1),
2283
 
                                  MYF(MY_ZEROFILL|MY_FAE|MY_WME));
 
2483
  nptr= *range= (uint32_t *)malloc(sizeof(unsigned int) * (count + 1));
 
2484
  memset(nptr, 0, sizeof(unsigned int) * (count + 1));
2284
2485
 
2285
2486
  ptr= (char *)string;
2286
2487
  x= 0;
2299
2500
{
2300
2501
  printf("Benchmark\n");
2301
2502
  if (con->engine)
2302
 
      printf("\tRunning for engine %s\n", con->engine);
 
2503
    printf("\tRunning for engine %s\n", con->engine);
2303
2504
  if (opt_label || opt_auto_generate_sql_type)
2304
2505
  {
2305
2506
    const char *ptr= opt_auto_generate_sql_type ? opt_auto_generate_sql_type : "query";
2316
2517
  printf("\tTotal time for tests: %ld.%03ld seconds\n",
2317
2518
         con->sum_of_time / 1000, con->sum_of_time % 1000);
2318
2519
  printf("\tStandard Deviation: %ld.%03ld\n", con->std_dev / 1000, con->std_dev % 1000);
2319
 
  printf("\tNumber of queries in create queries: %llu\n", con->create_count);
 
2520
  printf("\tNumber of queries in create queries: %"PRIu64"\n", con->create_count);
2320
2521
  printf("\tNumber of clients running queries: %u/%u\n",
2321
2522
         con->users, con->real_users);
2322
2523
  printf("\tNumber of times test was run: %u\n", iterations);
2323
 
  printf("\tAverage number of queries per client: %llu\n", con->avg_rows);
 
2524
  printf("\tAverage number of queries per client: %"PRIu64"\n", con->avg_rows);
2324
2525
  printf("\n");
2325
2526
}
2326
2527
 
2362
2563
    snprintf(label_buffer, HUGE_STRING_LENGTH, "query");
2363
2564
 
2364
2565
  snprintf(buffer, HUGE_STRING_LENGTH,
2365
 
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%u,%u,%u,%llu\n",
 
2566
           "%s,%s,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,%ld.%03ld,"
 
2567
           "%u,%u,%u,%"PRIu64"\n",
2366
2568
           con->engine ? con->engine : "", /* Storage engine we ran against */
2367
2569
           label_buffer, /* Load type */
2368
2570
           con->avg_timing / 1000, con->avg_timing % 1000, /* Time to load */
2374
2576
           con->users, /* Children used max_timing */
2375
2577
           con->real_users, /* Children used max_timing */
2376
2578
           con->avg_rows  /* Queries run */
2377
 
          );
2378
 
  my_write(csv_file, (uchar*) buffer, (uint)strlen(buffer), MYF(0));
 
2579
           );
 
2580
  my_write(csv_file, (unsigned char*) buffer, (uint32_t)strlen(buffer), MYF(0));
2379
2581
}
2380
2582
 
2381
2583
void
2388
2590
  con->max_timing= sptr->timing;
2389
2591
  con->min_rows= sptr->rows;
2390
2592
  con->max_rows= sptr->rows;
2391
 
 
 
2593
 
2392
2594
  /* At the moment we assume uniform */
2393
2595
  con->users= sptr->users;
2394
2596
  con->real_users= sptr->real_users;
2395
2597
  con->avg_rows= sptr->rows;
2396
 
 
 
2598
 
2397
2599
  /* With no next, we know it is the last element that was malloced */
2398
2600
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2399
2601
  {
2417
2619
  /* Now we do the create time operations */
2418
2620
  con->create_min_timing= sptr->create_timing;
2419
2621
  con->create_max_timing= sptr->create_timing;
2420
 
 
 
2622
 
2421
2623
  /* At the moment we assume uniform */
2422
2624
  con->create_count= sptr->create_count;
2423
 
 
 
2625
 
2424
2626
  /* With no next, we know it is the last element that was malloced */
2425
2627
  for (ptr= sptr, x= 0; x < iterations; ptr++, x++)
2426
2628
  {
2445
2647
  {
2446
2648
    nptr= ptr->next;
2447
2649
    if (ptr->string)
2448
 
      my_free(ptr->string, MYF(0));
 
2650
      free(ptr->string);
2449
2651
    if (ptr->option)
2450
 
      my_free(ptr->option, MYF(0));
2451
 
    my_free(ptr, MYF(0));
 
2652
      free(ptr->option);
 
2653
    free(ptr);
2452
2654
  }
2453
2655
}
2454
2656
 
2463
2665
  {
2464
2666
    nptr= ptr->next;
2465
2667
    if (ptr->string)
2466
 
      my_free(ptr->string, MYF(0));
2467
 
    my_free(ptr, MYF(0));
 
2668
      free(ptr->string);
 
2669
    free(ptr);
2468
2670
  }
2469
2671
}
2470
2672
 
2471
2673
void
2472
 
slap_close(DRIZZLE *drizzle)
 
2674
slap_close(drizzle_con_st *con)
2473
2675
{
2474
2676
  if (opt_only_print)
2475
2677
    return;
2476
2678
 
2477
 
  drizzle_close(drizzle);
 
2679
  drizzle_free(drizzle_con_drizzle(con));
2478
2680
}
2479
2681
 
2480
2682
void
2481
 
slap_connect(DRIZZLE *drizzle, bool connect_to_schema)
 
2683
slap_connect(drizzle_con_st *con, bool connect_to_schema)
2482
2684
{
2483
2685
  /* Connect to server */
2484
2686
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
2485
2687
  int x, connect_error= 1;
 
2688
  drizzle_return_t ret;
 
2689
  drizzle_st *drizzle;
2486
2690
 
2487
2691
  if (opt_only_print)
2488
2692
    return;
2489
2693
 
2490
2694
  if (opt_delayed_start)
2491
 
    my_sleep(random()%opt_delayed_start);
2492
 
 
2493
 
  drizzle_create(drizzle);
2494
 
 
2495
 
  if (opt_compress)
2496
 
    drizzle_options(drizzle,DRIZZLE_OPT_COMPRESS,NullS);
2497
 
  /* We always do opt_protocol to TCP/IP */
2498
 
  drizzle_options(drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
2499
 
  drizzle_options(drizzle, DRIZZLE_SET_CHARSET_NAME, default_charset);
 
2695
    usleep(random()%opt_delayed_start);
 
2696
 
 
2697
  if ((drizzle= drizzle_create(NULL)) == NULL ||
 
2698
      drizzle_con_add_tcp(drizzle, con, host, opt_drizzle_port, user,
 
2699
                          opt_password,
 
2700
                          connect_to_schema ? create_schema_string : NULL,
 
2701
                          DRIZZLE_CON_NONE) == NULL)
 
2702
  {
 
2703
    fprintf(stderr,"%s: Error creating drizzle object\n", my_progname);
 
2704
    exit(1);
 
2705
  }
2500
2706
 
2501
2707
  for (x= 0; x < 10; x++)
2502
2708
  {
2503
 
 
2504
 
 
2505
 
    if (drizzle_connect(drizzle, host, user, opt_password,
2506
 
                           connect_to_schema ? create_schema_string : NULL,
2507
 
                           opt_drizzle_port,
2508
 
                           opt_drizzle_unix_port,
2509
 
                           connect_flags))
 
2709
    if ((ret= drizzle_con_connect(con)) == DRIZZLE_RETURN_OK)
2510
2710
    {
2511
2711
      /* Connect suceeded */
2512
2712
      connect_error= 0;
2513
2713
      break;
2514
2714
    }
2515
 
    my_sleep(connection_retry_sleep);
 
2715
    usleep(connection_retry_sleep);
2516
2716
  }
2517
2717
  if (connect_error)
2518
2718
  {
2519
 
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n",
2520
 
            my_progname, drizzle_errno(drizzle), drizzle_error(drizzle));
 
2719
    fprintf(stderr,"%s: Error when connecting to server: %d %s\n", my_progname,
 
2720
            ret, drizzle_con_error(con));
2521
2721
    exit(1);
2522
2722
  }
2523
2723
 
2529
2729
{
2530
2730
  unsigned int x;
2531
2731
  long int sum_of_squares;
2532
 
  double catch;
 
2732
  double the_catch;
2533
2733
  stats *ptr;
2534
2734
 
2535
2735
  if (iterations == 1 || iterations == 0)
2546
2746
    sum_of_squares+= deviation*deviation;
2547
2747
  }
2548
2748
 
2549
 
  catch= sqrt((double)(sum_of_squares/(iterations -1)));
2550
 
  con->std_dev= (long int)catch;
 
2749
  the_catch= sqrt((double)(sum_of_squares/(iterations -1)));
 
2750
  con->std_dev= (long int)the_catch;
2551
2751
}