~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/mysqltest.c

  • Committer: Monty Taylor
  • Date: 2008-07-02 18:52:40 UTC
  • mfrom: (46 drizzle)
  • mto: This revision was merged to the branch mainline in revision 51.
  • Revision ID: monty@inaugust.com-20080702185240-dina7cb94k7rjl1a
Merged from trunk. Changed a test return value so that the test passes. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
static my_bool debug_info_flag= 0, debug_check_flag= 0;
75
75
static my_bool tty_password= 0;
76
76
static my_bool opt_mark_progress= 0;
77
 
static my_bool ps_protocol= 0, ps_protocol_enabled= 0;
78
 
static my_bool sp_protocol= 0, sp_protocol_enabled= 0;
79
 
static my_bool view_protocol= 0, view_protocol_enabled= 0;
80
77
static my_bool cursor_protocol= 0, cursor_protocol_enabled= 0;
81
78
static my_bool parsing_disabled= 0;
82
79
static my_bool display_result_vertically= FALSE,
156
153
 
157
154
static ulonglong progress_start= 0;
158
155
 
159
 
/* Precompiled re's */
160
 
static my_regex_t ps_re;     /* the query can be run using PS protocol */
161
 
static my_regex_t sp_re;     /* the query can be run as a SP */
162
 
static my_regex_t view_re;   /* the query can be run as a view*/
163
 
 
164
 
static void init_re(void);
165
 
static int match_re(my_regex_t *, char *);
166
156
static void free_re(void);
167
157
 
168
158
DYNAMIC_ARRAY q_lines;
320
310
  "start_timer",
321
311
  "end_timer",
322
312
  "character_set",
323
 
  "disable_ps_protocol",
324
 
  "enable_ps_protocol",
325
313
  "disable_reconnect",
326
314
  "enable_reconnect",
327
315
  "if",
4939
4927
  {"compress", 'C', "Use the compressed server/client protocol.",
4940
4928
   (uchar**) &opt_compress, (uchar**) &opt_compress, 0, GET_BOOL, NO_ARG, 0, 0, 0,
4941
4929
   0, 0, 0},
4942
 
  {"cursor-protocol", OPT_CURSOR_PROTOCOL, "Use cursors for prepared statements.",
4943
 
   (uchar**) &cursor_protocol, (uchar**) &cursor_protocol, 0,
4944
 
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4945
4930
  {"database", 'D', "Database to use.", (uchar**) &opt_db, (uchar**) &opt_db, 0,
4946
4931
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4947
4932
#ifdef DBUG_OFF
4981
4966
   "built-in default (" STRINGIFY_ARG(MYSQL_PORT) ").",
4982
4967
   (uchar**) &opt_port,
4983
4968
   (uchar**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4984
 
  {"protocol", OPT_MYSQL_PROTOCOL,
4985
 
    "The protocol of connection (tcp,socket,pipe,memory).",
4986
 
    0, 0, 0, GET_STR,  REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4987
 
  {"ps-protocol", OPT_PS_PROTOCOL, "Use prepared statements protocol for communication",
4988
 
   (uchar**) &ps_protocol, (uchar**) &ps_protocol, 0,
4989
 
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4990
4969
  {"quiet", 's', "Suppress all normal output.", (uchar**) &silent,
4991
4970
   (uchar**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4992
4971
  {"record", 'r', "Record output of test_file into result file.",
5003
4982
  {"sleep", 'T', "Sleep always this many seconds on sleep commands.",
5004
4983
   (uchar**) &opt_sleep, (uchar**) &opt_sleep, 0, GET_INT, REQUIRED_ARG, -1, -1, 0,
5005
4984
   0, 0, 0},
5006
 
  {"socket", 'S', "Socket file to use for connection.",
5007
 
   (uchar**) &unix_sock, (uchar**) &unix_sock, 0, GET_STR, REQUIRED_ARG, 0, 0, 0,
5008
 
   0, 0, 0},
5009
 
  {"sp-protocol", OPT_SP_PROTOCOL, "Use stored procedures for select",
5010
 
   (uchar**) &sp_protocol, (uchar**) &sp_protocol, 0,
5011
 
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
5012
4985
  {"tail-lines", OPT_TAIL_LINES,
5013
4986
   "Number of lines of the resul to include in a failure report",
5014
4987
   (uchar**) &opt_tail_lines, (uchar**) &opt_tail_lines, 0,
5025
4998
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
5026
4999
  {"version", 'V', "Output version information and exit.",
5027
5000
   0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0},
5028
 
  {"view-protocol", OPT_VIEW_PROTOCOL, "Use views for select",
5029
 
   (uchar**) &view_protocol, (uchar**) &view_protocol, 0,
5030
 
   GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
5031
5001
  { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
5032
5002
};
5033
5003
 
6106
6076
  DYNAMIC_STRING eval_query;
6107
6077
  char *query;
6108
6078
  int query_len;
6109
 
  my_bool view_created= 0, sp_created= 0;
6110
6079
  my_bool complete_query= ((flags & QUERY_SEND_FLAG) &&
6111
6080
                           (flags & QUERY_REAP_FLAG));
6112
6081
  DBUG_ENTER("run_query");
6156
6125
    dynstr_append_mem(ds, "\n", 1);
6157
6126
  }
6158
6127
 
6159
 
  if (view_protocol_enabled &&
6160
 
      complete_query &&
6161
 
      match_re(&view_re, query))
6162
 
  {
6163
 
    /*
6164
 
      Create the query as a view.
6165
 
      Use replace since view can exist from a failed mysqltest run
6166
 
    */
6167
 
    DYNAMIC_STRING query_str;
6168
 
    init_dynamic_string(&query_str,
6169
 
                        "CREATE OR REPLACE VIEW mysqltest_tmp_v AS ",
6170
 
                        query_len+64, 256);
6171
 
    dynstr_append_mem(&query_str, query, query_len);
6172
 
    if (util_query(mysql, query_str.str))
6173
 
    {
6174
 
      /*
6175
 
        Failed to create the view, this is not fatal
6176
 
        just run the query the normal way
6177
 
      */
6178
 
      DBUG_PRINT("view_create_error",
6179
 
                 ("Failed to create view '%s': %d: %s", query_str.str,
6180
 
                  mysql_errno(mysql), mysql_error(mysql)));
6181
 
 
6182
 
      /* Log error to create view */
6183
 
      verbose_msg("Failed to create view '%s' %d: %s", query_str.str,
6184
 
                  mysql_errno(mysql), mysql_error(mysql));
6185
 
    }
6186
 
    else
6187
 
    {
6188
 
      /*
6189
 
        Yes, it was possible to create this query as a view
6190
 
      */
6191
 
      view_created= 1;
6192
 
      query= (char*)"SELECT * FROM mysqltest_tmp_v";
6193
 
      query_len = strlen(query);
6194
 
 
6195
 
      /*
6196
 
        Collect warnings from create of the view that should otherwise
6197
 
        have been produced when the SELECT was executed
6198
 
      */
6199
 
      append_warnings(&ds_warnings, cur_con->util_mysql);
6200
 
    }
6201
 
 
6202
 
    dynstr_free(&query_str);
6203
 
 
6204
 
  }
6205
 
 
6206
 
  if (sp_protocol_enabled &&
6207
 
      complete_query &&
6208
 
      match_re(&sp_re, query))
6209
 
  {
6210
 
    /*
6211
 
      Create the query as a stored procedure
6212
 
      Drop first since sp can exist from a failed mysqltest run
6213
 
    */
6214
 
    DYNAMIC_STRING query_str;
6215
 
    init_dynamic_string(&query_str,
6216
 
                        "DROP PROCEDURE IF EXISTS mysqltest_tmp_sp;",
6217
 
                        query_len+64, 256);
6218
 
    util_query(mysql, query_str.str);
6219
 
    dynstr_set(&query_str, "CREATE PROCEDURE mysqltest_tmp_sp()\n");
6220
 
    dynstr_append_mem(&query_str, query, query_len);
6221
 
    if (util_query(mysql, query_str.str))
6222
 
    {
6223
 
      /*
6224
 
        Failed to create the stored procedure for this query,
6225
 
        this is not fatal just run the query the normal way
6226
 
      */
6227
 
      DBUG_PRINT("sp_create_error",
6228
 
                 ("Failed to create sp '%s': %d: %s", query_str.str,
6229
 
                  mysql_errno(mysql), mysql_error(mysql)));
6230
 
 
6231
 
      /* Log error to create sp */
6232
 
      verbose_msg("Failed to create sp '%s' %d: %s", query_str.str,
6233
 
                  mysql_errno(mysql), mysql_error(mysql));
6234
 
 
6235
 
    }
6236
 
    else
6237
 
    {
6238
 
      sp_created= 1;
6239
 
 
6240
 
      query= (char*)"CALL mysqltest_tmp_sp()";
6241
 
      query_len = strlen(query);
6242
 
    }
6243
 
    dynstr_free(&query_str);
6244
 
  }
6245
 
 
6246
6128
  if (display_result_sorted)
6247
6129
  {
6248
6130
    /*
6256
6138
  }
6257
6139
 
6258
6140
  /*
6259
 
    Find out how to run this query
6260
 
 
6261
6141
    Always run with normal C API if it's not a complete
6262
6142
    SEND + REAP
6263
 
 
6264
 
    If it is a '?' in the query it may be a SQL level prepared
6265
 
    statement already and we can't do it twice
6266
6143
  */
6267
 
  if (ps_protocol_enabled &&
6268
 
      complete_query &&
6269
 
      match_re(&ps_re, query))
6270
 
    run_query_stmt(mysql, command, query, query_len, ds, &ds_warnings);
6271
 
  else
6272
 
    run_query_normal(cn, command, flags, query, query_len,
6273
 
                     ds, &ds_warnings);
 
6144
  run_query_normal(cn, command, flags, query, query_len,
 
6145
                   ds, &ds_warnings);
6274
6146
 
6275
6147
  if (display_result_sorted)
6276
6148
  {
6280
6152
    dynstr_free(&ds_sorted);
6281
6153
  }
6282
6154
 
6283
 
  if (sp_created)
6284
 
  {
6285
 
    if (util_query(mysql, "DROP PROCEDURE mysqltest_tmp_sp "))
6286
 
      die("Failed to drop sp: %d: %s", mysql_errno(mysql), mysql_error(mysql));
6287
 
  }
6288
 
 
6289
 
  if (view_created)
6290
 
  {
6291
 
    if (util_query(mysql, "DROP VIEW mysqltest_tmp_v "))
6292
 
      die("Failed to drop view: %d: %s",
6293
 
          mysql_errno(mysql), mysql_error(mysql));
6294
 
  }
6295
 
 
6296
6155
  if (command->require_file[0])
6297
6156
  {
6298
6157
    /* A result file was specified for _this_ query
6315
6174
  Functions to detect different SQL statements
6316
6175
*/
6317
6176
 
6318
 
char *re_eprint(int err)
6319
 
{
6320
 
  static char epbuf[100];
6321
 
  size_t len= my_regerror(REG_ITOA|err, (my_regex_t *)NULL,
6322
 
                          epbuf, sizeof(epbuf));
6323
 
  assert(len <= sizeof(epbuf));
6324
 
  return(epbuf);
6325
 
}
6326
 
 
6327
 
void init_re_comp(my_regex_t *re, const char* str)
6328
 
{
6329
 
  int err= my_regcomp(re, str, (REG_EXTENDED | REG_ICASE | REG_NOSUB),
6330
 
                      &my_charset_latin1);
6331
 
  if (err)
6332
 
  {
6333
 
    char erbuf[100];
6334
 
    int len= my_regerror(err, re, erbuf, sizeof(erbuf));
6335
 
    die("error %s, %d/%d `%s'\n",
6336
 
        re_eprint(err), len, (int)sizeof(erbuf), erbuf);
6337
 
  }
6338
 
}
6339
 
 
6340
 
void init_re(void)
6341
 
{
6342
 
  /*
6343
 
    Filter for queries that can be run using the
6344
 
    MySQL Prepared Statements C API
6345
 
  */
6346
 
  const char *ps_re_str =
6347
 
    "^("
6348
 
    "[[:space:]]*REPLACE[[:space:]]|"
6349
 
    "[[:space:]]*INSERT[[:space:]]|"
6350
 
    "[[:space:]]*UPDATE[[:space:]]|"
6351
 
    "[[:space:]]*DELETE[[:space:]]|"
6352
 
    "[[:space:]]*SELECT[[:space:]]|"
6353
 
    "[[:space:]]*CREATE[[:space:]]+TABLE[[:space:]]|"
6354
 
    "[[:space:]]*DO[[:space:]]|"
6355
 
    "[[:space:]]*SET[[:space:]]+OPTION[[:space:]]|"
6356
 
    "[[:space:]]*DELETE[[:space:]]+MULTI[[:space:]]|"
6357
 
    "[[:space:]]*UPDATE[[:space:]]+MULTI[[:space:]]|"
6358
 
    "[[:space:]]*INSERT[[:space:]]+SELECT[[:space:]])";
6359
 
 
6360
 
  /*
6361
 
    Filter for queries that can be run using the
6362
 
    Stored procedures
6363
 
  */
6364
 
  const char *sp_re_str =ps_re_str;
6365
 
 
6366
 
  /*
6367
 
    Filter for queries that can be run as views
6368
 
  */
6369
 
  const char *view_re_str =
6370
 
    "^("
6371
 
    "[[:space:]]*SELECT[[:space:]])";
6372
 
 
6373
 
  init_re_comp(&ps_re, ps_re_str);
6374
 
  init_re_comp(&sp_re, sp_re_str);
6375
 
  init_re_comp(&view_re, view_re_str);
6376
 
}
6377
 
 
6378
 
 
6379
 
int match_re(my_regex_t *re, char *str)
6380
 
{
6381
 
  int err= my_regexec(re, str, (size_t)0, NULL, 0);
6382
 
 
6383
 
  if (err == 0)
6384
 
    return 1;
6385
 
  else if (err == REG_NOMATCH)
6386
 
    return 0;
6387
 
 
6388
 
  {
6389
 
    char erbuf[100];
6390
 
    int len= my_regerror(err, re, erbuf, sizeof(erbuf));
6391
 
    die("error %s, %d/%d `%s'\n",
6392
 
        re_eprint(err), len, (int)sizeof(erbuf), erbuf);
6393
 
  }
6394
 
  return 0;
6395
 
}
6396
 
 
6397
6177
void free_re(void)
6398
6178
{
6399
 
  my_regfree(&ps_re);
6400
 
  my_regfree(&sp_re);
6401
 
  my_regfree(&view_re);
6402
6179
  my_regex_end();
6403
6180
}
6404
6181
 
6586
6363
  init_dynamic_string(&ds_warning_messages, "", 0, 2048);
6587
6364
  parse_args(argc, argv);
6588
6365
 
6589
 
  var_set_int("$PS_PROTOCOL", ps_protocol);
6590
 
  var_set_int("$SP_PROTOCOL", sp_protocol);
6591
 
  var_set_int("$VIEW_PROTOCOL", view_protocol);
6592
 
  var_set_int("$CURSOR_PROTOCOL", cursor_protocol);
6593
 
 
6594
6366
  DBUG_PRINT("info",("result_file: '%s'",
6595
6367
                     result_file_name ? result_file_name : ""));
6596
6368
  if (mysql_server_init(embedded_server_arg_count,
6604
6376
    cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
6605
6377
    cur_file->lineno= 1;
6606
6378
  }
6607
 
  init_re();
6608
 
  ps_protocol_enabled= ps_protocol;
6609
 
  sp_protocol_enabled= sp_protocol;
6610
 
  view_protocol_enabled= view_protocol;
6611
 
  cursor_protocol_enabled= cursor_protocol;
6612
 
  /* Cursor protcol implies ps protocol */
6613
 
  if (cursor_protocol_enabled)
6614
 
    ps_protocol_enabled= 1;
6615
 
 
6616
6379
  cur_con= connections;
6617
6380
  if (!( mysql_init(&cur_con->mysql)))
6618
6381
    die("Failed in mysql_init()");
6627
6390
    mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR,
6628
6391
                  opt_charsets_dir);
6629
6392
 
6630
 
#if defined(HAVE_OPENSSL) && !defined(EMBEDDED_LIBRARY)
6631
 
 
6632
 
  if (opt_use_ssl)
6633
 
  {
6634
 
    mysql_ssl_set(&cur_con->mysql, opt_ssl_key, opt_ssl_cert, opt_ssl_ca,
6635
 
                  opt_ssl_capath, opt_ssl_cipher);
6636
 
#if MYSQL_VERSION_ID >= 50000
6637
 
    /* Turn on ssl_verify_server_cert only if host is "localhost" */
6638
 
    opt_ssl_verify_server_cert= opt_host && !strcmp(opt_host, "localhost");
6639
 
    mysql_options(&cur_con->mysql, MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
6640
 
                  &opt_ssl_verify_server_cert);
6641
 
#endif
6642
 
  }
6643
 
#endif
6644
 
 
6645
6393
  if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
6646
6394
    die("Out of memory");
6647
6395
 
6862
6610
      case Q_CHARACTER_SET:
6863
6611
        do_set_charset(command);
6864
6612
        break;
6865
 
      case Q_DISABLE_PS_PROTOCOL:
6866
 
        ps_protocol_enabled= 0;
6867
 
        /* Close any open statements */
6868
 
        close_statements();
6869
 
        break;
6870
 
      case Q_ENABLE_PS_PROTOCOL:
6871
 
        ps_protocol_enabled= ps_protocol;
6872
 
        break;
6873
6613
      case Q_DISABLE_RECONNECT:
6874
6614
        set_reconnect(&cur_con->mysql, 0);
6875
6615
        break;