1102
1105
char buff[1024];
1106
1107
va_start(args, fmt);
1107
len= vsnprintf(buff, sizeof(buff)-1, fmt, args);
1108
size_t len= vsnprintf(buff, sizeof(buff)-1, fmt, args);
1110
1111
ds_res.append(buff, len);
1111
1112
ds_res.append("\n");
1127
1126
static void cat_file(string* ds, const char* filename)
1133
if ((fd= internal::my_open(filename, O_RDONLY, MYF(0))) < 0)
1128
int fd= internal::my_open(filename, O_RDONLY, MYF(0));
1134
1130
die("Failed to open file '%s'", filename);
1135
while((len= internal::my_read(fd, (unsigned char*)&buff,
1136
sizeof(buff), MYF(0))) > 0)
1134
while((len= internal::my_read(fd, (unsigned char*)&buff, sizeof(buff), MYF(0))) > 0)
1138
1136
char *p= buff, *start= buff;
1139
1137
while (p < buff+len)
1171
static int run_command(const char * cmd, string * result)
1169
static int run_command(const char* cmd, string& result)
1173
assert(result!=NULL);
1171
FILE* res_file= popen(cmd, "r");
1173
die("popen(\"%s\", \"r\") failed", cmd);
1174
1175
char buf[512]= {0};
1178
if (!(res_file= popen(cmd, "r")))
1179
die("popen(\"%s\", \"r\") failed", cmd);
1181
1176
while (fgets(buf, sizeof(buf), res_file))
1183
1178
/* Save the output of this command in the supplied string */
1184
result->append(buf);
1187
error= pclose(res_file);
1181
int error= pclose(res_file);
1188
1182
return WEXITSTATUS(error);
1204
static int run_tool(const char *tool_path, string * result, ...)
1198
static int run_tool(const char *tool_path, string& result, ...)
1209
1200
string ds_cmdline;
1212
1201
append_os_quoted(&ds_cmdline, tool_path, NULL);
1213
1202
ds_cmdline.append(" ");
1215
1205
va_start(args, result);
1217
while ((arg= va_arg(args, char *)))
1206
while (const char* arg= va_arg(args, char *))
1219
1208
/* Options should be os quoted */
1220
1209
if (strncmp(arg, "--", 2) == 0)
1273
1261
Fallback to dump both files to result file and inform
1274
1262
about installing "diff"
1280
1266
"The two files differ but it was not possible to execute 'diff' in\n"
1281
1267
"order to show only the difference, tried both 'diff -u' or 'diff -c'.\n"
1282
"Instead the whole content of the two files was shown for you to diff manually. ;)\n\n"
1268
"Instead the whole content of the two files was shown for you to diff manually. ;)\n"
1283
1270
"To get a better report you should install 'diff' on your system, which you\n"
1284
1271
"for example can get from http://www.gnu.org/software/diffutils/diffutils.html\n"
1287
1274
ds_tmp.append(" --- ");
1288
1275
ds_tmp.append(filename1);
1313
enum compare_files_result_enum {
1299
enum compare_files_result_enum
1315
1302
RESULT_CONTENT_MISMATCH= 1,
1316
1303
RESULT_LENGTH_MISMATCH= 2
1333
1320
static int compare_files2(int fd, const char* filename2)
1335
1322
int error= RESULT_OK;
1337
1323
uint32_t len, len2;
1338
1324
char buff[512], buff2[512];
1339
1325
const char *fname= filename2;
1340
1326
string tmpfile;
1342
if ((fd2= internal::my_open(fname, O_RDONLY, MYF(0))) < 0)
1328
int fd2= internal::my_open(fname, O_RDONLY, MYF(0));
1344
1331
internal::my_close(fd, MYF(0));
1345
1332
if (! opt_testdir.empty())
1432
1419
static int string_cmp(string* ds, const char *fname)
1436
1421
char temp_file_path[FN_REFLEN];
1438
if ((fd= internal::create_temp_file(temp_file_path, TMPDIR,
1439
"tmp", MYF(MY_WME))) < 0)
1423
int fd= internal::create_temp_file(temp_file_path, TMPDIR, "tmp", MYF(MY_WME));
1440
1425
die("Failed to create temporary file for ds");
1442
1427
/* Write ds to temporary file and set file pos to beginning*/
1443
if (internal::my_write(fd, (unsigned char *) ds->c_str(), ds->length(),
1444
MYF(MY_FNABP | MY_WME)) ||
1428
if (internal::my_write(fd, (unsigned char *) ds->c_str(), ds->length(), MYF(MY_FNABP | MY_WME)) ||
1445
1429
lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
1447
1431
internal::my_close(fd, MYF(0));
1450
1434
die("Failed to write file '%s'", temp_file_path);
1453
error= compare_files2(fd, fname);
1437
int error= compare_files2(fd, fname);
1455
1439
internal::my_close(fd, MYF(0));
1456
1440
/* Remove the temporary file */
1457
1441
internal::my_delete(temp_file_path, MYF(0));
1477
1461
const char* mess= "Result content mismatch\n";
1480
assert(result_file_name.c_str());
1482
1463
if (access(result_file_name.c_str(), F_OK) != 0)
1483
1464
die("The specified result file does not exist: '%s'", result_file_name.c_str());
1485
switch (string_cmp(ds, result_file_name.c_str())) {
1466
switch (string_cmp(ds, result_file_name.c_str()))
1486
1468
case RESULT_OK:
1487
1469
break; /* ok */
1488
1470
case RESULT_LENGTH_MISMATCH:
1501
1483
if (access(reject_file, W_OK) == 0)
1503
1485
/* Result file directory is writable, save reject file there */
1504
internal::fn_format(reject_file, result_file_name.c_str(), NULL,
1505
".reject", MY_REPLACE_EXT);
1486
internal::fn_format(reject_file, result_file_name.c_str(), NULL, ".reject", MY_REPLACE_EXT);
1509
1490
/* Put reject file in opt_logdir */
1510
internal::fn_format(reject_file, result_file_name.c_str(), opt_logdir.c_str(),
1511
".reject", MY_REPLACE_DIR | MY_REPLACE_EXT);
1491
internal::fn_format(reject_file, result_file_name.c_str(), opt_logdir.c_str(), ".reject", MY_REPLACE_DIR | MY_REPLACE_EXT);
1513
1493
str_to_file(reject_file, ds->c_str(), ds->length());
1544
1522
static void check_require(string* ds, const string &fname)
1548
1524
if (string_cmp(ds, fname.c_str()))
1550
1526
char reason[FN_REFLEN];
1551
1527
internal::fn_format(reason, fname.c_str(), "", "", MY_REPLACE_EXT | MY_REPLACE_DIR);
1552
1528
abort_not_supported_test("Test requires: '%s'", reason);
1857
1832
and assign that string to the $variable
1863
lengths= drizzle_row_field_sizes(&res);
1864
for (i= 0; i < drizzle_result_column_count(&res); i++)
1835
size_t* lengths= drizzle_row_field_sizes(&res);
1836
for (uint32_t i= 0; i < drizzle_result_column_count(&res); i++)
1930
1901
/* Convert row number to int */
1931
row_no= atoi(ds_row.c_str());
1902
long row_no= atoi(ds_row.c_str());
1933
1904
istringstream buff(ds_row);
1934
1905
if ((buff >> row_no).fail())
1937
1908
/* Remove any surrounding "'s from the query - if there is any */
1938
1909
// (Don't get me started on this)
1939
char * unstripped_query= strdup(ds_query.c_str());
1910
char* unstripped_query= strdup(ds_query.c_str());
1940
1911
if (strip_surrounding(unstripped_query, '"', '"'))
1941
1912
die("Mismatched \"'s around query '%s'", ds_query.c_str());
1943
ds_query.append(unstripped_query);
1913
ds_query= unstripped_query;
1945
1915
/* Run the query */
1946
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(),
1916
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(), &ret) == NULL ||
1948
1917
ret != DRIZZLE_RETURN_OK)
1950
1919
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1952
die("Error running query '%s': %d %s", ds_query.c_str(),
1953
drizzle_result_error_code(&res), drizzle_result_error(&res));
1921
die("Error running query '%s': %d %s", ds_query.c_str(), drizzle_result_error_code(&res), drizzle_result_error(&res));
1954
1922
drizzle_result_free(&res);
1958
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
1959
drizzle_con_error(con));
1926
die("Error running query '%s': %d %s", ds_query.c_str(), ret, drizzle_con_error(con));
1962
1929
if (drizzle_result_column_count(&res) == 0 ||
1967
1934
/* Find column number from the given column name */
1969
1935
uint32_t num_fields= drizzle_result_column_count(&res);
1970
drizzle_column_st *column;
1972
for (i= 0; i < num_fields; i++)
1936
for (uint32_t i= 0; i < num_fields; i++)
1974
column= drizzle_column_next(&res);
1938
drizzle_column_st* column= drizzle_column_next(&res);
1975
1939
if (strcmp(drizzle_column_name(column), ds_col.c_str()) == 0 &&
1976
1940
strlen(drizzle_column_name(column)) == ds_col.length())
2402
2363
static void do_remove_file(st_command* command)
2405
2365
string ds_filename;
2406
2366
const struct command_arg rm_args[] = {
2407
2367
{ "filename", ARG_STRING, true, &ds_filename, "File to delete" }
2412
2372
rm_args, sizeof(rm_args)/sizeof(struct command_arg),
2415
error= internal::my_delete(ds_filename.c_str(), MYF(0)) != 0;
2375
int error= internal::my_delete(ds_filename.c_str(), MYF(0)) != 0;
2416
2376
handle_command_error(command, error);
2445
2404
sizeof(copy_file_args)/sizeof(struct command_arg),
2448
error= (internal::my_copy(ds_from_file.c_str(), ds_to_file.c_str(),
2407
int error= (internal::my_copy(ds_from_file.c_str(), ds_to_file.c_str(),
2449
2408
MYF(MY_DONT_OVERWRITE_FILE)) != 0);
2450
2409
handle_command_error(command, error);
2501
2460
static void do_file_exist(st_command* command)
2504
2462
string ds_filename;
2505
2463
const struct command_arg file_exist_args[] = {
2506
2464
{ "filename", ARG_STRING, true, &ds_filename, "File to check if it exist" }
2512
2470
sizeof(file_exist_args)/sizeof(struct command_arg),
2515
error= (access(ds_filename.c_str(), F_OK) != 0);
2473
int error= access(ds_filename.c_str(), F_OK) != 0;
2516
2474
handle_command_error(command, error);
2530
2488
static void do_mkdir(st_command* command)
2532
2490
string ds_dirname;
2534
2491
const struct command_arg mkdir_args[] = {
2535
2492
{"dirname", ARG_STRING, true, &ds_dirname, "Directory to create"}
2540
2497
mkdir_args, sizeof(mkdir_args)/sizeof(struct command_arg),
2543
error= mkdir(ds_dirname.c_str(), (0777 & internal::my_umask_dir)) != 0;
2500
int error= mkdir(ds_dirname.c_str(), (0777 & internal::my_umask_dir)) != 0;
2544
2501
handle_command_error(command, error);
2557
2514
static void do_rmdir(st_command* command)
2560
2516
string ds_dirname;
2561
2517
const struct command_arg rmdir_args[] = {
2562
2518
{"dirname", ARG_STRING, true, &ds_dirname, "Directory to remove"}
2567
2523
rmdir_args, sizeof(rmdir_args)/sizeof(struct command_arg),
2570
error= rmdir(ds_dirname.c_str()) != 0;
2526
int error= rmdir(ds_dirname.c_str()) != 0;
2571
2527
handle_command_error(command, error);
2599
2555
static void read_until_delimiter(string *ds,
2600
2556
string *ds_delimiter)
2604
2558
if (ds_delimiter->length() > MAX_DELIMITER_LENGTH)
2605
2559
die("Max delimiter length(%d) exceeded", MAX_DELIMITER_LENGTH);
2607
2561
/* Read from file until delimiter is found */
2610
c= my_getc(cur_file->file);
2564
char c= my_getc(cur_file->file);
2669
2622
read_until_delimiter(&ds_content, &ds_delimiter);
2670
str_to_file2(ds_filename.c_str(), ds_content.c_str(),
2671
ds_content.length(), append);
2623
str_to_file2(ds_filename.c_str(), ds_content.c_str(), ds_content.length(), append);
2798
2746
sizeof(diff_file_args)/sizeof(struct command_arg),
2801
if ((error= compare_files(ds_filename.c_str(), ds_filename2.c_str())))
2749
int error= compare_files(ds_filename.c_str(), ds_filename2.c_str());
2803
2752
/* Compare of the two files failed, append them to output
2804
2753
so the failure can be analyzed
2813
2762
static st_connection * find_connection_by_name(const char *name)
2816
for (con= g_connections; con < next_con; con++)
2764
for (st_connection* con= g_connections; con < next_con; con++)
2818
if (!strcmp(con->name, name))
2766
if (not strcmp(con->name, name))
2823
return 0; /* Connection not found */