~mdcallag/+junk/5.1-map

« back to all changes in this revision

Viewing changes to tests/mysql_client_test.c

  • Committer: msvensson at pilot
  • Date: 2007-04-24 09:11:45 UTC
  • mfrom: (2469.1.106)
  • Revision ID: sp1r-msvensson@pilot.blaudden-20070424091145-10463
Merge pilot.blaudden:/home/msvensson/mysql/my51-m-mysql_upgrade
into  pilot.blaudden:/home/msvensson/mysql/mysql-5.1-maint

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
};
84
84
 
85
85
#define myheader(str) \
 
86
DBUG_PRINT("test", ("name: %s", str));        \
86
87
if (opt_silent < 2) \
87
88
{ \
88
89
  fprintf(stdout, "\n\n#####################################\n"); \
89
 
  fprintf(stdout, "%d of (%d/%d): %s", test_count++, iter_count, \
 
90
  fprintf(stdout, "%u of (%u/%u): %s", test_count++, iter_count, \
90
91
                                     opt_count, str); \
91
92
  fprintf(stdout, "  \n#####################################\n"); \
92
93
}
 
94
 
93
95
#define myheader_r(str) \
 
96
DBUG_PRINT("test", ("name: %s", str));        \
94
97
if (!opt_silent) \
95
98
{ \
96
99
  fprintf(stdout, "\n\n#####################################\n"); \
100
103
 
101
104
static void print_error(const char *msg);
102
105
static void print_st_error(MYSQL_STMT *stmt, const char *msg);
103
 
static void client_disconnect();
 
106
static void client_disconnect(void);
104
107
 
105
108
 
106
109
/*
119
122
#define DIE(expr) \
120
123
        die(__FILE__, __LINE__, #expr)
121
124
 
122
 
void die(const char *file, int line, const char *expr)
 
125
static void die(const char *file, int line, const char *expr)
123
126
{
124
127
  fflush(stdout);
125
128
  fprintf(stderr, "%s:%d: check failed: '%s'\n", file, line, expr);
253
256
  mysql_simple_prepare(): a variant without the 'length' parameter.
254
257
*/
255
258
 
256
 
MYSQL_STMT *STDCALL
 
259
static MYSQL_STMT *STDCALL
257
260
mysql_simple_prepare(MYSQL *mysql_arg, const char *query)
258
261
{
259
262
  MYSQL_STMT *stmt= mysql_stmt_init(mysql_arg);
298
301
  mysql->reconnect= 1;
299
302
 
300
303
  if (!opt_silent)
301
 
    fprintf(stdout, " OK");
 
304
    fprintf(stdout, "OK");
302
305
 
303
306
  /* set AUTOCOMMIT to ON*/
304
307
  mysql_autocommit(mysql, TRUE);
321
324
  have_innodb= check_have_innodb(mysql);
322
325
 
323
326
  if (!opt_silent)
324
 
    fprintf(stdout, " OK");
 
327
    fprintf(stdout, "OK");
325
328
}
326
329
 
327
330
 
341
344
 
342
345
    mysql_query(mysql, query);
343
346
    if (!opt_silent)
344
 
      fprintf(stdout, " OK");
 
347
      fprintf(stdout, "OK");
345
348
 
346
349
    if (!opt_silent)
347
350
      fprintf(stdout, "\n closing the connection ...");
348
351
    mysql_close(mysql);
349
 
    fprintf(stdout, " OK\n");
 
352
    if (!opt_silent)
 
353
      fprintf(stdout, "OK\n");
350
354
  }
351
355
}
352
356
 
468
472
 
469
473
/* Process the result set */
470
474
 
471
 
int my_process_result_set(MYSQL_RES *result)
 
475
static int my_process_result_set(MYSQL_RES *result)
472
476
{
473
477
  MYSQL_ROW    row;
474
478
  MYSQL_FIELD  *field;
524
528
}
525
529
 
526
530
 
527
 
int my_process_result(MYSQL *mysql_arg)
 
531
static int my_process_result(MYSQL *mysql_arg)
528
532
{
529
533
  MYSQL_RES *result;
530
534
  int       row_count;
544
548
#define MAX_RES_FIELDS 50
545
549
#define MAX_FIELD_DATA_SIZE 255
546
550
 
547
 
int my_process_stmt_result(MYSQL_STMT *stmt)
 
551
static int my_process_stmt_result(MYSQL_STMT *stmt)
548
552
{
549
553
  int         field_count;
550
554
  int         row_count= 0;
2354
2358
}
2355
2359
 
2356
2360
 
 
2361
/* reads Qcache_hits from server and returns its value */
 
2362
static uint query_cache_hits(MYSQL *conn)
 
2363
{
 
2364
  MYSQL_RES *res;
 
2365
  MYSQL_ROW row;
 
2366
  int rc;
 
2367
  uint result;
 
2368
 
 
2369
  rc= mysql_query(conn, "show status like 'qcache_hits'");
 
2370
  myquery(rc);
 
2371
  res= mysql_use_result(conn);
 
2372
  DIE_UNLESS(res);
 
2373
 
 
2374
  row= mysql_fetch_row(res);
 
2375
  DIE_UNLESS(row);
 
2376
 
 
2377
  result= atoi(row[1]);
 
2378
  mysql_free_result(res);
 
2379
  return result;
 
2380
}
 
2381
 
 
2382
 
 
2383
/*
 
2384
  utility for the next test; expects 3 rows in the result from a SELECT,
 
2385
  compares each row/field with an expected value.
 
2386
 */
 
2387
#define test_ps_query_cache_result(i1,s1,l1,i2,s2,l2,i3,s3,l3)    \
 
2388
  r_metadata= mysql_stmt_result_metadata(stmt);                   \
 
2389
  DIE_UNLESS(r_metadata != NULL);                                 \
 
2390
  rc= mysql_stmt_fetch(stmt);                                     \
 
2391
  check_execute(stmt, rc);                                        \
 
2392
  if (!opt_silent)                                                \
 
2393
    fprintf(stdout, "\n row 1: %d, %s(%lu)", r_int_data,          \
 
2394
            r_str_data, r_str_length);                            \
 
2395
  DIE_UNLESS((r_int_data == i1) && (r_str_length == l1) &&        \
 
2396
             (strcmp(r_str_data, s1) == 0));                      \
 
2397
  rc= mysql_stmt_fetch(stmt);                                     \
 
2398
  check_execute(stmt, rc);                                        \
 
2399
  if (!opt_silent)                                                \
 
2400
    fprintf(stdout, "\n row 2: %d, %s(%lu)", r_int_data,          \
 
2401
            r_str_data, r_str_length);                            \
 
2402
  DIE_UNLESS((r_int_data == i2) && (r_str_length == l2) &&        \
 
2403
             (strcmp(r_str_data, s2) == 0));                      \
 
2404
  rc= mysql_stmt_fetch(stmt);                                     \
 
2405
  check_execute(stmt, rc);                                        \
 
2406
  if (!opt_silent)                                                \
 
2407
    fprintf(stdout, "\n row 3: %d, %s(%lu)", r_int_data,          \
 
2408
            r_str_data, r_str_length);                            \
 
2409
  DIE_UNLESS((r_int_data == i3) && (r_str_length == l3) &&        \
 
2410
             (strcmp(r_str_data, s3) == 0));                      \
 
2411
  rc= mysql_stmt_fetch(stmt);                                     \
 
2412
  DIE_UNLESS(rc == MYSQL_NO_DATA);                                \
 
2413
  mysql_free_result(r_metadata);
 
2414
 
 
2415
 
 
2416
/*
 
2417
  Test that prepared statements make use of the query cache just as normal
 
2418
  statements (BUG#735).
 
2419
*/
 
2420
static void test_ps_query_cache()
 
2421
{
 
2422
  MYSQL      *org_mysql= mysql, *lmysql;
 
2423
  MYSQL_STMT *stmt;
 
2424
  int        rc;
 
2425
  MYSQL_BIND p_bind[2],r_bind[2]; /* p: param bind; r: result bind */
 
2426
  int32      p_int_data, r_int_data;
 
2427
  char       p_str_data[32], r_str_data[32];
 
2428
  unsigned long p_str_length, r_str_length;
 
2429
  MYSQL_RES  *r_metadata;
 
2430
  char       query[MAX_TEST_QUERY_LENGTH];
 
2431
  uint       hits1, hits2;
 
2432
  enum enum_test_ps_query_cache
 
2433
  {
 
2434
    /*
 
2435
      We iterate the same prepare/executes block, but have iterations where
 
2436
      we vary the query cache conditions.
 
2437
    */
 
2438
    /* the query cache is enabled for the duration of prep&execs: */
 
2439
    TEST_QCACHE_ON= 0,
 
2440
    /*
 
2441
      same but using a new connection (to see if qcache serves results from
 
2442
      the previous connection as it should):
 
2443
    */
 
2444
    TEST_QCACHE_ON_WITH_OTHER_CONN,
 
2445
    /*
 
2446
      First border case: disables the query cache before prepare and
 
2447
      re-enables it before execution (to test if we have no bug then):
 
2448
    */
 
2449
    TEST_QCACHE_OFF_ON,
 
2450
    /*
 
2451
      Second border case: enables the query cache before prepare and
 
2452
      disables it before execution:
 
2453
    */
 
2454
    TEST_QCACHE_ON_OFF
 
2455
  };
 
2456
  enum enum_test_ps_query_cache iteration;
 
2457
  LINT_INIT(lmysql);
 
2458
 
 
2459
  myheader("test_ps_query_cache");
 
2460
 
 
2461
  /* prepare the table */
 
2462
 
 
2463
  rc= mysql_query(mysql, "drop table if exists t1");
 
2464
  myquery(rc);
 
2465
 
 
2466
  rc= mysql_query(mysql, "create table t1 (id1 int(11) NOT NULL default '0', "
 
2467
                         "value2 varchar(100), value1 varchar(100))");
 
2468
  myquery(rc);
 
2469
 
 
2470
  rc= mysql_query(mysql, "insert into t1 values (1, 'hh', 'hh'), "
 
2471
                          "(2, 'hh', 'hh'), (1, 'ii', 'ii'), (2, 'ii', 'ii')");
 
2472
  myquery(rc);
 
2473
 
 
2474
  for (iteration= TEST_QCACHE_ON; iteration < TEST_QCACHE_ON_OFF; iteration++)
 
2475
  {
 
2476
 
 
2477
    switch (iteration)
 
2478
    {
 
2479
    case TEST_QCACHE_ON:
 
2480
    case TEST_QCACHE_ON_OFF:
 
2481
      rc= mysql_query(mysql, "set global query_cache_size=1000000");
 
2482
      myquery(rc);
 
2483
      break;
 
2484
    case TEST_QCACHE_OFF_ON:
 
2485
      rc= mysql_query(mysql, "set global query_cache_size=0");
 
2486
      myquery(rc);
 
2487
      break;
 
2488
    case TEST_QCACHE_ON_WITH_OTHER_CONN:
 
2489
      if (!opt_silent)
 
2490
        fprintf(stdout, "\n Establishing a test connection ...");
 
2491
      if (!(lmysql= mysql_init(NULL)))
 
2492
      {
 
2493
        myerror("mysql_init() failed");
 
2494
        exit(1);
 
2495
      }
 
2496
      if (!(mysql_real_connect(lmysql, opt_host, opt_user,
 
2497
                               opt_password, current_db, opt_port,
 
2498
                               opt_unix_socket, 0)))
 
2499
      {
 
2500
        myerror("connection failed");
 
2501
        mysql_close(lmysql);
 
2502
        exit(1);
 
2503
      }
 
2504
      if (!opt_silent)
 
2505
        fprintf(stdout, "OK");
 
2506
      mysql= lmysql;
 
2507
    }
 
2508
 
 
2509
    strmov(query, "select id1, value1 from t1 where id1= ? or "
 
2510
           "CONVERT(value1 USING utf8)= ?");
 
2511
    stmt= mysql_simple_prepare(mysql, query);
 
2512
    check_stmt(stmt);
 
2513
 
 
2514
    verify_param_count(stmt, 2);
 
2515
 
 
2516
    switch(iteration)
 
2517
    {
 
2518
    case TEST_QCACHE_OFF_ON:
 
2519
      rc= mysql_query(mysql, "set global query_cache_size=1000000");
 
2520
      myquery(rc);
 
2521
      break;
 
2522
    case TEST_QCACHE_ON_OFF:
 
2523
      rc= mysql_query(mysql, "set global query_cache_size=0");
 
2524
      myquery(rc);
 
2525
    default:
 
2526
      break;
 
2527
    }
 
2528
 
 
2529
    bzero((char*) p_bind, sizeof(p_bind));
 
2530
    p_bind[0].buffer_type= MYSQL_TYPE_LONG;
 
2531
    p_bind[0].buffer= (void *)&p_int_data;
 
2532
    p_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
 
2533
    p_bind[1].buffer= (void *)p_str_data;
 
2534
    p_bind[1].buffer_length= array_elements(p_str_data);
 
2535
    p_bind[1].length= &p_str_length;
 
2536
 
 
2537
    rc= mysql_stmt_bind_param(stmt, p_bind);
 
2538
    check_execute(stmt, rc);
 
2539
 
 
2540
    p_int_data= 1;
 
2541
    strmov(p_str_data, "hh");
 
2542
    p_str_length= strlen(p_str_data);
 
2543
 
 
2544
    bzero((char*) r_bind, sizeof(r_bind));
 
2545
    r_bind[0].buffer_type= MYSQL_TYPE_LONG;
 
2546
    r_bind[0].buffer= (void *)&r_int_data;
 
2547
    r_bind[1].buffer_type= MYSQL_TYPE_VAR_STRING;
 
2548
    r_bind[1].buffer= (void *)r_str_data;
 
2549
    r_bind[1].buffer_length= array_elements(r_str_data);
 
2550
    r_bind[1].length= &r_str_length;
 
2551
 
 
2552
    rc= mysql_stmt_bind_result(stmt, r_bind);
 
2553
    check_execute(stmt, rc);
 
2554
 
 
2555
    rc= mysql_stmt_execute(stmt);
 
2556
    check_execute(stmt, rc);
 
2557
 
 
2558
    test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2);
 
2559
 
 
2560
    /* now retry with the same parameter values and see qcache hits */
 
2561
    hits1= query_cache_hits(mysql);
 
2562
    rc= mysql_stmt_execute(stmt);
 
2563
    check_execute(stmt, rc);
 
2564
    test_ps_query_cache_result(1, "hh", 2, 2, "hh", 2, 1, "ii", 2);
 
2565
    hits2= query_cache_hits(mysql);
 
2566
    switch(iteration)
 
2567
    {
 
2568
    case TEST_QCACHE_ON_WITH_OTHER_CONN:
 
2569
    case TEST_QCACHE_ON:                 /* should have hit */
 
2570
      DIE_UNLESS(hits2-hits1 == 1);
 
2571
      break;
 
2572
    case TEST_QCACHE_OFF_ON:
 
2573
    case TEST_QCACHE_ON_OFF:             /* should not have hit */
 
2574
      DIE_UNLESS(hits2-hits1 == 0);
 
2575
    }
 
2576
 
 
2577
    /* now modify parameter values and see qcache hits */
 
2578
    strmov(p_str_data, "ii");
 
2579
    p_str_length= strlen(p_str_data);
 
2580
    rc= mysql_stmt_execute(stmt);
 
2581
    check_execute(stmt, rc);
 
2582
    test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2);
 
2583
    hits1= query_cache_hits(mysql);
 
2584
 
 
2585
    switch(iteration)
 
2586
    {
 
2587
    case TEST_QCACHE_ON:
 
2588
    case TEST_QCACHE_OFF_ON:
 
2589
    case TEST_QCACHE_ON_OFF:             /* should not have hit */
 
2590
      DIE_UNLESS(hits2-hits1 == 0);
 
2591
      break;
 
2592
    case TEST_QCACHE_ON_WITH_OTHER_CONN: /* should have hit */
 
2593
      DIE_UNLESS(hits1-hits2 == 1);
 
2594
    }
 
2595
 
 
2596
    rc= mysql_stmt_execute(stmt);
 
2597
    check_execute(stmt, rc);
 
2598
 
 
2599
    test_ps_query_cache_result(1, "hh", 2, 1, "ii", 2, 2, "ii", 2);
 
2600
    hits2= query_cache_hits(mysql);
 
2601
 
 
2602
    mysql_stmt_close(stmt);
 
2603
 
 
2604
    switch(iteration)
 
2605
    {
 
2606
    case TEST_QCACHE_ON:                 /* should have hit */
 
2607
      DIE_UNLESS(hits2-hits1 == 1);
 
2608
      break;
 
2609
    case TEST_QCACHE_OFF_ON:
 
2610
    case TEST_QCACHE_ON_OFF:             /* should not have hit */
 
2611
      DIE_UNLESS(hits2-hits1 == 0);
 
2612
      break;
 
2613
    case TEST_QCACHE_ON_WITH_OTHER_CONN:
 
2614
      mysql_close(lmysql);
 
2615
      mysql= org_mysql;
 
2616
    }
 
2617
 
 
2618
  } /* for(iteration=...) */
 
2619
 
 
2620
  rc= mysql_query(mysql, "set global query_cache_size=0");
 
2621
  myquery(rc);
 
2622
 
 
2623
}
 
2624
 
 
2625
 
2357
2626
/* Test BUG#1115 (incorrect string parameter value allocation) */
2358
2627
 
2359
2628
static void test_bug1115()
4675
4944
  }
4676
4945
  lmysql->reconnect= 1;
4677
4946
  if (!opt_silent)
4678
 
    fprintf(stdout, " OK");
 
4947
    fprintf(stdout, "OK");
4679
4948
 
4680
4949
 
4681
4950
  /* set AUTOCOMMIT to ON*/
4722
4991
    close statements by hand once mysql_close() had been called.
4723
4992
    Now mysql_close() doesn't free any statements, so this test doesn't
4724
4993
    serve its original designation any more.
4725
 
    Here we free stmt2 and stmt3 by hande to avoid memory leaks.
 
4994
    Here we free stmt2 and stmt3 by hand to avoid memory leaks.
4726
4995
  */
4727
4996
  mysql_stmt_close(stmt2);
4728
4997
  mysql_stmt_close(stmt3);
7206
7475
    }
7207
7476
    lmysql->reconnect= 1;
7208
7477
    if (!opt_silent)
7209
 
      fprintf(stdout, " OK");
 
7478
      fprintf(stdout, "OK");
7210
7479
 
7211
7480
    mysql= lmysql;
7212
7481
    rc= mysql_query(mysql, "INSERT INTO test_grant VALUES(NULL)");
7546
7815
                       "", "", "", 19, 0);
7547
7816
 
7548
7817
  verify_prepare_field(result, 2, "table", "", MYSQL_TYPE_VAR_STRING,
7549
 
                       "", "", "", NAME_LEN, 0);
 
7818
                       "", "", "", NAME_CHAR_LEN, 0);
7550
7819
 
7551
7820
  verify_prepare_field(result, 3, "type", "", MYSQL_TYPE_VAR_STRING,
7552
7821
                       "", "", "", 10, 0);
7553
7822
 
7554
7823
  verify_prepare_field(result, 4, "possible_keys", "", MYSQL_TYPE_VAR_STRING,
7555
 
                       "", "", "", NAME_LEN*MAX_KEY, 0);
 
7824
                       "", "", "", NAME_CHAR_LEN*MAX_KEY, 0);
7556
7825
 
7557
7826
  verify_prepare_field(result, 5, "key", "", MYSQL_TYPE_VAR_STRING,
7558
 
                       "", "", "", NAME_LEN, 0);
 
7827
                       "", "", "", NAME_CHAR_LEN, 0);
7559
7828
 
7560
7829
  if (mysql_get_server_version(mysql) <= 50000)
7561
7830
  {
7565
7834
  else
7566
7835
  {
7567
7836
    verify_prepare_field(result, 6, "key_len", "", MYSQL_TYPE_VAR_STRING, "", 
7568
 
                         "", "", NAME_LEN*MAX_KEY, 0);
 
7837
                         "", "", NAME_CHAR_LEN*MAX_KEY, 0);
7569
7838
  }
7570
7839
 
7571
7840
  verify_prepare_field(result, 7, "ref", "", MYSQL_TYPE_VAR_STRING,
7572
 
                       "", "", "", NAME_LEN*16, 0);
 
7841
                       "", "", "", NAME_CHAR_LEN*16, 0);
7573
7842
 
7574
7843
  verify_prepare_field(result, 8, "rows", "", MYSQL_TYPE_LONGLONG,
7575
7844
                       "", "", "", 10, 0);
7667
7936
    }
7668
7937
    lmysql->reconnect= 1;
7669
7938
    if (!opt_silent)
7670
 
      fprintf(stdout, " OK");
 
7939
      fprintf(stdout, "OK");
7671
7940
 
7672
7941
    mysql= lmysql;
7673
7942
    rc= mysql_query(mysql, "INSERT INTO t1 VALUES(10, 'C')");
11753
12022
  stmt= mysql_stmt_init(mysql);
11754
12023
  rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11755
12024
  DIE_UNLESS(rc == 0);
 
12025
  if (!opt_silent)
 
12026
    printf("Excuting mysql_change_user\n");
11756
12027
  mysql_change_user(mysql, opt_user, opt_password, current_db);
 
12028
  if (!opt_silent)
 
12029
    printf("Excuting mysql_stmt_execute\n");
11757
12030
  rc= mysql_stmt_execute(stmt);
11758
12031
  DIE_UNLESS(rc != 0);
11759
12032
  if (rc)
11760
12033
  {
11761
12034
    if (!opt_silent)
11762
 
      printf("Got error (as expected):\n%s", mysql_stmt_error(stmt));
 
12035
      printf("Got error (as expected): '%s'\n", mysql_stmt_error(stmt));
11763
12036
  }
11764
12037
  /* check that connection is OK */
 
12038
  if (!opt_silent)
 
12039
    printf("Excuting mysql_stmt_close\n");
11765
12040
  mysql_stmt_close(stmt);
 
12041
  if (!opt_silent)
 
12042
    printf("Excuting mysql_stmt_init\n");
11766
12043
  stmt= mysql_stmt_init(mysql);
11767
12044
  rc= mysql_stmt_prepare(stmt, stmt_text, strlen(stmt_text));
11768
12045
  DIE_UNLESS(rc == 0);
12451
12728
 
12452
12729
  /* retreive all result sets till we are at the end */
12453
12730
  while(!mysql_stmt_fetch(stmt))
 
12731
    if (!opt_silent)
12454
12732
      printf("fetched result:%ld\n", Data);
12455
12733
 
12456
12734
  DIE_UNLESS(rc != MYSQL_NO_DATA);
12461
12739
  /* now we should be able to fetch the results again */
12462
12740
  /* but mysql_stmt_fetch returns MYSQL_NO_DATA */
12463
12741
  while(!(rc= mysql_stmt_fetch(stmt)))
 
12742
    if (!opt_silent)
12464
12743
      printf("fetched result after seek:%ld\n", Data);
12465
12744
  
12466
12745
  DIE_UNLESS(rc == MYSQL_NO_DATA);
13011
13290
    exit(1);
13012
13291
  }
13013
13292
  if (!opt_silent)
13014
 
    fprintf(stdout, " OK");
 
13293
    fprintf(stdout, "OK");
13015
13294
 
13016
13295
  len= mysql_real_escape_string(mysql, out, TEST_BUG8378_IN, 4);
13017
13296
 
13180
13459
 
13181
13460
  DIE_UNLESS(rc == MYSQL_NO_DATA);
13182
13461
 
13183
 
  printf("Fetched %d rows\n", row_count);
 
13462
  if (!opt_silent)
 
13463
    printf("Fetched %d rows\n", row_count);
13184
13464
  DBUG_ASSERT(row_count == 3);
13185
13465
 
13186
13466
  mysql_stmt_close(stmt);
15080
15360
 
15081
15361
  myheader("test_bug17667");
15082
15362
 
 
15363
  master_log_filename = (char *) malloc(strlen(opt_vardir) + strlen("/log/master.log") + 1);
 
15364
  strxmov(master_log_filename, opt_vardir, "/log/master.log", NullS);
 
15365
  if (!opt_silent)
 
15366
    printf("Opening '%s'\n", master_log_filename);
 
15367
  log_file= my_fopen(master_log_filename, (int) (O_RDONLY | O_BINARY), MYF(0));
 
15368
  free(master_log_filename);
 
15369
 
 
15370
  if (log_file == NULL)
 
15371
  {
 
15372
    if (!opt_silent)
 
15373
    {
 
15374
      printf("Could not find the log file, VARDIR/log/master.log, so "
 
15375
             "test_bug17667 is not run.\n"
 
15376
             "Run test from the mysql-test/mysql-test-run* program to set up "
 
15377
             "correct environment for this test.\n\n");
 
15378
    }
 
15379
    return;
 
15380
  }
 
15381
 
15083
15382
  for (statement_cursor= statements; statement_cursor->buffer != NULL;
15084
 
      statement_cursor++) {
 
15383
       statement_cursor++)
 
15384
  {
15085
15385
    if (statement_cursor->qt == QT_NORMAL)
15086
15386
    {
15087
15387
      /* Run statement as normal query */
15092
15392
    else if (statement_cursor->qt == QT_PREPARED)
15093
15393
    {
15094
15394
      /*
15095
 
         Run as prepared statement
 
15395
        Run as prepared statement
15096
15396
 
15097
 
         NOTE! All these queries should be in the log twice,
15098
 
         one time for prepare and one time for execute
 
15397
        NOTE! All these queries should be in the log twice,
 
15398
        one time for prepare and one time for execute
15099
15399
      */
15100
15400
      stmt= mysql_stmt_init(mysql);
15101
15401
 
15118
15418
  rc= mysql_query(mysql, "flush logs");
15119
15419
  myquery(rc);
15120
15420
 
15121
 
  master_log_filename = (char *) malloc(strlen(opt_vardir) + strlen("/log/master.log") + 1);
15122
 
  strcpy(master_log_filename, opt_vardir);
15123
 
  strcat(master_log_filename, "/log/master.log");
15124
 
  printf("Opening '%s'\n", master_log_filename);
15125
 
  log_file= my_fopen(master_log_filename, (int) (O_RDONLY | O_BINARY), MYF(MY_WME));
15126
 
  free(master_log_filename);
15127
 
 
15128
 
  if (log_file != NULL) {
15129
 
 
15130
 
    for (statement_cursor= statements; statement_cursor->buffer != NULL;
15131
 
        statement_cursor++) {
15132
 
      int expected_hits= 1, hits= 0;
15133
 
      char line_buffer[MAX_TEST_QUERY_LENGTH*2];
15134
 
      /* more than enough room for the query and some marginalia. */
15135
 
 
15136
 
      /* Prepared statments always occurs twice in log */
15137
 
      if (statement_cursor->qt == QT_PREPARED)
15138
 
        expected_hits++;
15139
 
 
15140
 
      /* Loop until we found expected number of log entries */
 
15421
  for (statement_cursor= statements; statement_cursor->buffer != NULL;
 
15422
       statement_cursor++)
 
15423
  {
 
15424
    int expected_hits= 1, hits= 0;
 
15425
    char line_buffer[MAX_TEST_QUERY_LENGTH*2];
 
15426
    /* more than enough room for the query and some marginalia. */
 
15427
 
 
15428
    /* Prepared statments always occurs twice in log */
 
15429
    if (statement_cursor->qt == QT_PREPARED)
 
15430
      expected_hits++;
 
15431
 
 
15432
    /* Loop until we found expected number of log entries */
 
15433
    do {
 
15434
      /* Loop until statement is found in log */
15141
15435
      do {
15142
 
        /* Loop until statement is found in log */
15143
 
        do {
15144
 
          memset(line_buffer, '/', MAX_TEST_QUERY_LENGTH*2);
15145
 
 
15146
 
          if(fgets(line_buffer, MAX_TEST_QUERY_LENGTH*2, log_file) == NULL)
15147
 
          {
15148
 
            /* If fgets returned NULL, it indicates either error or EOF */
15149
 
            if (feof(log_file))
15150
 
              DIE("Found EOF before all statements where found");
15151
 
 
15152
 
            fprintf(stderr, "Got error %d while reading from file\n",
15153
 
                    ferror(log_file));
15154
 
            DIE("Read error");
15155
 
          }
15156
 
 
15157
 
        } while (my_memmem(line_buffer, MAX_TEST_QUERY_LENGTH*2,
15158
 
                           statement_cursor->buffer,
15159
 
                           statement_cursor->length) == NULL);
15160
 
        hits++;
15161
 
      } while (hits < expected_hits);
15162
 
 
 
15436
        memset(line_buffer, '/', MAX_TEST_QUERY_LENGTH*2);
 
15437
 
 
15438
        if(fgets(line_buffer, MAX_TEST_QUERY_LENGTH*2, log_file) == NULL)
 
15439
        {
 
15440
          /* If fgets returned NULL, it indicates either error or EOF */
 
15441
          if (feof(log_file))
 
15442
            DIE("Found EOF before all statements where found");
 
15443
 
 
15444
          fprintf(stderr, "Got error %d while reading from file\n",
 
15445
                  ferror(log_file));
 
15446
          DIE("Read error");
 
15447
        }
 
15448
 
 
15449
      } while (my_memmem(line_buffer, MAX_TEST_QUERY_LENGTH*2,
 
15450
                         statement_cursor->buffer,
 
15451
                         statement_cursor->length) == NULL);
 
15452
      hits++;
 
15453
    } while (hits < expected_hits);
 
15454
 
 
15455
    if (!opt_silent)
15163
15456
      printf("Found statement starting with \"%s\"\n",
15164
15457
             statement_cursor->buffer);
15165
 
    }
 
15458
  }
15166
15459
 
 
15460
  if (!opt_silent)
15167
15461
    printf("success.  All queries found intact in the log.\n");
15168
15462
 
15169
 
  }
15170
 
  else
15171
 
  {
15172
 
    fprintf(stderr, "Could not find the log file, VARDIR/log/master.log, so "
15173
 
            "test_bug17667 is \ninconclusive.  Run test from the "
15174
 
            "mysql-test/mysql-test-run* program \nto set up the correct "
15175
 
            "environment for this test.\n\n");
15176
 
  }
15177
 
 
15178
 
  if (log_file != NULL)
15179
 
    my_fclose(log_file, MYF(0));
15180
 
 
 
15463
  my_fclose(log_file, MYF(0));
15181
15464
}
15182
15465
 
15183
15466
 
15743
16026
  for (i= 0; i < field_count; ++i)
15744
16027
  {
15745
16028
    field= mysql_fetch_field_direct(result, i);
15746
 
    printf("%s -> %s ... ", expr[i * 2], field->name);
 
16029
    if (!opt_silent)
 
16030
      printf("%s -> %s ... ", expr[i * 2], field->name);
15747
16031
    fflush(stdout);
15748
16032
    DIE_UNLESS(field->db[0] == 0 && field->org_table[0] == 0 &&
15749
16033
               field->table[0] == 0 && field->org_name[0] == 0);
15750
16034
    DIE_UNLESS(strcmp(field->name, expr[i * 2 + 1]) == 0);
15751
 
    puts("OK");
 
16035
    if (!opt_silent)
 
16036
      puts("OK");
15752
16037
  }
15753
16038
 
15754
16039
  mysql_free_result(result);
16067
16352
  { "test_bug15518", test_bug15518 },
16068
16353
  { "test_bug23383", test_bug23383 },
16069
16354
  { "test_bug21635", test_bug21635 },
16070
 
  { "test_status", test_status},
 
16355
  { "test_status",   test_status   },
16071
16356
  { "test_bug24179", test_bug24179 },
 
16357
  { "test_ps_query_cache", test_ps_query_cache },
16072
16358
  { 0, 0 }
16073
16359
};
16074
16360