~mkindahl/drizzle/remove-mem-casts

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Brian Aker
  • Date: 2008-07-26 04:51:46 UTC
  • mfrom: (202.1.25 codestyle)
  • Revision ID: brian@tangent.org-20080726045146-ax7ofn8aqnkycjl3
Merge from Monty

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