~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

Merged from client-rename-split.

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;
4644
4636
static void print_version(void)
4645
4637
{
4646
4638
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4647
 
         MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
 
4639
   MYSQL_SERVER_VERSION,SYSTEM_TYPE,MACHINE_TYPE);
4648
4640
}
4649
4641
 
4650
4642
static void usage(void)
4651
4643
{
4652
4644
  print_version();
4653
 
  printf("MySQL AB, by Sasha, Matt, Monty & Jani\n");
 
4645
  printf("DRIZZLE AB, by Sasha, Matt, Monty & Jani\n");
4654
4646
  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");
 
4647
  printf("Runs a test against the DRIZZLE server and compares output with a results file.\n\n");
4656
4648
  printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname);
4657
4649
  my_print_help(my_long_options);
4658
4650
  printf("  --no-defaults       Don't read default options from any options file.\n");
4682
4674
  if (!embedded_server_arg_count)
4683
4675
  {
4684
4676
    embedded_server_arg_count=1;
4685
 
    embedded_server_args[0]= (char*) "";                /* Progname */
 
4677
    embedded_server_args[0]= (char*) "";    /* Progname */
4686
4678
  }
4687
4679
  if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
4688
4680
    die("Failed to open file '%s'", buff);
4689
4681
 
4690
4682
  while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4691
 
         (str=fgets(argument,sizeof(argument), file)))
 
4683
   (str=fgets(argument,sizeof(argument), file)))
4692
4684
  {
4693
 
    *(strend(str)-1)=0;                         /* Remove end newline */
 
4685
    *(strend(str)-1)=0;        /* Remove end newline */
4694
4686
    if (!(embedded_server_args[embedded_server_arg_count]=
4695
 
          (char*) my_strdup(str,MYF(MY_WME))))
 
4687
    (char*) my_strdup(str,MYF(MY_WME))))
4696
4688
    {
4697
4689
      my_fclose(file,MYF(0));
4698
4690
      die("Out of memory");
4710
4702
 
4711
4703
static bool
4712
4704
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
4713
 
               char *argument)
 
4705
         char *argument)
4714
4706
{
4715
4707
  switch(optid) {
4716
4708
  case 'r':
4743
4735
    }
4744
4736
    fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4745
4737
    timer_file= buff;
4746
 
    unlink(timer_file);      /* Ignore error, may not exist */
 
4738
    unlink(timer_file);       /* Ignore error, may not exist */
4747
4739
    break;
4748
4740
  }
4749
4741
  case 'p':
4751
4743
    {
4752
4744
      my_free(opt_pass, MYF(MY_ALLOW_ZERO_PTR));
4753
4745
      opt_pass= my_strdup(argument, MYF(MY_FAE));
4754
 
      while (*argument) *argument++= 'x';               /* Destroy argument */
 
4746
      while (*argument) *argument++= 'x';    /* Destroy argument */
4755
4747
      tty_password= 0;
4756
4748
    }
4757
4749
    else
4899
4891
  Append the result for one field to the dynamic string ds
4900
4892
*/
4901
4893
 
4902
 
static void append_field(DYNAMIC_STRING *ds, uint col_idx, MYSQL_FIELD* field,
 
4894
static void append_field(DYNAMIC_STRING *ds, uint col_idx, DRIZZLE_FIELD* field,
4903
4895
                         const char* val, uint64_t len, bool is_null)
4904
4896
{
4905
4897
  if (col_idx < max_replace_column && replace_column[col_idx])
4934
4926
  Values may be converted with 'replace_column'
4935
4927
*/
4936
4928
 
4937
 
static void append_result(DYNAMIC_STRING *ds, MYSQL_RES *res)
 
4929
static void append_result(DYNAMIC_STRING *ds, DRIZZLE_RES *res)
4938
4930
{
4939
 
  MYSQL_ROW row;
4940
 
  uint32_t num_fields= mysql_num_fields(res);
4941
 
  MYSQL_FIELD *fields= mysql_fetch_fields(res);
 
4931
  DRIZZLE_ROW row;
 
4932
  uint32_t num_fields= drizzle_num_fields(res);
 
4933
  DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
4942
4934
  uint32_t *lengths;
4943
4935
 
4944
 
  while ((row = mysql_fetch_row(res)))
 
4936
  while ((row = drizzle_fetch_row(res)))
4945
4937
  {
4946
4938
    uint32_t i;
4947
 
    lengths = mysql_fetch_lengths(res);
 
4939
    lengths = drizzle_fetch_lengths(res);
4948
4940
    for (i = 0; i < num_fields; i++)
4949
4941
      append_field(ds, i, &fields[i],
4950
4942
                   (const char*)row[i], lengths[i], !row[i]);
4959
4951
*/
4960
4952
 
4961
4953
static void append_metadata(DYNAMIC_STRING *ds,
4962
 
                            MYSQL_FIELD *field,
 
4954
                            DRIZZLE_FIELD *field,
4963
4955
                            uint num_fields)
4964
4956
{
4965
 
  MYSQL_FIELD *field_end;
 
4957
  DRIZZLE_FIELD *field_end;
4966
4958
  dynstr_append(ds,"Catalog\tDatabase\tTable\tTable_alias\tColumn\t"
4967
4959
                "Column_alias\tType\tLength\tMax length\tIs_null\t"
4968
4960
                "Flags\tDecimals\tCharsetnr\n");
5030
5022
*/
5031
5023
 
5032
5024
static void append_table_headings(DYNAMIC_STRING *ds,
5033
 
                                  MYSQL_FIELD *field,
 
5025
                                  DRIZZLE_FIELD *field,
5034
5026
                                  uint num_fields)
5035
5027
{
5036
5028
  uint col_idx;
5050
5042
  Number of warnings appended to ds
5051
5043
*/
5052
5044
 
5053
 
static int append_warnings(DYNAMIC_STRING *ds, MYSQL* mysql)
 
5045
static int append_warnings(DYNAMIC_STRING *ds, DRIZZLE *drizzle)
5054
5046
{
5055
5047
  uint count;
5056
 
  MYSQL_RES *warn_res;
5057
 
 
5058
 
 
5059
 
  if (!(count= mysql_warning_count(mysql)))
 
5048
  DRIZZLE_RES *warn_res;
 
5049
 
 
5050
 
 
5051
  if (!(count= drizzle_warning_count(drizzle)))
5060
5052
    return(0);
5061
5053
 
5062
5054
  /*
5064
5056
    through PS API we should not issue SHOW WARNINGS until
5065
5057
    we have not read all results...
5066
5058
  */
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)))
 
5059
  assert(!drizzle_more_results(drizzle));
 
5060
 
 
5061
  if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
 
5062
    die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
 
5063
 
 
5064
  if (!(warn_res= drizzle_store_result(drizzle)))
5073
5065
    die("Warning count is %u but didn't get any warnings",
5074
 
        count);
 
5066
  count);
5075
5067
 
5076
5068
  append_result(ds, warn_res);
5077
 
  mysql_free_result(warn_res);
 
5069
  drizzle_free_result(warn_res);
5078
5070
 
5079
5071
  return(count);
5080
5072
}
5081
5073
 
5082
5074
 
5083
5075
/*
5084
 
  Run query using MySQL C API
 
5076
  Run query using DRIZZLE C API
5085
5077
 
5086
5078
  SYNOPSIS
5087
5079
    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
 
5080
    drizzle  DRIZZLE handle
 
5081
    command  current command pointer
 
5082
    flags  flags indicating if we should SEND and/or REAP
 
5083
    query  query string to execute
 
5084
    query_len  length query string to execute
 
5085
    ds    output buffer where to store result form query
5094
5086
*/
5095
5087
 
5096
5088
static void run_query_normal(struct st_connection *cn,
5098
5090
                             int flags, char *query, int query_len,
5099
5091
                             DYNAMIC_STRING *ds, DYNAMIC_STRING *ds_warnings)
5100
5092
{
5101
 
  MYSQL_RES *res= 0;
5102
 
  MYSQL *mysql= &cn->mysql;
 
5093
  DRIZZLE_RES *res= 0;
 
5094
  DRIZZLE *drizzle= &cn->drizzle;
5103
5095
  int err= 0, counter= 0;
5104
5096
 
5105
5097
  if (flags & QUERY_SEND_FLAG)
5109
5101
    */
5110
5102
    if (do_send_query(cn, query, query_len, flags))
5111
5103
    {
5112
 
      handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5113
 
                   mysql_sqlstate(mysql), ds);
 
5104
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5105
       drizzle_sqlstate(drizzle), ds);
5114
5106
      goto end;
5115
5107
    }
5116
5108
  }
5128
5120
  do
5129
5121
  {
5130
5122
    /*
5131
 
      When  on first result set, call mysql_read_query_result to retrieve
 
5123
      When  on first result set, call drizzle_read_query_result to retrieve
5132
5124
      answer to the query sent earlier
5133
5125
    */
5134
 
    if ((counter==0) && mysql_read_query_result(mysql))
 
5126
    if ((counter==0) && drizzle_read_query_result(drizzle))
5135
5127
    {
5136
 
      handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5137
 
                   mysql_sqlstate(mysql), ds);
 
5128
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5129
       drizzle_sqlstate(drizzle), ds);
5138
5130
      goto end;
5139
5131
 
5140
5132
    }
5142
5134
    /*
5143
5135
      Store the result of the query if it will return any fields
5144
5136
    */
5145
 
    if (mysql_field_count(mysql) && ((res= mysql_store_result(mysql)) == 0))
 
5137
    if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
5146
5138
    {
5147
 
      handle_error(command, mysql_errno(mysql), mysql_error(mysql),
5148
 
                   mysql_sqlstate(mysql), ds);
 
5139
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5140
       drizzle_sqlstate(drizzle), ds);
5149
5141
      goto end;
5150
5142
    }
5151
5143
 
5155
5147
 
5156
5148
      if (res)
5157
5149
      {
5158
 
        MYSQL_FIELD *fields= mysql_fetch_fields(res);
5159
 
        uint num_fields= mysql_num_fields(res);
 
5150
  DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
 
5151
  uint num_fields= drizzle_num_fields(res);
5160
5152
 
5161
 
        if (display_metadata)
 
5153
  if (display_metadata)
5162
5154
          append_metadata(ds, fields, num_fields);
5163
5155
 
5164
 
        if (!display_result_vertically)
5165
 
          append_table_headings(ds, fields, num_fields);
 
5156
  if (!display_result_vertically)
 
5157
    append_table_headings(ds, fields, num_fields);
5166
5158
 
5167
 
        append_result(ds, res);
 
5159
  append_result(ds, res);
5168
5160
      }
5169
5161
 
5170
5162
      /*
5171
 
        Need to call mysql_affected_rows() before the "new"
 
5163
        Need to call drizzle_affected_rows() before the "new"
5172
5164
        query to find the warnings
5173
5165
      */
5174
5166
      if (!disable_info)
5175
 
        affected_rows= mysql_affected_rows(mysql);
 
5167
        affected_rows= drizzle_affected_rows(drizzle);
5176
5168
 
5177
5169
      /*
5178
5170
        Add all warnings to the result. We can't do this if we are in
5179
5171
        the middle of processing results from multi-statement, because
5180
5172
        this will break protocol.
5181
5173
      */
5182
 
      if (!disable_warnings && !mysql_more_results(mysql))
 
5174
      if (!disable_warnings && !drizzle_more_results(drizzle))
5183
5175
      {
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
 
        }
 
5176
  if (append_warnings(ds_warnings, drizzle) || ds_warnings->length)
 
5177
  {
 
5178
    dynstr_append_mem(ds, "Warnings:\n", 10);
 
5179
    dynstr_append_mem(ds, ds_warnings->str, ds_warnings->length);
 
5180
  }
5189
5181
      }
5190
5182
 
5191
5183
      if (!disable_info)
5192
 
        append_info(ds, affected_rows, mysql_info(mysql));
 
5184
  append_info(ds, affected_rows, drizzle_info(drizzle));
5193
5185
    }
5194
5186
 
5195
5187
    if (res)
5196
5188
    {
5197
 
      mysql_free_result(res);
 
5189
      drizzle_free_result(res);
5198
5190
      res= 0;
5199
5191
    }
5200
5192
    counter++;
5201
 
  } while (!(err= mysql_next_result(mysql)));
 
5193
  } while (!(err= drizzle_next_result(drizzle)));
5202
5194
  if (err > 0)
5203
5195
  {
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);
 
5196
    /* We got an error from drizzle_next_result, maybe expected */
 
5197
    handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
 
5198
     drizzle_sqlstate(drizzle), ds);
5207
5199
    goto end;
5208
5200
  }
5209
5201
  assert(err == -1); /* Successful and there are no more results */
5214
5206
end:
5215
5207
 
5216
5208
  /*
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
 
5209
    We save the return code (drizzle_errno(drizzle)) from the last call sent
 
5210
    to the server into the drizzletest builtin variable $drizzle_errno. This
5219
5211
    variable then can be used from the test case itself.
5220
5212
  */
5221
 
  var_set_errno(mysql_errno(mysql));
 
5213
  var_set_errno(drizzle_errno(drizzle));
5222
5214
  return;
5223
5215
}
5224
5216
 
5235
5227
  ds    - dynamic string which is used for output buffer
5236
5228
 
5237
5229
  NOTE
5238
 
    If there is an unexpected error this function will abort mysqltest
 
5230
    If there is an unexpected error this function will abort drizzletest
5239
5231
    immediately.
5240
5232
*/
5241
5233
 
5315
5307
    else
5316
5308
      die("query '%s' failed with wrong sqlstate %s: '%s', instead of %s...",
5317
5309
          command->query, err_sqlstate, err_error,
5318
 
          command->expected_errors.err[0].code.sqlstate);
 
5310
    command->expected_errors.err[0].code.sqlstate);
5319
5311
  }
5320
5312
 
5321
5313
  return;
5361
5353
 
5362
5354
  SYNPOSIS
5363
5355
    run_query()
5364
 
     mysql      mysql handle
5365
 
     command    currrent command pointer
 
5356
     drizzle  DRIZZLE handle
 
5357
     command  currrent command pointer
5366
5358
 
5367
5359
  flags control the phased/stages of query execution to be performed
5368
5360
  if QUERY_SEND_FLAG bit is on, the query will be sent. If QUERY_REAP_FLAG
5369
5361
  is on the result will be read - for regular query, both bits must be on
5370
5362
*/
5371
5363
 
5372
 
static void run_query(struct st_connection *cn, 
 
5364
static void run_query(struct st_connection *cn,
5373
5365
                      struct st_command *command,
5374
5366
                      int flags)
5375
5367
{
5493
5485
  command->query[command->first_word_len]= save;
5494
5486
  if (type > 0)
5495
5487
  {
5496
 
    command->type=(enum enum_commands) type;            /* Found command */
 
5488
    command->type=(enum enum_commands) type;    /* Found command */
5497
5489
 
5498
5490
    /*
5499
5491
      Look for case where "query" was explicitly specified to
5507
5499
  }
5508
5500
  else
5509
5501
  {
5510
 
    /* No mysqltest command matched */
 
5502
    /* No drizzletest command matched */
5511
5503
 
5512
5504
    if (command->type != Q_COMMENT_WITH_COMMAND)
5513
5505
    {
5514
 
      /* A query that will sent to mysqld */
 
5506
      /* A query that will sent to drizzled */
5515
5507
      command->type= Q_QUERY;
5516
5508
    }
5517
5509
    else
5518
5510
    {
5519
 
      /* -- comment that didn't contain a mysqltest command */
 
5511
      /* -- comment that didn't contain a drizzletest command */
5520
5512
      command->type= Q_COMMENT;
5521
5513
      warning_msg("Suspicious command '--%s' detected, was this intentional? "\
5522
5514
                  "Use # instead of -- to avoid this warning",
5655
5647
  init_dynamic_string(&ds_warning_messages, "", 0, 2048);
5656
5648
  parse_args(argc, argv);
5657
5649
 
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
5650
  server_initialized= 1;
5663
5651
  if (cur_file == file_stack && cur_file->file == 0)
5664
5652
  {
5667
5655
    cur_file->lineno= 1;
5668
5656
  }
5669
5657
  cur_con= connections;
5670
 
  if (!( mysql_init(&cur_con->mysql)))
5671
 
    die("Failed in mysql_init()");
 
5658
  if (!( drizzle_create(&cur_con->drizzle)))
 
5659
    die("Failed in drizzle_create()");
5672
5660
  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,
 
5661
    drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NullS);
 
5662
  drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
 
5663
  drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_NAME,
5676
5664
                charset_info->csname);
5677
 
  int opt_protocol= MYSQL_PROTOCOL_TCP;
5678
 
  mysql_options(&cur_con->mysql,MYSQL_OPT_PROTOCOL,(char*)&opt_protocol);
 
5665
  int opt_protocol= DRIZZLE_PROTOCOL_TCP;
 
5666
  drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_PROTOCOL,(char*)&opt_protocol);
5679
5667
  if (opt_charsets_dir)
5680
 
    mysql_options(&cur_con->mysql, MYSQL_SET_CHARSET_DIR,
 
5668
    drizzle_options(&cur_con->drizzle, DRIZZLE_SET_CHARSET_DIR,
5681
5669
                  opt_charsets_dir);
5682
5670
 
5683
5671
  if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
5684
5672
    die("Out of memory");
5685
5673
 
5686
 
  safe_connect(&cur_con->mysql, cur_con->name, opt_host, opt_user, opt_pass,
 
5674
  safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5687
5675
               opt_db, opt_port);
5688
5676
 
5689
5677
  /* Use all time until exit if no explicit 'start_timer' */
5690
5678
  timer_start= timer_now();
5691
5679
 
5692
5680
  /*
5693
 
    Initialize $mysql_errno with -1, so we can
 
5681
    Initialize $drizzle_errno with -1, so we can
5694
5682
    - distinguish it from valid values ( >= 0 ) and
5695
5683
    - detect if there was never a command sent to the server
5696
5684
  */
5697
5685
  var_set_errno(-1);
5698
5686
 
5699
 
  /* Update $mysql_get_server_version to that of current connection */
5700
 
  var_set_mysql_get_server_version(&cur_con->mysql);
 
5687
  /* Update $drizzle_get_server_version to that of current connection */
 
5688
  var_set_drizzle_get_server_version(&cur_con->drizzle);
5701
5689
 
5702
5690
  if (opt_include)
5703
5691
  {
5729
5717
      case Q_CONNECTION: select_connection(command); break;
5730
5718
      case Q_DISCONNECT:
5731
5719
      case Q_DIRTY_CLOSE:
5732
 
        do_close_connection(command); break;
 
5720
  do_close_connection(command); break;
5733
5721
      case Q_ENABLE_QUERY_LOG:   disable_query_log=0; break;
5734
5722
      case Q_DISABLE_QUERY_LOG:  disable_query_log=1; break;
5735
5723
      case Q_ENABLE_ABORT_ON_ERROR:  abort_on_error=1; break;
5765
5753
      case Q_PERL: do_perl(command); break;
5766
5754
      case Q_DELIMITER:
5767
5755
        do_delimiter(command);
5768
 
        break;
 
5756
  break;
5769
5757
      case Q_DISPLAY_VERTICAL_RESULTS:
5770
5758
        display_result_vertically= true;
5771
5759
        break;
5772
5760
      case Q_DISPLAY_HORIZONTAL_RESULTS:
5773
 
        display_result_vertically= false;
 
5761
  display_result_vertically= false;
5774
5762
        break;
5775
5763
      case Q_SORTED_RESULT:
5776
5764
        /*
5777
5765
          Turn on sorting of result set, will be reset after next
5778
5766
          command
5779
5767
        */
5780
 
        display_result_sorted= true;
 
5768
  display_result_sorted= true;
5781
5769
        break;
5782
5770
      case Q_LET: do_let(command); break;
5783
5771
      case Q_EVAL_RESULT:
5785
5773
      case Q_EVAL:
5786
5774
      case Q_QUERY_VERTICAL:
5787
5775
      case Q_QUERY_HORIZONTAL:
5788
 
        if (command->query == command->query_buf)
 
5776
  if (command->query == command->query_buf)
5789
5777
        {
5790
5778
          /* Skip the first part of command, i.e query_xxx */
5791
 
          command->query= command->first_argument;
 
5779
    command->query= command->first_argument;
5792
5780
          command->first_word_len= 0;
5793
5781
        }
5794
 
        /* fall through */
 
5782
  /* fall through */
5795
5783
      case Q_QUERY:
5796
5784
      case Q_REAP:
5797
5785
      {
5798
 
        bool old_display_result_vertically= display_result_vertically;
 
5786
  bool old_display_result_vertically= display_result_vertically;
5799
5787
        /* Default is full query, both reap and send  */
5800
5788
        int flags= QUERY_REAP_FLAG | QUERY_SEND_FLAG;
5801
5789
 
5813
5801
        /* Check for special property for this query */
5814
5802
        display_result_vertically|= (command->type == Q_QUERY_VERTICAL);
5815
5803
 
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++;
 
5804
  if (save_file[0])
 
5805
  {
 
5806
    strmake(command->require_file, save_file, sizeof(save_file) - 1);
 
5807
    save_file[0]= 0;
 
5808
  }
 
5809
  run_query(cur_con, command, flags);
 
5810
  command_executed++;
5823
5811
        command->last_argument= command->end;
5824
5812
 
5825
5813
        /* Restore settings */
5826
 
        display_result_vertically= old_display_result_vertically;
 
5814
  display_result_vertically= old_display_result_vertically;
5827
5815
 
5828
 
        break;
 
5816
  break;
5829
5817
      }
5830
5818
      case Q_SEND:
5831
5819
        if (!*command->first_argument)
5839
5827
        }
5840
5828
 
5841
5829
        /* Remove "send" if this is first iteration */
5842
 
        if (command->query == command->query_buf)
5843
 
          command->query= command->first_argument;
 
5830
  if (command->query == command->query_buf)
 
5831
    command->query= command->first_argument;
5844
5832
 
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
 
5833
  /*
 
5834
    run_query() can execute a query partially, depending on the flags.
 
5835
    QUERY_SEND_FLAG flag without QUERY_REAP_FLAG tells it to just send
5848
5836
          the query and read the result some time later when reap instruction
5849
 
          is given on this connection.
 
5837
    is given on this connection.
5850
5838
        */
5851
 
        run_query(cur_con, command, QUERY_SEND_FLAG);
5852
 
        command_executed++;
 
5839
  run_query(cur_con, command, QUERY_SEND_FLAG);
 
5840
  command_executed++;
5853
5841
        command->last_argument= command->end;
5854
 
        break;
 
5842
  break;
5855
5843
      case Q_REQUIRE:
5856
 
        do_get_file_name(command, save_file, sizeof(save_file));
5857
 
        break;
 
5844
  do_get_file_name(command, save_file, sizeof(save_file));
 
5845
  break;
5858
5846
      case Q_ERROR:
5859
5847
        do_get_errcodes(command);
5860
 
        break;
 
5848
  break;
5861
5849
      case Q_REPLACE:
5862
 
        do_get_replace(command);
5863
 
        break;
 
5850
  do_get_replace(command);
 
5851
  break;
5864
5852
      case Q_REPLACE_REGEX:
5865
5853
        do_get_replace_regex(command);
5866
5854
        break;
5867
5855
      case Q_REPLACE_COLUMN:
5868
 
        do_get_replace_column(command);
5869
 
        break;
 
5856
  do_get_replace_column(command);
 
5857
  break;
5870
5858
      case Q_SAVE_MASTER_POS: do_save_master_pos(); break;
5871
5859
      case Q_SYNC_WITH_MASTER: do_sync_with_master(command); break;
5872
5860
      case Q_SYNC_SLAVE_WITH_MASTER:
5873
5861
      {
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;
 
5862
  do_save_master_pos();
 
5863
  if (*command->first_argument)
 
5864
    select_connection(command);
 
5865
  else
 
5866
    select_connection_name("slave");
 
5867
  do_sync_with_master2(0);
 
5868
  break;
5881
5869
      }
5882
 
      case Q_COMMENT:                           /* Ignore row */
 
5870
      case Q_COMMENT:        /* Ignore row */
5883
5871
        command->last_argument= command->end;
5884
 
        break;
 
5872
  break;
5885
5873
      case Q_PING:
5886
 
        (void) mysql_ping(&cur_con->mysql);
5887
 
        break;
 
5874
  (void) drizzle_ping(&cur_con->drizzle);
 
5875
  break;
5888
5876
      case Q_EXEC:
5889
 
        do_exec(command);
5890
 
        command_executed++;
5891
 
        break;
 
5877
  do_exec(command);
 
5878
  command_executed++;
 
5879
  break;
5892
5880
      case Q_START_TIMER:
5893
 
        /* Overwrite possible earlier start of timer */
5894
 
        timer_start= timer_now();
5895
 
        break;
 
5881
  /* Overwrite possible earlier start of timer */
 
5882
  timer_start= timer_now();
 
5883
  break;
5896
5884
      case Q_END_TIMER:
5897
 
        /* End timer before ending mysqltest */
5898
 
        timer_output();
5899
 
        break;
 
5885
  /* End timer before ending drizzletest */
 
5886
  timer_output();
 
5887
  break;
5900
5888
      case Q_CHARACTER_SET:
5901
 
        do_set_charset(command);
5902
 
        break;
 
5889
  do_set_charset(command);
 
5890
  break;
5903
5891
      case Q_DISABLE_RECONNECT:
5904
 
        set_reconnect(&cur_con->mysql, 0);
 
5892
        set_reconnect(&cur_con->drizzle, 0);
5905
5893
        break;
5906
5894
      case Q_ENABLE_RECONNECT:
5907
 
        set_reconnect(&cur_con->mysql, 1);
 
5895
        set_reconnect(&cur_con->drizzle, 1);
5908
5896
        break;
5909
5897
      case Q_DISABLE_PARSING:
5910
5898
        if (parsing_disabled == 0)
6003
5991
 
6004
5992
      if (record)
6005
5993
      {
6006
 
        /* Recording - dump the output from test to result file */
6007
 
        str_to_file(result_file_name, ds_res.str, ds_res.length);
 
5994
  /* Recording - dump the output from test to result file */
 
5995
  str_to_file(result_file_name, ds_res.str, ds_res.length);
6008
5996
      }
6009
5997
      else
6010
5998
      {
6011
 
        /* Check that the output from test is equal to result file
6012
 
           - detect missing result file
6013
 
           - detect zero size result file
 
5999
  /* Check that the output from test is equal to result file
 
6000
     - detect missing result file
 
6001
     - detect zero size result file
6014
6002
        */
6015
 
        check_result(&ds_res);
 
6003
  check_result(&ds_res);
6016
6004
      }
6017
6005
    }
6018
6006
    else
6061
6049
  before executing any commands. The time we measure is
6062
6050
 
6063
6051
  - If no explicit 'start_timer' or 'end_timer' is given in the
6064
 
  test case, the timer measure how long we execute in mysqltest.
 
6052
  test case, the timer measure how long we execute in drizzletest.
6065
6053
 
6066
6054
  - If only 'start_timer' is given we measure how long we execute
6067
 
  from that point until we terminate mysqltest.
 
6055
  from that point until we terminate drizzletest.
6068
6056
 
6069
6057
  - 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
 
6058
  from that we enter drizzletest to the 'end_timer' is command is
6071
6059
  executed.
6072
6060
 
6073
6061
  - If both 'start_timer' and 'end_timer' are given we measure
6156
6144
 
6157
6145
/* Definitions for replace result */
6158
6146
 
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;
 
6147
typedef struct st_pointer_array {    /* when using array-strings */
 
6148
  TYPELIB typelib;        /* Pointer to strings */
 
6149
  uchar  *str;          /* Strings is here */
 
6150
  int7  *flag;          /* Flag about each var. */
 
6151
  uint  array_allocs,max_count,length,max_length;
6164
6152
} POINTER_ARRAY;
6165
6153
 
6166
6154
struct st_replace;
6167
6155
struct st_replace *init_replace(char * *from, char * *to, uint count,
6168
 
                                char * word_end_chars);
 
6156
        char * word_end_chars);
6169
6157
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
6170
6158
void replace_strings_append(struct st_replace *rep, DYNAMIC_STRING* ds,
6171
6159
                            const char *from, int len);
6211
6199
  for (i= 1,pos= word_end_chars ; i < 256 ; i++)
6212
6200
    if (my_isspace(charset_info,i))
6213
6201
      *pos++= i;
6214
 
  *pos=0;                                       /* End pointer */
 
6202
  *pos=0;          /* End pointer */
6215
6203
  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)))
 
6204
          (char**) to_array.typelib.type_names,
 
6205
          (uint) from_array.typelib.count,
 
6206
          word_end_chars)))
6219
6207
    die("Can't initialize replace from '%s'", command->query);
6220
6208
  free_pointer_array(&from_array);
6221
6209
  free_pointer_array(&to_array);
6602
6590
#define LAST_CHAR_CODE 259
6603
6591
 
6604
6592
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 */
 
6593
  uint  *bits;        /* Pointer to used sets */
 
6594
  short next[LAST_CHAR_CODE];    /* Pointer to next sets */
 
6595
  uint  found_len;      /* Best match to date */
 
6596
  int  found_offset;
 
6597
  uint  table_offset;
 
6598
  uint  size_of_bits;      /* For convinience */
6611
6599
} REP_SET;
6612
6600
 
6613
6601
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;
 
6602
  uint    count;      /* Number of sets */
 
6603
  uint    extra;      /* Extra sets in buffer */
 
6604
  uint    invisible;    /* Sets not chown */
 
6605
  uint    size_of_bits;
 
6606
  REP_SET  *set,*set_buffer;
 
6607
  uint    *bit_buffer;
6620
6608
} REP_SETS;
6621
6609
 
6622
6610
typedef struct st_found_set {
6667
6655
/* Init a replace structure for further calls */
6668
6656
 
6669
6657
REPLACE *init_replace(char * *from, char * *to,uint count,
6670
 
                      char * word_end_chars)
 
6658
          char * word_end_chars)
6671
6659
{
6672
6660
  static const int SPACE_CHAR= 256;
6673
6661
  static const int START_OF_LINE= 257;
6707
6695
    return(0);
6708
6696
  found_sets=0;
6709
6697
  if (!(found_set= (FOUND_SET*) my_malloc(sizeof(FOUND_SET)*max_length*count,
6710
 
                                          MYF(MY_WME))))
 
6698
            MYF(MY_WME))))
6711
6699
  {
6712
6700
    free_sets(&sets);
6713
6701
    return(0);
6714
6702
  }
6715
 
  VOID(make_new_set(&sets));                    /* Set starting set */
6716
 
  make_sets_invisible(&sets);                   /* Hide previus sets */
 
6703
  VOID(make_new_set(&sets));      /* Set starting set */
 
6704
  make_sets_invisible(&sets);      /* Hide previus sets */
6717
6705
  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 */
 
6706
  word_states=make_new_set(&sets);    /* Start of new word */
 
6707
  start_states=make_new_set(&sets);    /* This is first state */
6720
6708
  if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME))))
6721
6709
  {
6722
6710
    free_sets(&sets);
6732
6720
      internal_set_bit(start_states,states+1);
6733
6721
      if (!from[i][2])
6734
6722
      {
6735
 
        start_states->table_offset=i;
6736
 
        start_states->found_offset=1;
 
6723
  start_states->table_offset=i;
 
6724
  start_states->found_offset=1;
6737
6725
      }
6738
6726
    }
6739
6727
    else if (from[i][0] == '\\' && from[i][1] == '$')
6742
6730
      internal_set_bit(word_states,states);
6743
6731
      if (!from[i][2] && start_states->table_offset == (uint) ~0)
6744
6732
      {
6745
 
        start_states->table_offset=i;
6746
 
        start_states->found_offset=0;
 
6733
  start_states->table_offset=i;
 
6734
  start_states->found_offset=0;
6747
6735
      }
6748
6736
    }
6749
6737
    else
6750
6738
    {
6751
6739
      internal_set_bit(word_states,states);
6752
6740
      if (from[i][0] == '\\' && (from[i][1] == 'b' && from[i][2]))
6753
 
        internal_set_bit(start_states,states+1);
 
6741
  internal_set_bit(start_states,states+1);
6754
6742
      else
6755
 
        internal_set_bit(start_states,states);
 
6743
  internal_set_bit(start_states,states);
6756
6744
    }
6757
6745
    for (pos=from[i], len=0; *pos ; pos++)
6758
6746
    {
6759
6747
      if (*pos == '\\' && *(pos+1))
6760
6748
      {
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
 
        }
 
6749
  pos++;
 
6750
  switch (*pos) {
 
6751
  case 'b':
 
6752
    follow_ptr->chr = SPACE_CHAR;
 
6753
    break;
 
6754
  case '^':
 
6755
    follow_ptr->chr = START_OF_LINE;
 
6756
    break;
 
6757
  case '$':
 
6758
    follow_ptr->chr = END_OF_LINE;
 
6759
    break;
 
6760
  case 'r':
 
6761
    follow_ptr->chr = '\r';
 
6762
    break;
 
6763
  case 't':
 
6764
    follow_ptr->chr = '\t';
 
6765
    break;
 
6766
  case 'v':
 
6767
    follow_ptr->chr = '\v';
 
6768
    break;
 
6769
  default:
 
6770
    follow_ptr->chr = (uchar) *pos;
 
6771
    break;
 
6772
  }
6785
6773
      }
6786
6774
      else
6787
 
        follow_ptr->chr= (uchar) *pos;
 
6775
  follow_ptr->chr= (uchar) *pos;
6788
6776
      follow_ptr->table_offset=i;
6789
6777
      follow_ptr->len= ++len;
6790
6778
      follow_ptr++;
6800
6788
  for (set_nr=0,pos=0 ; set_nr < sets.count ; set_nr++)
6801
6789
  {
6802
6790
    set=sets.set+set_nr;
6803
 
    default_state= 0;                           /* Start from beginning */
 
6791
    default_state= 0;        /* Start from beginning */
6804
6792
 
6805
6793
    /* If end of found-string not found or start-set with current set */
6806
6794
 
6808
6796
    {
6809
6797
      if (!follow[i].chr)
6810
6798
      {
6811
 
        if (! default_state)
6812
 
          default_state= find_found(found_set,set->table_offset,
6813
 
                                    set->found_offset+1);
 
6799
  if (! default_state)
 
6800
    default_state= find_found(found_set,set->table_offset,
 
6801
            set->found_offset+1);
6814
6802
      }
6815
6803
    }
6816
 
    copy_bits(sets.set+used_sets,set);          /* Save set for changes */
 
6804
    copy_bits(sets.set+used_sets,set);    /* Save set for changes */
6817
6805
    if (!default_state)
6818
 
      or_bits(sets.set+used_sets,sets.set);     /* Can restart from start */
 
6806
      or_bits(sets.set+used_sets,sets.set);  /* Can restart from start */
6819
6807
 
6820
6808
    /* Find all chars that follows current sets */
6821
6809
    bzero((char*) used_chars,sizeof(used_chars));
6823
6811
    {
6824
6812
      used_chars[follow[i].chr]=1;
6825
6813
      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;
 
6814
     follow[i].len > 1) || follow[i].chr == END_OF_LINE)
 
6815
  used_chars[0]=1;
6828
6816
    }
6829
6817
 
6830
6818
    /* Mark word_chars used if \b is in state */
6831
6819
    if (used_chars[SPACE_CHAR])
6832
6820
      for (pos= word_end_chars ; *pos ; pos++)
6833
 
        used_chars[(int) (uchar) *pos] = 1;
 
6821
  used_chars[(int) (uchar) *pos] = 1;
6834
6822
 
6835
6823
    /* Handle other used characters */
6836
6824
    for (chr= 0 ; chr < 256 ; chr++)
6837
6825
    {
6838
6826
      if (! used_chars[chr])
6839
 
        set->next[chr]= chr ? default_state : -1;
 
6827
  set->next[chr]= chr ? default_state : -1;
6840
6828
      else
6841
6829
      {
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;
 
6830
  new_set=make_new_set(&sets);
 
6831
  set=sets.set+set_nr;      /* if realloc */
 
6832
  new_set->table_offset=set->table_offset;
 
6833
  new_set->found_len=set->found_len;
 
6834
  new_set->found_offset=set->found_offset+1;
 
6835
  found_end=0;
6848
6836
 
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);
 
6837
  for (i= (uint) ~0 ; (i=get_next_bit(sets.set+used_sets,i)) ; )
 
6838
  {
 
6839
    if (!follow[i].chr || follow[i].chr == chr ||
 
6840
        (follow[i].chr == SPACE_CHAR &&
 
6841
         (is_word_end[chr] ||
 
6842
    (!chr && follow[i].len > 1 && ! follow[i+1].chr))) ||
 
6843
        (follow[i].chr == END_OF_LINE && ! chr))
 
6844
    {
 
6845
      if ((! chr || (follow[i].chr && !follow[i+1].chr)) &&
 
6846
    follow[i].len > found_end)
 
6847
        found_end=follow[i].len;
 
6848
      if (chr && follow[i].chr)
 
6849
        internal_set_bit(new_set,i+1);    /* To next set */
 
6850
      else
 
6851
        internal_set_bit(new_set,i);
 
6852
    }
 
6853
  }
 
6854
  if (found_end)
 
6855
  {
 
6856
    new_set->found_len=0;      /* Set for testing if first */
 
6857
    bits_set=0;
 
6858
    for (i= (uint) ~0; (i=get_next_bit(new_set,i)) ;)
 
6859
    {
 
6860
      if ((follow[i].chr == SPACE_CHAR ||
 
6861
     follow[i].chr == END_OF_LINE) && ! chr)
 
6862
        bit_nr=i+1;
 
6863
      else
 
6864
        bit_nr=i;
 
6865
      if (follow[bit_nr-1].len < found_end ||
 
6866
    (new_set->found_len &&
 
6867
     (chr == 0 || !follow[bit_nr].chr)))
 
6868
        internal_clear_bit(new_set,i);
 
6869
      else
 
6870
      {
 
6871
        if (chr == 0 || !follow[bit_nr].chr)
 
6872
        {          /* best match  */
 
6873
    new_set->table_offset=follow[bit_nr].table_offset;
 
6874
    if (chr || (follow[i].chr == SPACE_CHAR ||
 
6875
          follow[i].chr == END_OF_LINE))
 
6876
      new_set->found_offset=found_end;  /* New match */
 
6877
    new_set->found_len=found_end;
 
6878
        }
 
6879
        bits_set++;
 
6880
      }
 
6881
    }
 
6882
    if (bits_set == 1)
 
6883
    {
 
6884
      set->next[chr] = find_found(found_set,
 
6885
          new_set->table_offset,
 
6886
          new_set->found_offset);
 
6887
      free_last_set(&sets);
 
6888
    }
 
6889
    else
 
6890
      set->next[chr] = find_set(&sets,new_set);
 
6891
  }
 
6892
  else
 
6893
    set->next[chr] = find_set(&sets,new_set);
6906
6894
      }
6907
6895
    }
6908
6896
  }
6910
6898
  /* Alloc replace structure for the replace-state-machine */
6911
6899
 
6912
6900
  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))))
 
6901
            sizeof(REPLACE_STRING)*(found_sets+1)+
 
6902
            sizeof(char *)*count+result_len,
 
6903
            MYF(MY_WME | MY_ZEROFILL))))
6916
6904
  {
6917
6905
    rep_str=(REPLACE_STRING*) (replace+sets.count);
6918
6906
    to_array= (char **) (rep_str+found_sets+1);
6928
6916
    {
6929
6917
      pos=from[found_set[i-1].table_offset];
6930
6918
      rep_str[i].found= !bcmp((const uchar*) pos,
6931
 
                              (const uchar*) "\\^", 3) ? 2 : 1;
 
6919
            (const uchar*) "\\^", 3) ? 2 : 1;
6932
6920
      rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
6933
6921
      rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
6934
6922
      rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+
6935
 
        end_of_word(pos);
 
6923
  end_of_word(pos);
6936
6924
    }
6937
6925
    for (i=0 ; i < sets.count ; i++)
6938
6926
    {
6939
6927
      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));
 
6928
  if (sets.set[i].next[j] >= 0)
 
6929
    replace[i].next[j]=replace+sets.set[i].next[j];
 
6930
  else
 
6931
    replace[i].next[j]=(REPLACE*) (rep_str+(-sets.set[i].next[j]-1));
6944
6932
    }
6945
6933
  }
6946
6934
  my_free(follow,MYF(0));
6955
6943
  bzero((char*) sets,sizeof(*sets));
6956
6944
  sets->size_of_bits=((states+7)/8);
6957
6945
  if (!(sets->set_buffer=(REP_SET*) my_malloc(sizeof(REP_SET)*SET_MALLOC_HUNC,
6958
 
                                              MYF(MY_WME))))
 
6946
                MYF(MY_WME))))
6959
6947
    return 1;
6960
6948
  if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits*
6961
 
                                           SET_MALLOC_HUNC,MYF(MY_WME))))
 
6949
             SET_MALLOC_HUNC,MYF(MY_WME))))
6962
6950
  {
6963
6951
    my_free(sets->set,MYF(0));
6964
6952
    return 1;
6994
6982
  count=sets->count+sets->invisible+SET_MALLOC_HUNC;
6995
6983
  if (!(set=(REP_SET*) my_realloc((uchar*) sets->set_buffer,
6996
6984
                                  sizeof(REP_SET)*count,
6997
 
                                  MYF(MY_WME))))
 
6985
          MYF(MY_WME))))
6998
6986
    return 0;
6999
6987
  sets->set_buffer=set;
7000
6988
  sets->set=set+sets->invisible;
7001
6989
  if (!(bit_buffer=(uint*) my_realloc((uchar*) sets->bit_buffer,
7002
 
                                      (sizeof(uint)*sets->size_of_bits)*count,
7003
 
                                      MYF(MY_WME))))
 
6990
              (sizeof(uint)*sets->size_of_bits)*count,
 
6991
              MYF(MY_WME))))
7004
6992
    return 0;
7005
6993
  sets->bit_buffer=bit_buffer;
7006
6994
  for (i=0 ; i < count ; i++)
7050
7038
void copy_bits(REP_SET *to,REP_SET *from)
7051
7039
{
7052
7040
  memcpy((uchar*) to->bits,(uchar*) from->bits,
7053
 
         (size_t) (sizeof(uint) * to->size_of_bits));
 
7041
   (size_t) (sizeof(uint) * to->size_of_bits));
7054
7042
}
7055
7043
 
7056
7044
int cmp_bits(REP_SET *set1,REP_SET *set2)
7057
7045
{
7058
7046
  return bcmp((uchar*) set1->bits,(uchar*) set2->bits,
7059
 
              sizeof(uint) * set1->size_of_bits);
 
7047
        sizeof(uint) * set1->size_of_bits);
7060
7048
}
7061
7049
 
7062
7050
 
7098
7086
      return i;
7099
7087
    }
7100
7088
  }
7101
 
  return i;                             /* return new postion */
 
7089
  return i;        /* return new postion */
7102
7090
}
7103
7091
 
7104
7092
/* find if there is a found_set with same table_offset & found_offset
7113
7101
  int i;
7114
7102
  for (i=0 ; (uint) i < found_sets ; i++)
7115
7103
    if (found_set[i].table_offset == table_offset &&
7116
 
        found_set[i].found_offset == found_offset)
 
7104
  found_set[i].found_offset == found_offset)
7117
7105
      return -i-2;
7118
7106
  found_set[i].table_offset=table_offset;
7119
7107
  found_set[i].found_offset=found_offset;
7120
7108
  found_sets++;
7121
 
  return -i-2;                          /* return new postion */
 
7109
  return -i-2;        /* return new postion */
7122
7110
}
7123
7111
 
7124
7112
/* Return 1 if regexp starts with \b or ends with \b*/
7134
7122
  char * end=strend(pos);
7135
7123
  return ((end > pos+2 && !bcmp((const uchar*) end-2,
7136
7124
                                (const uchar*) "\\b", 2)) ||
7137
 
          (end >= pos+2 && !bcmp((const uchar*) end-2,
 
7125
    (end >= pos+2 && !bcmp((const uchar*) end-2,
7138
7126
                                (const uchar*) "\\$",2))) ? 1 : 0;
7139
7127
}
7140
7128
 
7142
7130
 * Handle replacement of strings
7143
7131
 ****************************************************************************/
7144
7132
 
7145
 
#define PC_MALLOC               256     /* Bytes for pointers */
7146
 
#define PS_MALLOC               512     /* Bytes for data */
 
7133
#define PC_MALLOC    256  /* Bytes for pointers */
 
7134
#define PS_MALLOC    512  /* Bytes for data */
7147
7135
 
7148
7136
int insert_pointer_name(POINTER_ARRAY *pa,char * name)
7149
7137
{
7155
7143
  if (! pa->typelib.count)
7156
7144
  {
7157
7145
    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))))
 
7146
    my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
 
7147
         (sizeof(char *)+sizeof(*pa->flag))*
 
7148
         (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
7161
7149
      return(-1);
7162
7150
    if (!(pa->str= (uchar*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
7163
 
                                     MYF(MY_WME))))
 
7151
             MYF(MY_WME))))
7164
7152
    {
7165
7153
      my_free((char*) pa->typelib.type_names,MYF(0));
7166
7154
      return (-1);
7167
7155
    }
7168
7156
    pa->max_count=(PC_MALLOC-MALLOC_OVERHEAD)/(sizeof(uchar*)+
7169
 
                                               sizeof(*pa->flag));
 
7157
                 sizeof(*pa->flag));
7170
7158
    pa->flag= (int7*) (pa->typelib.type_names+pa->max_count);
7171
7159
    pa->length=0;
7172
7160
    pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;
7176
7164
  if (pa->length+length >= pa->max_length)
7177
7165
  {
7178
7166
    if (!(new_pos= (uchar*) my_realloc((uchar*) pa->str,
7179
 
                                      (uint) (pa->max_length+PS_MALLOC),
7180
 
                                      MYF(MY_WME))))
 
7167
              (uint) (pa->max_length+PS_MALLOC),
 
7168
              MYF(MY_WME))))
7181
7169
      return(1);
7182
7170
    if (new_pos != pa->str)
7183
7171
    {
7184
7172
      my_ptrdiff_t diff=PTR_BYTE_DIFF(new_pos,pa->str);
7185
7173
      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*);
 
7174
  pa->typelib.type_names[i]= ADD_TO_PTR(pa->typelib.type_names[i],diff,
 
7175
                char*);
7188
7176
      pa->str=new_pos;
7189
7177
    }
7190
7178
    pa->max_length+=PS_MALLOC;
7195
7183
    pa->array_allocs++;
7196
7184
    len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
7197
7185
    if (!(new_array=(const char **) my_realloc((uchar*) pa->typelib.type_names,
7198
 
                                               (uint) len/
 
7186
                 (uint) len/
7199
7187
                                               (sizeof(uchar*)+sizeof(*pa->flag))*
7200
7188
                                               (sizeof(uchar*)+sizeof(*pa->flag)),
7201
7189
                                               MYF(MY_WME))))
7205
7193
    pa->max_count=len/(sizeof(uchar*) + sizeof(*pa->flag));
7206
7194
    pa->flag= (int7*) (pa->typelib.type_names+pa->max_count);
7207
7195
    memcpy((uchar*) pa->flag,(char *) (pa->typelib.type_names+old_count),
7208
 
           old_count*sizeof(*pa->flag));
 
7196
     old_count*sizeof(*pa->flag));
7209
7197
  }
7210
 
  pa->flag[pa->typelib.count]=0;                        /* Reset flag */
 
7198
  pa->flag[pa->typelib.count]=0;      /* Reset flag */
7211
7199
  pa->typelib.type_names[pa->typelib.count++]= (char*) pa->str+pa->length;
7212
 
  pa->typelib.type_names[pa->typelib.count]= NullS;     /* Put end-mark */
 
7200
  pa->typelib.type_names[pa->typelib.count]= NullS;  /* Put end-mark */
7213
7201
  VOID(strmov((char*) pa->str+pa->length,name));
7214
7202
  pa->length+=length;
7215
7203
  return(0);