~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Monty Taylor
  • Date: 2008-07-28 02:08:00 UTC
  • mto: (212.5.1 codestyle)
  • mto: This revision was merged to the branch mainline in revision 219.
  • Revision ID: monty@inaugust.com-20080728020800-qx1h6nh8lo3ywzfz
Moved myisam headers to storage/myisam.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2000 MySQL AB
 
1
/* Copyright (C) 2008 Drizzle Open Source Development Team 
2
2
 
3
3
   This program is free software; you can redistribute it and/or modify
4
4
   it under the terms of the GNU General Public License as published by
14
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
15
15
 
16
16
/*
17
 
  mysqltest
 
17
  drizzletest
18
18
 
19
19
  Tool used for executing a .test file
20
20
 
21
 
  See the "MySQL Test framework manual" for more information
22
 
  http://dev.mysql.com/doc/mysqltest/en/index.html
 
21
  See the "DRIZZLE Test framework manual" for more information
 
22
  http://dev.mysql.com/doc/drizzletest/en/index.html
23
23
 
24
24
  Please keep the test framework tools identical in all versions!
25
25
 
80
80
static bool server_initialized= 0;
81
81
static bool is_windows= 0;
82
82
static char **default_argv;
83
 
static const char *load_default_groups[]= { "mysqltest", "client", 0 };
 
83
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
84
84
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
85
85
 
86
86
static uint start_lineno= 0; /* Start line of current command */
126
126
 
127
127
static CHARSET_INFO *charset_info= &my_charset_latin1; /* Default charset */
128
128
 
129
 
static const char *embedded_server_groups[]=
130
 
{
131
 
  "server",
132
 
  "embedded",
133
 
  "mysqltest_SERVER",
134
 
  NullS
135
 
};
136
 
 
137
129
static int embedded_server_arg_count=0;
138
130
static char *embedded_server_args[MAX_EMBEDDED_SERVER_ARGS];
139
131
 
186
178
 
187
179
struct st_connection
188
180
{
189
 
  MYSQL mysql;
 
181
  DRIZZLE drizzle;
190
182
  /* Used when creating views and sp, to avoid implicit commit */
191
 
  MYSQL* util_mysql;
 
183
  DRIZZLE *util_drizzle;
192
184
  char *name;
193
185
};
194
186
struct st_connection connections[128];
195
187
struct st_connection* cur_con= NULL, *next_con, *connections_end;
196
188
 
197
189
/*
198
 
  List of commands in mysqltest
 
190
  List of commands in drizzletest
199
191
  Must match the "command_names" array
200
192
  Add new commands before Q_UNKNOWN!
201
193
*/
202
194
enum enum_commands {
203
195
  Q_CONNECTION=1,     Q_QUERY,
204
 
  Q_CONNECT,        Q_SLEEP, Q_REAL_SLEEP,
205
 
  Q_INC,                    Q_DEC,
206
 
  Q_SOURCE,         Q_DISCONNECT,
207
 
  Q_LET,                    Q_ECHO,
208
 
  Q_WHILE,          Q_END_BLOCK,
209
 
  Q_SYSTEM,         Q_RESULT,
210
 
  Q_REQUIRE,        Q_SAVE_MASTER_POS,
 
196
  Q_CONNECT,      Q_SLEEP, Q_REAL_SLEEP,
 
197
  Q_INC,        Q_DEC,
 
198
  Q_SOURCE,      Q_DISCONNECT,
 
199
  Q_LET,        Q_ECHO,
 
200
  Q_WHILE,      Q_END_BLOCK,
 
201
  Q_SYSTEM,      Q_RESULT,
 
202
  Q_REQUIRE,      Q_SAVE_MASTER_POS,
211
203
  Q_SYNC_WITH_MASTER,
212
204
  Q_SYNC_SLAVE_WITH_MASTER,
213
205
  Q_ERROR,
214
 
  Q_SEND,                   Q_REAP,
215
 
  Q_DIRTY_CLOSE,            Q_REPLACE, Q_REPLACE_COLUMN,
216
 
  Q_PING,                   Q_EVAL,
 
206
  Q_SEND,        Q_REAP,
 
207
  Q_DIRTY_CLOSE,      Q_REPLACE, Q_REPLACE_COLUMN,
 
208
  Q_PING,        Q_EVAL,
217
209
  Q_EVAL_RESULT,
218
210
  Q_ENABLE_QUERY_LOG, Q_DISABLE_QUERY_LOG,
219
211
  Q_ENABLE_RESULT_LOG, Q_DISABLE_RESULT_LOG,
235
227
  Q_CHMOD_FILE, Q_APPEND_FILE, Q_CAT_FILE, Q_DIFF_FILES,
236
228
  Q_SEND_QUIT, Q_CHANGE_USER, Q_MKDIR, Q_RMDIR,
237
229
 
238
 
  Q_UNKNOWN,                           /* Unknown command.   */
239
 
  Q_COMMENT,                           /* Comments, ignored. */
 
230
  Q_UNKNOWN,             /* Unknown command.   */
 
231
  Q_COMMENT,             /* Comments, ignored. */
240
232
  Q_COMMENT_WITH_COMMAND
241
233
};
242
234
 
308
300
  "copy_file",
309
301
  "perl",
310
302
  "die",
311
 
               
 
303
              
312
304
  /* Don't execute any more commands, compare result */
313
305
  "exit",
314
306
  "skip",
367
359
};
368
360
 
369
361
TYPELIB command_typelib= {array_elements(command_names),"",
370
 
                          command_names, 0};
 
362
        command_names, 0};
371
363
 
372
364
DYNAMIC_STRING ds_res, ds_progress, ds_warning_messages;
373
365
 
446
438
  send_one_query executes query in separate thread, which is
447
439
  necessary in embedded library to run 'send' in proper way.
448
440
  This implementation doesn't handle errors returned
449
 
  by mysql_send_query. It's technically possible, though
 
441
  by drizzle_send_query. It's technically possible, though
450
442
  I don't see where it is needed.
451
443
*/
452
444
pthread_handler_t send_one_query(void *arg)
453
445
{
454
446
  struct st_connection *cn= (struct st_connection*)arg;
455
447
 
456
 
  mysql_thread_init();
457
 
  VOID(mysql_send_query(&cn->mysql, cn->cur_query, cn->cur_query_len));
 
448
  drizzle_thread_init();
 
449
  VOID(drizzle_send_query(&cn->drizzle, cn->cur_query, cn->cur_query_len));
458
450
 
459
 
  mysql_thread_end();
 
451
  drizzle_thread_end();
460
452
  pthread_mutex_lock(&cn->mutex);
461
453
  cn->query_done= 1;
462
454
  VOID(pthread_cond_signal(&cn->cond));
471
463
  pthread_t tid;
472
464
 
473
465
  if (flags & QUERY_REAP_FLAG)
474
 
    return mysql_send_query(&cn->mysql, q, q_len);
 
466
    return drizzle_send_query(&cn->drizzle, q, q_len);
475
467
 
476
468
  if (pthread_mutex_init(&cn->mutex, NULL) ||
477
469
      pthread_cond_init(&cn->cond, NULL))
499
491
 
500
492
#else /*EMBEDDED_LIBRARY*/
501
493
 
502
 
#define do_send_query(cn,q,q_len,flags) mysql_send_query(&cn->mysql, q, q_len)
 
494
#define do_send_query(cn,q,q_len,flags) drizzle_send_query(&cn->drizzle, q, q_len)
503
495
 
504
496
#endif /*EMBEDDED_LIBRARY*/
505
497
 
518
510
    case '$':
519
511
      if (escaped)
520
512
      {
521
 
        escaped= 0;
522
 
        dynstr_append_mem(query_eval, p, 1);
 
513
  escaped= 0;
 
514
  dynstr_append_mem(query_eval, p, 1);
523
515
      }
524
516
      else
525
517
      {
526
 
        if (!(v= var_get(p, &p, 0, 0)))
527
 
          die("Bad variable in eval");
528
 
        dynstr_append_mem(query_eval, v->str_val, v->str_val_len);
 
518
  if (!(v= var_get(p, &p, 0, 0)))
 
519
    die("Bad variable in eval");
 
520
  dynstr_append_mem(query_eval, v->str_val, v->str_val_len);
529
521
      }
530
522
      break;
531
523
    case '\\':
532
524
      next_c= *(p+1);
533
525
      if (escaped)
534
526
      {
535
 
        escaped= 0;
536
 
        dynstr_append_mem(query_eval, p, 1);
 
527
  escaped= 0;
 
528
  dynstr_append_mem(query_eval, p, 1);
537
529
      }
538
530
      else if (next_c == '\\' || next_c == '$' || next_c == '"')
539
531
      {
540
532
        /* Set escaped only if next char is \, " or $ */
541
 
        escaped= 1;
 
533
  escaped= 1;
542
534
 
543
535
        if (pass_through_escape_chars)
544
536
        {
547
539
        }
548
540
      }
549
541
      else
550
 
        dynstr_append_mem(query_eval, p, 1);
 
542
  dynstr_append_mem(query_eval, p, 1);
551
543
      break;
552
544
    default:
553
545
      escaped= 0;
567
559
 
568
560
  SYNOPSIS
569
561
  show_query
570
 
  mysql - connection to use
 
562
  drizzle - connection to use
571
563
  query - query to run
572
564
 
573
565
*/
574
566
 
575
 
static void show_query(MYSQL* mysql, const char* query)
 
567
static void show_query(DRIZZLE *drizzle, const char* query)
576
568
{
577
 
  MYSQL_RES* res;
578
 
 
579
 
 
580
 
  if (!mysql)
 
569
  DRIZZLE_RES* res;
 
570
 
 
571
 
 
572
  if (!drizzle)
581
573
    return;
582
574
 
583
 
  if (mysql_query(mysql, query))
 
575
  if (drizzle_query(drizzle, query))
584
576
  {
585
577
    log_msg("Error running query '%s': %d %s",
586
 
            query, mysql_errno(mysql), mysql_error(mysql));
 
578
            query, drizzle_errno(drizzle), drizzle_error(drizzle));
587
579
    return;
588
580
  }
589
581
 
590
 
  if ((res= mysql_store_result(mysql)) == NULL)
 
582
  if ((res= drizzle_store_result(drizzle)) == NULL)
591
583
  {
592
584
    /* No result set returned */
593
585
    return;
594
586
  }
595
587
 
596
588
  {
597
 
    MYSQL_ROW row;
 
589
    DRIZZLE_ROW row;
598
590
    unsigned int i;
599
591
    unsigned int row_num= 0;
600
 
    unsigned int num_fields= mysql_num_fields(res);
601
 
    MYSQL_FIELD *fields= mysql_fetch_fields(res);
 
592
    unsigned int num_fields= drizzle_num_fields(res);
 
593
    DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
602
594
 
603
595
    fprintf(stderr, "=== %s ===\n", query);
604
 
    while ((row= mysql_fetch_row(res)))
 
596
    while ((row= drizzle_fetch_row(res)))
605
597
    {
606
 
      uint32_t *lengths= mysql_fetch_lengths(res);
 
598
      uint32_t *lengths= drizzle_fetch_lengths(res);
607
599
      row_num++;
608
600
 
609
601
      fprintf(stderr, "---- %d. ----\n", row_num);
618
610
      fprintf(stderr, "=");
619
611
    fprintf(stderr, "\n\n");
620
612
  }
621
 
  mysql_free_result(res);
 
613
  drizzle_free_result(res);
622
614
 
623
615
  return;
624
616
}
633
625
 
634
626
  SYNOPSIS
635
627
  show_warnings_before_error
636
 
  mysql - connection to use
 
628
  drizzle - connection to use
637
629
 
638
630
*/
639
631
 
640
 
static void show_warnings_before_error(MYSQL* mysql)
 
632
static void show_warnings_before_error(DRIZZLE *drizzle)
641
633
{
642
 
  MYSQL_RES* res;
 
634
  DRIZZLE_RES* res;
643
635
  const char* query= "SHOW WARNINGS";
644
636
 
645
637
 
646
 
  if (!mysql)
 
638
  if (!drizzle)
647
639
    return;
648
640
 
649
 
  if (mysql_query(mysql, query))
 
641
  if (drizzle_query(drizzle, query))
650
642
  {
651
643
    log_msg("Error running query '%s': %d %s",
652
 
            query, mysql_errno(mysql), mysql_error(mysql));
 
644
            query, drizzle_errno(drizzle), drizzle_error(drizzle));
653
645
    return;
654
646
  }
655
647
 
656
 
  if ((res= mysql_store_result(mysql)) == NULL)
 
648
  if ((res= drizzle_store_result(drizzle)) == NULL)
657
649
  {
658
650
    /* No result set returned */
659
651
    return;
660
652
  }
661
653
 
662
 
  if (mysql_num_rows(res) <= 1)
 
654
  if (drizzle_num_rows(res) <= 1)
663
655
  {
664
656
    /* Don't display the last row, it's "last error" */
665
657
  }
666
658
  else
667
659
  {
668
 
    MYSQL_ROW row;
 
660
    DRIZZLE_ROW row;
669
661
    unsigned int row_num= 0;
670
 
    unsigned int num_fields= mysql_num_fields(res);
 
662
    unsigned int num_fields= drizzle_num_fields(res);
671
663
 
672
664
    fprintf(stderr, "\nWarnings from just before the error:\n");
673
 
    while ((row= mysql_fetch_row(res)))
 
665
    while ((row= drizzle_fetch_row(res)))
674
666
    {
675
667
      uint32_t i;
676
 
      uint32_t *lengths= mysql_fetch_lengths(res);
 
668
      uint32_t *lengths= drizzle_fetch_lengths(res);
677
669
 
678
 
      if (++row_num >= mysql_num_rows(res))
 
670
      if (++row_num >= drizzle_num_rows(res))
679
671
      {
680
672
        /* Don't display the last row, it's "last error" */
681
673
        break;
689
681
      fprintf(stderr, "\n");
690
682
    }
691
683
  }
692
 
  mysql_free_result(res);
 
684
  drizzle_free_result(res);
693
685
 
694
686
  return;
695
687
}
820
812
 
821
813
  for (--next_con; next_con >= connections; --next_con)
822
814
  {
823
 
    mysql_close(&next_con->mysql);
824
 
    if (next_con->util_mysql)
825
 
      mysql_close(next_con->util_mysql);
 
815
    drizzle_close(&next_con->drizzle);
 
816
    if (next_con->util_drizzle)
 
817
      drizzle_close(next_con->util_drizzle);
826
818
    my_free(next_con->name, MYF(MY_ALLOW_ZERO_PTR));
827
819
  }
828
820
  return;
875
867
  my_free(opt_pass,MYF(MY_ALLOW_ZERO_PTR));
876
868
  free_defaults(default_argv);
877
869
 
878
 
  /* Only call mysql_server_end if mysql_server_init has been called */
 
870
  /* Only call drizzle_server_end if drizzle_server_init has been called */
879
871
  if (server_initialized)
880
 
    mysql_server_end();
 
872
    drizzle_server_end();
881
873
 
882
874
  return;
883
875
}
923
915
  dying= 1;
924
916
 
925
917
  /* Print the error message */
926
 
  fprintf(stderr, "mysqltest: ");
 
918
  fprintf(stderr, "drizzletest: ");
927
919
  if (cur_file && cur_file != file_stack)
928
920
    fprintf(stderr, "In included file \"%s\": ",
929
921
            cur_file->file_name);
971
963
    been produced prior to the error
972
964
  */
973
965
  if (cur_con)
974
 
    show_warnings_before_error(&cur_con->mysql);
 
966
    show_warnings_before_error(&cur_con->drizzle);
975
967
 
976
968
  cleanup_and_exit(1);
977
969
}
1018
1010
    return;
1019
1011
 
1020
1012
  va_start(args, fmt);
1021
 
  fprintf(stderr, "mysqltest: ");
 
1013
  fprintf(stderr, "drizzletest: ");
1022
1014
  if (cur_file && cur_file != file_stack)
1023
1015
    fprintf(stderr, "In included file \"%s\": ",
1024
1016
            cur_file->file_name);
1040
1032
 
1041
1033
 
1042
1034
  va_start(args, fmt);
1043
 
  dynstr_append(&ds_warning_messages, "mysqltest: ");
 
1035
  dynstr_append(&ds_warning_messages, "drizzletest: ");
1044
1036
  if (start_lineno != 0)
1045
1037
  {
1046
1038
    dynstr_append(&ds_warning_messages, "Warning detected ");
1292
1284
    /* Print diff directly to stdout */
1293
1285
    fprintf(stderr, "%s\n", ds_tmp.str);
1294
1286
  }
1295
 
 
 
1287
 
1296
1288
  dynstr_free(&ds_tmp);
1297
1289
 
1298
1290
}
1647
1639
 
1648
1640
 
1649
1641
VAR* var_get(const char *var_name, const char **var_name_end, bool raw,
1650
 
             bool ignore_not_existing)
 
1642
       bool ignore_not_existing)
1651
1643
{
1652
1644
  int digit;
1653
1645
  VAR *v;
1665
1657
    if (var_name == save_var_name)
1666
1658
    {
1667
1659
      if (ignore_not_existing)
1668
 
        return(0);
 
1660
  return(0);
1669
1661
      die("Empty variable");
1670
1662
    }
1671
1663
    length= (uint) (var_name - save_var_name);
1679
1671
      strmake(buff, save_var_name, length);
1680
1672
      v= var_from_env(buff, "");
1681
1673
    }
1682
 
    var_name--; /* Point at last character */
 
1674
    var_name--;  /* Point at last character */
1683
1675
  }
1684
1676
  else
1685
1677
    v = var_reg + digit;
1776
1768
 
1777
1769
/*
1778
1770
  Store an integer (typically the returncode of the last SQL)
1779
 
  statement in the mysqltest builtin variable $mysql_errno
 
1771
  statement in the drizzletest builtin variable $drizzle_errno
1780
1772
*/
1781
1773
 
1782
1774
static void var_set_errno(int sql_errno)
1783
1775
{
1784
 
  var_set_int("$mysql_errno", sql_errno);
 
1776
  var_set_int("$drizzle_errno", sql_errno);
1785
1777
}
1786
1778
 
1787
1779
 
1788
1780
/*
1789
 
  Update $mysql_get_server_version variable with version
 
1781
  Update $drizzle_get_server_version variable with version
1790
1782
  of the currently connected server
1791
1783
*/
1792
1784
 
1793
 
static void var_set_mysql_get_server_version(MYSQL* mysql)
 
1785
static void var_set_drizzle_get_server_version(DRIZZLE *drizzle)
1794
1786
{
1795
 
  var_set_int("$mysql_get_server_version", mysql_get_server_version(mysql));
 
1787
  var_set_int("$drizzle_get_server_version", drizzle_get_server_version(drizzle));
1796
1788
}
1797
1789
 
1798
1790
 
1801
1793
 
1802
1794
  SYNOPSIS
1803
1795
  var_query_set()
1804
 
  var           variable to set from query
 
1796
  var          variable to set from query
1805
1797
  query       start of query string to execute
1806
1798
  query_end   end of the query string to execute
1807
1799
 
1822
1814
static void var_query_set(VAR *var, const char *query, const char** query_end)
1823
1815
{
1824
1816
  char *end = (char*)((query_end && *query_end) ?
1825
 
                      *query_end : query + strlen(query));
1826
 
  MYSQL_RES *res;
1827
 
  MYSQL_ROW row;
1828
 
  MYSQL* mysql = &cur_con->mysql;
 
1817
          *query_end : query + strlen(query));
 
1818
  DRIZZLE_RES *res;
 
1819
  DRIZZLE_ROW row;
 
1820
  DRIZZLE *drizzle= &cur_con->drizzle;
1829
1821
  DYNAMIC_STRING ds_query;
1830
1822
 
1831
1823
 
1839
1831
  init_dynamic_string(&ds_query, 0, (end - query) + 32, 256);
1840
1832
  do_eval(&ds_query, query, end, false);
1841
1833
 
1842
 
  if (mysql_real_query(mysql, ds_query.str, ds_query.length))
 
1834
  if (drizzle_real_query(drizzle, ds_query.str, ds_query.length))
1843
1835
    die("Error running query '%s': %d %s", ds_query.str,
1844
 
        mysql_errno(mysql), mysql_error(mysql));
1845
 
  if (!(res= mysql_store_result(mysql)))
 
1836
  drizzle_errno(drizzle), drizzle_error(drizzle));
 
1837
  if (!(res= drizzle_store_result(drizzle)))
1846
1838
    die("Query '%s' didn't return a result set", ds_query.str);
1847
1839
  dynstr_free(&ds_query);
1848
1840
 
1849
 
  if ((row= mysql_fetch_row(res)) && row[0])
 
1841
  if ((row= drizzle_fetch_row(res)) && row[0])
1850
1842
  {
1851
1843
    /*
1852
1844
      Concatenate all fields in the first row with tab in between
1857
1849
    uint32_t *lengths;
1858
1850
 
1859
1851
    init_dynamic_string(&result, "", 512, 512);
1860
 
    lengths= mysql_fetch_lengths(res);
1861
 
    for (i= 0; i < mysql_num_fields(res); i++)
 
1852
    lengths= drizzle_fetch_lengths(res);
 
1853
    for (i= 0; i < drizzle_num_fields(res); i++)
1862
1854
    {
1863
1855
      if (row[i])
1864
1856
      {
1865
1857
        /* Add column to tab separated string */
1866
 
        dynstr_append_mem(&result, row[i], lengths[i]);
 
1858
  dynstr_append_mem(&result, row[i], lengths[i]);
1867
1859
      }
1868
1860
      dynstr_append_mem(&result, "\t", 1);
1869
1861
    }
1874
1866
  else
1875
1867
    eval_expr(var, "", 0);
1876
1868
 
1877
 
  mysql_free_result(res);
 
1869
  drizzle_free_result(res);
1878
1870
  return;
1879
1871
}
1880
1872
 
1905
1897
{
1906
1898
  long row_no;
1907
1899
  int col_no= -1;
1908
 
  MYSQL_RES* res;
1909
 
  MYSQL* mysql= &cur_con->mysql;
 
1900
  DRIZZLE_RES* res;
 
1901
  DRIZZLE *drizzle= &cur_con->drizzle;
1910
1902
 
1911
1903
  static DYNAMIC_STRING ds_query;
1912
1904
  static DYNAMIC_STRING ds_col;
1934
1926
    die("Mismatched \"'s around query '%s'", ds_query.str);
1935
1927
 
1936
1928
  /* Run the query */
1937
 
  if (mysql_real_query(mysql, ds_query.str, ds_query.length))
 
1929
  if (drizzle_real_query(drizzle, ds_query.str, ds_query.length))
1938
1930
    die("Error running query '%s': %d %s", ds_query.str,
1939
 
        mysql_errno(mysql), mysql_error(mysql));
1940
 
  if (!(res= mysql_store_result(mysql)))
 
1931
  drizzle_errno(drizzle), drizzle_error(drizzle));
 
1932
  if (!(res= drizzle_store_result(drizzle)))
1941
1933
    die("Query '%s' didn't return a result set", ds_query.str);
1942
1934
 
1943
1935
  {
1944
1936
    /* Find column number from the given column name */
1945
1937
    uint i;
1946
 
    uint num_fields= mysql_num_fields(res);
1947
 
    MYSQL_FIELD *fields= mysql_fetch_fields(res);
 
1938
    uint num_fields= drizzle_num_fields(res);
 
1939
    DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
1948
1940
 
1949
1941
    for (i= 0; i < num_fields; i++)
1950
1942
    {
1957
1949
    }
1958
1950
    if (col_no == -1)
1959
1951
    {
1960
 
      mysql_free_result(res);
 
1952
      drizzle_free_result(res);
1961
1953
      die("Could not find column '%s' in the result of '%s'",
1962
1954
          ds_col.str, ds_query.str);
1963
1955
    }
1966
1958
 
1967
1959
  {
1968
1960
    /* Get the value */
1969
 
    MYSQL_ROW row;
 
1961
    DRIZZLE_ROW row;
1970
1962
    long rows= 0;
1971
1963
    const char* value= "No such row";
1972
1964
 
1973
 
    while ((row= mysql_fetch_row(res)))
 
1965
    while ((row= drizzle_fetch_row(res)))
1974
1966
    {
1975
1967
      if (++rows == row_no)
1976
1968
      {
1987
1979
    eval_expr(var, value, 0);
1988
1980
  }
1989
1981
  dynstr_free(&ds_query);
1990
 
  mysql_free_result(res);
 
1982
  drizzle_free_result(res);
1991
1983
 
1992
1984
  return;
1993
1985
}
2101
2093
 
2102
2094
  SYNOPSIS
2103
2095
  do_source()
2104
 
  query called command
 
2096
  query  called command
2105
2097
 
2106
2098
  DESCRIPTION
2107
2099
  source <file_name>
2191
2183
 
2192
2184
  SYNOPSIS
2193
2185
  do_exec()
2194
 
  query called command
 
2186
  query  called command
2195
2187
 
2196
2188
  DESCRIPTION
2197
2189
  exec <command>
2202
2194
  It can thus be used to execute a command that shall fail.
2203
2195
 
2204
2196
  NOTE
2205
 
  Although mysqltest is executed from cygwin shell, the command will be
 
2197
  Although drizzletest is executed from cygwin shell, the command will be
2206
2198
  executed in "cmd.exe". Thus commands like "rm" etc can NOT be used, use
2207
 
  mysqltest commmand(s) like "remove_file" for that
 
2199
  drizzletest commmand(s) like "remove_file" for that
2208
2200
*/
2209
2201
 
2210
2202
static void do_exec(struct st_command *command)
2306
2298
 
2307
2299
  SYNOPSIS
2308
2300
  do_modify_var()
2309
 
  query called command
 
2301
  query  called command
2310
2302
  operator    operation to perform on the var
2311
2303
 
2312
2304
  DESCRIPTION
2347
2339
  Wrapper for 'system' function
2348
2340
 
2349
2341
  NOTE
2350
 
  If mysqltest is executed from cygwin shell, the command will be
 
2342
  If drizzletest is executed from cygwin shell, the command will be
2351
2343
  executed in the "windows command interpreter" cmd.exe and we prepend "sh"
2352
2344
  to make it be executed by cygwins "bash". Thus commands like "rm",
2353
2345
  "mkdir" as well as shellscripts can executed by "system" in Windows.
2363
2355
/*
2364
2356
  SYNOPSIS
2365
2357
  do_system
2366
 
  command       called command
 
2358
  command  called command
2367
2359
 
2368
2360
  DESCRIPTION
2369
2361
  system <command>
2406
2398
/*
2407
2399
  SYNOPSIS
2408
2400
  do_remove_file
2409
 
  command       called command
 
2401
  command  called command
2410
2402
 
2411
2403
  DESCRIPTION
2412
2404
  remove_file <file_name>
2436
2428
/*
2437
2429
  SYNOPSIS
2438
2430
  do_copy_file
2439
 
  command       command handle
 
2431
  command  command handle
2440
2432
 
2441
2433
  DESCRIPTION
2442
2434
  copy_file <from_file> <to_file>
2473
2465
/*
2474
2466
  SYNOPSIS
2475
2467
  do_chmod_file
2476
 
  command       command handle
 
2468
  command  command handle
2477
2469
 
2478
2470
  DESCRIPTION
2479
2471
  chmod <octal> <file_name>
2487
2479
  static DYNAMIC_STRING ds_mode;
2488
2480
  static DYNAMIC_STRING ds_file;
2489
2481
  const struct command_arg chmod_file_args[] = {
2490
 
    { "mode", ARG_STRING, true, &ds_mode, "Mode of file(octal) ex. 0660"}, 
 
2482
    { "mode", ARG_STRING, true, &ds_mode, "Mode of file(octal) ex. 0660"},
2491
2483
    { "filename", ARG_STRING, true, &ds_file, "Filename of file to modify" }
2492
2484
  };
2493
2485
 
2512
2504
/*
2513
2505
  SYNOPSIS
2514
2506
  do_file_exists
2515
 
  command       called command
 
2507
  command  called command
2516
2508
 
2517
2509
  DESCRIPTION
2518
2510
  fiile_exist <file_name>
2543
2535
/*
2544
2536
  SYNOPSIS
2545
2537
  do_mkdir
2546
 
  command       called command
 
2538
  command  called command
2547
2539
 
2548
2540
  DESCRIPTION
2549
2541
  mkdir <dir_name>
2572
2564
/*
2573
2565
  SYNOPSIS
2574
2566
  do_rmdir
2575
 
  command       called command
 
2567
  command  called command
2576
2568
 
2577
2569
  DESCRIPTION
2578
2570
  rmdir <dir_name>
2706
2698
/*
2707
2699
  SYNOPSIS
2708
2700
  do_write_file
2709
 
  command       called command
 
2701
  command  called command
2710
2702
 
2711
2703
  DESCRIPTION
2712
2704
  write_file <file_name> [<delimiter>];
2739
2731
/*
2740
2732
  SYNOPSIS
2741
2733
  do_append_file
2742
 
  command       called command
 
2734
  command  called command
2743
2735
 
2744
2736
  DESCRIPTION
2745
2737
  append_file <file_name> [<delimiter>];
2770
2762
/*
2771
2763
  SYNOPSIS
2772
2764
  do_cat_file
2773
 
  command       called command
 
2765
  command  called command
2774
2766
 
2775
2767
  DESCRIPTION
2776
2768
  cat_file <file_name>;
2803
2795
/*
2804
2796
  SYNOPSIS
2805
2797
  do_diff_files
2806
 
  command       called command
 
2798
  command  called command
2807
2799
 
2808
2800
  DESCRIPTION
2809
2801
  diff_files <file1> <file2>;
2861
2853
/*
2862
2854
  SYNOPSIS
2863
2855
  do_send_quit
2864
 
  command       called command
 
2856
  command  called command
2865
2857
 
2866
2858
  DESCRIPTION
2867
2859
  Sends a simple quit command to the server for the named connection.
2886
2878
  if (!(con= find_connection_by_name(name)))
2887
2879
    die("connection '%s' not found in connection pool", name);
2888
2880
 
2889
 
  simple_command(&con->mysql,COM_QUIT,0,0,1);
 
2881
  simple_command(&con->drizzle,COM_QUIT,0,0,1);
2890
2882
 
2891
2883
  return;
2892
2884
}
2910
2902
 
2911
2903
static void do_change_user(struct st_command *command)
2912
2904
{
2913
 
  MYSQL *mysql = &cur_con->mysql;
 
2905
  DRIZZLE *drizzle= &cur_con->drizzle;
2914
2906
  /* static keyword to make the NetWare compiler happy. */
2915
2907
  static DYNAMIC_STRING ds_user, ds_passwd, ds_db;
2916
2908
  const struct command_arg change_user_args[] = {
2927
2919
                     ',');
2928
2920
 
2929
2921
  if (!ds_user.length)
2930
 
    dynstr_set(&ds_user, mysql->user);
 
2922
    dynstr_set(&ds_user, drizzle->user);
2931
2923
 
2932
2924
  if (!ds_passwd.length)
2933
 
    dynstr_set(&ds_passwd, mysql->passwd);
 
2925
    dynstr_set(&ds_passwd, drizzle->passwd);
2934
2926
 
2935
2927
  if (!ds_db.length)
2936
 
    dynstr_set(&ds_db, mysql->db);
 
2928
    dynstr_set(&ds_db, drizzle->db);
2937
2929
 
2938
 
  if (mysql_change_user(mysql, ds_user.str, ds_passwd.str, ds_db.str))
2939
 
    die("change user failed: %s", mysql_error(mysql));
 
2930
  if (drizzle_change_user(drizzle, ds_user.str, ds_passwd.str, ds_db.str))
 
2931
    die("change user failed: %s", drizzle_error(drizzle));
2940
2932
 
2941
2933
  dynstr_free(&ds_user);
2942
2934
  dynstr_free(&ds_passwd);
2949
2941
/*
2950
2942
  SYNOPSIS
2951
2943
  do_perl
2952
 
  command       command handle
 
2944
  command  command handle
2953
2945
 
2954
2946
  DESCRIPTION
2955
2947
  perl [<delimiter>];
3069
3061
do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused)))
3070
3062
{
3071
3063
  static int SLAVE_POLL_INTERVAL= 300000;
3072
 
  MYSQL* mysql = &cur_con->mysql;
 
3064
  DRIZZLE *drizzle= &cur_con->drizzle;
3073
3065
  for (;;)
3074
3066
  {
3075
 
    MYSQL_RES *res= NULL;
3076
 
    MYSQL_ROW row;
 
3067
    DRIZZLE_RES *res= NULL;
 
3068
    DRIZZLE_ROW row;
3077
3069
    int done;
3078
3070
 
3079
 
    if (mysql_query(mysql,"show status like 'Slave_running'") ||
3080
 
        !(res=mysql_store_result(mysql)))
 
3071
    if (drizzle_query(drizzle,"show status like 'Slave_running'") ||
 
3072
  !(res=drizzle_store_result(drizzle)))
3081
3073
      die("Query failed while probing slave for stop: %s",
3082
 
          mysql_error(mysql));
3083
 
    if (!(row=mysql_fetch_row(res)) || !row[1])
 
3074
    drizzle_error(drizzle));
 
3075
    if (!(row=drizzle_fetch_row(res)) || !row[1])
3084
3076
    {
3085
 
      mysql_free_result(res);
 
3077
      drizzle_free_result(res);
3086
3078
      die("Strange result from query while probing slave for stop");
3087
3079
    }
3088
3080
    done = !strcmp(row[1],"OFF");
3089
 
    mysql_free_result(res);
 
3081
    drizzle_free_result(res);
3090
3082
    if (done)
3091
3083
      break;
3092
3084
    my_sleep(SLAVE_POLL_INTERVAL);
3097
3089
 
3098
3090
static void do_sync_with_master2(long offset)
3099
3091
{
3100
 
  MYSQL_RES *res;
3101
 
  MYSQL_ROW row;
3102
 
  MYSQL *mysql= &cur_con->mysql;
 
3092
  DRIZZLE_RES *res;
 
3093
  DRIZZLE_ROW row;
 
3094
  DRIZZLE *drizzle= &cur_con->drizzle;
3103
3095
  char query_buf[FN_REFLEN+128];
3104
3096
  int tries= 0;
3105
3097
 
3107
3099
    die("Calling 'sync_with_master' without calling 'save_master_pos'");
3108
3100
 
3109
3101
  sprintf(query_buf, "select master_pos_wait('%s', %ld)", master_pos.file,
3110
 
          master_pos.pos + offset);
 
3102
    master_pos.pos + offset);
3111
3103
 
3112
3104
wait_for_position:
3113
3105
 
3114
 
  if (mysql_query(mysql, query_buf))
3115
 
    die("failed in '%s': %d: %s", query_buf, mysql_errno(mysql),
3116
 
        mysql_error(mysql));
 
3106
  if (drizzle_query(drizzle, query_buf))
 
3107
    die("failed in '%s': %d: %s", query_buf, drizzle_errno(drizzle),
 
3108
        drizzle_error(drizzle));
3117
3109
 
3118
 
  if (!(res= mysql_store_result(mysql)))
3119
 
    die("mysql_store_result() returned NULL for '%s'", query_buf);
3120
 
  if (!(row= mysql_fetch_row(res)))
 
3110
  if (!(res= drizzle_store_result(drizzle)))
 
3111
    die("drizzle_store_result() returned NULL for '%s'", query_buf);
 
3112
  if (!(row= drizzle_fetch_row(res)))
3121
3113
  {
3122
 
    mysql_free_result(res);
 
3114
    drizzle_free_result(res);
3123
3115
    die("empty result in %s", query_buf);
3124
3116
  }
3125
3117
  if (!row[0])
3128
3120
      It may be that the slave SQL thread has not started yet, though START
3129
3121
      SLAVE has been issued ?
3130
3122
    */
3131
 
    mysql_free_result(res);
 
3123
    drizzle_free_result(res);
3132
3124
    if (tries++ == 30)
3133
3125
    {
3134
 
      show_query(mysql, "SHOW MASTER STATUS");
3135
 
      show_query(mysql, "SHOW SLAVE STATUS");
 
3126
      show_query(drizzle, "SHOW MASTER STATUS");
 
3127
      show_query(drizzle, "SHOW SLAVE STATUS");
3136
3128
      die("could not sync with master ('%s' returned NULL)", query_buf);
3137
3129
    }
3138
3130
    sleep(1); /* So at most we will wait 30 seconds and make 31 tries */
3139
3131
    goto wait_for_position;
3140
3132
  }
3141
 
  mysql_free_result(res);
 
3133
  drizzle_free_result(res);
3142
3134
  return;
3143
3135
}
3144
3136
 
3164
3156
 
3165
3157
/*
3166
3158
  when ndb binlog is on, this call will wait until last updated epoch
3167
 
  (locally in the mysqld) has been received into the binlog
 
3159
  (locally in the drizzled) has been received into the binlog
3168
3160
*/
3169
3161
static int do_save_master_pos(void)
3170
3162
{
3171
 
  MYSQL_RES *res;
3172
 
  MYSQL_ROW row;
3173
 
  MYSQL *mysql = &cur_con->mysql;
 
3163
  DRIZZLE_RES *res;
 
3164
  DRIZZLE_ROW row;
 
3165
  DRIZZLE *drizzle= &cur_con->drizzle;
3174
3166
  const char *query;
3175
3167
 
3176
3168
 
3177
 
  if (mysql_query(mysql, query= "show master status"))
 
3169
  if (drizzle_query(drizzle, query= "show master status"))
3178
3170
    die("failed in 'show master status': %d %s",
3179
 
        mysql_errno(mysql), mysql_error(mysql));
 
3171
  drizzle_errno(drizzle), drizzle_error(drizzle));
3180
3172
 
3181
 
  if (!(res = mysql_store_result(mysql)))
3182
 
    die("mysql_store_result() retuned NULL for '%s'", query);
3183
 
  if (!(row = mysql_fetch_row(res)))
 
3173
  if (!(res = drizzle_store_result(drizzle)))
 
3174
    die("drizzle_store_result() retuned NULL for '%s'", query);
 
3175
  if (!(row = drizzle_fetch_row(res)))
3184
3176
    die("empty result in show master status");
3185
3177
  strnmov(master_pos.file, row[0], sizeof(master_pos.file)-1);
3186
3178
  master_pos.pos = strtoul(row[1], (char**) 0, 10);
3187
 
  mysql_free_result(res);
 
3179
  drizzle_free_result(res);
3188
3180
  return(0);
3189
3181
}
3190
3182
 
3194
3186
 
3195
3187
  SYNOPSIS
3196
3188
  do_let()
3197
 
  query called command
 
3189
  query  called command
3198
3190
 
3199
3191
  DESCRIPTION
3200
3192
  let $<var_name>=<var_val><delimiter>
3252
3244
 
3253
3245
  SYNOPSIS
3254
3246
  do_sleep()
3255
 
  q            called command
 
3247
  q         called command
3256
3248
  real_sleep   use the value from opt_sleep as number of seconds to sleep
3257
3249
               if real_sleep is false
3258
3250
 
3455
3447
 
3456
3448
      /* Convert the sting to int */
3457
3449
      if (!str2int(start, 10, (long) INT_MIN, (long) INT_MAX, &val))
3458
 
        die("Invalid argument to error: '%s'", command->first_argument);
 
3450
  die("Invalid argument to error: '%s'", command->first_argument);
3459
3451
 
3460
3452
      to->code.errnum= (uint) val;
3461
3453
      to->type= ERR_ERRNO;
3505
3497
  if (*from == '"' || *from == '\'')
3506
3498
    sep= *from++;
3507
3499
  else
3508
 
    sep=' ';                            /* Separated with space */
 
3500
    sep=' ';        /* Separated with space */
3509
3501
 
3510
3502
  for ( ; (c=*from) ; from++)
3511
3503
  {
3512
3504
    if (c == '\\' && from[1])
3513
 
    {                                   /* Escaped character */
 
3505
    {          /* Escaped character */
3514
3506
      /* We can't translate \0 -> ASCII 0 as replace can't handle ASCII 0 */
3515
3507
      switch (*++from) {
3516
3508
      case 'n':
3517
 
        *to++= '\n';
3518
 
        break;
 
3509
  *to++= '\n';
 
3510
  break;
3519
3511
      case 't':
3520
 
        *to++= '\t';
3521
 
        break;
 
3512
  *to++= '\t';
 
3513
  break;
3522
3514
      case 'r':
3523
 
        *to++ = '\r';
3524
 
        break;
 
3515
  *to++ = '\r';
 
3516
  break;
3525
3517
      case 'b':
3526
 
        *to++ = '\b';
3527
 
        break;
3528
 
      case 'Z':                         /* ^Z must be escaped on Win32 */
3529
 
        *to++='\032';
3530
 
        break;
 
3518
  *to++ = '\b';
 
3519
  break;
 
3520
      case 'Z':        /* ^Z must be escaped on Win32 */
 
3521
  *to++='\032';
 
3522
  break;
3531
3523
      default:
3532
 
        *to++ = *from;
3533
 
        break;
 
3524
  *to++ = *from;
 
3525
  break;
3534
3526
      }
3535
3527
    }
3536
3528
    else if (c == sep)
3537
3529
    {
3538
3530
      if (c == ' ' || c != *++from)
3539
 
        break;                          /* Found end of string */
3540
 
      *to++=c;                          /* Copy duplicated separator */
 
3531
  break;        /* Found end of string */
 
3532
      *to++=c;        /* Copy duplicated separator */
3541
3533
    }
3542
3534
    else
3543
3535
      *to++=c;
3545
3537
  if (*from != ' ' && *from)
3546
3538
    die("Wrong string argument in %s", command->query);
3547
3539
 
3548
 
  while (my_isspace(charset_info,*from))        /* Point to next string */
 
3540
  while (my_isspace(charset_info,*from))  /* Point to next string */
3549
3541
    from++;
3550
3542
 
3551
 
  *to =0;                               /* End of string marker */
3552
 
  *to_ptr= to+1;                        /* Store pointer to end */
 
3543
  *to =0;        /* End of string marker */
 
3544
  *to_ptr= to+1;      /* Store pointer to end */
3553
3545
  *from_ptr= from;
3554
3546
 
3555
3547
  /* Check if this was a variable */
3558
3550
    const char *end= to;
3559
3551
    VAR *var=var_get(start, &end, 0, 1);
3560
3552
    if (var && to == (char*) end+1)
3561
 
      return(var->str_val);     /* return found variable value */
 
3553
      return(var->str_val);  /* return found variable value */
3562
3554
  }
3563
3555
  return(start);
3564
3556
}
3565
3557
 
3566
3558
 
3567
 
static void set_reconnect(MYSQL* mysql, int val)
 
3559
static void set_reconnect(DRIZZLE *drizzle, int val)
3568
3560
{
3569
3561
  bool reconnect= val;
3570
3562
 
3571
 
  mysql_options(mysql, MYSQL_OPT_RECONNECT, (char *)&reconnect);
 
3563
  drizzle_options(drizzle, DRIZZLE_OPT_RECONNECT, (char *)&reconnect);
3572
3564
 
3573
3565
  return;
3574
3566
}
3579
3571
  if (!(cur_con= find_connection_by_name(name)))
3580
3572
    die("connection '%s' not found in connection pool", name);
3581
3573
 
3582
 
  /* Update $mysql_get_server_version to that of current connection */
3583
 
  var_set_mysql_get_server_version(&cur_con->mysql);
 
3574
  /* Update $drizzle_get_server_version to that of current connection */
 
3575
  var_set_drizzle_get_server_version(&cur_con->drizzle);
3584
3576
 
3585
3577
  return(0);
3586
3578
}
3624
3616
 
3625
3617
  if (command->type == Q_DIRTY_CLOSE)
3626
3618
  {
3627
 
    if (con->mysql.net.vio)
 
3619
    if (con->drizzle.net.vio)
3628
3620
    {
3629
 
      vio_delete(con->mysql.net.vio);
3630
 
      con->mysql.net.vio = 0;
 
3621
      vio_delete(con->drizzle.net.vio);
 
3622
      con->drizzle.net.vio = 0;
3631
3623
    }
3632
3624
  }
3633
3625
 
3634
 
  mysql_close(&con->mysql);
 
3626
  drizzle_close(&con->drizzle);
3635
3627
 
3636
 
  if (con->util_mysql)
3637
 
    mysql_close(con->util_mysql);
3638
 
  con->util_mysql= 0;
 
3628
  if (con->util_drizzle)
 
3629
    drizzle_close(con->util_drizzle);
 
3630
  con->util_drizzle= 0;
3639
3631
 
3640
3632
  my_free(con->name, MYF(0));
3641
3633
 
3675
3667
 
3676
3668
*/
3677
3669
 
3678
 
static void safe_connect(MYSQL* mysql, const char *name, const char *host,
 
3670
static void safe_connect(DRIZZLE *drizzle, const char *name, const char *host,
3679
3671
                  const char *user, const char *pass, const char *db,
3680
3672
                  int port)
3681
3673
{
3683
3675
  static ulong connection_retry_sleep= 100000; /* Microseconds */
3684
3676
 
3685
3677
 
3686
 
  while(!mysql_real_connect(mysql, host, user, pass, db, port, NULL,
 
3678
  while(!drizzle_connect(drizzle, host, user, pass, db, port, NULL,
3687
3679
                            CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS))
3688
3680
  {
3689
3681
    /*
3694
3686
      on protocol/connection type
3695
3687
    */
3696
3688
 
3697
 
    if ((mysql_errno(mysql) == CR_CONN_HOST_ERROR ||
3698
 
         mysql_errno(mysql) == CR_CONNECTION_ERROR) &&
 
3689
    if ((drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
 
3690
         drizzle_errno(drizzle) == CR_CONNECTION_ERROR) &&
3699
3691
        failed_attempts < opt_max_connect_retries)
3700
3692
    {
3701
3693
      verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3702
 
                  opt_max_connect_retries, mysql_errno(mysql),
3703
 
                  mysql_error(mysql));
 
3694
                  opt_max_connect_retries, drizzle_errno(drizzle),
 
3695
                  drizzle_error(drizzle));
3704
3696
      my_sleep(connection_retry_sleep);
3705
3697
    }
3706
3698
    else
3707
3699
    {
3708
3700
      if (failed_attempts > 0)
3709
3701
        die("Could not open connection '%s' after %d attempts: %d %s", name,
3710
 
            failed_attempts, mysql_errno(mysql), mysql_error(mysql));
 
3702
            failed_attempts, drizzle_errno(drizzle), drizzle_error(drizzle));
3711
3703
      else
3712
3704
        die("Could not open connection '%s': %d %s", name,
3713
 
            mysql_errno(mysql), mysql_error(mysql));
 
3705
            drizzle_errno(drizzle), drizzle_error(drizzle));
3714
3706
    }
3715
3707
    failed_attempts++;
3716
3708
  }
3742
3734
*/
3743
3735
 
3744
3736
static int connect_n_handle_errors(struct st_command *command,
3745
 
                            MYSQL* con, const char* host,
 
3737
                            DRIZZLE *con, const char* host,
3746
3738
                            const char* user, const char* pass,
3747
3739
                            const char* db, int port, const char* sock)
3748
3740
{
3775
3767
    dynstr_append_mem(ds, delimiter, delimiter_length);
3776
3768
    dynstr_append_mem(ds, "\n", 1);
3777
3769
  }
3778
 
  if (!mysql_real_connect(con, host, user, pass, db, port, 0,
 
3770
  if (!drizzle_connect(con, host, user, pass, db, port, 0,
3779
3771
                          CLIENT_MULTI_STATEMENTS))
3780
3772
  {
3781
 
    var_set_errno(mysql_errno(con));
3782
 
    handle_error(command, mysql_errno(con), mysql_error(con),
3783
 
                 mysql_sqlstate(con), ds);
 
3773
    var_set_errno(drizzle_errno(con));
 
3774
    handle_error(command, drizzle_errno(con), drizzle_error(con),
 
3775
     drizzle_sqlstate(con), ds);
3784
3776
    return 0; /* Not connected */
3785
3777
  }
3786
3778
 
3791
3783
 
3792
3784
 
3793
3785
/*
3794
 
  Open a new connection to MySQL Server with the parameters
 
3786
  Open a new connection to DRIZZLE Server with the parameters
3795
3787
  specified. Make the new connection the current connection.
3796
3788
 
3797
3789
  SYNOPSIS
3798
3790
  do_connect()
3799
 
  q            called command
 
3791
  q         called command
3800
3792
 
3801
3793
  DESCRIPTION
3802
3794
  connect(<name>,<host>,<user>,[<pass>,[<db>,[<port>,<sock>[<opts>]]]]);
3892
3884
    else if (!strncmp(con_options, "COMPRESS", 8))
3893
3885
      con_compress= 1;
3894
3886
    else
3895
 
      die("Illegal option to connect: %.*s", 
 
3887
      die("Illegal option to connect: %.*s",
3896
3888
          (int) (end - con_options), con_options);
3897
3889
    /* Process next option */
3898
3890
    con_options= end;
3900
3892
 
3901
3893
  if (find_connection_by_name(ds_connection_name.str))
3902
3894
    die("Connection %s already exists", ds_connection_name.str);
3903
 
    
 
3895
   
3904
3896
  if (next_con != connections_end)
3905
3897
    con_slot= next_con;
3906
3898
  else
3913
3905
#ifdef EMBEDDED_LIBRARY
3914
3906
  con_slot->query_done= 1;
3915
3907
#endif
3916
 
  if (!mysql_init(&con_slot->mysql))
3917
 
    die("Failed on mysql_init()");
 
3908
  if (!drizzle_create(&con_slot->drizzle))
 
3909
    die("Failed on drizzle_create()");
3918
3910
  if (opt_compress || con_compress)
3919
 
    mysql_options(&con_slot->mysql, MYSQL_OPT_COMPRESS, NullS);
3920
 
  mysql_options(&con_slot->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
3921
 
  mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_NAME,
 
3911
    drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NullS);
 
3912
  drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
 
3913
  drizzle_options(&con_slot->drizzle, DRIZZLE_SET_CHARSET_NAME,
3922
3914
                charset_info->csname);
3923
 
  int opt_protocol= MYSQL_PROTOCOL_TCP;
3924
 
  mysql_options(&con_slot->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
3915
  int opt_protocol= DRIZZLE_PROTOCOL_TCP;
 
3916
  drizzle_options(&con_slot->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
3925
3917
  if (opt_charsets_dir)
3926
 
    mysql_options(&con_slot->mysql, MYSQL_SET_CHARSET_DIR,
 
3918
    drizzle_options(&con_slot->drizzle, DRIZZLE_SET_CHARSET_DIR,
3927
3919
                  opt_charsets_dir);
3928
3920
 
3929
3921
  /* Use default db name */
3934
3926
  if (ds_database.length && !strcmp(ds_database.str,"*NO-ONE*"))
3935
3927
    dynstr_set(&ds_database, "");
3936
3928
 
3937
 
  if (connect_n_handle_errors(command, &con_slot->mysql,
 
3929
  if (connect_n_handle_errors(command, &con_slot->drizzle,
3938
3930
                              ds_host.str,ds_user.str,
3939
3931
                              ds_password.str, ds_database.str,
3940
3932
                              con_port, ds_sock.str))
3942
3934
    if (!(con_slot->name= my_strdup(ds_connection_name.str, MYF(MY_WME))))
3943
3935
      die("Out of memory");
3944
3936
    cur_con= con_slot;
3945
 
    
 
3937
   
3946
3938
    if (con_slot == next_con)
3947
3939
      next_con++; /* if we used the next_con slot, advance the pointer */
3948
3940
  }
3949
3941
 
3950
 
  /* Update $mysql_get_server_version to that of current connection */
3951
 
  var_set_mysql_get_server_version(&cur_con->mysql);
 
3942
  /* Update $drizzle_get_server_version to that of current connection */
 
3943
  var_set_drizzle_get_server_version(&cur_con->drizzle);
3952
3944
 
3953
3945
  dynstr_free(&ds_connection_name);
3954
3946
  dynstr_free(&ds_host);
3995
3987
  SYNOPSIS
3996
3988
  do_block()
3997
3989
  cmd        Type of block
3998
 
  q            called command
 
3990
  q         called command
3999
3991
 
4000
3992
  DESCRIPTION
4001
3993
  if ([!]<expr>)
4105
4097
    return 0;
4106
4098
 
4107
4099
  for (i= 1; i < length &&
4108
 
         (c= my_getc(cur_file->file)) == *(delim + i);
 
4100
   (c= my_getc(cur_file->file)) == *(delim + i);
4109
4101
       i++)
4110
4102
    tmp[i]= c;
4111
4103
 
4112
4104
  if (i == length)
4113
 
    return 1;                                   /* Found delimiter */
 
4105
    return 1;          /* Found delimiter */
4114
4106
 
4115
4107
  /* didn't find delimiter, push back things that we read */
4116
4108
  my_ungetc(c);
4169
4161
  found_eof:
4170
4162
      if (cur_file->file != stdin)
4171
4163
      {
4172
 
        my_fclose(cur_file->file, MYF(0));
 
4164
  my_fclose(cur_file->file, MYF(0));
4173
4165
        cur_file->file= 0;
4174
4166
      }
4175
4167
      my_free((uchar*) cur_file->file_name, MYF(MY_ALLOW_ZERO_PTR));
4204
4196
    case R_NORMAL:
4205
4197
      if (end_of_query(c))
4206
4198
      {
4207
 
        *p= 0;
4208
 
        return(0);
 
4199
  *p= 0;
 
4200
  return(0);
4209
4201
      }
4210
4202
      else if ((c == '{' &&
4211
4203
                (!my_strnncoll_simple(charset_info, (const uchar*) "while", 5,
4215
4207
      {
4216
4208
        /* Only if and while commands can be terminated by { */
4217
4209
        *p++= c;
4218
 
        *p= 0;
4219
 
        return(0);
 
4210
  *p= 0;
 
4211
  return(0);
4220
4212
      }
4221
4213
      else if (c == '\'' || c == '"' || c == '`')
4222
4214
      {
4223
4215
        last_quote= c;
4224
 
        state= R_Q;
 
4216
  state= R_Q;
4225
4217
      }
4226
4218
      break;
4227
4219
 
4229
4221
      if (c == '\n')
4230
4222
      {
4231
4223
        /* Comments are terminated by newline */
4232
 
        *p= 0;
4233
 
        return(0);
 
4224
  *p= 0;
 
4225
  return(0);
4234
4226
      }
4235
4227
      break;
4236
4228
 
4238
4230
      if (c == '#' || c == '-')
4239
4231
      {
4240
4232
        /* A # or - in the first position of the line - this is a comment */
4241
 
        state = R_COMMENT;
 
4233
  state = R_COMMENT;
4242
4234
      }
4243
4235
      else if (my_isspace(charset_info, c))
4244
4236
      {
4245
4237
        /* Skip all space at begining of line */
4246
 
        if (c == '\n')
 
4238
  if (c == '\n')
4247
4239
        {
4248
4240
          /* Query hasn't started yet */
4249
 
          start_lineno= cur_file->lineno;
 
4241
    start_lineno= cur_file->lineno;
4250
4242
        }
4251
 
        skip_char= 1;
 
4243
  skip_char= 1;
4252
4244
      }
4253
4245
      else if (end_of_query(c))
4254
4246
      {
4255
 
        *p= 0;
4256
 
        return(0);
 
4247
  *p= 0;
 
4248
  return(0);
4257
4249
      }
4258
4250
      else if (c == '}')
4259
4251
      {
4260
4252
        /* A "}" need to be by itself in the begining of a line to terminate */
4261
4253
        *p++= c;
4262
 
        *p= 0;
4263
 
        return(0);
 
4254
  *p= 0;
 
4255
  return(0);
4264
4256
      }
4265
4257
      else if (c == '\'' || c == '"' || c == '`')
4266
4258
      {
4267
4259
        last_quote= c;
4268
 
        state= R_Q;
 
4260
  state= R_Q;
4269
4261
      }
4270
4262
      else
4271
 
        state= R_NORMAL;
 
4263
  state= R_NORMAL;
4272
4264
      break;
4273
4265
 
4274
4266
    case R_Q:
4275
4267
      if (c == last_quote)
4276
 
        state= R_NORMAL;
 
4268
  state= R_NORMAL;
4277
4269
      else if (c == '\\')
4278
 
        state= R_SLASH_IN_Q;
 
4270
  state= R_SLASH_IN_Q;
4279
4271
      break;
4280
4272
 
4281
4273
    case R_SLASH_IN_Q:
4294
4286
      /* completed before we pass buf_end */
4295
4287
      if ((charlen > 1) && (p + charlen) <= buf_end)
4296
4288
      {
4297
 
        int i;
4298
 
        char* mb_start = p;
4299
 
 
4300
 
        *p++ = c;
4301
 
 
4302
 
        for (i= 1; i < charlen; i++)
4303
 
        {
4304
 
          if (feof(cur_file->file))
4305
 
            goto found_eof;
4306
 
          c= my_getc(cur_file->file);
4307
 
          *p++ = c;
4308
 
        }
4309
 
        if (! my_ismbchar(charset_info, mb_start, p))
4310
 
        {
4311
 
          /* It was not a multiline char, push back the characters */
4312
 
          /* We leave first 'c', i.e. pretend it was a normal char */
4313
 
          while (p > mb_start)
4314
 
            my_ungetc(*--p);
4315
 
        }
 
4289
  int i;
 
4290
  char* mb_start = p;
 
4291
 
 
4292
  *p++ = c;
 
4293
 
 
4294
  for (i= 1; i < charlen; i++)
 
4295
  {
 
4296
    if (feof(cur_file->file))
 
4297
      goto found_eof;
 
4298
    c= my_getc(cur_file->file);
 
4299
    *p++ = c;
 
4300
  }
 
4301
  if (! my_ismbchar(charset_info, mb_start, p))
 
4302
  {
 
4303
    /* It was not a multiline char, push back the characters */
 
4304
    /* We leave first 'c', i.e. pretend it was a normal char */
 
4305
    while (p > mb_start)
 
4306
      my_ungetc(*--p);
 
4307
  }
4316
4308
      }
4317
4309
      else
4318
4310
#endif
4319
 
        *p++= c;
 
4311
  *p++= c;
4320
4312
    }
4321
4313
  }
4322
4314
  die("The input buffer is too small for this query.x\n" \
4379
4371
 
4380
4372
/*
4381
4373
  Check a command that is about to be sent (or should have been
4382
 
  sent if parsing was enabled) to mysql server for
 
4374
  sent if parsing was enabled) to DRIZZLE server for
4383
4375
  suspicious things and generate warnings.
4384
4376
*/
4385
4377
 
4391
4383
  {
4392
4384
    /*
4393
4385
      Look for query's that lines that start with a -- comment
4394
 
      and has a mysqltest command
 
4386
      and has a drizzletest command
4395
4387
    */
4396
4388
    if (ptr[0] == '\n' &&
4397
4389
        ptr[1] && ptr[1] == '-' &&
4412
4404
      *end= 0;
4413
4405
      type= find_type(start, &command_typelib, 1+2);
4414
4406
      if (type)
4415
 
        warning_msg("Embedded mysqltest command '--%s' detected in "
 
4407
        warning_msg("Embedded drizzletest command '--%s' detected in "
4416
4408
                    "query '%s' was this intentional? ",
4417
4409
                    start, command->query);
4418
4410
      *end= save;
4639
4631
};
4640
4632
 
4641
4633
 
4642
 
#include <help_start.h>
4643
 
 
4644
4634
static void print_version(void)
4645
4635
{
4646
4636
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4647
 
         MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
 
4637
   MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4648
4638
}
4649
4639
 
4650
4640
static void usage(void)
4651
4641
{
4652
4642
  print_version();
4653
 
  printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
 
4643
  printf("DRIZZLE AB, by Sasha, Matt, Monty & Jani\n");
4654
4644
  printf("This software comes with ABSOLUTELY NO WARRANTY\n\n");
4655
 
  printf("Runs a test against the mysql server and compares output with a results file.\n\n");
 
4645
  printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4656
4646
  printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4657
4647
  my_print_help(my_long_options);
4658
4648
  printf("  --no-defaults       Don't read default options from any options file.\n");
4659
4649
  my_print_variables(my_long_options);
4660
4650
}
4661
4651
 
4662
 
#include <help_end.h>
4663
 
 
4664
 
 
4665
4652
/*
4666
4653
  Read arguments for embedded server and put them into
4667
4654
  embedded_server_args[]
4682
4669
  if (!embedded_server_arg_count)
4683
4670
  {
4684
4671
    embedded_server_arg_count=1;
4685
 
    embedded_server_args[0]= (char*) "";                /* Progname */
 
4672
    embedded_server_args[0]= (char*) "";    /* Progname */
4686
4673
  }
4687
4674
  if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
4688
4675
    die("Failed to open file '%s'", buff);
4689
4676
 
4690
4677
  while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4691
 
         (str=fgets(argument,sizeof(argument), file)))
 
4678
   (str=fgets(argument,sizeof(argument), file)))
4692
4679
  {
4693
 
    *(strend(str)-1)=0;                         /* Remove end newline */
 
4680
    *(strend(str)-1)=0;        /* Remove end newline */
4694
4681
    if (!(embedded_server_args[embedded_server_arg_count]=
4695
 
          (char*) my_strdup(str,MYF(MY_WME))))
 
4682
    (char*) my_strdup(str,MYF(MY_WME))))
4696
4683
    {
4697
4684
      my_fclose(file,MYF(0));
4698
4685
      die("Out of memory");
4710
4697
 
4711
4698
static bool
4712
4699
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
4713
 
               char *argument)
 
4700
         char *argument)
4714
4701
{
4715
4702
  switch(optid) {
4716
4703
  case 'r':
4743
4730
    }
4744
4731
    fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4745
4732
    timer_file= buff;
4746
 
    unlink(timer_file);      /* Ignore error, may not exist */
 
4733
    unlink(timer_file);       /* Ignore error, may not exist */
4747
4734
    break;
4748
4735
  }
4749
4736
  case 'p':
4751
4738
    {
4752
4739
      my_free(opt_pass, MYF(MY_ALLOW_ZERO_PTR));
4753
4740
      opt_pass= my_strdup(argument, MYF(MY_FAE));
4754
 
      while (*argument) *argument++= 'x';               /* Destroy argument */
 
4741
      while (*argument) *argument++= 'x';    /* Destroy argument */
4755
4742
      tty_password= 0;
4756
4743
    }
4757
4744
    else
4899
4886
  Append the result for one field to the dynamic string ds
4900
4887
*/
4901
4888
 
4902
 
static void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD* field,
 
4889
static void append_field(DYNAMIC_STRING *ds, uint col_idx, DRIZZLE_FIELD* field,
4903
4890
                         const char* val, uint64_t len, bool is_null)
4904
4891
{
4905
4892
  if (col_idx < max_replace_column && replace_column[col_idx])
4934
4921
  Values may be converted with 'replace_column'
4935
4922
*/
4936
4923
 
4937
 
static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
 
4924
static void append_result(DYNAMIC_STRING *ds, DRIZZLE_RES *res)
4938
4925
{
4939
 
  MYSQL_ROW row;
4940
 
  uint32_t num_fields= mysql_num_fields(res);
4941
 
  MYSQL_FIELD *fields= mysql_fetch_fields(res);
 
4926
  DRIZZLE_ROW row;
 
4927
  uint32_t num_fields= drizzle_num_fields(res);
 
4928
  DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4942
4929
  uint32_t *lengths;
4943
4930
 
4944
 
  while ((row = mysql_fetch_row(res)))
 
4931
  while ((row = drizzle_fetch_row(res)))
4945
4932
  {
4946
4933
    uint32_t i;
4947
 
    lengths = mysql_fetch_lengths(res);
 
4934
    lengths = drizzle_fetch_lengths(res);
4948
4935
    for (i = 0; i < num_fields; i++)
4949
4936
      append_field(ds, i, &fields[i],
4950
4937
                   (const char*)row[i], lengths[i], !row[i]);
4959
4946
*/
4960
4947
 
4961
4948
static void append_metadata(DYNAMIC_STRING *ds,
4962
 
                            MYSQL_FIELD *field,
 
4949
                            DRIZZLE_FIELD *field,
4963
4950
                            uint num_fields)
4964
4951
{
4965
 
  MYSQL_FIELD *field_end;
 
4952
  DRIZZLE_FIELD *field_end;
4966
4953
  dynstr_append(ds,"Catalog\tDatabase\tTable\tTable_alias\tColumn\t"
4967
4954
                "Column_alias\tType\tLength\tMax length\tIs_null\t"
4968
4955
                "Flags\tDecimals\tCharsetnr\n");
5030
5017
*/
5031
5018
 
5032
5019
static void append_table_headings(DYNAMIC_STRING *ds,
5033
 
                                  MYSQL_FIELD *field,
 
5020
                                  DRIZZLE_FIELD *field,
5034
5021
                                  uint num_fields)
5035
5022
{
5036
5023
  uint col_idx;
5050
5037
  Number of warnings appended to ds
5051
5038
*/
5052
5039
 
5053
 
static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql)
 
5040
static int append_warnings(DYNAMIC_STRING *ds, DRIZZLE *drizzle)
5054
5041
{
5055
5042
  uint count;
5056
 
  MYSQL_RES *warn_res;
5057
 
 
5058
 
 
5059
 
  if (!(count= mysql_warning_count(mysql)))
 
5043
  DRIZZLE_RES *warn_res;
 
5044
 
 
5045
 
 
5046
  if (!(count= drizzle_warning_count(drizzle)))
5060
5047
    return(0);
5061
5048
 
5062
5049
  /*
5064
5051
    through PS API we should not issue SHOW WARNINGS until
5065
5052
    we have not read all results...
5066
5053
  */
5067
 
  assert(!mysql_more_results(mysql));
5068
 
 
5069
 
  if (mysql_real_query(mysql, "SHOW WARNINGS", 13))
5070
 
    die("Error running query \"SHOW WARNINGS\": %s", mysql_error(mysql));
5071
 
 
5072
 
  if (!(warn_res= mysql_store_result(mysql)))
 
5054
  assert(!drizzle_more_results(drizzle));
 
5055
 
 
5056
  if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
 
5057
    die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
 
5058
 
 
5059
  if (!(warn_res= drizzle_store_result(drizzle)))
5073
5060
    die("Warning count is %u but didn't get any warnings",
5074
 
        count);
 
5061
  count);
5075
5062
 
5076
5063
  append_result(ds, warn_res);
5077
 
  mysql_free_result(warn_res);
 
5064
  drizzle_free_result(warn_res);
5078
5065
 
5079
5066
  return(count);
5080
5067
}
5081
5068
 
5082
5069
 
5083
5070
/*
5084
 
  Run query using MySQL C API
 
5071
  Run query using DRIZZLE C API
5085
5072
 
5086
5073
  SYNOPSIS
5087
5074
    run_query_normal()
5088
 
    mysql       mysql handle
5089
 
    command     current command pointer
5090
 
    flags       flags indicating if we should SEND and/or REAP
5091
 
    query       query string to execute
5092
 
    query_len   length query string to execute
5093
 
    ds          output buffer where to store result form query
 
5075
    drizzle  DRIZZLE handle
 
5076
    command  current command pointer
 
5077
    flags  flags indicating if we should SEND and/or REAP
 
5078
    query  query string to execute
 
5079
    query_len  length query string to execute
 
5080
    ds    output buffer where to store result form query
5094
5081
*/
5095
5082
 
5096
5083
static void run_query_normal(struct st_connection *cn,
5098
5085
                             int flags, char *query, int query_len,
5099
5086
                             DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings)
5100
5087
{
5101
 
  MYSQL_RES *res= 0;
5102
 
  MYSQL *mysql= &cn->mysql;
 
5088
  DRIZZLE_RES *res= 0;
 
5089
  DRIZZLE *drizzle= &cn->drizzle;
5103
5090
  int err= 0, counter= 0;
5104
5091
 
5105
5092
  if (flags & QUERY_SEND_FLAG)
5109
5096
    */
5110
5097
    if (do_send_query(cn, query, query_len, flags))
5111
5098
    {
5112
 
      handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5113
 
                   mysql_sqlstate(mysql), ds);
 
5099
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5100
       drizzle_sqlstate(drizzle), ds);
5114
5101
      goto end;
5115
5102
    }
5116
5103
  }
5128
5115
  do
5129
5116
  {
5130
5117
    /*
5131
 
      When  on first result set, call mysql_read_query_result to retrieve
 
5118
      When  on first result set, call drizzle_read_query_result to retrieve
5132
5119
      answer to the query sent earlier
5133
5120
    */
5134
 
    if ((counter==0) && mysql_read_query_result(mysql))
 
5121
    if ((counter==0) && drizzle_read_query_result(drizzle))
5135
5122
    {
5136
 
      handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5137
 
                   mysql_sqlstate(mysql), ds);
 
5123
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5124
       drizzle_sqlstate(drizzle), ds);
5138
5125
      goto end;
5139
5126
 
5140
5127
    }
5142
5129
    /*
5143
5130
      Store the result of the query if it will return any fields
5144
5131
    */
5145
 
    if (mysql_field_count(mysql) && ((res= mysql_store_result(mysql)) == 0))
 
5132
    if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
5146
5133
    {
5147
 
      handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5148
 
                   mysql_sqlstate(mysql), ds);
 
5134
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5135
       drizzle_sqlstate(drizzle), ds);
5149
5136
      goto end;
5150
5137
    }
5151
5138
 
5155
5142
 
5156
5143
      if (res)
5157
5144
      {
5158
 
        MYSQL_FIELD *fields= mysql_fetch_fields(res);
5159
 
        uint num_fields= mysql_num_fields(res);
 
5145
  DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
 
5146
  uint num_fields= drizzle_num_fields(res);
5160
5147
 
5161
 
        if (display_metadata)
 
5148
  if (display_metadata)
5162
5149
          append_metadata(ds, fields, num_fields);
5163
5150
 
5164
 
        if (!display_result_vertically)
5165
 
          append_table_headings(ds, fields, num_fields);
 
5151
  if (!display_result_vertically)
 
5152
    append_table_headings(ds, fields, num_fields);
5166
5153
 
5167
 
        append_result(ds, res);
 
5154
  append_result(ds, res);
5168
5155
      }
5169
5156
 
5170
5157
      /*
5171
 
        Need to call mysql_affected_rows() before the "new"
 
5158
        Need to call drizzle_affected_rows() before the "new"
5172
5159
        query to find the warnings
5173
5160
      */
5174
5161
      if (!disable_info)
5175
 
        affected_rows= mysql_affected_rows(mysql);
 
5162
        affected_rows= drizzle_affected_rows(drizzle);
5176
5163
 
5177
5164
      /*
5178
5165
        Add all warnings to the result. We can't do this if we are in
5179
5166
        the middle of processing results from multi-statement, because
5180
5167
        this will break protocol.
5181
5168
      */
5182
 
      if (!disable_warnings && !mysql_more_results(mysql))
 
5169
      if (!disable_warnings && !drizzle_more_results(drizzle))
5183
5170
      {
5184
 
        if (append_warnings(ds_warnings, mysql) || ds_warnings->length)
5185
 
        {
5186
 
          dynstr_append_mem(ds, "Warnings:\n", 10);
5187
 
          dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
5188
 
        }
 
5171
  if (append_warnings(ds_warnings, drizzle) || ds_warnings->length)
 
5172
  {
 
5173
    dynstr_append_mem(ds, "Warnings:\n", 10);
 
5174
    dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
 
5175
  }
5189
5176
      }
5190
5177
 
5191
5178
      if (!disable_info)
5192
 
        append_info(ds, affected_rows, mysql_info(mysql));
 
5179
  append_info(ds, affected_rows, drizzle_info(drizzle));
5193
5180
    }
5194
5181
 
5195
5182
    if (res)
5196
5183
    {
5197
 
      mysql_free_result(res);
 
5184
      drizzle_free_result(res);
5198
5185
      res= 0;
5199
5186
    }
5200
5187
    counter++;
5201
 
  } while (!(err= mysql_next_result(mysql)));
 
5188
  } while (!(err= drizzle_next_result(drizzle)));
5202
5189
  if (err > 0)
5203
5190
  {
5204
 
    /* We got an error from mysql_next_result, maybe expected */
5205
 
    handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5206
 
                 mysql_sqlstate(mysql), ds);
 
5191
    /* We got an error from drizzle_next_result, maybe expected */
 
5192
    handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5193
     drizzle_sqlstate(drizzle), ds);
5207
5194
    goto end;
5208
5195
  }
5209
5196
  assert(err == -1); /* Successful and there are no more results */
5214
5201
end:
5215
5202
 
5216
5203
  /*
5217
 
    We save the return code (mysql_errno(mysql)) from the last call sent
5218
 
    to the server into the mysqltest builtin variable $mysql_errno. This
 
5204
    We save the return code (drizzle_errno(drizzle)) from the last call sent
 
5205
    to the server into the drizzletest builtin variable $drizzle_errno. This
5219
5206
    variable then can be used from the test case itself.
5220
5207
  */
5221
 
  var_set_errno(mysql_errno(mysql));
 
5208
  var_set_errno(drizzle_errno(drizzle));
5222
5209
  return;
5223
5210
}
5224
5211
 
5235
5222
  ds    - dynamic string which is used for output buffer
5236
5223
 
5237
5224
  NOTE
5238
 
    If there is an unexpected error this function will abort mysqltest
 
5225
    If there is an unexpected error this function will abort drizzletest
5239
5226
    immediately.
5240
5227
*/
5241
5228
 
5315
5302
    else
5316
5303
      die("query '%s' failed with wrong sqlstate %s: '%s', instead of %s...",
5317
5304
          command->query, err_sqlstate, err_error,
5318
 
          command->expected_errors.err[0].code.sqlstate);
 
5305
    command->expected_errors.err[0].code.sqlstate);
5319
5306
  }
5320
5307
 
5321
5308
  return;
5361
5348
 
5362
5349
  SYNPOSIS
5363
5350
    run_query()
5364
 
     mysql      mysql handle
5365
 
     command    currrent command pointer
 
5351
     drizzle  DRIZZLE handle
 
5352
     command  currrent command pointer
5366
5353
 
5367
5354
  flags control the phased/stages of query execution to be performed
5368
5355
  if QUERY_SEND_FLAG bit is on, the query will be sent. If QUERY_REAP_FLAG
5369
5356
  is on the result will be read - for regular query, both bits must be on
5370
5357
*/
5371
5358
 
5372
 
static void run_query(struct st_connection *cn, 
 
5359
static void run_query(struct st_connection *cn,
5373
5360
                      struct st_command *command,
5374
5361
                      int flags)
5375
5362
{
5493
5480
  command->query[command->first_word_len]= save;
5494
5481
  if (type > 0)
5495
5482
  {
5496
 
    command->type=(enum enum_commands) type;            /* Found command */
 
5483
    command->type=(enum enum_commands) type;    /* Found command */
5497
5484
 
5498
5485
    /*
5499
5486
      Look for case where "query" was explicitly specified to
5507
5494
  }
5508
5495
  else
5509
5496
  {
5510
 
    /* No mysqltest command matched */
 
5497
    /* No drizzletest command matched */
5511
5498
 
5512
5499
    if (command->type != Q_COMMENT_WITH_COMMAND)
5513
5500
    {
5514
 
      /* A query that will sent to mysqld */
 
5501
      /* A query that will sent to drizzled */
5515
5502
      command->type= Q_QUERY;
5516
5503
    }
5517
5504
    else
5518
5505
    {
5519
 
      /* -- comment that didn't contain a mysqltest command */
 
5506
      /* -- comment that didn't contain a drizzletest command */
5520
5507
      command->type= Q_COMMENT;
5521
5508
      warning_msg("Suspicious command '--%s' detected, was this intentional? "\
5522
5509
                  "Use # instead of -- to avoid this warning",
5655
5642
  init_dynamic_string(&ds_warning_messages, "", 0, 2048);
5656
5643
  parse_args(argc, argv);
5657
5644
 
5658
 
  if (mysql_server_init(embedded_server_arg_count,
5659
 
                        embedded_server_args,
5660
 
                        (char**) embedded_server_groups))
5661
 
    die("Can't initialize MySQL server");
5662
5645
  server_initialized= 1;
5663
5646
  if (cur_file == file_stack && cur_file->file == 0)
5664
5647
  {
5667
5650
    cur_file->lineno= 1;
5668
5651
  }
5669
5652
  cur_con= connections;
5670
 
  if (!( mysql_init(&cur_con->mysql)))
5671
 
    die("Failed in mysql_init()");
 
5653
  if (!( drizzle_create(&cur_con->drizzle)))
 
5654
    die("Failed in drizzle_create()");
5672
5655
  if (opt_compress)
5673
 
    mysql_options(&cur_con->mysql,MYSQL_OPT_COMPRESS,NullS);
5674
 
  mysql_options(&cur_con->mysql, MYSQL_OPT_LOCAL_INFILE, 0);
5675
 
  mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_NAME,
 
5656
    drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NullS);
 
5657
  drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
 
5658
  drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_NAME,
5676
5659
                charset_info->csname);
5677
 
  int opt_protocol= MYSQL_PROTOCOL_TCP;
5678
 
  mysql_options(&cur_con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
5660
  int opt_protocol= DRIZZLE_PROTOCOL_TCP;
 
5661
  drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
5679
5662
  if (opt_charsets_dir)
5680
 
    mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR,
 
5663
    drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_DIR,
5681
5664
                  opt_charsets_dir);
5682
5665
 
5683
5666
  if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5684
5667
    die("Out of memory");
5685
5668
 
5686
 
  safe_connect(&cur_con->mysql, cur_con->name, opt_host, opt_user, opt_pass,
 
5669
  safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5687
5670
               opt_db, opt_port);
5688
5671
 
5689
5672
  /* Use all time until exit if no explicit 'start_timer' */
5690
5673
  timer_start= timer_now();
5691
5674
 
5692
5675
  /*
5693
 
    Initialize $mysql_errno with -1, so we can
 
5676
    Initialize $drizzle_errno with -1, so we can
5694
5677
    - distinguish it from valid values ( >= 0 ) and
5695
5678
    - detect if there was never a command sent to the server
5696
5679
  */
5697
5680
  var_set_errno(-1);
5698
5681
 
5699
 
  /* Update $mysql_get_server_version to that of current connection */
5700
 
  var_set_mysql_get_server_version(&cur_con->mysql);
 
5682
  /* Update $drizzle_get_server_version to that of current connection */
 
5683
  var_set_drizzle_get_server_version(&cur_con->drizzle);
5701
5684
 
5702
5685
  if (opt_include)
5703
5686
  {
5729
5712
      case Q_CONNECTION: select_connection(command); break;
5730
5713
      case Q_DISCONNECT:
5731
5714
      case Q_DIRTY_CLOSE:
5732
 
        do_close_connection(command); break;
 
5715
  do_close_connection(command); break;
5733
5716
      case Q_ENABLE_QUERY_LOG:   disable_query_log=0; break;
5734
5717
      case Q_DISABLE_QUERY_LOG:  disable_query_log=1; break;
5735
5718
      case Q_ENABLE_ABORT_ON_ERROR:  abort_on_error=1; break;
5765
5748
      case Q_PERL: do_perl(command); break;
5766
5749
      case Q_DELIMITER:
5767
5750
        do_delimiter(command);
5768
 
        break;
 
5751
  break;
5769
5752
      case Q_DISPLAY_VERTICAL_RESULTS:
5770
5753
        display_result_vertically= true;
5771
5754
        break;
5772
5755
      case Q_DISPLAY_HORIZONTAL_RESULTS:
5773
 
        display_result_vertically= false;
 
5756
  display_result_vertically= false;
5774
5757
        break;
5775
5758
      case Q_SORTED_RESULT:
5776
5759
        /*
5777
5760
          Turn on sorting of result set, will be reset after next
5778
5761
          command
5779
5762
        */
5780
 
        display_result_sorted= true;
 
5763
  display_result_sorted= true;
5781
5764
        break;
5782
5765
      case Q_LET: do_let(command); break;
5783
5766
      case Q_EVAL_RESULT:
5785
5768
      case Q_EVAL:
5786
5769
      case Q_QUERY_VERTICAL:
5787
5770
      case Q_QUERY_HORIZONTAL:
5788
 
        if (command->query == command->query_buf)
 
5771
  if (command->query == command->query_buf)
5789
5772
        {
5790
5773
          /* Skip the first part of command, i.e query_xxx */
5791
 
          command->query= command->first_argument;
 
5774
    command->query= command->first_argument;
5792
5775
          command->first_word_len= 0;
5793
5776
        }
5794
 
        /* fall through */
 
5777
  /* fall through */
5795
5778
      case Q_QUERY:
5796
5779
      case Q_REAP:
5797
5780
      {
5798
 
        bool old_display_result_vertically= display_result_vertically;
 
5781
  bool old_display_result_vertically= display_result_vertically;
5799
5782
        /* Default is full query, both reap and send  */
5800
5783
        int flags= QUERY_REAP_FLAG | QUERY_SEND_FLAG;
5801
5784
 
5813
5796
        /* Check for special property for this query */
5814
5797
        display_result_vertically|= (command->type == Q_QUERY_VERTICAL);
5815
5798
 
5816
 
        if (save_file[0])
5817
 
        {
5818
 
          strmake(command->require_file, save_file, sizeof(save_file) - 1);
5819
 
          save_file[0]= 0;
5820
 
        }
5821
 
        run_query(cur_con, command, flags);
5822
 
        command_executed++;
 
5799
  if (save_file[0])
 
5800
  {
 
5801
    strmake(command->require_file, save_file, sizeof(save_file) - 1);
 
5802
    save_file[0]= 0;
 
5803
  }
 
5804
  run_query(cur_con, command, flags);
 
5805
  command_executed++;
5823
5806
        command->last_argument= command->end;
5824
5807
 
5825
5808
        /* Restore settings */
5826
 
        display_result_vertically= old_display_result_vertically;
 
5809
  display_result_vertically= old_display_result_vertically;
5827
5810
 
5828
 
        break;
 
5811
  break;
5829
5812
      }
5830
5813
      case Q_SEND:
5831
5814
        if (!*command->first_argument)
5839
5822
        }
5840
5823
 
5841
5824
        /* Remove "send" if this is first iteration */
5842
 
        if (command->query == command->query_buf)
5843
 
          command->query= command->first_argument;
 
5825
  if (command->query == command->query_buf)
 
5826
    command->query= command->first_argument;
5844
5827
 
5845
 
        /*
5846
 
          run_query() can execute a query partially, depending on the flags.
5847
 
          QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
 
5828
  /*
 
5829
    run_query() can execute a query partially, depending on the flags.
 
5830
    QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
5848
5831
          the query and read the result some time later when reap instruction
5849
 
          is given on this connection.
 
5832
    is given on this connection.
5850
5833
        */
5851
 
        run_query(cur_con, command, QUERY_SEND_FLAG);
5852
 
        command_executed++;
 
5834
  run_query(cur_con, command, QUERY_SEND_FLAG);
 
5835
  command_executed++;
5853
5836
        command->last_argument= command->end;
5854
 
        break;
 
5837
  break;
5855
5838
      case Q_REQUIRE:
5856
 
        do_get_file_name(command, save_file, sizeof(save_file));
5857
 
        break;
 
5839
  do_get_file_name(command, save_file, sizeof(save_file));
 
5840
  break;
5858
5841
      case Q_ERROR:
5859
5842
        do_get_errcodes(command);
5860
 
        break;
 
5843
  break;
5861
5844
      case Q_REPLACE:
5862
 
        do_get_replace(command);
5863
 
        break;
 
5845
  do_get_replace(command);
 
5846
  break;
5864
5847
      case Q_REPLACE_REGEX:
5865
5848
        do_get_replace_regex(command);
5866
5849
        break;
5867
5850
      case Q_REPLACE_COLUMN:
5868
 
        do_get_replace_column(command);
5869
 
        break;
 
5851
  do_get_replace_column(command);
 
5852
  break;
5870
5853
      case Q_SAVE_MASTER_POS: do_save_master_pos(); break;
5871
5854
      case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break;
5872
5855
      case Q_SYNC_SLAVE_WITH_MASTER:
5873
5856
      {
5874
 
        do_save_master_pos();
5875
 
        if (*command->first_argument)
5876
 
          select_connection(command);
5877
 
        else
5878
 
          select_connection_name("slave");
5879
 
        do_sync_with_master2(0);
5880
 
        break;
 
5857
  do_save_master_pos();
 
5858
  if (*command->first_argument)
 
5859
    select_connection(command);
 
5860
  else
 
5861
    select_connection_name("slave");
 
5862
  do_sync_with_master2(0);
 
5863
  break;
5881
5864
      }
5882
 
      case Q_COMMENT:                           /* Ignore row */
 
5865
      case Q_COMMENT:        /* Ignore row */
5883
5866
        command->last_argument= command->end;
5884
 
        break;
 
5867
  break;
5885
5868
      case Q_PING:
5886
 
        (void) mysql_ping(&cur_con->mysql);
5887
 
        break;
 
5869
  (void) drizzle_ping(&cur_con->drizzle);
 
5870
  break;
5888
5871
      case Q_EXEC:
5889
 
        do_exec(command);
5890
 
        command_executed++;
5891
 
        break;
 
5872
  do_exec(command);
 
5873
  command_executed++;
 
5874
  break;
5892
5875
      case Q_START_TIMER:
5893
 
        /* Overwrite possible earlier start of timer */
5894
 
        timer_start= timer_now();
5895
 
        break;
 
5876
  /* Overwrite possible earlier start of timer */
 
5877
  timer_start= timer_now();
 
5878
  break;
5896
5879
      case Q_END_TIMER:
5897
 
        /* End timer before ending mysqltest */
5898
 
        timer_output();
5899
 
        break;
 
5880
  /* End timer before ending drizzletest */
 
5881
  timer_output();
 
5882
  break;
5900
5883
      case Q_CHARACTER_SET:
5901
 
        do_set_charset(command);
5902
 
        break;
 
5884
  do_set_charset(command);
 
5885
  break;
5903
5886
      case Q_DISABLE_RECONNECT:
5904
 
        set_reconnect(&cur_con->mysql, 0);
 
5887
        set_reconnect(&cur_con->drizzle, 0);
5905
5888
        break;
5906
5889
      case Q_ENABLE_RECONNECT:
5907
 
        set_reconnect(&cur_con->mysql, 1);
 
5890
        set_reconnect(&cur_con->drizzle, 1);
5908
5891
        break;
5909
5892
      case Q_DISABLE_PARSING:
5910
5893
        if (parsing_disabled == 0)
6003
5986
 
6004
5987
      if (record)
6005
5988
      {
6006
 
        /* Recording - dump the output from test to result file */
6007
 
        str_to_file(result_file_name, ds_res.str, ds_res.length);
 
5989
  /* Recording - dump the output from test to result file */
 
5990
  str_to_file(result_file_name, ds_res.str, ds_res.length);
6008
5991
      }
6009
5992
      else
6010
5993
      {
6011
 
        /* Check that the output from test is equal to result file
6012
 
           - detect missing result file
6013
 
           - detect zero size result file
 
5994
  /* Check that the output from test is equal to result file
 
5995
     - detect missing result file
 
5996
     - detect zero size result file
6014
5997
        */
6015
 
        check_result(&ds_res);
 
5998
  check_result(&ds_res);
6016
5999
      }
6017
6000
    }
6018
6001
    else
6061
6044
  before executing any commands. The time we measure is
6062
6045
 
6063
6046
  - If no explicit 'start_timer' or 'end_timer' is given in the
6064
 
  test case, the timer measure how long we execute in mysqltest.
 
6047
  test case, the timer measure how long we execute in drizzletest.
6065
6048
 
6066
6049
  - If only 'start_timer' is given we measure how long we execute
6067
 
  from that point until we terminate mysqltest.
 
6050
  from that point until we terminate drizzletest.
6068
6051
 
6069
6052
  - If only 'end_timer' is given we measure how long we execute
6070
 
  from that we enter mysqltest to the 'end_timer' is command is
 
6053
  from that we enter drizzletest to the 'end_timer' is command is
6071
6054
  executed.
6072
6055
 
6073
6056
  - If both 'start_timer' and 'end_timer' are given we measure
6156
6139
 
6157
6140
/* Definitions for replace result */
6158
6141
 
6159
 
typedef struct st_pointer_array {               /* when using array-strings */
6160
 
  TYPELIB typelib;                              /* Pointer to strings */
6161
 
  uchar *str;                                   /* Strings is here */
6162
 
  int7  *flag;                                  /* Flag about each var. */
6163
 
  uint  array_allocs,max_count,length,max_length;
 
6142
typedef struct st_pointer_array {    /* when using array-strings */
 
6143
  TYPELIB typelib;        /* Pointer to strings */
 
6144
  uchar  *str;          /* Strings is here */
 
6145
  int7  *flag;          /* Flag about each var. */
 
6146
  uint  array_allocs,max_count,length,max_length;
6164
6147
} POINTER_ARRAY;
6165
6148
 
6166
6149
struct st_replace;
6167
6150
struct st_replace *init_replace(char * *from, char * *to, uint count,
6168
 
                                char * word_end_chars);
 
6151
        char * word_end_chars);
6169
6152
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6170
6153
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
6171
6154
                            const char *from, int len);
6211
6194
  for (i= 1,pos= word_end_chars ; i < 256 ; i++)
6212
6195
    if (my_isspace(charset_info,i))
6213
6196
      *pos++= i;
6214
 
  *pos=0;                                       /* End pointer */
 
6197
  *pos=0;          /* End pointer */
6215
6198
  if (!(glob_replace= init_replace((char**) from_array.typelib.type_names,
6216
 
                                  (char**) to_array.typelib.type_names,
6217
 
                                  (uint) from_array.typelib.count,
6218
 
                                  word_end_chars)))
 
6199
          (char**) to_array.typelib.type_names,
 
6200
          (uint) from_array.typelib.count,
 
6201
          word_end_chars)))
6219
6202
    die("Can't initialize replace from '%s'", command->query);
6220
6203
  free_pointer_array(&from_array);
6221
6204
  free_pointer_array(&to_array);
6602
6585
#define LAST_CHAR_CODE 259
6603
6586
 
6604
6587
typedef struct st_rep_set {
6605
 
  uint  *bits;                          /* Pointer to used sets */
6606
 
  short next[LAST_CHAR_CODE];           /* Pointer to next sets */
6607
 
  uint  found_len;                      /* Best match to date */
6608
 
  int   found_offset;
6609
 
  uint  table_offset;
6610
 
  uint  size_of_bits;                   /* For convinience */
 
6588
  uint  *bits;        /* Pointer to used sets */
 
6589
  short next[LAST_CHAR_CODE];    /* Pointer to next sets */
 
6590
  uint  found_len;      /* Best match to date */
 
6591
  int  found_offset;
 
6592
  uint  table_offset;
 
6593
  uint  size_of_bits;      /* For convinience */
6611
6594
} REP_SET;
6612
6595
 
6613
6596
typedef struct st_rep_sets {
6614
 
  uint          count;                  /* Number of sets */
6615
 
  uint          extra;                  /* Extra sets in buffer */
6616
 
  uint          invisible;              /* Sets not chown */
6617
 
  uint          size_of_bits;
6618
 
  REP_SET       *set,*set_buffer;
6619
 
  uint          *bit_buffer;
 
6597
  uint    count;      /* Number of sets */
 
6598
  uint    extra;      /* Extra sets in buffer */
 
6599
  uint    invisible;    /* Sets not chown */
 
6600
  uint    size_of_bits;
 
6601
  REP_SET  *set,*set_buffer;
 
6602
  uint    *bit_buffer;
6620
6603
} REP_SETS;
6621
6604
 
6622
6605
typedef struct st_found_set {
6667
6650
/* Init a replace structure for further calls */
6668
6651
 
6669
6652
REPLACE *init_replace(char * *from, char * *to,uint count,
6670
 
                      char * word_end_chars)
 
6653
          char * word_end_chars)
6671
6654
{
6672
6655
  static const int SPACE_CHAR= 256;
6673
6656
  static const int START_OF_LINE= 257;
6707
6690
    return(0);
6708
6691
  found_sets=0;
6709
6692
  if (!(found_set= (FOUND_SET*) my_malloc(sizeof(FOUND_SET)*max_length*count,
6710
 
                                          MYF(MY_WME))))
 
6693
            MYF(MY_WME))))
6711
6694
  {
6712
6695
    free_sets(&sets);
6713
6696
    return(0);
6714
6697
  }
6715
 
  VOID(make_new_set(&sets));                    /* Set starting set */
6716
 
  make_sets_invisible(&sets);                   /* Hide previus sets */
 
6698
  VOID(make_new_set(&sets));      /* Set starting set */
 
6699
  make_sets_invisible(&sets);      /* Hide previus sets */
6717
6700
  used_sets=-1;
6718
 
  word_states=make_new_set(&sets);              /* Start of new word */
6719
 
  start_states=make_new_set(&sets);             /* This is first state */
 
6701
  word_states=make_new_set(&sets);    /* Start of new word */
 
6702
  start_states=make_new_set(&sets);    /* This is first state */
6720
6703
  if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME))))
6721
6704
  {
6722
6705
    free_sets(&sets);
6732
6715
      internal_set_bit(start_states,states+1);
6733
6716
      if (!from[i][2])
6734
6717
      {
6735
 
        start_states->table_offset=i;
6736
 
        start_states->found_offset=1;
 
6718
  start_states->table_offset=i;
 
6719
  start_states->found_offset=1;
6737
6720
      }
6738
6721
    }
6739
6722
    else if (from[i][0] == '\\' && from[i][1] == '$')
6742
6725
      internal_set_bit(word_states,states);
6743
6726
      if (!from[i][2] && start_states->table_offset == (uint) ~0)
6744
6727
      {
6745
 
        start_states->table_offset=i;
6746
 
        start_states->found_offset=0;
 
6728
  start_states->table_offset=i;
 
6729
  start_states->found_offset=0;
6747
6730
      }
6748
6731
    }
6749
6732
    else
6750
6733
    {
6751
6734
      internal_set_bit(word_states,states);
6752
6735
      if (from[i][0] == '\\' && (from[i][1] == 'b' && from[i][2]))
6753
 
        internal_set_bit(start_states,states+1);
 
6736
  internal_set_bit(start_states,states+1);
6754
6737
      else
6755
 
        internal_set_bit(start_states,states);
 
6738
  internal_set_bit(start_states,states);
6756
6739
    }
6757
6740
    for (pos=from[i], len=0; *pos ; pos++)
6758
6741
    {
6759
6742
      if (*pos == '\\' && *(pos+1))
6760
6743
      {
6761
 
        pos++;
6762
 
        switch (*pos) {
6763
 
        case 'b':
6764
 
          follow_ptr->chr = SPACE_CHAR;
6765
 
          break;
6766
 
        case '^':
6767
 
          follow_ptr->chr = START_OF_LINE;
6768
 
          break;
6769
 
        case '$':
6770
 
          follow_ptr->chr = END_OF_LINE;
6771
 
          break;
6772
 
        case 'r':
6773
 
          follow_ptr->chr = '\r';
6774
 
          break;
6775
 
        case 't':
6776
 
          follow_ptr->chr = '\t';
6777
 
          break;
6778
 
        case 'v':
6779
 
          follow_ptr->chr = '\v';
6780
 
          break;
6781
 
        default:
6782
 
          follow_ptr->chr = (uchar) *pos;
6783
 
          break;
6784
 
        }
 
6744
  pos++;
 
6745
  switch (*pos) {
 
6746
  case 'b':
 
6747
    follow_ptr->chr = SPACE_CHAR;
 
6748
    break;
 
6749
  case '^':
 
6750
    follow_ptr->chr = START_OF_LINE;
 
6751
    break;
 
6752
  case '$':
 
6753
    follow_ptr->chr = END_OF_LINE;
 
6754
    break;
 
6755
  case 'r':
 
6756
    follow_ptr->chr = '\r';
 
6757
    break;
 
6758
  case 't':
 
6759
    follow_ptr->chr = '\t';
 
6760
    break;
 
6761
  case 'v':
 
6762
    follow_ptr->chr = '\v';
 
6763
    break;
 
6764
  default:
 
6765
    follow_ptr->chr = (uchar) *pos;
 
6766
    break;
 
6767
  }
6785
6768
      }
6786
6769
      else
6787
 
        follow_ptr->chr= (uchar) *pos;
 
6770
  follow_ptr->chr= (uchar) *pos;
6788
6771
      follow_ptr->table_offset=i;
6789
6772
      follow_ptr->len= ++len;
6790
6773
      follow_ptr++;
6800
6783
  for (set_nr=0,pos=0 ; set_nr < sets.count ; set_nr++)
6801
6784
  {
6802
6785
    set=sets.set+set_nr;
6803
 
    default_state= 0;                           /* Start from beginning */
 
6786
    default_state= 0;        /* Start from beginning */
6804
6787
 
6805
6788
    /* If end of found-string not found or start-set with current set */
6806
6789
 
6808
6791
    {
6809
6792
      if (!follow[i].chr)
6810
6793
      {
6811
 
        if (! default_state)
6812
 
          default_state= find_found(found_set,set->table_offset,
6813
 
                                    set->found_offset+1);
 
6794
  if (! default_state)
 
6795
    default_state= find_found(found_set,set->table_offset,
 
6796
            set->found_offset+1);
6814
6797
      }
6815
6798
    }
6816
 
    copy_bits(sets.set+used_sets,set);          /* Save set for changes */
 
6799
    copy_bits(sets.set+used_sets,set);    /* Save set for changes */
6817
6800
    if (!default_state)
6818
 
      or_bits(sets.set+used_sets,sets.set);     /* Can restart from start */
 
6801
      or_bits(sets.set+used_sets,sets.set);  /* Can restart from start */
6819
6802
 
6820
6803
    /* Find all chars that follows current sets */
6821
6804
    bzero((char*) used_chars,sizeof(used_chars));
6823
6806
    {
6824
6807
      used_chars[follow[i].chr]=1;
6825
6808
      if ((follow[i].chr == SPACE_CHAR && !follow[i+1].chr &&
6826
 
           follow[i].len > 1) || follow[i].chr == END_OF_LINE)
6827
 
        used_chars[0]=1;
 
6809
     follow[i].len > 1) || follow[i].chr == END_OF_LINE)
 
6810
  used_chars[0]=1;
6828
6811
    }
6829
6812
 
6830
6813
    /* Mark word_chars used if \b is in state */
6831
6814
    if (used_chars[SPACE_CHAR])
6832
6815
      for (pos= word_end_chars ; *pos ; pos++)
6833
 
        used_chars[(int) (uchar) *pos] = 1;
 
6816
  used_chars[(int) (uchar) *pos] = 1;
6834
6817
 
6835
6818
    /* Handle other used characters */
6836
6819
    for (chr= 0 ; chr < 256 ; chr++)
6837
6820
    {
6838
6821
      if (! used_chars[chr])
6839
 
        set->next[chr]= chr ? default_state : -1;
 
6822
  set->next[chr]= chr ? default_state : -1;
6840
6823
      else
6841
6824
      {
6842
 
        new_set=make_new_set(&sets);
6843
 
        set=sets.set+set_nr;                    /* if realloc */
6844
 
        new_set->table_offset=set->table_offset;
6845
 
        new_set->found_len=set->found_len;
6846
 
        new_set->found_offset=set->found_offset+1;
6847
 
        found_end=0;
 
6825
  new_set=make_new_set(&sets);
 
6826
  set=sets.set+set_nr;      /* if realloc */
 
6827
  new_set->table_offset=set->table_offset;
 
6828
  new_set->found_len=set->found_len;
 
6829
  new_set->found_offset=set->found_offset+1;
 
6830
  found_end=0;
6848
6831
 
6849
 
        for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
6850
 
        {
6851
 
          if (!follow[i].chr || follow[i].chr == chr ||
6852
 
              (follow[i].chr == SPACE_CHAR &&
6853
 
               (is_word_end[chr] ||
6854
 
                (!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
6855
 
              (follow[i].chr == END_OF_LINE && ! chr))
6856
 
          {
6857
 
            if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
6858
 
                follow[i].len > found_end)
6859
 
              found_end=follow[i].len;
6860
 
            if (chr && follow[i].chr)
6861
 
              internal_set_bit(new_set,i+1);            /* To next set */
6862
 
            else
6863
 
              internal_set_bit(new_set,i);
6864
 
          }
6865
 
        }
6866
 
        if (found_end)
6867
 
        {
6868
 
          new_set->found_len=0;                 /* Set for testing if first */
6869
 
          bits_set=0;
6870
 
          for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
6871
 
          {
6872
 
            if ((follow[i].chr == SPACE_CHAR ||
6873
 
                 follow[i].chr == END_OF_LINE) && ! chr)
6874
 
              bit_nr=i+1;
6875
 
            else
6876
 
              bit_nr=i;
6877
 
            if (follow[bit_nr-1].len < found_end ||
6878
 
                (new_set->found_len &&
6879
 
                 (chr == 0 || !follow[bit_nr].chr)))
6880
 
              internal_clear_bit(new_set,i);
6881
 
            else
6882
 
            {
6883
 
              if (chr == 0 || !follow[bit_nr].chr)
6884
 
              {                                 /* best match  */
6885
 
                new_set->table_offset=follow[bit_nr].table_offset;
6886
 
                if (chr || (follow[i].chr == SPACE_CHAR ||
6887
 
                            follow[i].chr == END_OF_LINE))
6888
 
                  new_set->found_offset=found_end;      /* New match */
6889
 
                new_set->found_len=found_end;
6890
 
              }
6891
 
              bits_set++;
6892
 
            }
6893
 
          }
6894
 
          if (bits_set == 1)
6895
 
          {
6896
 
            set->next[chr] = find_found(found_set,
6897
 
                                        new_set->table_offset,
6898
 
                                        new_set->found_offset);
6899
 
            free_last_set(&sets);
6900
 
          }
6901
 
          else
6902
 
            set->next[chr] = find_set(&sets,new_set);
6903
 
        }
6904
 
        else
6905
 
          set->next[chr] = find_set(&sets,new_set);
 
6832
  for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
 
6833
  {
 
6834
    if (!follow[i].chr || follow[i].chr == chr ||
 
6835
        (follow[i].chr == SPACE_CHAR &&
 
6836
         (is_word_end[chr] ||
 
6837
    (!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
 
6838
        (follow[i].chr == END_OF_LINE && ! chr))
 
6839
    {
 
6840
      if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
 
6841
    follow[i].len > found_end)
 
6842
        found_end=follow[i].len;
 
6843
      if (chr && follow[i].chr)
 
6844
        internal_set_bit(new_set,i+1);    /* To next set */
 
6845
      else
 
6846
        internal_set_bit(new_set,i);
 
6847
    }
 
6848
  }
 
6849
  if (found_end)
 
6850
  {
 
6851
    new_set->found_len=0;      /* Set for testing if first */
 
6852
    bits_set=0;
 
6853
    for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
 
6854
    {
 
6855
      if ((follow[i].chr == SPACE_CHAR ||
 
6856
     follow[i].chr == END_OF_LINE) && ! chr)
 
6857
        bit_nr=i+1;
 
6858
      else
 
6859
        bit_nr=i;
 
6860
      if (follow[bit_nr-1].len < found_end ||
 
6861
    (new_set->found_len &&
 
6862
     (chr == 0 || !follow[bit_nr].chr)))
 
6863
        internal_clear_bit(new_set,i);
 
6864
      else
 
6865
      {
 
6866
        if (chr == 0 || !follow[bit_nr].chr)
 
6867
        {          /* best match  */
 
6868
    new_set->table_offset=follow[bit_nr].table_offset;
 
6869
    if (chr || (follow[i].chr == SPACE_CHAR ||
 
6870
          follow[i].chr == END_OF_LINE))
 
6871
      new_set->found_offset=found_end;  /* New match */
 
6872
    new_set->found_len=found_end;
 
6873
        }
 
6874
        bits_set++;
 
6875
      }
 
6876
    }
 
6877
    if (bits_set == 1)
 
6878
    {
 
6879
      set->next[chr] = find_found(found_set,
 
6880
          new_set->table_offset,
 
6881
          new_set->found_offset);
 
6882
      free_last_set(&sets);
 
6883
    }
 
6884
    else
 
6885
      set->next[chr] = find_set(&sets,new_set);
 
6886
  }
 
6887
  else
 
6888
    set->next[chr] = find_set(&sets,new_set);
6906
6889
      }
6907
6890
    }
6908
6891
  }
6910
6893
  /* Alloc replace structure for the replace-state-machine */
6911
6894
 
6912
6895
  if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+
6913
 
                                    sizeof(REPLACE_STRING)*(found_sets+1)+
6914
 
                                    sizeof(char *)*count+result_len,
6915
 
                                    MYF(MY_WME | MY_ZEROFILL))))
 
6896
            sizeof(REPLACE_STRING)*(found_sets+1)+
 
6897
            sizeof(char *)*count+result_len,
 
6898
            MYF(MY_WME | MY_ZEROFILL))))
6916
6899
  {
6917
6900
    rep_str=(REPLACE_STRING*) (replace+sets.count);
6918
6901
    to_array= (char **) (rep_str+found_sets+1);
6928
6911
    {
6929
6912
      pos=from[found_set[i-1].table_offset];
6930
6913
      rep_str[i].found= !bcmp((const uchar*) pos,
6931
 
                              (const uchar*) "\\^", 3) ? 2 : 1;
 
6914
            (const uchar*) "\\^", 3) ? 2 : 1;
6932
6915
      rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
6933
6916
      rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
6934
6917
      rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
6935
 
        end_of_word(pos);
 
6918
  end_of_word(pos);
6936
6919
    }
6937
6920
    for (i=0 ; i < sets.count ; i++)
6938
6921
    {
6939
6922
      for (j=0 ; j < 256 ; j++)
6940
 
        if (sets.set[i].next[j] >= 0)
6941
 
          replace[i].next[j]=replace+sets.set[i].next[j];
6942
 
        else
6943
 
          replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1));
 
6923
  if (sets.set[i].next[j] >= 0)
 
6924
    replace[i].next[j]=replace+sets.set[i].next[j];
 
6925
  else
 
6926
    replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1));
6944
6927
    }
6945
6928
  }
6946
6929
  my_free(follow,MYF(0));
6955
6938
  bzero((char*) sets,sizeof(*sets));
6956
6939
  sets->size_of_bits=((states+7)/8);
6957
6940
  if (!(sets->set_buffer=(REP_SET*) my_malloc(sizeof(REP_SET)*SET_MALLOC_HUNC,
6958
 
                                              MYF(MY_WME))))
 
6941
                MYF(MY_WME))))
6959
6942
    return 1;
6960
6943
  if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits*
6961
 
                                           SET_MALLOC_HUNC,MYF(MY_WME))))
 
6944
             SET_MALLOC_HUNC,MYF(MY_WME))))
6962
6945
  {
6963
6946
    my_free(sets->set,MYF(0));
6964
6947
    return 1;
6994
6977
  count=sets->count+sets->invisible+SET_MALLOC_HUNC;
6995
6978
  if (!(set=(REP_SET*) my_realloc((uchar*) sets->set_buffer,
6996
6979
                                  sizeof(REP_SET)*count,
6997
 
                                  MYF(MY_WME))))
 
6980
          MYF(MY_WME))))
6998
6981
    return 0;
6999
6982
  sets->set_buffer=set;
7000
6983
  sets->set=set+sets->invisible;
7001
6984
  if (!(bit_buffer=(uint*) my_realloc((uchar*) sets->bit_buffer,
7002
 
                                      (sizeof(uint)*sets->size_of_bits)*count,
7003
 
                                      MYF(MY_WME))))
 
6985
              (sizeof(uint)*sets->size_of_bits)*count,
 
6986
              MYF(MY_WME))))
7004
6987
    return 0;
7005
6988
  sets->bit_buffer=bit_buffer;
7006
6989
  for (i=0 ; i < count ; i++)
7050
7033
void copy_bits(REP_SET *to,REP_SET *from)
7051
7034
{
7052
7035
  memcpy((uchar*) to->bits,(uchar*) from->bits,
7053
 
         (size_t) (sizeof(uint) * to->size_of_bits));
 
7036
   (size_t) (sizeof(uint) * to->size_of_bits));
7054
7037
}
7055
7038
 
7056
7039
int cmp_bits(REP_SET *set1,REP_SET *set2)
7057
7040
{
7058
7041
  return bcmp((uchar*) set1->bits,(uchar*) set2->bits,
7059
 
              sizeof(uint) * set1->size_of_bits);
 
7042
        sizeof(uint) * set1->size_of_bits);
7060
7043
}
7061
7044
 
7062
7045
 
7098
7081
      return i;
7099
7082
    }
7100
7083
  }
7101
 
  return i;                             /* return new postion */
 
7084
  return i;        /* return new postion */
7102
7085
}
7103
7086
 
7104
7087
/* find if there is a found_set with same table_offset & found_offset
7113
7096
  int i;
7114
7097
  for (i=0 ; (uint) i < found_sets ; i++)
7115
7098
    if (found_set[i].table_offset == table_offset &&
7116
 
        found_set[i].found_offset == found_offset)
 
7099
  found_set[i].found_offset == found_offset)
7117
7100
      return -i-2;
7118
7101
  found_set[i].table_offset=table_offset;
7119
7102
  found_set[i].found_offset=found_offset;
7120
7103
  found_sets++;
7121
 
  return -i-2;                          /* return new postion */
 
7104
  return -i-2;        /* return new postion */
7122
7105
}
7123
7106
 
7124
7107
/* Return 1 if regexp starts with \b or ends with \b*/
7134
7117
  char * end=strend(pos);
7135
7118
  return ((end > pos+2 && !bcmp((const uchar*) end-2,
7136
7119
                                (const uchar*) "\\b", 2)) ||
7137
 
          (end >= pos+2 && !bcmp((const uchar*) end-2,
 
7120
    (end >= pos+2 && !bcmp((const uchar*) end-2,
7138
7121
                                (const uchar*) "\\$",2))) ? 1 : 0;
7139
7122
}
7140
7123
 
7142
7125
 * Handle replacement of strings
7143
7126
 ****************************************************************************/
7144
7127
 
7145
 
#define PC_MALLOC               256     /* Bytes for pointers */
7146
 
#define PS_MALLOC               512     /* Bytes for data */
 
7128
#define PC_MALLOC    256  /* Bytes for pointers */
 
7129
#define PS_MALLOC    512  /* Bytes for data */
7147
7130
 
7148
7131
int insert_pointer_name(POINTER_ARRAY *pa,char * name)
7149
7132
{
7155
7138
  if (! pa->typelib.count)
7156
7139
  {
7157
7140
    if (!(pa->typelib.type_names=(const char **)
7158
 
          my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
7159
 
                     (sizeof(char *)+sizeof(*pa->flag))*
7160
 
                     (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
 
7141
    my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
 
7142
         (sizeof(char *)+sizeof(*pa->flag))*
 
7143
         (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
7161
7144
      return(-1);
7162
7145
    if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
7163
 
                                     MYF(MY_WME))))
 
7146
             MYF(MY_WME))))
7164
7147
    {
7165
7148
      my_free((char*) pa->typelib.type_names,MYF(0));
7166
7149
      return (-1);
7167
7150
    }
7168
7151
    pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+
7169
 
                                               sizeof(*pa->flag));
 
7152
                 sizeof(*pa->flag));
7170
7153
    pa->flag= (int7*) (pa->typelib.type_names+pa->max_count);
7171
7154
    pa->length=0;
7172
7155
    pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;
7176
7159
  if (pa->length+length >= pa->max_length)
7177
7160
  {
7178
7161
    if (!(new_pos= (uchar*) my_realloc((uchar*) pa->str,
7179
 
                                      (uint) (pa->max_length+PS_MALLOC),
7180
 
                                      MYF(MY_WME))))
 
7162
              (uint) (pa->max_length+PS_MALLOC),
 
7163
              MYF(MY_WME))))
7181
7164
      return(1);
7182
7165
    if (new_pos != pa->str)
7183
7166
    {
7184
7167
      my_ptrdiff_t diff=PTR_BYTE_DIFF(new_pos,pa->str);
7185
7168
      for (i=0 ; i < pa->typelib.count ; i++)
7186
 
        pa->typelib.type_names[i]= ADD_TO_PTR(pa->typelib.type_names[i],diff,
7187
 
                                              char*);
 
7169
  pa->typelib.type_names[i]= ADD_TO_PTR(pa->typelib.type_names[i],diff,
 
7170
                char*);
7188
7171
      pa->str=new_pos;
7189
7172
    }
7190
7173
    pa->max_length+=PS_MALLOC;
7195
7178
    pa->array_allocs++;
7196
7179
    len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
7197
7180
    if (!(new_array=(const char **) my_realloc((uchar*) pa->typelib.type_names,
7198
 
                                               (uint) len/
 
7181
                 (uint) len/
7199
7182
                                               (sizeof(uchar*)+sizeof(*pa->flag))*
7200
7183
                                               (sizeof(uchar*)+sizeof(*pa->flag)),
7201
7184
                                               MYF(MY_WME))))
7205
7188
    pa->max_count=len/(sizeof(uchar*) + sizeof(*pa->flag));
7206
7189
    pa->flag= (int7*) (pa->typelib.type_names+pa->max_count);
7207
7190
    memcpy((uchar*) pa->flag,(char *) (pa->typelib.type_names+old_count),
7208
 
           old_count*sizeof(*pa->flag));
 
7191
     old_count*sizeof(*pa->flag));
7209
7192
  }
7210
 
  pa->flag[pa->typelib.count]=0;                        /* Reset flag */
 
7193
  pa->flag[pa->typelib.count]=0;      /* Reset flag */
7211
7194
  pa->typelib.type_names[pa->typelib.count++]= (char*) pa->str+pa->length;
7212
 
  pa->typelib.type_names[pa->typelib.count]= NullS;     /* Put end-mark */
 
7195
  pa->typelib.type_names[pa->typelib.count]= NullS;  /* Put end-mark */
7213
7196
  VOID(strmov((char*) pa->str+pa->length,name));
7214
7197
  pa->length+=length;
7215
7198
  return(0);