~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to client/drizzletest.cc

  • Committer: Padraig O'Sullivan
  • Date: 2009-03-21 20:26:28 UTC
  • mto: (960.2.5 mordred)
  • mto: This revision was merged to the branch mainline in revision 961.
  • Revision ID: osullivan.padraig@gmail.com-20090321202628-nh6qsi825m4d4av6
Removing the queues.[h,cc] files from the mysys directory. The only place
where they are needed now is in the MyISAM storage engine. Thus, I moved the
files there and updated the files in the MyISAM storage engine
appropriately.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
#define MTEST_VERSION "3.3"
40
40
 
41
 
#include "config.h"
 
41
#include "client_priv.h"
42
42
 
43
43
#include <queue>
44
44
#include <map>
45
45
#include <string>
46
 
 
47
 
#include <pcrecpp.h>
48
 
 
49
 
#include "client_priv.h"
 
46
#include <vector>
 
47
 
 
48
#include PCRE_HEADER
 
49
 
50
50
#include <mysys/hash.h>
51
51
#include <stdarg.h>
52
52
 
53
53
#include "errname.h"
54
54
 
 
55
/* Added this for string translation. */
 
56
#include <drizzled/gettext.h>
 
57
 
55
58
using namespace std;
56
59
 
57
60
#define MAX_VAR_NAME_LENGTH    256
58
61
#define MAX_COLUMNS            256
59
62
#define MAX_EMBEDDED_SERVER_ARGS 64
60
63
#define MAX_DELIMITER_LENGTH 16
61
 
 
62
64
/* Flags controlling send and reap */
63
65
#define QUERY_SEND_FLAG  1
64
66
#define QUERY_REAP_FLAG  2
65
67
 
66
68
enum {
67
69
  OPT_PS_PROTOCOL, OPT_SP_PROTOCOL, OPT_CURSOR_PROTOCOL, OPT_VIEW_PROTOCOL,
68
 
  OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES
 
70
  OPT_MAX_CONNECT_RETRIES, OPT_MARK_PROGRESS, OPT_LOG_DIR, OPT_TAIL_LINES,
 
71
  OPT_TESTDIR
69
72
};
70
73
 
71
74
static int record= 0, opt_sleep= -1;
72
 
static char *opt_db= 0, *opt_pass= 0;
73
 
const char *opt_user= 0, *opt_host= 0, *unix_sock= 0, *opt_basedir= "./";
 
75
static char *opt_db= NULL, *opt_pass= NULL;
 
76
const char *opt_user= NULL, *opt_host= NULL, *unix_sock= NULL,
 
77
           *opt_basedir= "./";
74
78
const char *opt_logdir= "";
75
 
const char *opt_include= 0, *opt_charsets_dir;
76
 
static int opt_port= 0;
 
79
const char *opt_include= NULL, *opt_charsets_dir;
 
80
const char *opt_testdir= NULL;
 
81
static uint32_t opt_port= 0;
77
82
static int opt_max_connect_retries;
78
 
static bool opt_compress= 0, silent= 0, verbose= 0;
79
 
static bool debug_info_flag= 0, debug_check_flag= 0;
80
 
static bool tty_password= 0;
81
 
static bool opt_mark_progress= 0;
82
 
static bool parsing_disabled= 0;
 
83
static bool opt_compress= false, silent= false, verbose= false;
 
84
static bool debug_info_flag= false, debug_check_flag= false;
 
85
static bool tty_password= false;
 
86
static bool opt_mark_progress= false;
 
87
static bool parsing_disabled= false;
83
88
static bool display_result_vertically= false,
84
89
  display_metadata= false, display_result_sorted= false;
85
 
static bool disable_query_log= 0, disable_result_log= 0;
86
 
static bool disable_warnings= 0;
87
 
static bool disable_info= 1;
88
 
static bool abort_on_error= 1;
89
 
static bool server_initialized= 0;
90
 
static bool is_windows= 0;
 
90
static bool disable_query_log= false, disable_result_log= false;
 
91
static bool disable_warnings= false;
 
92
static bool disable_info= true;
 
93
static bool abort_on_error= true;
 
94
static bool server_initialized= false;
 
95
static bool is_windows= false;
91
96
static char **default_argv;
92
97
static const char *load_default_groups[]= { "drizzletest", "client", 0 };
93
98
static char line_buffer[MAX_DELIMITER_LENGTH], *line_buffer_pos= line_buffer;
94
99
 
95
 
static uint start_lineno= 0; /* Start line of current command */
96
 
static uint my_end_arg= 0;
 
100
static uint32_t start_lineno= 0; /* Start line of current command */
 
101
static uint32_t my_end_arg= 0;
97
102
 
98
103
/* Number of lines of the result to include in failure report */
99
 
static uint opt_tail_lines= 0;
 
104
static uint32_t opt_tail_lines= 0;
100
105
 
101
106
static char delimiter[MAX_DELIMITER_LENGTH]= ";";
102
 
static uint delimiter_length= 1;
 
107
static uint32_t delimiter_length= 1;
103
108
 
104
109
static char TMPDIR[FN_REFLEN];
105
110
 
125
130
{
126
131
  FILE* file;
127
132
  const char *file_name;
128
 
  uint lineno; /* Current line in file */
 
133
  uint32_t lineno; /* Current line in file */
129
134
};
130
135
 
131
136
static struct st_test_file file_stack[16];
165
170
master_pos_st master_pos;
166
171
 
167
172
/* if set, all results are concated and compared against this file */
168
 
const char *result_file_name= 0;
 
173
const char *result_file_name= NULL;
169
174
 
170
175
typedef struct st_var
171
176
{
227
232
  Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS,
228
233
  Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_SORTED_RESULT,
229
234
  Q_START_TIMER, Q_END_TIMER,
230
 
  Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL,
 
235
  Q_CHARACTER_SET,
231
236
  Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT,
232
237
  Q_IF,
233
238
  Q_DISABLE_PARSING, Q_ENABLE_PARSING,
345
350
  enum match_err_type type;
346
351
  union
347
352
  {
348
 
    uint errnum;
 
353
    uint32_t errnum;
349
354
    char sqlstate[SQLSTATE_LENGTH+1];  /* \0 terminated string */
350
355
  } code;
351
356
};
353
358
struct st_expected_errors
354
359
{
355
360
  struct st_match_err err[10];
356
 
  uint count;
 
361
  uint32_t count;
357
362
};
358
363
static struct st_expected_errors saved_expected_errors;
359
364
 
388
393
VAR* var_from_env(const char *, const char *);
389
394
VAR* var_init(VAR* v, const char *name, int name_len, const char *val,
390
395
              int val_len);
391
 
void var_free(void* v);
 
396
extern "C" void var_free(void* v);
392
397
VAR* var_get(const char *var_name, const char** var_name_end,
393
398
             bool raw, bool ignore_not_existing);
394
399
void eval_expr(VAR* v, const char *p, const char** p_end);
395
 
bool match_delimiter(int c, const char *delim, uint length);
 
400
bool match_delimiter(int c, const char *delim, uint32_t length);
396
401
void dump_result_to_reject_file(char *buf, int size);
397
402
void dump_result_to_log_file(const char *buf, int size);
398
403
void dump_warning_messages(void);
405
410
 
406
411
/* For replace_column */
407
412
static char *replace_column[MAX_COLUMNS];
408
 
static uint max_replace_column= 0;
 
413
static uint32_t max_replace_column= 0;
409
414
void do_get_replace_column(struct st_command*);
410
415
void free_replace_column(void);
411
416
 
430
435
void replace_append_mem(string *ds, const char *val,
431
436
                        int len);
432
437
void replace_append(string *ds, const char *val);
433
 
void replace_append_uint(string *ds, uint val);
 
438
void replace_append_uint(string *ds, uint32_t val);
434
439
void append_sorted(string* ds, string* ds_input);
435
440
 
436
441
void handle_error(struct st_command*,
439
444
void handle_no_error(struct st_command*);
440
445
 
441
446
 
442
 
#define do_send_query(cn,q,q_len,flags) drizzle_send_query(&cn->drizzle, q, q_len)
 
447
#define do_send_query(cn,q,q_len,flags) drizzleclient_send_query(&cn->drizzle, q, q_len)
443
448
 
444
449
void do_eval(string *query_eval, const char *query,
445
450
             const char *query_end, bool pass_through_escape_chars)
514
519
void append_os_quoted(string *str, const char *append, ...)
515
520
{
516
521
  const char *quote_str= "\'";
517
 
  const uint  quote_len= 1;
 
522
  const uint32_t  quote_len= 1;
518
523
 
519
524
  va_list dirty_text;
520
525
 
533
538
      str->append(quote_str, quote_len);
534
539
      cur_pos= next_pos + 1;
535
540
    }
536
 
    str->append(cur_pos, next_pos - cur_pos);
 
541
    str->append(cur_pos);
537
542
    append= va_arg(dirty_text, char *);
538
543
  }
539
544
  va_end(dirty_text);
562
567
  if (!drizzle)
563
568
    return;
564
569
 
565
 
  if (drizzle_query(drizzle, query))
 
570
  if (drizzleclient_query(drizzle, query))
566
571
  {
567
572
    log_msg("Error running query '%s': %d %s",
568
 
            query, drizzle_errno(drizzle), drizzle_error(drizzle));
 
573
            query, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
569
574
    return;
570
575
  }
571
576
 
572
 
  if ((res= drizzle_store_result(drizzle)) == NULL)
 
577
  if ((res= drizzleclient_store_result(drizzle)) == NULL)
573
578
  {
574
579
    /* No result set returned */
575
580
    return;
579
584
    DRIZZLE_ROW row;
580
585
    unsigned int i;
581
586
    unsigned int row_num= 0;
582
 
    unsigned int num_fields= drizzle_num_fields(res);
583
 
    const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
 
587
    unsigned int num_fields= drizzleclient_num_fields(res);
 
588
    const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
584
589
 
585
590
    fprintf(stderr, "=== %s ===\n", query);
586
 
    while ((row= drizzle_fetch_row(res)))
 
591
    while ((row= drizzleclient_fetch_row(res)))
587
592
    {
588
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
593
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
589
594
      row_num++;
590
595
 
591
596
      fprintf(stderr, "---- %d. ----\n", row_num);
600
605
      fprintf(stderr, "=");
601
606
    fprintf(stderr, "\n\n");
602
607
  }
603
 
  drizzle_free_result(res);
 
608
  drizzleclient_free_result(res);
604
609
 
605
610
  return;
606
611
}
628
633
  if (!drizzle)
629
634
    return;
630
635
 
631
 
  if (drizzle_query(drizzle, query))
 
636
  if (drizzleclient_query(drizzle, query))
632
637
  {
633
638
    log_msg("Error running query '%s': %d %s",
634
 
            query, drizzle_errno(drizzle), drizzle_error(drizzle));
 
639
            query, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
635
640
    return;
636
641
  }
637
642
 
638
 
  if ((res= drizzle_store_result(drizzle)) == NULL)
 
643
  if ((res= drizzleclient_store_result(drizzle)) == NULL)
639
644
  {
640
645
    /* No result set returned */
641
646
    return;
642
647
  }
643
648
 
644
 
  if (drizzle_num_rows(res) <= 1)
 
649
  if (drizzleclient_num_rows(res) <= 1)
645
650
  {
646
651
    /* Don't display the last row, it's "last error" */
647
652
  }
649
654
  {
650
655
    DRIZZLE_ROW row;
651
656
    unsigned int row_num= 0;
652
 
    unsigned int num_fields= drizzle_num_fields(res);
 
657
    unsigned int num_fields= drizzleclient_num_fields(res);
653
658
 
654
659
    fprintf(stderr, "\nWarnings from just before the error:\n");
655
 
    while ((row= drizzle_fetch_row(res)))
 
660
    while ((row= drizzleclient_fetch_row(res)))
656
661
    {
657
662
      uint32_t i;
658
 
      uint32_t *lengths= drizzle_fetch_lengths(res);
 
663
      uint32_t *lengths= drizzleclient_fetch_lengths(res);
659
664
 
660
 
      if (++row_num >= drizzle_num_rows(res))
 
665
      if (++row_num >= drizzleclient_num_rows(res))
661
666
      {
662
667
        /* Don't display the last row, it's "last error" */
663
668
        break;
671
676
      fprintf(stderr, "\n");
672
677
    }
673
678
  }
674
 
  drizzle_free_result(res);
 
679
  drizzleclient_free_result(res);
675
680
 
676
681
  return;
677
682
}
762
767
}
763
768
 
764
769
 
765
 
static void handle_command_error(struct st_command *command, uint error)
 
770
static void handle_command_error(struct st_command *command, uint32_t error)
766
771
{
767
772
 
768
773
  if (error != 0)
769
774
  {
770
 
    uint i;
 
775
    uint32_t i;
771
776
 
772
777
    if (command->abort_on_error)
773
778
      die("command \"%.*s\" failed with error %d",
800
805
 
801
806
  for (--next_con; next_con >= connections; --next_con)
802
807
  {
803
 
    drizzle_close(&next_con->drizzle);
 
808
    drizzleclient_close(&next_con->drizzle);
804
809
    if (next_con->util_drizzle)
805
 
      drizzle_close(next_con->util_drizzle);
 
810
      drizzleclient_close(next_con->util_drizzle);
806
811
    free(next_con->name);
807
812
  }
808
813
  return;
816
821
  {
817
822
    if (cur_file->file && cur_file->file != stdin)
818
823
    {
819
 
      my_fclose(cur_file->file, MYF(0));
 
824
      fclose(cur_file->file);
820
825
    }
821
826
    free((unsigned char*) cur_file->file_name);
822
827
    cur_file->file_name= 0;
827
832
 
828
833
static void free_used_memory(void)
829
834
{
830
 
  uint i;
 
835
  uint32_t i;
831
836
 
832
837
 
833
838
  close_connections();
837
842
  vector<struct st_command *>::iterator iter;
838
843
  for (iter= q_lines.begin() ; iter < q_lines.end() ; iter++)
839
844
  {
840
 
    struct st_command * q_line= *(iter.base());
 
845
    struct st_command * q_line= *iter;
841
846
    if (q_line->query_buf != NULL)
842
847
    {
843
848
      free(q_line->query_buf);
1074
1079
static void cat_file(string* ds, const char* filename)
1075
1080
{
1076
1081
  int fd;
1077
 
  uint len;
 
1082
  uint32_t len;
1078
1083
  char buff[512];
1079
1084
 
1080
1085
  if ((fd= my_open(filename, O_RDONLY, MYF(0))) < 0)
1156
1161
  string ds_cmdline;
1157
1162
 
1158
1163
 
1159
 
  append_os_quoted(&ds_cmdline, tool_path);
 
1164
  append_os_quoted(&ds_cmdline, tool_path, NULL);
1160
1165
  ds_cmdline.append(" ");
1161
1166
 
1162
1167
  va_start(args, result);
1206
1211
               "2>&1",
1207
1212
               NULL) > 1) /* Most "diff" tools return >1 if error */
1208
1213
  {
1209
 
    ds_tmp= "";
1210
1214
 
1211
1215
    /* Fallback to context diff with "diff -c" */
1212
1216
    if (run_tool("diff",
1221
1225
        Fallback to dump both files to result file and inform
1222
1226
        about installing "diff"
1223
1227
      */
1224
 
      ds_tmp= "";
 
1228
      ds_tmp.clear();
1225
1229
 
1226
1230
      ds_tmp.append(
1227
1231
                    "\n"
1282
1286
{
1283
1287
  int error= RESULT_OK;
1284
1288
  File fd2;
1285
 
  uint len, len2;
 
1289
  uint32_t len, len2;
1286
1290
  char buff[512], buff2[512];
 
1291
  const char *fname= filename2;
 
1292
  string tmpfile;
1287
1293
 
1288
 
  if ((fd2= my_open(filename2, O_RDONLY, MYF(0))) < 0)
 
1294
  if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
1289
1295
  {
1290
1296
    my_close(fd, MYF(0));
1291
 
    die("Failed to open second file: '%s'", filename2);
 
1297
    if (opt_testdir != NULL)
 
1298
    {
 
1299
      tmpfile= opt_testdir;
 
1300
      if (tmpfile[tmpfile.length()] != '/')
 
1301
        tmpfile.append("/");
 
1302
      tmpfile.append(filename2);
 
1303
      fname= tmpfile.c_str();
 
1304
    }
 
1305
    if ((fd2= my_open(fname, O_RDONLY, MYF(0))) < 0)
 
1306
    {
 
1307
      my_close(fd, MYF(0));
 
1308
    
 
1309
      die("Failed to open second file: '%s'", fname);
 
1310
    }
1292
1311
  }
1293
1312
  while((len= my_read(fd, (unsigned char*)&buff,
1294
1313
                      sizeof(buff), MYF(0))) > 0)
1374
1393
  char temp_file_path[FN_REFLEN];
1375
1394
 
1376
1395
  if ((fd= create_temp_file(temp_file_path, NULL,
1377
 
                            "tmp", O_CREAT | O_SHARE | O_RDWR,
 
1396
                            "tmp", O_CREAT | O_RDWR,
1378
1397
                            MYF(MY_WME))) < 0)
1379
1398
    die("Failed to create temporary file for ds");
1380
1399
 
1381
1400
  /* Write ds to temporary file and set file pos to beginning*/
1382
1401
  if (my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1383
1402
               MYF(MY_FNABP | MY_WME)) ||
1384
 
      my_seek(fd, 0, SEEK_SET, MYF(0)) == MY_FILEPOS_ERROR)
 
1403
      lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
1385
1404
  {
1386
1405
    my_close(fd, MYF(0));
1387
1406
    /* Remove the temporary file */
1454
1473
    ds->erase(); /* Don't create a .log file */
1455
1474
 
1456
1475
    show_diff(NULL, result_file_name, reject_file);
1457
 
    die(mess);
 
1476
    die("%s",mess);
1458
1477
    break;
1459
1478
  }
1460
1479
  default: /* impossible */
1538
1557
}
1539
1558
 
1540
1559
 
1541
 
static unsigned char *get_var_key(const unsigned char* var, size_t *len,
1542
 
                          bool __attribute__((unused)) t)
 
1560
extern "C"
 
1561
unsigned char *get_var_key(const unsigned char* var, size_t *len, bool)
1543
1562
{
1544
1563
  register char* key;
1545
1564
  key = ((VAR*)var)->name;
1558
1577
  if (!val_len && val)
1559
1578
    val_len = strlen(val) ;
1560
1579
  val_alloc_len = val_len + 16; /* room to grow */
1561
 
  if (!(tmp_var=v) && !(tmp_var = (VAR*)my_malloc(sizeof(*tmp_var)
1562
 
                                                  + name_len+1, MYF(MY_WME))))
 
1580
  if (!(tmp_var=v) && !(tmp_var = (VAR*)malloc(sizeof(*tmp_var)
 
1581
                                               + name_len+1)))
1563
1582
    die("Out of memory");
1564
1583
 
1565
1584
  tmp_var->name = (name) ? (char*) tmp_var + sizeof(*tmp_var) : 0;
1566
1585
  tmp_var->alloced = (v == 0);
1567
1586
 
1568
 
  if (!(tmp_var->str_val = (char *)my_malloc(val_alloc_len+1, MYF(MY_WME))))
 
1587
  if (!(tmp_var->str_val = (char *)malloc(val_alloc_len+1)))
1569
1588
    die("Out of memory");
1570
1589
 
1571
1590
  memcpy(tmp_var->name, name, name_len);
1618
1637
  if (digit < 0 || digit >= 10)
1619
1638
  {
1620
1639
    const char *save_var_name = var_name, *end;
1621
 
    uint length;
 
1640
    uint32_t length;
1622
1641
    end = (var_name_end) ? *var_name_end : 0;
1623
1642
    while (my_isvar(charset_info,*var_name) && var_name != end)
1624
1643
      var_name++;
1628
1647
        return(0);
1629
1648
      die("Empty variable");
1630
1649
    }
1631
 
    length= (uint) (var_name - save_var_name);
 
1650
    length= (uint32_t) (var_name - save_var_name);
1632
1651
    if (length >= MAX_VAR_NAME_LENGTH)
1633
1652
      die("Too long variable name: %s", save_var_name);
1634
1653
 
1636
1655
                                 length)))
1637
1656
    {
1638
1657
      char buff[MAX_VAR_NAME_LENGTH+1];
1639
 
      strmake(buff, save_var_name, length);
 
1658
      strncpy(buff, save_var_name, length);
 
1659
      buff[length]= '\0';
1640
1660
      v= var_from_env(buff, "");
1641
1661
    }
1642
1662
    var_name--;  /* Point at last character */
1692
1712
  digit= *var_name - '0';
1693
1713
  if (!(digit < 10 && digit >= 0))
1694
1714
  {
1695
 
    v= var_obtain(var_name, (uint) (var_name_end - var_name));
 
1715
    v= var_obtain(var_name, (uint32_t) (var_name_end - var_name));
1696
1716
  }
1697
1717
  else
1698
1718
    v= var_reg + digit;
1711
1731
    snprintf(buf, sizeof(buf), "%.*s=%.*s",
1712
1732
             v->name_len, v->name,
1713
1733
             v->str_val_len, v->str_val);
1714
 
    if (!(v->env_s= my_strdup(buf, MYF(MY_WME))))
 
1734
    if (!(v->env_s= strdup(buf)))
1715
1735
      die("Out of memory");
1716
1736
    putenv(v->env_s);
1717
1737
    free(old_env_s);
1736
1756
 
1737
1757
/*
1738
1758
  Store an integer (typically the returncode of the last SQL)
1739
 
  statement in the drizzletest builtin variable $drizzle_errno
 
1759
  statement in the drizzletest builtin variable $drizzleclient_errno
1740
1760
*/
1741
1761
 
1742
1762
static void var_set_errno(int sql_errno)
1743
1763
{
1744
 
  var_set_int("$drizzle_errno", sql_errno);
 
1764
  var_set_int("$drizzleclient_errno", sql_errno);
1745
1765
}
1746
1766
 
1747
1767
 
1748
1768
/*
1749
 
  Update $drizzle_get_server_version variable with version
 
1769
  Update $drizzleclient_get_server_version variable with version
1750
1770
  of the currently connected server
1751
1771
*/
1752
1772
 
1753
 
static void var_set_drizzle_get_server_version(DRIZZLE *drizzle)
 
1773
static void var_set_drizzleclient_get_server_version(DRIZZLE *drizzle)
1754
1774
{
1755
 
  var_set_int("$drizzle_get_server_version", drizzle_get_server_version(drizzle));
 
1775
  var_set_int("$drizzleclient_get_server_version", drizzleclient_get_server_version(drizzle));
1756
1776
}
1757
1777
 
1758
1778
 
1798
1818
  /* Eval the query, thus replacing all environment variables */
1799
1819
  do_eval(&ds_query, query, end, false);
1800
1820
 
1801
 
  if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
 
1821
  if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1802
1822
    die("Error running query '%s': %d %s", ds_query.c_str(),
1803
 
        drizzle_errno(drizzle), drizzle_error(drizzle));
1804
 
  if (!(res= drizzle_store_result(drizzle)))
 
1823
        drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
 
1824
  if (!(res= drizzleclient_store_result(drizzle)))
1805
1825
    die("Query '%s' didn't return a result set", ds_query.c_str());
1806
1826
 
1807
 
  if ((row= drizzle_fetch_row(res)) && row[0])
 
1827
  if ((row= drizzleclient_fetch_row(res)) && row[0])
1808
1828
  {
1809
1829
    /*
1810
1830
      Concatenate all fields in the first row with tab in between
1814
1834
    uint32_t i;
1815
1835
    uint32_t *lengths;
1816
1836
 
1817
 
    lengths= drizzle_fetch_lengths(res);
1818
 
    for (i= 0; i < drizzle_num_fields(res); i++)
 
1837
    lengths= drizzleclient_fetch_lengths(res);
 
1838
    for (i= 0; i < drizzleclient_num_fields(res); i++)
1819
1839
    {
1820
1840
      if (row[i])
1821
1841
      {
1830
1850
  else
1831
1851
    eval_expr(var, "", 0);
1832
1852
 
1833
 
  drizzle_free_result(res);
 
1853
  drizzleclient_free_result(res);
1834
1854
  return;
1835
1855
}
1836
1856
 
1889
1909
  char * unstripped_query= strdup(ds_query.c_str());
1890
1910
  if (strip_surrounding(unstripped_query, '"', '"'))
1891
1911
    die("Mismatched \"'s around query '%s'", ds_query.c_str());
1892
 
  ds_query= unstripped_query;
 
1912
  ds_query.clear();
 
1913
  ds_query.append(unstripped_query);
1893
1914
 
1894
1915
  /* Run the query */
1895
 
  if (drizzle_real_query(drizzle, ds_query.c_str(), ds_query.length()))
 
1916
  if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1896
1917
    die("Error running query '%s': %d %s", ds_query.c_str(),
1897
 
        drizzle_errno(drizzle), drizzle_error(drizzle));
1898
 
  if (!(res= drizzle_store_result(drizzle)))
 
1918
        drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
 
1919
  if (!(res= drizzleclient_store_result(drizzle)))
1899
1920
    die("Query '%s' didn't return a result set", ds_query.c_str());
1900
1921
 
1901
1922
  {
1902
1923
    /* Find column number from the given column name */
1903
 
    uint i;
1904
 
    uint num_fields= drizzle_num_fields(res);
1905
 
    const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
 
1924
    uint32_t i;
 
1925
    uint32_t num_fields= drizzleclient_num_fields(res);
 
1926
    const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
1906
1927
 
1907
1928
    for (i= 0; i < num_fields; i++)
1908
1929
    {
1915
1936
    }
1916
1937
    if (col_no == -1)
1917
1938
    {
1918
 
      drizzle_free_result(res);
 
1939
      drizzleclient_free_result(res);
1919
1940
      die("Could not find column '%s' in the result of '%s'",
1920
1941
          ds_col.c_str(), ds_query.c_str());
1921
1942
    }
1927
1948
    long rows= 0;
1928
1949
    const char* value= "No such row";
1929
1950
 
1930
 
    while ((row= drizzle_fetch_row(res)))
 
1951
    while ((row= drizzleclient_fetch_row(res)))
1931
1952
    {
1932
1953
      if (++rows == row_no)
1933
1954
      {
1943
1964
    }
1944
1965
    eval_expr(var, value, 0);
1945
1966
  }
1946
 
  drizzle_free_result(res);
 
1967
  drizzleclient_free_result(res);
1947
1968
 
1948
1969
  return;
1949
1970
}
1955
1976
  dest->int_dirty= src->int_dirty;
1956
1977
 
1957
1978
  /* Alloc/realloc data for str_val in dest */
1958
 
  if (dest->alloced_len < src->alloced_len &&
1959
 
      !(dest->str_val= dest->str_val
1960
 
        ? (char *)my_realloc(dest->str_val, src->alloced_len, MYF(MY_WME))
1961
 
        : (char *)my_malloc(src->alloced_len, MYF(MY_WME))))
1962
 
    die("Out of memory");
 
1979
  if (dest->alloced_len < src->alloced_len)
 
1980
  {
 
1981
    char *tmpptr= (char *)realloc(dest->str_val, src->alloced_len);
 
1982
    if (tmpptr == NULL)
 
1983
      die("Out of memory");
 
1984
    dest->str_val= tmpptr;
 
1985
  }
1963
1986
  else
1964
1987
    dest->alloced_len= src->alloced_len;
1965
1988
 
2011
2034
      static int MIN_VAR_ALLOC= 32;
2012
2035
      v->alloced_len = (new_val_len < MIN_VAR_ALLOC - 1) ?
2013
2036
        MIN_VAR_ALLOC : new_val_len + 1;
2014
 
      if (!(v->str_val =
2015
 
            v->str_val ? (char *)my_realloc(v->str_val, v->alloced_len+1,
2016
 
                                            MYF(MY_WME)) :
2017
 
            (char *)my_malloc(v->alloced_len+1, MYF(MY_WME))))
 
2037
      char *tmpptr= (char *)realloc(v->str_val, v->alloced_len+1);
 
2038
      if (tmpptr == NULL)
2018
2039
        die("Out of memory");
 
2040
      v->str_val= tmpptr;
2019
2041
    }
2020
2042
    v->str_val_len = new_val_len;
2021
2043
    memcpy(v->str_val, p, new_val_len);
2033
2055
 
2034
2056
  if (!test_if_hard_path(name))
2035
2057
  {
2036
 
    strxmov(buff, opt_basedir, name, NULL);
 
2058
    sprintf(buff,"%s%s",opt_basedir,name);
2037
2059
    name=buff;
2038
2060
  }
2039
2061
  fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
2041
2063
  if (cur_file == file_stack_end)
2042
2064
    die("Source directives are nesting too deep");
2043
2065
  cur_file++;
2044
 
  if (!(cur_file->file = my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
 
2066
  if (!(cur_file->file= fopen(buff, "r")))
2045
2067
  {
2046
2068
    cur_file--;
2047
2069
    die("Could not open '%s' for reading", buff);
2048
2070
  }
2049
 
  cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
 
2071
  if (!(cur_file->file_name= strdup(buff)))
 
2072
    die("Out of memory");
2050
2073
  cur_file->lineno=1;
2051
2074
  return(0);
2052
2075
}
2086
2109
    ; /* Do nothing */
2087
2110
  else
2088
2111
  {
 
2112
    if (opt_testdir != NULL)
 
2113
    {
 
2114
      string testdir(opt_testdir);
 
2115
      if (testdir[testdir.length()] != '/')
 
2116
        testdir.append("/");
 
2117
      testdir.append(ds_filename);
 
2118
      ds_filename.swap(testdir);
 
2119
    }
2089
2120
    open_file(ds_filename.c_str());
2090
2121
  }
2091
2122
 
2197
2228
  error= pclose(res_file);
2198
2229
  if (error > 0)
2199
2230
  {
2200
 
    uint status= WEXITSTATUS(error), i;
 
2231
    uint32_t status= WEXITSTATUS(error), i;
2201
2232
    bool ok= 0;
2202
2233
 
2203
2234
    if (command->abort_on_error)
2466
2497
 
2467
2498
static void do_mkdir(struct st_command *command)
2468
2499
{
 
2500
  string ds_dirname;
2469
2501
  int error;
2470
 
  string ds_dirname;
2471
2502
  const struct command_arg mkdir_args[] = {
2472
2503
    {"dirname", ARG_STRING, true, &ds_dirname, "Directory to create"}
2473
2504
  };
2477
2508
                     mkdir_args, sizeof(mkdir_args)/sizeof(struct command_arg),
2478
2509
                     ' ');
2479
2510
 
2480
 
  error= my_mkdir(ds_dirname.c_str(), 0777, MYF(0)) != 0;
 
2511
  error= mkdir(ds_dirname.c_str(), (0777 & my_umask_dir)) != 0;
2481
2512
  handle_command_error(command, error);
2482
2513
  return;
2483
2514
}
2597
2628
 
2598
2629
  /* If no delimiter was provided, use EOF */
2599
2630
  if (ds_delimiter.length() == 0)
2600
 
    ds_delimiter= "EOF";
 
2631
    ds_delimiter.append("EOF");
2601
2632
 
2602
2633
  if (!append && access(ds_filename.c_str(), F_OK) == 0)
2603
2634
  {
2814
2845
 
2815
2846
*/
2816
2847
 
2817
 
static void do_change_user(struct st_command *command)
 
2848
static void do_change_user(struct st_command *)
2818
2849
{
2819
 
  DRIZZLE *drizzle= &cur_con->drizzle;
2820
 
  /* static keyword to make the NetWare compiler happy. */
2821
 
  string ds_user, ds_passwd, ds_db;
2822
 
  const struct command_arg change_user_args[] = {
2823
 
    { "user", ARG_STRING, false, &ds_user, "User to connect as" },
2824
 
    { "password", ARG_STRING, false, &ds_passwd, "Password used when connecting" },
2825
 
    { "database", ARG_STRING, false, &ds_db, "Database to select after connect" },
2826
 
  };
2827
 
 
2828
 
 
2829
 
 
2830
 
  check_command_args(command, command->first_argument,
2831
 
                     change_user_args,
2832
 
                     sizeof(change_user_args)/sizeof(struct command_arg),
2833
 
                     ',');
2834
 
 
2835
 
  if (!ds_user.length())
2836
 
    ds_user= drizzle->user;
2837
 
 
2838
 
  if (!ds_passwd.length())
2839
 
    ds_passwd= drizzle->passwd;
2840
 
 
2841
 
  if (!ds_db.length())
2842
 
    ds_db= drizzle->db;
2843
 
 
2844
 
  if (drizzle_change_user(drizzle, ds_user.c_str(),
2845
 
                          ds_passwd.c_str(), ds_db.c_str()))
2846
 
    die("change user failed: %s", drizzle_error(drizzle));
2847
 
 
2848
 
 
2849
 
  return;
 
2850
  assert(0);
2850
2851
}
2851
2852
 
2852
 
 
2853
2853
/*
2854
2854
  SYNOPSIS
2855
2855
  do_perl
2891
2891
 
2892
2892
  /* If no delimiter was provided, use EOF */
2893
2893
  if (ds_delimiter.length() == 0)
2894
 
    ds_delimiter= "EOF";
 
2894
    ds_delimiter.append("EOF");
2895
2895
 
2896
2896
  read_until_delimiter(&ds_script, &ds_delimiter);
2897
2897
 
2898
2898
  /* Create temporary file name */
2899
2899
  if ((fd= create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
2900
 
                            "tmp", O_CREAT | O_SHARE | O_RDWR,
 
2900
                            "tmp", O_CREAT | O_RDWR,
2901
2901
                            MYF(MY_WME))) < 0)
2902
2902
    die("Failed to create temporary file for perl command");
2903
2903
  my_close(fd, MYF(0));
2965
2965
 
2966
2966
 
2967
2967
static void
2968
 
do_wait_for_slave_to_stop(struct st_command *c __attribute__((unused)))
 
2968
do_wait_for_slave_to_stop(struct st_command *)
2969
2969
{
2970
2970
  static int SLAVE_POLL_INTERVAL= 300000;
2971
2971
  DRIZZLE *drizzle= &cur_con->drizzle;
2975
2975
    DRIZZLE_ROW row;
2976
2976
    int done;
2977
2977
 
2978
 
    if (drizzle_query(drizzle,"show status like 'Slave_running'") ||
2979
 
        !(res=drizzle_store_result(drizzle)))
 
2978
    if (drizzleclient_query(drizzle,"show status like 'Slave_running'") ||
 
2979
        !(res=drizzleclient_store_result(drizzle)))
2980
2980
      die("Query failed while probing slave for stop: %s",
2981
 
          drizzle_error(drizzle));
2982
 
    if (!(row=drizzle_fetch_row(res)) || !row[1])
 
2981
          drizzleclient_error(drizzle));
 
2982
    if (!(row=drizzleclient_fetch_row(res)) || !row[1])
2983
2983
    {
2984
 
      drizzle_free_result(res);
 
2984
      drizzleclient_free_result(res);
2985
2985
      die("Strange result from query while probing slave for stop");
2986
2986
    }
2987
2987
    done = !strcmp(row[1],"OFF");
2988
 
    drizzle_free_result(res);
 
2988
    drizzleclient_free_result(res);
2989
2989
    if (done)
2990
2990
      break;
2991
 
    my_sleep(SLAVE_POLL_INTERVAL);
 
2991
    usleep(SLAVE_POLL_INTERVAL);
2992
2992
  }
2993
2993
  return;
2994
2994
}
3010
3010
 
3011
3011
wait_for_position:
3012
3012
 
3013
 
  if (drizzle_query(drizzle, query_buf))
3014
 
    die("failed in '%s': %d: %s", query_buf, drizzle_errno(drizzle),
3015
 
        drizzle_error(drizzle));
 
3013
  if (drizzleclient_query(drizzle, query_buf))
 
3014
    die("failed in '%s': %d: %s", query_buf, drizzleclient_errno(drizzle),
 
3015
        drizzleclient_error(drizzle));
3016
3016
 
3017
 
  if (!(res= drizzle_store_result(drizzle)))
3018
 
    die("drizzle_store_result() returned NULL for '%s'", query_buf);
3019
 
  if (!(row= drizzle_fetch_row(res)))
 
3017
  if (!(res= drizzleclient_store_result(drizzle)))
 
3018
    die("drizzleclient_store_result() returned NULL for '%s'", query_buf);
 
3019
  if (!(row= drizzleclient_fetch_row(res)))
3020
3020
  {
3021
 
    drizzle_free_result(res);
 
3021
    drizzleclient_free_result(res);
3022
3022
    die("empty result in %s", query_buf);
3023
3023
  }
3024
3024
  if (!row[0])
3027
3027
      It may be that the slave SQL thread has not started yet, though START
3028
3028
      SLAVE has been issued ?
3029
3029
    */
3030
 
    drizzle_free_result(res);
 
3030
    drizzleclient_free_result(res);
3031
3031
    if (tries++ == 30)
3032
3032
    {
3033
3033
      show_query(drizzle, "SHOW MASTER STATUS");
3037
3037
    sleep(1); /* So at most we will wait 30 seconds and make 31 tries */
3038
3038
    goto wait_for_position;
3039
3039
  }
3040
 
  drizzle_free_result(res);
 
3040
  drizzleclient_free_result(res);
3041
3041
  return;
3042
3042
}
3043
3043
 
3073
3073
  const char *query;
3074
3074
 
3075
3075
 
3076
 
  if (drizzle_query(drizzle, query= "show master status"))
 
3076
  if (drizzleclient_query(drizzle, query= "show master status"))
3077
3077
    die("failed in 'show master status': %d %s",
3078
 
        drizzle_errno(drizzle), drizzle_error(drizzle));
 
3078
        drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3079
3079
 
3080
 
  if (!(res = drizzle_store_result(drizzle)))
3081
 
    die("drizzle_store_result() retuned NULL for '%s'", query);
3082
 
  if (!(row = drizzle_fetch_row(res)))
 
3080
  if (!(res = drizzleclient_store_result(drizzle)))
 
3081
    die("drizzleclient_store_result() retuned NULL for '%s'", query);
 
3082
  if (!(row = drizzleclient_fetch_row(res)))
3083
3083
    die("empty result in show master status");
3084
 
  my_stpncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
 
3084
  strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3085
3085
  master_pos.pos = strtoul(row[1], (char**) 0, 10);
3086
 
  drizzle_free_result(res);
 
3086
  drizzleclient_free_result(res);
3087
3087
  return(0);
3088
3088
}
3089
3089
 
3191
3191
    sleep_val= opt_sleep;
3192
3192
 
3193
3193
  if (sleep_val)
3194
 
    my_sleep((uint32_t) (sleep_val * 1000000L));
 
3194
    usleep((uint32_t) (sleep_val * 1000000L));
3195
3195
  command->last_argument= sleep_end;
3196
3196
  return 0;
3197
3197
}
3198
3198
 
3199
3199
 
3200
3200
static void do_get_file_name(struct st_command *command,
3201
 
                             char* dest, uint dest_max_len)
 
3201
                             char* dest, uint32_t dest_max_len)
3202
3202
{
3203
3203
  char *p= command->first_argument, *name;
3204
3204
  if (!*p)
3209
3209
  if (*p)
3210
3210
    *p++= 0;
3211
3211
  command->last_argument= p;
3212
 
  strmake(dest, name, dest_max_len - 1);
 
3212
  strncpy(dest, name, dest_max_len - 1);
3213
3213
}
3214
3214
 
3215
3215
 
3227
3227
  if(*p)
3228
3228
    *p++= 0;
3229
3229
  command->last_argument= p;
3230
 
  charset_info= get_charset_by_csname(charset_name,MY_CS_PRIMARY,MYF(MY_WME));
 
3230
  charset_info= get_charset_by_csname(charset_name, MY_CS_PRIMARY);
3231
3231
  if (!charset_info)
3232
3232
    abort_not_supported_test("Test requires charset '%s'", charset_name);
3233
3233
}
3234
3234
 
3235
 
static uint get_errcode_from_name(char *error_name, char *error_end)
 
3235
static uint32_t get_errcode_from_name(char *error_name, char *error_end)
3236
3236
{
3237
3237
  /* SQL error as string */
3238
3238
  st_error *e= global_error_names;
3246
3246
      (as in ER_WRONG_VALUE vs. ER_WRONG_VALUE_COUNT).
3247
3247
    */
3248
3248
    if (!strncmp(error_name, e->name, (int) (error_end - error_name)) &&
3249
 
        (uint) strlen(e->name) == (uint) (error_end - error_name))
 
3249
        (uint32_t) strlen(e->name) == (uint32_t) (error_end - error_name))
3250
3250
    {
3251
3251
      return(e->code);
3252
3252
    }
3260
3260
{
3261
3261
  struct st_match_err *to= saved_expected_errors.err;
3262
3262
  char *p= command->first_argument;
3263
 
  uint count= 0;
 
3263
  uint32_t count= 0;
3264
3264
 
3265
3265
 
3266
3266
 
3339
3339
      if (!str2int(start, 10, (long) INT_MIN, (long) INT_MAX, &val))
3340
3340
        die("Invalid argument to error: '%s'", command->first_argument);
3341
3341
 
3342
 
      to->code.errnum= (uint) val;
 
3342
      to->code.errnum= (uint32_t) val;
3343
3343
      to->type= ERR_ERRNO;
3344
3344
    }
3345
3345
    to++;
3450
3450
{
3451
3451
  bool reconnect= val;
3452
3452
 
3453
 
  drizzle_options(drizzle, DRIZZLE_OPT_RECONNECT, (char *)&reconnect);
 
3453
  drizzleclient_options(drizzle, DRIZZLE_OPT_RECONNECT, (char *)&reconnect);
3454
3454
 
3455
3455
  return;
3456
3456
}
3461
3461
  if (!(cur_con= find_connection_by_name(name)))
3462
3462
    die("connection '%s' not found in connection pool", name);
3463
3463
 
3464
 
  /* Update $drizzle_get_server_version to that of current connection */
3465
 
  var_set_drizzle_get_server_version(&cur_con->drizzle);
 
3464
  /* Update $drizzleclient_get_server_version to that of current connection */
 
3465
  var_set_drizzleclient_get_server_version(&cur_con->drizzle);
3466
3466
 
3467
3467
  return(0);
3468
3468
}
3508
3508
  {
3509
3509
    if (con->drizzle.net.vio)
3510
3510
    {
3511
 
      net_close(&(con->drizzle.net));
 
3511
      drizzleclient_net_close(&(con->drizzle.net));
3512
3512
    }
3513
3513
  }
3514
3514
 
3515
 
  drizzle_close(&con->drizzle);
 
3515
  drizzleclient_close(&con->drizzle);
3516
3516
 
3517
3517
  if (con->util_drizzle)
3518
 
    drizzle_close(con->util_drizzle);
 
3518
    drizzleclient_close(con->util_drizzle);
3519
3519
  con->util_drizzle= 0;
3520
3520
 
3521
3521
  free(con->name);
3524
3524
    When the connection is closed set name to "-closed_connection-"
3525
3525
    to make it possible to reuse the connection name.
3526
3526
  */
3527
 
  if (!(con->name = my_strdup("-closed_connection-", MYF(MY_WME))))
 
3527
  if (!(con->name = strdup("-closed_connection-")))
3528
3528
    die("Out of memory");
3529
3529
 
3530
3530
  return;
3564
3564
  static uint32_t connection_retry_sleep= 100000; /* Microseconds */
3565
3565
 
3566
3566
 
3567
 
  while(!drizzle_connect(drizzle, host, user, pass, db, port, NULL,
 
3567
  while(!drizzleclient_connect(drizzle, host, user, pass, db, port, NULL,
3568
3568
                         CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS))
3569
3569
  {
3570
3570
    /*
3575
3575
      on protocol/connection type
3576
3576
    */
3577
3577
 
3578
 
    if ((drizzle_errno(drizzle) == CR_CONN_HOST_ERROR ||
3579
 
         drizzle_errno(drizzle) == CR_CONNECTION_ERROR) &&
 
3578
    if ((drizzleclient_errno(drizzle) == CR_CONN_HOST_ERROR ||
 
3579
         drizzleclient_errno(drizzle) == CR_CONNECTION_ERROR) &&
3580
3580
        failed_attempts < opt_max_connect_retries)
3581
3581
    {
3582
3582
      verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3583
 
                  opt_max_connect_retries, drizzle_errno(drizzle),
3584
 
                  drizzle_error(drizzle));
3585
 
      my_sleep(connection_retry_sleep);
 
3583
                  opt_max_connect_retries, drizzleclient_errno(drizzle),
 
3584
                  drizzleclient_error(drizzle));
 
3585
      usleep(connection_retry_sleep);
3586
3586
    }
3587
3587
    else
3588
3588
    {
3589
3589
      if (failed_attempts > 0)
3590
3590
        die("Could not open connection '%s' after %d attempts: %d %s", name,
3591
 
            failed_attempts, drizzle_errno(drizzle), drizzle_error(drizzle));
 
3591
            failed_attempts, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3592
3592
      else
3593
3593
        die("Could not open connection '%s': %d %s", name,
3594
 
            drizzle_errno(drizzle), drizzle_error(drizzle));
 
3594
            drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3595
3595
    }
3596
3596
    failed_attempts++;
3597
3597
  }
3653
3653
    ds_res.append(delimiter);
3654
3654
    ds_res.append("\n");
3655
3655
  }
3656
 
  if (!drizzle_connect(con, host, user, pass, db, port, 0,
 
3656
  if (!drizzleclient_connect(con, host, user, pass, db, port, 0,
3657
3657
                       CLIENT_MULTI_STATEMENTS))
3658
3658
  {
3659
 
    var_set_errno(drizzle_errno(con));
3660
 
    handle_error(command, drizzle_errno(con), drizzle_error(con),
3661
 
                 drizzle_sqlstate(con), &ds_res);
 
3659
    var_set_errno(drizzleclient_errno(con));
 
3660
    handle_error(command, drizzleclient_errno(con), drizzleclient_error(con),
 
3661
                 drizzleclient_sqlstate(con), &ds_res);
3662
3662
    return 0; /* Not connected */
3663
3663
  }
3664
3664
 
3744
3744
    {
3745
3745
      char buff[FN_REFLEN];
3746
3746
      fn_format(buff, ds_sock.c_str(), TMPDIR, "", 0);
3747
 
      ds_sock= buff;
 
3747
      ds_sock.clear();
 
3748
      ds_sock.append(buff);
3748
3749
    }
3749
3750
  }
3750
3751
 
3785
3786
          (int) (sizeof(connections)/sizeof(struct st_connection)));
3786
3787
  }
3787
3788
 
3788
 
  if (!drizzle_create(&con_slot->drizzle))
3789
 
    die("Failed on drizzle_create()");
 
3789
  if (!drizzleclient_create(&con_slot->drizzle))
 
3790
    die("Failed on drizzleclient_create()");
3790
3791
  if (opt_compress || con_compress)
3791
 
    drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NULL);
3792
 
  drizzle_options(&con_slot->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
 
3792
    drizzleclient_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NULL);
 
3793
  
3793
3794
 
3794
3795
  /* Use default db name */
3795
3796
  if (ds_database.length() == 0)
3796
 
    ds_database= opt_db;
 
3797
    ds_database.append(opt_db);
3797
3798
 
3798
3799
  /* Special database to allow one to connect without a database name */
3799
3800
  if (ds_database.length() && !strcmp(ds_database.c_str(),"*NO-ONE*"))
3800
 
    ds_database= "";
 
3801
    ds_database.clear();
3801
3802
 
3802
3803
  if (connect_n_handle_errors(command, &con_slot->drizzle,
3803
3804
                              ds_host.c_str(),ds_user.c_str(),
3812
3813
      next_con++; /* if we used the next_con slot, advance the pointer */
3813
3814
  }
3814
3815
 
3815
 
  /* Update $drizzle_get_server_version to that of current connection */
3816
 
  var_set_drizzle_get_server_version(&cur_con->drizzle);
 
3816
  /* Update $drizzleclient_get_server_version to that of current connection */
 
3817
  var_set_drizzleclient_get_server_version(&cur_con->drizzle);
3817
3818
 
3818
3819
  return;
3819
3820
}
3945
3946
  if (!(*p))
3946
3947
    die("Can't set empty delimiter");
3947
3948
 
3948
 
  strmake(delimiter, p, sizeof(delimiter) - 1);
 
3949
  strncpy(delimiter, p, sizeof(delimiter) - 1);
3949
3950
  delimiter_length= strlen(delimiter);
3950
3951
 
3951
3952
  command->last_argument= p + delimiter_length;
3953
3954
}
3954
3955
 
3955
3956
 
3956
 
bool match_delimiter(int c, const char *delim, uint length)
 
3957
bool match_delimiter(int c, const char *delim, uint32_t length)
3957
3958
{
3958
 
  uint i;
 
3959
  uint32_t i;
3959
3960
  char tmp[MAX_DELIMITER_LENGTH];
3960
3961
 
3961
3962
  if (c != *delim)
4026
4027
  found_eof:
4027
4028
      if (cur_file->file != stdin)
4028
4029
      {
4029
 
        my_fclose(cur_file->file, MYF(0));
 
4030
        fclose(cur_file->file);
4030
4031
        cur_file->file= 0;
4031
4032
      }
4032
4033
      free((unsigned char*) cur_file->file_name);
4255
4256
        ptr[2] && ptr[2] == '-' &&
4256
4257
        ptr[3])
4257
4258
    {
4258
 
      uint type;
 
4259
      uint32_t type;
4259
4260
      char save;
4260
4261
      char *end, *start= (char*)ptr+3;
4261
4262
      /* Skip leading spaces */
4366
4367
    return(0);
4367
4368
  }
4368
4369
  if (!(*command_ptr= command=
4369
 
        (struct st_command*) my_malloc(sizeof(*command),
4370
 
                                       MYF(MY_WME|MY_ZEROFILL))))
 
4370
        (struct st_command*) malloc(sizeof(*command))))
4371
4371
    die(NULL);
 
4372
  memset(command, 0, sizeof(*command));
4372
4373
  q_lines.push_back(command);
4373
4374
  command->type= Q_UNKNOWN;
4374
4375
 
4395
4396
  while (*p && my_isspace(charset_info, *p))
4396
4397
    p++;
4397
4398
 
4398
 
  if (!(command->query_buf= command->query= my_strdup(p, MYF(MY_WME))))
 
4399
  if (!(command->query_buf= command->query= strdup(p)))
4399
4400
    die("Out of memory");
4400
4401
 
4401
4402
  /* Calculate first word length(the command), terminated by space or ( */
4402
4403
  p= command->query;
4403
4404
  while (*p && !my_isspace(charset_info, *p) && *p != '(')
4404
4405
    p++;
4405
 
  command->first_word_len= (uint) (p - command->query);
 
4406
  command->first_word_len= (uint32_t) (p - command->query);
4406
4407
 
4407
4408
  /* Skip spaces between command and first argument */
4408
4409
  while (*p && my_isspace(charset_info, *p))
4440
4441
   GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4441
4442
  {"include", 'i', "Include SQL before each test case.", (char**) &opt_include,
4442
4443
   (char**) &opt_include, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
4444
  {"testdir", OPT_TESTDIR, "Path to use to search for test files",
 
4445
   (char**) &opt_testdir,
 
4446
   (char**) &opt_testdir, 0,GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4443
4447
  {"logdir", OPT_LOG_DIR, "Directory for log files", (char**) &opt_logdir,
4444
4448
   (char**) &opt_logdir, 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4445
4449
  {"mark-progress", OPT_MARK_PROGRESS,
4450
4454
   "Max number of connection attempts when connecting to server",
4451
4455
   (char**) &opt_max_connect_retries, (char**) &opt_max_connect_retries, 0,
4452
4456
   GET_INT, REQUIRED_ARG, 500, 1, 10000, 0, 0, 0},
4453
 
  {"password", 'p', "Password to use when connecting to server.",
 
4457
  {"password", 'P', "Password to use when connecting to server.",
4454
4458
   0, 0, 0, GET_STR, OPT_ARG, 0, 0, 0, 0, 0, 0},
4455
 
  {"port", 'P', "Port number to use for connection or 0 for default to, in "
4456
 
   "order of preference, my.cnf, $DRIZZLE_TCP_PORT, "
 
4459
  {"port", 'p', "Port number to use for connection or 0 for default to, in "
 
4460
   "order of preference, drizzle.cnf, $DRIZZLE_TCP_PORT, "
4457
4461
   "built-in default (" STRINGIFY_ARG(DRIZZLE_PORT) ").",
4458
 
   (char**) &opt_port,
4459
 
   (char**) &opt_port, 0, GET_INT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
 
4462
   0, 0, 0, GET_UINT, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
4460
4463
  {"quiet", 's', "Suppress all normal output.", (char**) &silent,
4461
4464
   (char**) &silent, 0, GET_BOOL, NO_ARG, 0, 0, 0, 0, 0, 0},
4462
4465
  {"record", 'r', "Record output of test_file into result file.",
4496
4499
static void print_version(void)
4497
4500
{
4498
4501
  printf("%s  Ver %s Distrib %s, for %s (%s)\n",my_progname,MTEST_VERSION,
4499
 
         drizzle_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
 
4502
         drizzleclient_get_client_info(),SYSTEM_TYPE,MACHINE_TYPE);
4500
4503
}
4501
4504
 
4502
4505
static void usage(void)
4523
4526
 
4524
4527
  if (!test_if_hard_path(name))
4525
4528
  {
4526
 
    strxmov(buff, opt_basedir, name, NULL);
 
4529
    sprintf(buff,"%s%s",opt_basedir,name);
4527
4530
    name=buff;
4528
4531
  }
4529
4532
  fn_format(buff, name, "", "", MY_UNPACK_FILENAME);
4533
4536
    embedded_server_arg_count=1;
4534
4537
    embedded_server_args[0]= (char*) "";    /* Progname */
4535
4538
  }
4536
 
  if (!(file=my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(MY_WME))))
 
4539
  if (!(file= fopen(buff, "r")))
4537
4540
    die("Failed to open file '%s'", buff);
4538
4541
 
4539
4542
  while (embedded_server_arg_count < MAX_EMBEDDED_SERVER_ARGS &&
4541
4544
  {
4542
4545
    *(strchr(str, '\0')-1)=0;        /* Remove end newline */
4543
4546
    if (!(embedded_server_args[embedded_server_arg_count]=
4544
 
          (char*) my_strdup(str,MYF(MY_WME))))
 
4547
          (char*) strdup(str)))
4545
4548
    {
4546
 
      my_fclose(file,MYF(0));
 
4549
      fclose(file);
4547
4550
      die("Out of memory");
4548
4551
 
4549
4552
    }
4550
4553
    embedded_server_arg_count++;
4551
4554
  }
4552
 
  my_fclose(file,MYF(0));
 
4555
  fclose(file);
4553
4556
  if (str)
4554
4557
    die("Too many arguments in option file: %s",name);
4555
4558
 
4557
4560
}
4558
4561
 
4559
4562
 
4560
 
static bool
4561
 
get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
4562
 
               char *argument)
 
4563
extern "C" bool
 
4564
get_one_option(int optid, const struct my_option *, char *argument)
4563
4565
{
 
4566
  char *endchar= NULL;
 
4567
  uint64_t temp_drizzle_port= 0;
 
4568
 
4564
4569
  switch(optid) {
4565
4570
  case 'r':
4566
4571
    record = 1;
4570
4575
    char buff[FN_REFLEN];
4571
4576
    if (!test_if_hard_path(argument))
4572
4577
    {
4573
 
      strxmov(buff, opt_basedir, argument, NULL);
 
4578
      sprintf(buff,"%s%s",opt_basedir,argument);
4574
4579
      argument= buff;
4575
4580
    }
4576
4581
    fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4577
4582
    assert(cur_file == file_stack && cur_file->file == 0);
4578
 
    if (!(cur_file->file=
4579
 
          my_fopen(buff, O_RDONLY | FILE_BINARY, MYF(0))))
 
4583
    if (!(cur_file->file= fopen(buff, "r")))
4580
4584
      die("Could not open '%s' for reading: errno = %d", buff, errno);
4581
 
    cur_file->file_name= my_strdup(buff, MYF(MY_FAE));
 
4585
    if (!(cur_file->file_name= strdup(buff)))
 
4586
      die("Out of memory");
4582
4587
    cur_file->lineno= 1;
4583
4588
    break;
4584
4589
  }
4587
4592
    static char buff[FN_REFLEN];
4588
4593
    if (!test_if_hard_path(argument))
4589
4594
    {
4590
 
      strxmov(buff, opt_basedir, argument, NULL);
 
4595
      sprintf(buff,"%s%s",opt_basedir,argument);
4591
4596
      argument= buff;
4592
4597
    }
4593
4598
    fn_format(buff, argument, "", "", MY_UNPACK_FILENAME);
4596
4601
    break;
4597
4602
  }
4598
4603
  case 'p':
 
4604
    temp_drizzle_port= (uint64_t) strtoul(argument, &endchar, 10);
 
4605
    /* if there is an alpha character this is not a valid port */
 
4606
    if (strlen(endchar) != 0)
 
4607
    {
 
4608
      fprintf(stderr, _("Non-integer value supplied for port.  If you are trying to enter a password please use --password instead.\n"));
 
4609
      exit(1);
 
4610
    }
 
4611
    /* If the port number is > 65535 it is not a valid port
 
4612
       This also helps with potential data loss casting unsigned long to a
 
4613
       uint32_t. */
 
4614
    if ((temp_drizzle_port == 0) || (temp_drizzle_port > 65535))
 
4615
    {
 
4616
      fprintf(stderr, _("Value supplied for port is not valid.\n"));
 
4617
      exit(1);
 
4618
    }
 
4619
    else
 
4620
    {
 
4621
      opt_port= (uint32_t) temp_drizzle_port;
 
4622
    }
 
4623
    break;
 
4624
  case 'P':
4599
4625
    if (argument)
4600
4626
    {
4601
 
      free(opt_pass);
4602
 
      opt_pass= my_strdup(argument, MYF(MY_FAE));
4603
 
      while (*argument) *argument++= 'x';    /* Destroy argument */
 
4627
      if (opt_pass)
 
4628
        free(opt_pass);
 
4629
      opt_pass = strdup(argument);
 
4630
      if (opt_pass == NULL)
 
4631
        die("Out of memory");
 
4632
      while (*argument)
 
4633
      {
 
4634
        /* Overwriting password with 'x' */
 
4635
        *argument++= 'x';
 
4636
      }
4604
4637
      tty_password= 0;
4605
4638
    }
4606
4639
    else
4607
4640
      tty_password= 1;
4608
4641
    break;
4609
4642
  case 't':
4610
 
    my_stpncpy(TMPDIR, argument, sizeof(TMPDIR));
 
4643
    strncpy(TMPDIR, argument, sizeof(TMPDIR));
4611
4644
    break;
4612
4645
  case 'A':
4613
4646
    if (!embedded_server_arg_count)
4617
4650
    }
4618
4651
    if (embedded_server_arg_count == MAX_EMBEDDED_SERVER_ARGS-1 ||
4619
4652
        !(embedded_server_args[embedded_server_arg_count++]=
4620
 
          my_strdup(argument, MYF(MY_FAE))))
 
4653
          strdup(argument)))
4621
4654
    {
4622
4655
      die("Can't use server argument");
4623
4656
    }
4638
4671
 
4639
4672
static int parse_args(int argc, char **argv)
4640
4673
{
4641
 
  load_defaults("my",load_default_groups,&argc,&argv);
 
4674
  load_defaults("drizzle",load_default_groups,&argc,&argv);
4642
4675
  default_argv= argv;
4643
4676
 
4644
4677
  if ((handle_options(&argc, &argv, my_long_options, get_one_option)))
4652
4685
  if (argc == 1)
4653
4686
    opt_db= *argv;
4654
4687
  if (tty_password)
4655
 
    opt_pass= get_tty_password(NULL);          /* purify tested */
 
4688
    opt_pass= drizzleclient_get_tty_password(NULL);          /* purify tested */
4656
4689
  if (debug_info_flag)
4657
4690
    my_end_arg= MY_CHECK_ERROR | MY_GIVE_INFO;
4658
4691
  if (debug_check_flag)
4679
4712
  int flags= O_WRONLY | O_CREAT;
4680
4713
  if (!test_if_hard_path(fname))
4681
4714
  {
4682
 
    strxmov(buff, opt_basedir, fname, NULL);
 
4715
    sprintf(buff,"%s%s",opt_basedir,fname);
4683
4716
    fname= buff;
4684
4717
  }
4685
4718
  fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);
4689
4722
  if ((fd= my_open(buff, flags,
4690
4723
                   MYF(MY_WME | MY_FFNF))) < 0)
4691
4724
    die("Could not open '%s' for writing: errno = %d", buff, errno);
4692
 
  if (append && my_seek(fd, 0, SEEK_END, MYF(0)) == MY_FILEPOS_ERROR)
 
4725
  if (append && lseek(fd, 0, SEEK_END) == MY_FILEPOS_ERROR)
4693
4726
    die("Could not find end of file '%s': errno = %d", buff, errno);
4694
4727
  if (my_write(fd, (unsigned char*)str, size, MYF(MY_WME|MY_FNABP)))
4695
4728
    die("write failed");
4748
4781
  Append the result for one field to the dynamic string ds
4749
4782
*/
4750
4783
 
4751
 
static void append_field(string *ds, uint col_idx, const DRIZZLE_FIELD* field,
 
4784
static void append_field(string *ds, uint32_t col_idx, const DRIZZLE_FIELD* field,
4752
4785
                         const char* val, uint64_t len, bool is_null)
4753
4786
{
4754
4787
  if (col_idx < max_replace_column && replace_column[col_idx])
4786
4819
static void append_result(string *ds, DRIZZLE_RES *res)
4787
4820
{
4788
4821
  DRIZZLE_ROW row;
4789
 
  uint32_t num_fields= drizzle_num_fields(res);
4790
 
  const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
 
4822
  uint32_t num_fields= drizzleclient_num_fields(res);
 
4823
  const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
4791
4824
  uint32_t *lengths;
4792
4825
 
4793
 
  while ((row = drizzle_fetch_row(res)))
 
4826
  while ((row = drizzleclient_fetch_row(res)))
4794
4827
  {
4795
4828
    uint32_t i;
4796
 
    lengths = drizzle_fetch_lengths(res);
 
4829
    lengths = drizzleclient_fetch_lengths(res);
4797
4830
    for (i = 0; i < num_fields; i++)
4798
4831
      append_field(ds, i, &fields[i],
4799
4832
                   (const char*)row[i], lengths[i], !row[i]);
4810
4843
 
4811
4844
static void append_metadata(string *ds,
4812
4845
                            const DRIZZLE_FIELD *field,
4813
 
                            uint num_fields)
 
4846
                            uint32_t num_fields)
4814
4847
{
4815
4848
  const DRIZZLE_FIELD *field_end;
4816
4849
  ds->append("Catalog\tDatabase\tTable\tTable_alias\tColumn\t"
4881
4914
 
4882
4915
static void append_table_headings(string *ds,
4883
4916
                                  const DRIZZLE_FIELD *field,
4884
 
                                  uint num_fields)
 
4917
                                  uint32_t num_fields)
4885
4918
{
4886
 
  uint col_idx;
 
4919
  uint32_t col_idx;
4887
4920
  for (col_idx= 0; col_idx < num_fields; col_idx++)
4888
4921
  {
4889
4922
    if (col_idx)
4902
4935
 
4903
4936
static int append_warnings(string *ds, DRIZZLE *drizzle)
4904
4937
{
4905
 
  uint count;
 
4938
  uint32_t count;
4906
4939
  DRIZZLE_RES *warn_res;
4907
4940
 
4908
4941
 
4909
 
  if (!(count= drizzle_warning_count(drizzle)))
 
4942
  if (!(count= drizzleclient_warning_count(drizzle)))
4910
4943
    return(0);
4911
4944
 
4912
4945
  /*
4914
4947
    through PS API we should not issue SHOW WARNINGS until
4915
4948
    we have not read all results...
4916
4949
  */
4917
 
  assert(!drizzle_more_results(drizzle));
4918
 
 
4919
 
  if (drizzle_real_query(drizzle, "SHOW WARNINGS", 13))
4920
 
    die("Error running query \"SHOW WARNINGS\": %s", drizzle_error(drizzle));
4921
 
 
4922
 
  if (!(warn_res= drizzle_store_result(drizzle)))
 
4950
  assert(!drizzleclient_more_results(drizzle));
 
4951
 
 
4952
  if (drizzleclient_real_query(drizzle, "SHOW WARNINGS", 13))
 
4953
    die("Error running query \"SHOW WARNINGS\": %s", drizzleclient_error(drizzle));
 
4954
 
 
4955
  if (!(warn_res= drizzleclient_store_result(drizzle)))
4923
4956
    die("Warning count is %u but didn't get any warnings",
4924
4957
        count);
4925
4958
 
4958
4991
     */
4959
4992
    if (do_send_query(cn, query, query_len, flags))
4960
4993
    {
4961
 
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4962
 
                   drizzle_sqlstate(drizzle), ds);
 
4994
      handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
 
4995
                   drizzleclient_sqlstate(drizzle), ds);
4963
4996
      goto end;
4964
4997
    }
4965
4998
  }
4969
5002
  do
4970
5003
  {
4971
5004
    /*
4972
 
      When  on first result set, call drizzle_read_query_result to retrieve
 
5005
      When  on first result set, call drizzleclient_read_query_result to retrieve
4973
5006
      answer to the query sent earlier
4974
5007
    */
4975
 
    if ((counter==0) && drizzle_read_query_result(drizzle))
 
5008
    if ((counter==0) && drizzleclient_read_query_result(drizzle))
4976
5009
    {
4977
 
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4978
 
                   drizzle_sqlstate(drizzle), ds);
 
5010
      handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
 
5011
                   drizzleclient_sqlstate(drizzle), ds);
4979
5012
      goto end;
4980
5013
 
4981
5014
    }
4983
5016
    /*
4984
5017
      Store the result of the query if it will return any fields
4985
5018
    */
4986
 
    if (drizzle_field_count(drizzle) && ((res= drizzle_store_result(drizzle)) == 0))
 
5019
    if (drizzleclient_field_count(drizzle) && ((res= drizzleclient_store_result(drizzle)) == 0))
4987
5020
    {
4988
 
      handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
4989
 
                   drizzle_sqlstate(drizzle), ds);
 
5021
      handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
 
5022
                   drizzleclient_sqlstate(drizzle), ds);
4990
5023
      goto end;
4991
5024
    }
4992
5025
 
4996
5029
 
4997
5030
      if (res)
4998
5031
      {
4999
 
        const DRIZZLE_FIELD *fields= drizzle_fetch_fields(res);
5000
 
        uint num_fields= drizzle_num_fields(res);
 
5032
        const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
 
5033
        uint32_t num_fields= drizzleclient_num_fields(res);
5001
5034
 
5002
5035
        if (display_metadata)
5003
5036
          append_metadata(ds, fields, num_fields);
5009
5042
      }
5010
5043
 
5011
5044
      /*
5012
 
        Need to call drizzle_affected_rows() before the "new"
 
5045
        Need to call drizzleclient_affected_rows() before the "new"
5013
5046
        query to find the warnings
5014
5047
      */
5015
5048
      if (!disable_info)
5016
 
        affected_rows= drizzle_affected_rows(drizzle);
 
5049
        affected_rows= drizzleclient_affected_rows(drizzle);
5017
5050
 
5018
5051
      /*
5019
5052
        Add all warnings to the result. We can't do this if we are in
5020
5053
        the middle of processing results from multi-statement, because
5021
5054
        this will break protocol.
5022
5055
      */
5023
 
      if (!disable_warnings && !drizzle_more_results(drizzle))
 
5056
      if (!disable_warnings && !drizzleclient_more_results(drizzle))
5024
5057
      {
5025
5058
        if (append_warnings(ds_warnings, drizzle) || ds_warnings->length())
5026
5059
        {
5030
5063
      }
5031
5064
 
5032
5065
      if (!disable_info)
5033
 
        append_info(ds, affected_rows, drizzle_info(drizzle));
 
5066
        append_info(ds, affected_rows, drizzleclient_info(drizzle));
5034
5067
    }
5035
5068
 
5036
5069
    if (res)
5037
5070
    {
5038
 
      drizzle_free_result(res);
 
5071
      drizzleclient_free_result(res);
5039
5072
      res= 0;
5040
5073
    }
5041
5074
    counter++;
5042
 
  } while (!(err= drizzle_next_result(drizzle)));
 
5075
  } while (!(err= drizzleclient_next_result(drizzle)));
5043
5076
  if (err > 0)
5044
5077
  {
5045
 
    /* We got an error from drizzle_next_result, maybe expected */
5046
 
    handle_error(command, drizzle_errno(drizzle), drizzle_error(drizzle),
5047
 
                 drizzle_sqlstate(drizzle), ds);
 
5078
    /* We got an error from drizzleclient_next_result, maybe expected */
 
5079
    handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
 
5080
                 drizzleclient_sqlstate(drizzle), ds);
5048
5081
    goto end;
5049
5082
  }
5050
5083
  assert(err == -1); /* Successful and there are no more results */
5055
5088
end:
5056
5089
 
5057
5090
  /*
5058
 
    We save the return code (drizzle_errno(drizzle)) from the last call sent
5059
 
    to the server into the drizzletest builtin variable $drizzle_errno. This
 
5091
    We save the return code (drizzleclient_errno(drizzle)) from the last call sent
 
5092
    to the server into the drizzletest builtin variable $drizzleclient_errno. This
5060
5093
    variable then can be used from the test case itself.
5061
5094
  */
5062
 
  var_set_errno(drizzle_errno(drizzle));
 
5095
  var_set_errno(drizzleclient_errno(drizzle));
5063
5096
  return;
5064
5097
}
5065
5098
 
5084
5117
                  unsigned int err_errno, const char *err_error,
5085
5118
                  const char *err_sqlstate, string *ds)
5086
5119
{
5087
 
  uint i;
 
5120
  uint32_t i;
5088
5121
 
5089
5122
 
5090
5123
  if (command->require_file[0])
5107
5140
  if (command->abort_on_error)
5108
5141
    die("query '%s' failed: %d: %s", command->query, err_errno, err_error);
5109
5142
 
5110
 
  for (i= 0 ; (uint) i < command->expected_errors.count ; i++)
 
5143
  for (i= 0 ; (uint32_t) i < command->expected_errors.count ; i++)
5111
5144
  {
5112
5145
    if (((command->expected_errors.err[i].type == ERR_ERRNO) &&
5113
5146
         (command->expected_errors.err[i].code.errnum == err_errno)) ||
5308
5341
static void get_command_type(struct st_command* command)
5309
5342
{
5310
5343
  char save;
5311
 
  uint type;
 
5344
  uint32_t type;
5312
5345
 
5313
5346
 
5314
5347
  if (*command->query == '}')
5391
5424
 
5392
5425
*/
5393
5426
 
5394
 
static void mark_progress(struct st_command* command __attribute__((unused)),
5395
 
                          int line)
 
5427
static void mark_progress(struct st_command*, int line)
5396
5428
{
5397
5429
  char buf[32], *end;
5398
5430
  uint64_t timer= timer_now();
5428
5460
{
5429
5461
  struct st_command *command;
5430
5462
  bool q_send_flag= 0, abort_flag= 0;
5431
 
  uint command_executed= 0, last_command_executed= 0;
 
5463
  uint32_t command_executed= 0, last_command_executed= 0;
5432
5464
  char save_file[FN_REFLEN];
5433
5465
  struct stat res_info;
5434
5466
  MY_INIT(argv[0]);
5463
5495
                1024, 0, 0, get_var_key, var_free, MYF(0)))
5464
5496
    die("Variable hash initialization failed");
5465
5497
 
5466
 
  var_set_string("$DRIZZLE_SERVER_VERSION", drizzle_get_client_info());
 
5498
  var_set_string("$DRIZZLE_SERVER_VERSION", drizzleclient_get_client_info());
5467
5499
 
5468
5500
  memset(&master_pos, 0, sizeof(master_pos));
5469
5501
 
5482
5514
  if (cur_file == file_stack && cur_file->file == 0)
5483
5515
  {
5484
5516
    cur_file->file= stdin;
5485
 
    cur_file->file_name= my_strdup("<stdin>", MYF(MY_WME));
 
5517
    cur_file->file_name= strdup("<stdin>");
 
5518
    if (cur_file->file_name == NULL)
 
5519
      die("Out of memory");
5486
5520
    cur_file->lineno= 1;
5487
5521
  }
5488
5522
  cur_con= connections;
5489
 
  if (!( drizzle_create(&cur_con->drizzle)))
5490
 
    die("Failed in drizzle_create()");
 
5523
  if (!( drizzleclient_create(&cur_con->drizzle)))
 
5524
    die("Failed in drizzleclient_create()");
5491
5525
  if (opt_compress)
5492
 
    drizzle_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5493
 
  drizzle_options(&cur_con->drizzle, DRIZZLE_OPT_LOCAL_INFILE, 0);
 
5526
    drizzleclient_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5494
5527
 
5495
 
  if (!(cur_con->name = my_strdup("default", MYF(MY_WME))))
 
5528
  if (!(cur_con->name = strdup("default")))
5496
5529
    die("Out of memory");
5497
5530
 
5498
5531
  safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5502
5535
  timer_start= timer_now();
5503
5536
 
5504
5537
  /*
5505
 
    Initialize $drizzle_errno with -1, so we can
 
5538
    Initialize $drizzleclient_errno with -1, so we can
5506
5539
    - distinguish it from valid values ( >= 0 ) and
5507
5540
    - detect if there was never a command sent to the server
5508
5541
  */
5509
5542
  var_set_errno(-1);
5510
5543
 
5511
 
  /* Update $drizzle_get_server_version to that of current connection */
5512
 
  var_set_drizzle_get_server_version(&cur_con->drizzle);
 
5544
  /* Update $drizzleclient_get_server_version to that of current connection */
 
5545
  var_set_drizzleclient_get_server_version(&cur_con->drizzle);
5513
5546
 
5514
5547
  if (opt_include)
5515
5548
  {
5629
5662
 
5630
5663
        if (save_file[0])
5631
5664
        {
5632
 
          strmake(command->require_file, save_file, sizeof(save_file) - 1);
 
5665
          strncpy(command->require_file, save_file, sizeof(save_file) - 1);
5633
5666
          save_file[0]= 0;
5634
5667
        }
5635
5668
        run_query(cur_con, command, flags);
5697
5730
        command->last_argument= command->end;
5698
5731
        break;
5699
5732
      case Q_PING:
5700
 
        (void) drizzle_ping(&cur_con->drizzle);
 
5733
        (void) drizzleclient_ping(&cur_con->drizzle);
5701
5734
        break;
5702
5735
      case Q_EXEC:
5703
5736
        do_exec(command);
5927
5960
    die("Missing argument in %s", command->query);
5928
5961
 
5929
5962
  /* Allocate a buffer for results */
5930
 
  start= buff= (char *)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
 
5963
  start= buff= (char *)malloc(strlen(from)+1);
5931
5964
  while (*from)
5932
5965
  {
5933
5966
    char *to;
5934
 
    uint column_number;
 
5967
    uint32_t column_number;
5935
5968
 
5936
5969
    to= get_string(&buff, &from, command);
5937
5970
    if (!(column_number= atoi(to)) || column_number > MAX_COLUMNS)
5940
5973
      die("Wrong number of arguments to replace_column in '%s'", command->query);
5941
5974
    to= get_string(&buff, &from, command);
5942
5975
    free(replace_column[column_number-1]);
5943
 
    replace_column[column_number-1]= my_strdup(to, MYF(MY_WME | MY_FAE));
 
5976
    replace_column[column_number-1]= strdup(to);
 
5977
    if (replace_column[column_number-1] == NULL)
 
5978
      die("Out of memory");
5944
5979
    set_if_bigger(max_replace_column, column_number);
5945
5980
  }
5946
5981
  free(start);
5950
5985
 
5951
5986
void free_replace_column()
5952
5987
{
5953
 
  uint i;
 
5988
  uint32_t i;
5954
5989
  for (i=0 ; i < max_replace_column ; i++)
5955
5990
  {
5956
5991
    if (replace_column[i])
5974
6009
  TYPELIB typelib;        /* Pointer to strings */
5975
6010
  unsigned char  *str;          /* Strings is here */
5976
6011
  uint8_t *flag;          /* Flag about each var. */
5977
 
  uint  array_allocs,max_count,length,max_length;
 
6012
  uint32_t  array_allocs,max_count,length,max_length;
5978
6013
} POINTER_ARRAY;
5979
6014
 
5980
6015
struct st_replace;
5981
 
struct st_replace *init_replace(char * *from, char * *to, uint count,
 
6016
struct st_replace *init_replace(char * *from, char * *to, uint32_t count,
5982
6017
                                char * word_end_chars);
5983
6018
int insert_pointer_name(POINTER_ARRAY *pa,char * name);
5984
6019
void replace_strings_append(struct st_replace *rep, string* ds,
5997
6032
 
5998
6033
void do_get_replace(struct st_command *command)
5999
6034
{
6000
 
  uint i;
 
6035
  uint32_t i;
6001
6036
  char *from= command->first_argument;
6002
6037
  char *buff, *start;
6003
6038
  char word_end_chars[256], *pos;
6010
6045
  memset(&from_array, 0, sizeof(from_array));
6011
6046
  if (!*from)
6012
6047
    die("Missing argument in %s", command->query);
6013
 
  start= buff= (char *)my_malloc(strlen(from)+1,MYF(MY_WME | MY_FAE));
 
6048
  start= buff= (char *)malloc(strlen(from)+1);
6014
6049
  while (*from)
6015
6050
  {
6016
6051
    char *to= buff;
6028
6063
  *pos=0;          /* End pointer */
6029
6064
  if (!(glob_replace= init_replace((char**) from_array.typelib.type_names,
6030
6065
                                   (char**) to_array.typelib.type_names,
6031
 
                                   (uint) from_array.typelib.count,
 
6066
                                   (uint32_t) from_array.typelib.count,
6032
6067
                                   word_end_chars)))
6033
6068
    die("Can't initialize replace from '%s'", command->query);
6034
6069
  free_pointer_array(&from_array);
6059
6094
typedef struct st_replace_found {
6060
6095
  bool found;
6061
6096
  char *replace_string;
6062
 
  uint to_offset;
 
6097
  uint32_t to_offset;
6063
6098
  int from_offset;
6064
6099
} REPLACE_STRING;
6065
6100
 
6185
6220
  char* buf,*expr_end;
6186
6221
  char* p;
6187
6222
  char* buf_p;
6188
 
  uint expr_len= strlen(expr);
 
6223
  uint32_t expr_len= strlen(expr);
6189
6224
  char last_c = 0;
6190
6225
  struct st_regex reg;
6191
6226
 
6192
 
  /* my_malloc() will die on fail with MY_FAE */
6193
 
  res=(struct st_replace_regex*)my_malloc(
6194
 
                                          sizeof(*res)+expr_len ,MYF(MY_FAE+MY_WME));
 
6227
  res=(st_replace_regex*)malloc(sizeof(*res)+expr_len);
 
6228
  if (!res)
 
6229
    return NULL;
6195
6230
  my_init_dynamic_array(&res->regex_arr,sizeof(struct st_regex),128,128);
6196
6231
 
6197
6232
  buf= (char*)res + sizeof(*res);
6248
6283
      die("Out of memory");
6249
6284
  }
6250
6285
  res->odd_buf_len= res->even_buf_len= 8192;
6251
 
  res->even_buf= (char*)my_malloc(res->even_buf_len,MYF(MY_WME+MY_FAE));
6252
 
  res->odd_buf= (char*)my_malloc(res->odd_buf_len,MYF(MY_WME+MY_FAE));
 
6286
  res->even_buf= (char*)malloc(res->even_buf_len);
 
6287
  res->odd_buf= (char*)malloc(res->odd_buf_len);
6253
6288
  res->buf= res->even_buf;
6254
6289
 
6255
6290
  return res;
6281
6316
 
6282
6317
static int multi_reg_replace(struct st_replace_regex* r,char* val)
6283
6318
{
6284
 
  uint i;
 
6319
  uint32_t i;
6285
6320
  char* in_buf, *out_buf;
6286
6321
  int* buf_len_p;
6287
6322
 
6357
6392
 
6358
6393
 
6359
6394
/*
6360
 
  auxiluary macro used by reg_replace
6361
 
  makes sure the result buffer has sufficient length
6362
 
*/
6363
 
#define SECURE_REG_BUF   if (buf_len < need_buf_len)                    \
6364
 
  {                                                                     \
6365
 
    int off= res_p - buf;                                               \
6366
 
    buf= (char*)my_realloc(buf,need_buf_len,MYF(MY_WME+MY_FAE));        \
6367
 
    res_p= buf + off;                                                   \
6368
 
    buf_len= need_buf_len;                                              \
6369
 
  }                                                                     \
6370
 
                                                                        \
6371
 
/*
6372
6395
  Performs a regex substitution
6373
6396
 
6374
6397
  IN:
6384
6407
                char *replace, char *in_string, int icase)
6385
6408
{
6386
6409
  string string_to_match(in_string);
6387
 
  pcrecpp::RE_Options opt;
6388
 
 
6389
 
  if (icase)
6390
 
    opt.set_caseless(true);
6391
 
 
6392
 
  if (!pcrecpp::RE(pattern, opt).Replace(replace,&string_to_match)){
 
6410
  const char *error= NULL;
 
6411
  int erroffset;
 
6412
  int ovector[3];
 
6413
  pcre *re= pcre_compile(pattern,
 
6414
                         icase ? PCRE_CASELESS : 0,
 
6415
                         &error, &erroffset, NULL);
 
6416
  if (re == NULL)
 
6417
    return 1;
 
6418
 
 
6419
  int rc= pcre_exec(re, NULL, in_string, (int)strlen(in_string),
 
6420
                    0, 0, ovector, 3);
 
6421
  if (rc < 0)
 
6422
  {
 
6423
    pcre_free(re);
6393
6424
    return 1;
6394
6425
  }
6395
6426
 
6396
 
  const char * new_str= string_to_match.c_str();
6397
 
  *buf_len_p= strlen(new_str);
 
6427
  char *substring_to_replace= in_string + ovector[0];
 
6428
  int substring_length= ovector[1] - ovector[0];
 
6429
  *buf_len_p= strlen(in_string) - substring_length + strlen(replace);
6398
6430
  char * new_buf = (char *)malloc(*buf_len_p+1);
6399
6431
  if (new_buf == NULL)
6400
6432
  {
 
6433
    pcre_free(re);
6401
6434
    return 1;
6402
6435
  }
6403
 
  strcpy(new_buf, new_str);
6404
 
  buf_p= &new_buf;
6405
 
 
 
6436
 
 
6437
  memset(new_buf, 0, *buf_len_p+1);
 
6438
  strncpy(new_buf, in_string, substring_to_replace-in_string);
 
6439
  strncpy(new_buf+(substring_to_replace-in_string), replace, strlen(replace));
 
6440
  strncpy(new_buf+(substring_to_replace-in_string)+strlen(replace),
 
6441
          substring_to_replace + substring_length,
 
6442
          strlen(in_string)
 
6443
            - substring_length
 
6444
            - (substring_to_replace-in_string));
 
6445
  *buf_p= new_buf;
 
6446
 
 
6447
  pcre_free(re);
6406
6448
  return 0;
6407
6449
}
6408
6450
 
6409
6451
 
6410
6452
#ifndef WORD_BIT
6411
 
#define WORD_BIT (8*sizeof(uint))
 
6453
#define WORD_BIT (8*sizeof(uint32_t))
6412
6454
#endif
6413
6455
 
6414
6456
#define SET_MALLOC_HUNC 64
6415
6457
#define LAST_CHAR_CODE 259
6416
6458
 
6417
6459
typedef struct st_rep_set {
6418
 
  uint  *bits;        /* Pointer to used sets */
 
6460
  uint32_t  *bits;        /* Pointer to used sets */
6419
6461
  short next[LAST_CHAR_CODE];    /* Pointer to next sets */
6420
 
  uint  found_len;      /* Best match to date */
 
6462
  uint32_t  found_len;      /* Best match to date */
6421
6463
  int  found_offset;
6422
 
  uint  table_offset;
6423
 
  uint  size_of_bits;      /* For convinience */
 
6464
  uint32_t  table_offset;
 
6465
  uint32_t  size_of_bits;      /* For convinience */
6424
6466
} REP_SET;
6425
6467
 
6426
6468
typedef struct st_rep_sets {
6427
 
  uint    count;      /* Number of sets */
6428
 
  uint    extra;      /* Extra sets in buffer */
6429
 
  uint    invisible;    /* Sets not chown */
6430
 
  uint    size_of_bits;
 
6469
  uint32_t    count;      /* Number of sets */
 
6470
  uint32_t    extra;      /* Extra sets in buffer */
 
6471
  uint32_t    invisible;    /* Sets not chown */
 
6472
  uint32_t    size_of_bits;
6431
6473
  REP_SET  *set,*set_buffer;
6432
 
  uint    *bit_buffer;
 
6474
  uint32_t    *bit_buffer;
6433
6475
} REP_SETS;
6434
6476
 
6435
6477
typedef struct st_found_set {
6436
 
  uint table_offset;
 
6478
  uint32_t table_offset;
6437
6479
  int found_offset;
6438
6480
} FOUND_SET;
6439
6481
 
6440
6482
typedef struct st_follow {
6441
6483
  int chr;
6442
 
  uint table_offset;
6443
 
  uint len;
 
6484
  uint32_t table_offset;
 
6485
  uint32_t len;
6444
6486
} FOLLOWS;
6445
6487
 
6446
6488
 
6447
 
int init_sets(REP_SETS *sets,uint states);
 
6489
int init_sets(REP_SETS *sets,uint32_t states);
6448
6490
REP_SET *make_new_set(REP_SETS *sets);
6449
6491
void make_sets_invisible(REP_SETS *sets);
6450
6492
void free_last_set(REP_SETS *sets);
6451
6493
void free_sets(REP_SETS *sets);
6452
 
void internal_set_bit(REP_SET *set, uint bit);
6453
 
void internal_clear_bit(REP_SET *set, uint bit);
 
6494
void internal_set_bit(REP_SET *set, uint32_t bit);
 
6495
void internal_clear_bit(REP_SET *set, uint32_t bit);
6454
6496
void or_bits(REP_SET *to,REP_SET *from);
6455
6497
void copy_bits(REP_SET *to,REP_SET *from);
6456
6498
int cmp_bits(REP_SET *set1,REP_SET *set2);
6457
 
int get_next_bit(REP_SET *set,uint lastpos);
 
6499
int get_next_bit(REP_SET *set,uint32_t lastpos);
6458
6500
int find_set(REP_SETS *sets,REP_SET *find);
6459
 
int find_found(FOUND_SET *found_set,uint table_offset,
 
6501
int find_found(FOUND_SET *found_set,uint32_t table_offset,
6460
6502
               int found_offset);
6461
 
uint start_at_word(char * pos);
6462
 
uint end_of_word(char * pos);
6463
 
 
6464
 
static uint found_sets=0;
6465
 
 
6466
 
 
6467
 
static uint replace_len(char * str)
 
6503
uint32_t start_at_word(char * pos);
 
6504
uint32_t end_of_word(char * pos);
 
6505
 
 
6506
static uint32_t found_sets=0;
 
6507
 
 
6508
 
 
6509
static uint32_t replace_len(char * str)
6468
6510
{
6469
 
  uint len=0;
 
6511
  uint32_t len=0;
6470
6512
  while (*str)
6471
6513
  {
6472
6514
    if (str[0] == '\\' && str[1])
6479
6521
 
6480
6522
/* Init a replace structure for further calls */
6481
6523
 
6482
 
REPLACE *init_replace(char * *from, char * *to,uint count,
 
6524
REPLACE *init_replace(char * *from, char * *to,uint32_t count,
6483
6525
                      char * word_end_chars)
6484
6526
{
6485
6527
  static const int SPACE_CHAR= 256;
6486
6528
  static const int START_OF_LINE= 257;
6487
6529
  static const int END_OF_LINE= 258;
6488
6530
 
6489
 
  uint i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
 
6531
  uint32_t i,j,states,set_nr,len,result_len,max_length,found_end,bits_set,bit_nr;
6490
6532
  int used_sets,chr,default_state;
6491
6533
  char used_chars[LAST_CHAR_CODE],is_word_end[256];
6492
6534
  char * pos, *to_pos, **to_array;
6508
6550
      return(0);
6509
6551
    }
6510
6552
    states+=len+1;
6511
 
    result_len+=(uint) strlen(to[i])+1;
 
6553
    result_len+=(uint32_t) strlen(to[i])+1;
6512
6554
    if (len > max_length)
6513
6555
      max_length=len;
6514
6556
  }
6519
6561
  if (init_sets(&sets,states))
6520
6562
    return(0);
6521
6563
  found_sets=0;
6522
 
  if (!(found_set= (FOUND_SET*) my_malloc(sizeof(FOUND_SET)*max_length*count,
6523
 
                                          MYF(MY_WME))))
 
6564
  if (!(found_set= (FOUND_SET*) malloc(sizeof(FOUND_SET)*max_length*count)))
 
6565
                                
6524
6566
  {
6525
6567
    free_sets(&sets);
6526
6568
    return(0);
6530
6572
  used_sets=-1;
6531
6573
  word_states=make_new_set(&sets);    /* Start of new word */
6532
6574
  start_states=make_new_set(&sets);    /* This is first state */
6533
 
  if (!(follow=(FOLLOWS*) my_malloc((states+2)*sizeof(FOLLOWS),MYF(MY_WME))))
 
6575
  if (!(follow=(FOLLOWS*) malloc((states+2)*sizeof(FOLLOWS))))
6534
6576
  {
6535
6577
    free_sets(&sets);
6536
6578
    free(found_set);
6606
6648
    follow_ptr->table_offset=i;
6607
6649
    follow_ptr->len=len;
6608
6650
    follow_ptr++;
6609
 
    states+=(uint) len+1;
 
6651
    states+=(uint32_t) len+1;
6610
6652
  }
6611
6653
 
6612
6654
 
6722
6764
 
6723
6765
  /* Alloc replace structure for the replace-state-machine */
6724
6766
 
6725
 
  if ((replace=(REPLACE*) my_malloc(sizeof(REPLACE)*(sets.count)+
6726
 
                                    sizeof(REPLACE_STRING)*(found_sets+1)+
6727
 
                                    sizeof(char *)*count+result_len,
6728
 
                                    MYF(MY_WME | MY_ZEROFILL))))
 
6767
  if ((replace=(REPLACE*) malloc(sizeof(REPLACE)*(sets.count)+
 
6768
                                 sizeof(REPLACE_STRING)*(found_sets+1)+
 
6769
                                 sizeof(char *)*count+result_len)))
6729
6770
  {
 
6771
    memset(replace, 0, sizeof(REPLACE)*(sets.count)+
 
6772
                       sizeof(REPLACE_STRING)*(found_sets+1)+
 
6773
                       sizeof(char *)*count+result_len);
6730
6774
    rep_str=(REPLACE_STRING*) (replace+sets.count);
6731
6775
    to_array= (char **) (rep_str+found_sets+1);
6732
6776
    to_pos=(char *) (to_array+count);
6733
6777
    for (i=0 ; i < count ; i++)
6734
6778
    {
6735
6779
      to_array[i]=to_pos;
6736
 
      to_pos=my_stpcpy(to_pos,to[i])+1;
 
6780
      to_pos=strcpy(to_pos,to[i])+strlen(to[i])+1;
6737
6781
    }
6738
6782
    rep_str[0].found=1;
6739
6783
    rep_str[0].replace_string=0;
6762
6806
}
6763
6807
 
6764
6808
 
6765
 
int init_sets(REP_SETS *sets,uint states)
 
6809
int init_sets(REP_SETS *sets,uint32_t states)
6766
6810
{
6767
6811
  memset(sets, 0, sizeof(*sets));
6768
6812
  sets->size_of_bits=((states+7)/8);
6769
 
  if (!(sets->set_buffer=(REP_SET*) my_malloc(sizeof(REP_SET)*SET_MALLOC_HUNC,
6770
 
                                              MYF(MY_WME))))
 
6813
  if (!(sets->set_buffer=(REP_SET*) malloc(sizeof(REP_SET)*SET_MALLOC_HUNC)))
6771
6814
    return 1;
6772
 
  if (!(sets->bit_buffer=(uint*) my_malloc(sizeof(uint)*sets->size_of_bits*
6773
 
                                           SET_MALLOC_HUNC,MYF(MY_WME))))
 
6815
  if (!(sets->bit_buffer=(uint*) malloc(sizeof(uint32_t)*sets->size_of_bits*
 
6816
                                        SET_MALLOC_HUNC)))
6774
6817
  {
6775
6818
    free(sets->set);
6776
6819
    return 1;
6789
6832
 
6790
6833
REP_SET *make_new_set(REP_SETS *sets)
6791
6834
{
6792
 
  uint i,count,*bit_buffer;
 
6835
  uint32_t i,count,*bit_buffer;
6793
6836
  REP_SET *set;
6794
6837
  if (sets->extra)
6795
6838
  {
6796
6839
    sets->extra--;
6797
6840
    set=sets->set+ sets->count++;
6798
 
    memset(set->bits, 0, sizeof(uint)*sets->size_of_bits);
 
6841
    memset(set->bits, 0, sizeof(uint32_t)*sets->size_of_bits);
6799
6842
    memset(&set->next[0], 0, sizeof(set->next[0])*LAST_CHAR_CODE);
6800
6843
    set->found_offset=0;
6801
6844
    set->found_len=0;
6804
6847
    return set;
6805
6848
  }
6806
6849
  count=sets->count+sets->invisible+SET_MALLOC_HUNC;
6807
 
  if (!(set=(REP_SET*) my_realloc((unsigned char*) sets->set_buffer,
6808
 
                                  sizeof(REP_SET)*count,
6809
 
                                  MYF(MY_WME))))
 
6850
  if (!(set=(REP_SET*) realloc((unsigned char*) sets->set_buffer,
 
6851
                                  sizeof(REP_SET)*count)))
6810
6852
    return 0;
6811
6853
  sets->set_buffer=set;
6812
6854
  sets->set=set+sets->invisible;
6813
 
  if (!(bit_buffer=(uint*) my_realloc((unsigned char*) sets->bit_buffer,
6814
 
                                      (sizeof(uint)*sets->size_of_bits)*count,
6815
 
                                      MYF(MY_WME))))
 
6855
  if (!(bit_buffer=(uint*) realloc((unsigned char*) sets->bit_buffer,
 
6856
                                   (sizeof(uint32_t)*sets->size_of_bits)*count)))
6816
6857
    return 0;
6817
6858
  sets->bit_buffer=bit_buffer;
6818
6859
  for (i=0 ; i < count ; i++)
6838
6879
  return;
6839
6880
}
6840
6881
 
6841
 
void internal_set_bit(REP_SET *set, uint bit)
 
6882
void internal_set_bit(REP_SET *set, uint32_t bit)
6842
6883
{
6843
6884
  set->bits[bit / WORD_BIT] |= 1 << (bit % WORD_BIT);
6844
6885
  return;
6845
6886
}
6846
6887
 
6847
 
void internal_clear_bit(REP_SET *set, uint bit)
 
6888
void internal_clear_bit(REP_SET *set, uint32_t bit)
6848
6889
{
6849
6890
  set->bits[bit / WORD_BIT] &= ~ (1 << (bit % WORD_BIT));
6850
6891
  return;
6853
6894
 
6854
6895
void or_bits(REP_SET *to,REP_SET *from)
6855
6896
{
6856
 
  register uint i;
 
6897
  register uint32_t i;
6857
6898
  for (i=0 ; i < to->size_of_bits ; i++)
6858
6899
    to->bits[i]|=from->bits[i];
6859
6900
  return;
6862
6903
void copy_bits(REP_SET *to,REP_SET *from)
6863
6904
{
6864
6905
  memcpy(to->bits,from->bits,
6865
 
         (size_t) (sizeof(uint) * to->size_of_bits));
 
6906
         (size_t) (sizeof(uint32_t) * to->size_of_bits));
6866
6907
}
6867
6908
 
6868
6909
int cmp_bits(REP_SET *set1,REP_SET *set2)
6869
6910
{
6870
 
  return memcmp(set1->bits,set2->bits, sizeof(uint) * set1->size_of_bits);
 
6911
  return memcmp(set1->bits,set2->bits, sizeof(uint32_t) * set1->size_of_bits);
6871
6912
}
6872
6913
 
6873
6914
 
6874
6915
/* Get next set bit from set. */
6875
6916
 
6876
 
int get_next_bit(REP_SET *set,uint lastpos)
 
6917
int get_next_bit(REP_SET *set,uint32_t lastpos)
6877
6918
{
6878
 
  uint pos,*start,*end,bits;
 
6919
  uint32_t pos,*start,*end,bits;
6879
6920
 
6880
6921
  start=set->bits+ ((lastpos+1) / WORD_BIT);
6881
6922
  end=set->bits + set->size_of_bits;
6885
6926
    bits=start[0];
6886
6927
  if (!bits)
6887
6928
    return 0;
6888
 
  pos=(uint) (start-set->bits)*WORD_BIT;
 
6929
  pos=(uint32_t) (start-set->bits)*WORD_BIT;
6889
6930
  while (! (bits & 1))
6890
6931
  {
6891
6932
    bits>>=1;
6900
6941
 
6901
6942
int find_set(REP_SETS *sets,REP_SET *find)
6902
6943
{
6903
 
  uint i;
 
6944
  uint32_t i;
6904
6945
  for (i=0 ; i < sets->count-1 ; i++)
6905
6946
  {
6906
6947
    if (!cmp_bits(sets->set+i,find))
6919
6960
   set->next[] == -1 is reserved for end without replaces.
6920
6961
*/
6921
6962
 
6922
 
int find_found(FOUND_SET *found_set,uint table_offset, int found_offset)
 
6963
int find_found(FOUND_SET *found_set,uint32_t table_offset, int found_offset)
6923
6964
{
6924
6965
  int i;
6925
 
  for (i=0 ; (uint) i < found_sets ; i++)
 
6966
  for (i=0 ; (uint32_t) i < found_sets ; i++)
6926
6967
    if (found_set[i].table_offset == table_offset &&
6927
6968
        found_set[i].found_offset == found_offset)
6928
6969
      return -i-2;
6934
6975
 
6935
6976
/* Return 1 if regexp starts with \b or ends with \b*/
6936
6977
 
6937
 
uint start_at_word(char * pos)
 
6978
uint32_t start_at_word(char * pos)
6938
6979
{
6939
6980
  return (((!memcmp(pos, "\\b",2) && pos[2]) ||
6940
6981
           !memcmp(pos, "\\^", 2)) ? 1 : 0);
6941
6982
}
6942
6983
 
6943
 
uint end_of_word(char * pos)
 
6984
uint32_t end_of_word(char * pos)
6944
6985
{
6945
6986
  char * end= strchr(pos, '\0');
6946
6987
  return ((end > pos+2 && !memcmp(end-2, "\\b", 2)) ||
6956
6997
 
6957
6998
int insert_pointer_name(POINTER_ARRAY *pa,char * name)
6958
6999
{
6959
 
  uint i,length,old_count;
 
7000
  uint32_t i,length,old_count;
6960
7001
  unsigned char *new_pos;
6961
7002
  const char **new_array;
6962
7003
 
6964
7005
  if (! pa->typelib.count)
6965
7006
  {
6966
7007
    if (!(pa->typelib.type_names=(const char **)
6967
 
          my_malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
 
7008
          malloc(((PC_MALLOC-MALLOC_OVERHEAD)/
6968
7009
                     (sizeof(char *)+sizeof(*pa->flag))*
6969
 
                     (sizeof(char *)+sizeof(*pa->flag))),MYF(MY_WME))))
 
7010
                     (sizeof(char *)+sizeof(*pa->flag))))))
6970
7011
      return(-1);
6971
 
    if (!(pa->str= (unsigned char*) my_malloc((uint) (PS_MALLOC-MALLOC_OVERHEAD),
6972
 
                                      MYF(MY_WME))))
 
7012
    if (!(pa->str= (unsigned char*) malloc(PS_MALLOC-MALLOC_OVERHEAD)))
6973
7013
    {
6974
7014
      free((char*) pa->typelib.type_names);
6975
7015
      return (-1);
6981
7021
    pa->max_length=PS_MALLOC-MALLOC_OVERHEAD;
6982
7022
    pa->array_allocs=1;
6983
7023
  }
6984
 
  length=(uint) strlen(name)+1;
 
7024
  length=(uint32_t) strlen(name)+1;
6985
7025
  if (pa->length+length >= pa->max_length)
6986
7026
  {
6987
 
    if (!(new_pos= (unsigned char*) my_realloc((unsigned char*) pa->str,
6988
 
                                       (uint) (pa->max_length+PS_MALLOC),
6989
 
                                       MYF(MY_WME))))
 
7027
    if (!(new_pos= (unsigned char*)realloc((unsigned char*)pa->str,
 
7028
                                           (size_t)(pa->max_length+PS_MALLOC))))
6990
7029
      return(1);
6991
7030
    if (new_pos != pa->str)
6992
7031
    {
7000
7039
  }
7001
7040
  if (pa->typelib.count >= pa->max_count-1)
7002
7041
  {
7003
 
    int len;
 
7042
    size_t len;
7004
7043
    pa->array_allocs++;
7005
7044
    len=(PC_MALLOC*pa->array_allocs - MALLOC_OVERHEAD);
7006
 
    if (!(new_array=(const char **) my_realloc((unsigned char*) pa->typelib.type_names,
7007
 
                                               (uint) len/
7008
 
                                               (sizeof(unsigned char*)+sizeof(*pa->flag))*
7009
 
                                               (sizeof(unsigned char*)+sizeof(*pa->flag)),
7010
 
                                               MYF(MY_WME))))
 
7045
    if (!(new_array=
 
7046
         (const char **)realloc((unsigned char*) pa->typelib.type_names,
 
7047
                                 len/
 
7048
                                  (sizeof(unsigned char*)+sizeof(*pa->flag))*
 
7049
                                  (sizeof(unsigned char*)+sizeof(*pa->flag)))))
7011
7050
      return(1);
7012
7051
    pa->typelib.type_names=new_array;
7013
7052
    old_count=pa->max_count;
7019
7058
  pa->flag[pa->typelib.count]=0;      /* Reset flag */
7020
7059
  pa->typelib.type_names[pa->typelib.count++]= (char*) pa->str+pa->length;
7021
7060
  pa->typelib.type_names[pa->typelib.count]= NULL;  /* Put end-mark */
7022
 
  my_stpcpy((char*) pa->str+pa->length,name);
 
7061
  strcpy((char*) pa->str+pa->length,name);
7023
7062
  pa->length+=length;
7024
7063
  return(0);
7025
7064
} /* insert_pointer_name */
7075
7114
  replace_append_mem(ds, val, strlen(val));
7076
7115
}
7077
7116
 
7078
 
/* Append uint to ds, with optional replace */
7079
 
void replace_append_uint(string *ds, uint val)
 
7117
/* Append uint32_t to ds, with optional replace */
 
7118
void replace_append_uint(string *ds, uint32_t val)
7080
7119
{
7081
7120
  char buff[22]; /* This should be enough for any int */
7082
7121
  char *end= int64_t10_to_str(val, buff, 10);
7101
7140
 
7102
7141
void append_sorted(string* ds, string *ds_input)
7103
7142
{
7104
 
  priority_queue<string> lines;
 
7143
  priority_queue<string, vector<string>, greater<string> > lines;
7105
7144
 
7106
7145
  if (ds_input->empty())
7107
7146
    return;  /* No input */
7112
7151
  if (eol_pos == string::npos)
7113
7152
    return; // We should have at least one header here
7114
7153
 
7115
 
  ds->append(ds_input->substr(0, eol_pos));
 
7154
  ds->append(ds_input->substr(0, eol_pos+1));
7116
7155
 
7117
7156
  unsigned long start_pos= eol_pos+1;
7118
7157
 
7121
7160
 
7122
7161
    eol_pos= ds_input->find_first_of('\n', start_pos);
7123
7162
    /* Find end of line */
7124
 
    lines.push(ds_input->substr(start_pos, eol_pos-start_pos));
 
7163
    lines.push(ds_input->substr(start_pos, eol_pos-start_pos+1));
7125
7164
    start_pos= eol_pos+1;
7126
7165
 
7127
7166
  } while ( eol_pos != string::npos);