230
230
typedef boost::unordered_map<string, VAR *> var_hash_t;
231
231
var_hash_t var_hash;
236
st_connection() : con(drizzle)
238
drizzle_con_add_options(*this, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
241
operator drizzle::connection_c&()
246
operator drizzle_con_st*()
251
drizzle::drizzle_c drizzle;
252
drizzle::connection_c con;
239
st_connection g_connections[128];
240
st_connection* cur_con= NULL, *next_con;
255
typedef map<string, st_connection*> connections_t;
256
connections_t g_connections;
257
st_connection* cur_con= NULL;
243
260
List of commands in drizzletest
475
492
/* For replace_regex */
476
493
void do_get_replace_regex(st_command* command);
478
void replace_append_mem(string *ds, const char *val,
495
void replace_append_mem(string& ds, const char *val, int len);
480
496
void replace_append(string *ds, const char *val);
481
497
void replace_append_uint(string *ds, uint32_t val);
482
void append_sorted(string* ds, string* ds_input);
498
void append_sorted(string& ds, const string& ds_input);
484
void handle_error(struct st_command*,
500
void handle_error(st_command*,
485
501
unsigned int err_errno, const char *err_error,
486
502
const char *err_sqlstate, string *ds);
487
void handle_no_error(struct st_command*);
503
void handle_no_error(st_command*);
490
506
void do_eval(string *query_eval, const char *query,
601
static void show_query(drizzle_con_st *con, const char* query)
616
static int dt_query_log(drizzle::connection_c& con, drizzle::result_c& res, const std::string& query)
603
drizzle_result_st res;
604
drizzle_return_t ret;
609
if (drizzle_query_str(con, &res, query, &ret) == NULL ||
610
ret != DRIZZLE_RETURN_OK)
618
if (drizzle_return_t ret= con.query(res, query))
612
620
if (ret == DRIZZLE_RETURN_ERROR_CODE)
614
log_msg("Error running query '%s': %d %s",
615
query, drizzle_result_error_code(&res),
616
drizzle_result_error(&res));
617
drizzle_result_free(&res);
622
log_msg("Error running query '%s': %d %s", query.c_str(), res.error_code(), res.error());
621
log_msg("Error running query '%s': %d %s",
622
query, ret, drizzle_con_error(con));
626
log_msg("Error running query '%s': %d %s", query.c_str(), ret, con.error());
627
if (drizzle_result_column_count(&res) == 0 ||
628
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
630
/* No result set returned */
631
drizzle_result_free(&res);
638
unsigned int row_num= 0;
639
unsigned int num_fields= drizzle_result_column_count(&res);
640
drizzle_column_st *column;
642
fprintf(stderr, "=== %s ===\n", query);
643
while ((row= drizzle_row_next(&res)))
630
return res.column_count() == 0;
633
static void show_query(drizzle::connection_c& con, const char* query)
635
drizzle::result_c res;
636
if (dt_query_log(con, res, query))
639
unsigned int row_num= 0;
640
unsigned int num_fields= res.column_count();
642
fprintf(stderr, "=== %s ===\n", query);
643
while (drizzle_row_t row= res.row_next())
645
size_t *lengths= res.row_field_sizes();
648
fprintf(stderr, "---- %d. ----\n", row_num);
650
for (unsigned int i= 0; i < num_fields; i++)
645
size_t *lengths= drizzle_row_field_sizes(&res);
648
fprintf(stderr, "---- %d. ----\n", row_num);
649
drizzle_column_seek(&res, 0);
650
for(i= 0; i < num_fields; i++)
652
column= drizzle_column_next(&res);
653
fprintf(stderr, "%s\t%.*s\n",
654
drizzle_column_name(column),
655
(int)lengths[i], row[i] ? row[i] : "NULL");
652
drizzle_column_st* column= res.column_next();
653
fprintf(stderr, "%s\t%.*s\n", drizzle_column_name(column), (int)lengths[i], row[i] ? row[i] : "NULL");
658
for (i= 0; i < strlen(query)+8; i++)
659
fprintf(stderr, "=");
660
fprintf(stderr, "\n\n");
662
drizzle_result_free(&res);
656
for (size_t i= 0; i < strlen(query)+8; i++)
657
fprintf(stderr, "=");
658
fprintf(stderr, "\n\n");
679
static void show_warnings_before_error(drizzle_con_st *con)
675
static void show_warnings_before_error(drizzle::connection_c& con)
681
drizzle_result_st res;
682
drizzle_return_t ret;
683
const char* query= "SHOW WARNINGS";
688
if (drizzle_query_str(con, &res, query, &ret) == NULL ||
689
ret != DRIZZLE_RETURN_OK)
691
if (ret == DRIZZLE_RETURN_ERROR_CODE)
693
log_msg("Error running query '%s': %d %s",
694
query, drizzle_result_error_code(&res),
695
drizzle_result_error(&res));
696
drizzle_result_free(&res);
700
log_msg("Error running query '%s': %d %s",
701
query, ret, drizzle_con_error(con));
706
if (drizzle_result_column_count(&res) == 0 ||
707
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
709
/* No result set returned */
710
drizzle_result_free(&res);
714
if (drizzle_result_row_count(&res) <= 1)
716
/* Don't display the last row, it's "last error" */
677
drizzle::result_c res;
678
if (dt_query_log(con, res, "show warnings"))
681
if (res.row_count() >= 2) /* Don't display the last row, it's "last error" */
721
683
unsigned int row_num= 0;
722
unsigned int num_fields= drizzle_result_column_count(&res);
684
unsigned int num_fields= res.column_count();
724
686
fprintf(stderr, "\nWarnings from just before the error:\n");
725
while ((row= drizzle_row_next(&res)))
687
while (drizzle_row_t row= res.row_next())
728
size_t *lengths= drizzle_row_field_sizes(&res);
689
size_t *lengths= res.row_field_sizes();
730
if (++row_num >= drizzle_result_row_count(&res))
691
if (++row_num >= res.row_count())
732
693
/* Don't display the last row, it's "last error" */
736
for(i= 0; i < num_fields; i++)
697
for (uint32_t i= 0; i < num_fields; i++)
738
fprintf(stderr, "%.*s ", (int)lengths[i],
739
row[i] ? row[i] : "NULL");
699
fprintf(stderr, "%.*s ", (int)lengths[i], row[i] ? row[i] : "NULL");
741
701
fprintf(stderr, "\n");
744
drizzle_result_free(&res);
757
714
const char *argname; /* Name of argument */
758
715
enum arg_type type; /* Type of argument */
759
716
bool required; /* Argument required */
844
798
if (command->abort_on_error)
845
die("command \"%.*s\" failed with error %d",
846
command->first_word_len, command->query, error);
847
for (i= 0; i < command->expected_errors.count; i++)
799
die("command \"%.*s\" failed with error %d", command->first_word_len, command->query, error);
800
for (uint32_t i= 0; i < command->expected_errors.count; i++)
849
if ((command->expected_errors.err[i].type == ERR_ERRNO) &&
850
(command->expected_errors.err[i].code.errnum == error))
802
if (command->expected_errors.err[i].type == ERR_ERRNO &&
803
command->expected_errors.err[i].code.errnum == error)
947
885
void die(const char *fmt, ...)
953
888
Protect against dying twice
954
889
first time 'die' is called, try to write log files
955
890
second time, just exit
892
static bool dying= false;
958
894
cleanup_and_exit(1);
961
897
/* Print the error message */
962
898
fprintf(stderr, "drizzletest: ");
963
899
if (cur_file && cur_file != file_stack.data())
964
fprintf(stderr, "In included file \"%s\": ",
965
cur_file->file_name);
900
fprintf(stderr, "In included file \"%s\": ", cur_file->file_name);
966
901
if (start_lineno > 0)
967
902
fprintf(stderr, "At line %u: ", start_lineno);
970
906
va_start(args, fmt);
971
907
vfprintf(stderr, fmt, args);
1049
985
void verbose_msg(const char *fmt, ...)
1056
990
va_start(args, fmt);
1057
991
fprintf(stderr, "drizzletest: ");
1058
992
if (cur_file && cur_file != file_stack.data())
1059
fprintf(stderr, "In included file \"%s\": ",
1060
cur_file->file_name);
993
fprintf(stderr, "In included file \"%s\": ", cur_file->file_name);
1061
994
if (start_lineno != 0)
1062
995
fprintf(stderr, "At line %u: ", start_lineno);
1063
996
vfprintf(stderr, fmt, args);
1126
static void cat_file(string* ds, const char* filename)
1058
static void cat_file(string& ds, const char* filename)
1128
1060
int fd= internal::my_open(filename, O_RDONLY, MYF(0));
1130
1062
die("Failed to open file '%s'", filename);
1132
1063
char buff[512];
1134
while((len= internal::my_read(fd, (unsigned char*)&buff, sizeof(buff), MYF(0))) > 0)
1064
while (uint32_t len= internal::my_read(fd, (unsigned char*)&buff, sizeof(buff), MYF(0)))
1136
1066
char *p= buff, *start= buff;
1137
1067
while (p < buff+len)
1425
1353
die("Failed to create temporary file for ds");
1427
1355
/* Write ds to temporary file and set file pos to beginning*/
1428
if (internal::my_write(fd, (unsigned char *) ds->c_str(), ds->length(), MYF(MY_FNABP | MY_WME)) ||
1356
if (internal::my_write(fd, (unsigned char *) ds.data(), ds.length(), MYF(MY_FNABP | MY_WME)) ||
1429
1357
lseek(fd, 0, SEEK_SET) == MY_FILEPOS_ERROR)
1431
1359
internal::my_close(fd, MYF(0));
1490
1418
/* Put reject file in opt_logdir */
1491
1419
internal::fn_format(reject_file, result_file_name.c_str(), opt_logdir.c_str(), ".reject", MY_REPLACE_DIR | MY_REPLACE_EXT);
1493
str_to_file(reject_file, ds->c_str(), ds->length());
1421
str_to_file(reject_file, ds.data(), ds.length());
1495
ds->erase(); /* Don't create a .log file */
1423
ds.erase(); /* Don't create a .log file */
1497
1425
show_diff(NULL, result_file_name.c_str(), reject_file);
1498
1426
die("%s",mess);
1716
static void dt_query(drizzle::connection_c& con, drizzle::result_c& res, const std::string& query)
1718
if (drizzle_return_t ret= con.query(res, query))
1720
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1722
die("Error running query '%s': %d %s", query.c_str(), res.error_code(), res.error());
1726
die("Error running query '%s': %d %s", query.c_str(), ret, con.error());
1729
if (res.column_count() == 0)
1730
die("Query '%s' didn't return a result set", query.c_str());
1788
1733
static void var_query_set(VAR *var, const char *query, const char** query_end)
1790
const char *end = (char*)((query_end && *query_end) ?
1791
*query_end : query + strlen(query));
1792
drizzle_result_st res;
1793
drizzle_return_t ret;
1795
drizzle_con_st *con= &cur_con->con;
1735
const char *end = ((query_end && *query_end) ? *query_end : query + strlen(query));
1736
drizzle::connection_c& con= *cur_con;
1799
1738
while (end > query && *end != '`')
1802
1741
die("Syntax error in query, missing '`'");
1805
1745
/* Eval the query, thus replacing all environment variables */
1806
1746
do_eval(&ds_query, query, end, false);
1808
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(),
1810
ret != DRIZZLE_RETURN_OK)
1812
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1814
die("Error running query '%s': %d %s", ds_query.c_str(),
1815
drizzle_result_error_code(&res), drizzle_result_error(&res));
1816
drizzle_result_free(&res);
1820
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
1821
drizzle_con_error(con));
1824
if (drizzle_result_column_count(&res) == 0 ||
1825
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
1826
die("Query '%s' didn't return a result set", ds_query.c_str());
1748
drizzle::result_c res;
1749
dt_query(con, res, ds_query);
1828
if ((row= drizzle_row_next(&res)) && row[0])
1751
drizzle_row_t row= res.row_next();
1831
1755
Concatenate all fields in the first row with tab in between
1832
1756
and assign that string to the $variable
1835
size_t* lengths= drizzle_row_field_sizes(&res);
1836
for (uint32_t i= 0; i < drizzle_result_column_count(&res); i++)
1759
size_t* lengths= res.row_field_sizes();
1760
for (uint32_t i= 0; i < res.column_count(); i++)
1840
1764
/* Add column to tab separated string */
1841
1765
result.append(row[i], lengths[i]);
1843
result.append("\t", 1);
1845
end= result.c_str() + result.length()-1;
1769
end= result.c_str() + result.length() - 1;
1846
1770
eval_expr(var, result.c_str(), (const char**) &end);
1849
1773
eval_expr(var, "", 0);
1851
drizzle_result_free(&res);
1912
1831
die("Mismatched \"'s around query '%s'", ds_query.c_str());
1913
1832
ds_query= unstripped_query;
1916
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(), &ret) == NULL ||
1917
ret != DRIZZLE_RETURN_OK)
1919
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1921
die("Error running query '%s': %d %s", ds_query.c_str(), drizzle_result_error_code(&res), drizzle_result_error(&res));
1922
drizzle_result_free(&res);
1926
die("Error running query '%s': %d %s", ds_query.c_str(), ret, drizzle_con_error(con));
1929
if (drizzle_result_column_count(&res) == 0 ||
1930
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
1931
die("Query '%s' didn't return a result set", ds_query.c_str());
1834
drizzle::result_c res;
1835
dt_query(con, res, ds_query);
1934
1838
/* Find column number from the given column name */
1935
uint32_t num_fields= drizzle_result_column_count(&res);
1839
uint32_t num_fields= res.column_count();
1936
1840
for (uint32_t i= 0; i < num_fields; i++)
1938
drizzle_column_st* column= drizzle_column_next(&res);
1842
drizzle_column_st* column= res.column_next();
1939
1843
if (strcmp(drizzle_column_name(column), ds_col.c_str()) == 0 &&
1940
1844
strlen(drizzle_column_name(column)) == ds_col.length())
2230
2126
if (command->abort_on_error)
2232
log_msg("exec of '%s' failed, error: %d, status: %d, errno: %d",
2233
ds_cmd.c_str(), error, status, errno);
2128
log_msg("exec of '%s' failed, error: %d, status: %d, errno: %d", ds_cmd.c_str(), error, status, errno);
2234
2129
die("command \"%s\" failed", command->first_argument);
2252
2147
command->expected_errors.err[0].code.errnum != 0)
2254
2149
/* Error code we wanted was != 0, i.e. not an expected success */
2255
log_msg("exec of '%s failed, error: %d, errno: %d",
2256
ds_cmd.c_str(), error, errno);
2150
log_msg("exec of '%s failed, error: %d, errno: %d", ds_cmd.c_str(), error, errno);
2257
2151
die("command \"%s\" succeeded - should have failed with errno %d...",
2258
2152
command->first_argument, command->expected_errors.err[0].code.errnum);
2783
2665
static void do_send_quit(st_command* command)
2785
char *p= command->first_argument, *name;
2787
drizzle_result_st result;
2788
drizzle_return_t ret;
2667
char* p= command->first_argument;
2791
2670
die("Missing connection name in send_quit");
2793
while (*p && !my_isspace(charset_info,*p))
2672
while (*p && !my_isspace(charset_info, *p))
2798
2677
command->last_argument= p;
2800
if (!(con= find_connection_by_name(name)))
2679
st_connection* con= find_ptr2(g_connections, name);
2801
2681
die("connection '%s' not found in connection pool", name);
2803
if (drizzle_quit(&con->con,&result, &ret))
2804
drizzle_result_free(&result);
2683
drizzle::result_c result;
2684
drizzle_return_t ret;
2685
drizzle_quit(*con, &result.b_, &ret);
2872
2750
read_until_delimiter(&ds_script, &ds_delimiter);
2874
2752
/* Create temporary file name */
2875
if ((fd= internal::create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"),
2876
"tmp", MYF(MY_WME))) < 0)
2753
int fd= internal::create_temp_file(temp_file_path, getenv("MYSQLTEST_VARDIR"), "tmp", MYF(MY_WME));
2877
2755
die("Failed to create temporary file for perl command");
2878
2756
internal::my_close(fd, MYF(0));
2882
2760
/* Format the "perl <filename>" command */
2883
2761
snprintf(buf, sizeof(buf), "perl %s", temp_file_path);
2885
if (!(res_file= popen(buf, "r")) && command->abort_on_error)
2763
FILE* res_file= popen(buf, "r");
2764
if (not res_file && command->abort_on_error)
2886
2765
die("popen(\"%s\", \"r\") failed", buf);
2888
2767
while (fgets(buf, sizeof(buf), res_file))
2928
2807
static void do_echo(st_command* command)
2930
2809
string ds_echo;
2933
2810
do_eval(&ds_echo, command->first_argument, command->end, false);
2934
2811
ds_res.append(ds_echo.c_str(), ds_echo.length());
2935
2812
ds_res.append("\n");
2936
2813
command->last_argument= command->end;
2940
2816
static void do_wait_for_slave_to_stop()
2942
2818
static int SLAVE_POLL_INTERVAL= 300000;
2943
drizzle_con_st *con= &cur_con->con;
2819
drizzle::connection_c& con= *cur_con;
2946
drizzle_result_st res;
2947
drizzle_return_t ret;
2951
if (drizzle_query_str(con,&res,"show status like 'Slave_running'",
2952
&ret) == NULL || ret != DRIZZLE_RETURN_OK)
2954
if (ret == DRIZZLE_RETURN_ERROR_CODE)
2956
die("Query failed while probing slave for stop: %s",
2957
drizzle_result_error(&res));
2958
drizzle_result_free(&res);
2962
die("Query failed while probing slave for stop: %s",
2963
drizzle_con_error(con));
2967
if (drizzle_result_column_count(&res) == 0 ||
2968
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
2970
die("Query failed while probing slave for stop: %s",
2971
drizzle_con_error(con));
2974
if (!(row=drizzle_row_next(&res)) || !row[1])
2976
drizzle_result_free(&res);
2822
drizzle::result_c res;
2823
dt_query(con, res, "show status like 'Slave_running'");
2824
drizzle_row_t row= res.row_next();
2825
if (!row || !row[1])
2977
2827
die("Strange result from query while probing slave for stop");
2979
done = !strcmp(row[1],"OFF");
2980
drizzle_result_free(&res);
2829
if (!strcmp(row[1], "OFF"))
2983
2831
usleep(SLAVE_POLL_INTERVAL);
3002
2847
wait_for_position:
3004
if (drizzle_query_str(con, &res, query_buf, &ret) == NULL ||
3005
ret != DRIZZLE_RETURN_OK)
3007
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3009
die("failed in '%s': %d: %s", query_buf, drizzle_result_error_code(&res),
3010
drizzle_result_error(&res));
3011
drizzle_result_free(&res);
3014
die("failed in '%s': %d: %s", query_buf, ret, drizzle_con_error(con));
3017
if (drizzle_result_column_count(&res) == 0 ||
3018
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3019
die("drizzle_result_buffer() returned NULL for '%s'", query_buf);
3021
if (!(row= drizzle_row_next(&res)))
3023
drizzle_result_free(&res);
2849
drizzle::result_c res;
2850
dt_query(con, res, query_buf);
2852
drizzle_row_t row= res.row_next();
3024
2855
die("empty result in %s", query_buf);
3069
2897
static void do_save_master_pos()
3071
drizzle_result_st res;
3072
drizzle_return_t ret;
3074
drizzle_con_st *con= &cur_con->con;
3078
if (drizzle_query_str(con, &res, query= "show master status", &ret) == NULL ||
3079
ret != DRIZZLE_RETURN_OK)
3081
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3083
die("failed in '%s': %d: %s", query, drizzle_result_error_code(&res),
3084
drizzle_result_error(&res));
3085
drizzle_result_free(&res);
3088
die("failed in '%s': %d: %s", query, ret, drizzle_con_error(con));
3091
if (drizzle_result_column_count(&res) == 0 ||
3092
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3093
die("drizzleclient_store_result() retuned NULL for '%s'", query);
3094
if (!(row = drizzle_row_next(&res)))
2899
drizzle::connection_c& con= *cur_con;
2900
const char *query= "show master status";
2902
drizzle::result_c res;
2903
dt_query(con, res, query);
2904
drizzle_row_t row= res.row_next();
3095
2906
die("empty result in show master status");
3096
2907
strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3097
2908
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3098
drizzle_result_free(&res);
3250
3060
static void fill_global_error_names()
3252
drizzle_result_st res;
3253
drizzle_return_t ret;
3254
drizzle_con_st *con= &cur_con->con;
3062
drizzle::connection_c& con= *cur_con;
3256
3064
global_error_names.clear();
3258
const std::string ds_query("select error_name, error_code from data_dictionary.errors");
3259
if (drizzle_query_str(con, &res, ds_query.c_str(), &ret) == NULL ||
3260
ret != DRIZZLE_RETURN_OK)
3262
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3264
die("Error running query '%s': %d %s", ds_query.c_str(), drizzle_result_error_code(&res), drizzle_result_error(&res));
3268
die("Error running query '%s': %d %s", ds_query.c_str(), ret, drizzle_con_error(con));
3271
if (drizzle_result_column_count(&res) == 0 ||
3272
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3274
drizzle_result_free(&res);
3275
die("Query '%s' didn't return a result set", ds_query.c_str());
3278
while (drizzle_row_t row= drizzle_row_next(&res))
3066
drizzle::result_c res;
3067
dt_query(con, res, "select error_name, error_code from data_dictionary.errors");
3068
while (drizzle_row_t row= res.row_next())
3280
3070
if (not row[0])
3283
3073
Concatenate all fields in the first row with tab in between
3284
3074
and assign that string to the $variable
3286
size_t *lengths= drizzle_row_field_sizes(&res);
3076
size_t *lengths= res.row_field_sizes();
3289
3079
global_error_names[string(row[0], lengths[0])] = boost::lexical_cast<uint32_t>(string(row[1], lengths[1]));
3291
3081
catch (boost::bad_lexical_cast &ex)
3293
drizzle_result_free(&res);
3294
3083
die("Invalid error_code from Drizzle: %s", ex.what());
3299
drizzle_result_free(&res);
3302
3088
static uint32_t get_errcode_from_name(const char *error_name, const char *error_end)
3505
static int select_connection_name(const char *name)
3291
static void select_connection_name(const char *name)
3507
if (!(cur_con= find_connection_by_name(name)))
3293
if (!(cur_con= find_ptr2(g_connections, name)))
3508
3294
die("connection '%s' not found in connection pool", name);
3510
3296
/* Update $drizzleclient_get_server_version to that of current connection */
3511
var_set_drizzleclient_get_server_version(&cur_con->con);
3297
var_set_drizzleclient_get_server_version(*cur_con);
3517
static int select_connection(st_command* command)
3301
static void select_connection(st_command* command)
3520
3303
char *p= command->first_argument;
3524
3305
die("Missing connection name in connect");
3526
3307
while (*p && !my_isspace(charset_info,*p))
3530
3311
command->last_argument= p;
3531
return(select_connection_name(name));
3312
select_connection_name(name);
3535
3316
static void do_close_connection(st_command* command)
3537
char *p= command->first_argument, *name;
3318
char* p= command->first_argument;
3541
3320
die("Missing connection name in disconnect");
3543
3322
while (*p && !my_isspace(charset_info,*p))
3548
3327
command->last_argument= p;
3550
if (!(con= find_connection_by_name(name)))
3329
st_connection* con= find_ptr2(g_connections, name);
3551
3331
die("connection '%s' not found in connection pool", name);
3553
if (con->drizzle != NULL)
3555
drizzle_free(con->drizzle);
3561
When the connection is closed set name to "-closed_connection-"
3562
to make it possible to reuse the connection name.
3564
con->name = strdup("-closed_connection-");
3332
g_connections.erase(name);
3593
static void safe_connect(drizzle_con_st *con, const char *name,
3594
const string host, const string user, const char *pass,
3595
const string db, uint32_t port)
3362
static st_connection* safe_connect(const char *name, const string host, const string user, const char *pass, const string db, uint32_t port)
3597
3364
uint32_t failed_attempts= 0;
3598
static uint32_t connection_retry_sleep= 100000; /* Microseconds */
3599
drizzle_return_t ret;
3365
st_connection* con0= new st_connection;
3366
drizzle_con_st* con= *con0;
3601
3367
drizzle_con_set_tcp(con, host.c_str(), port);
3602
3368
drizzle_con_set_auth(con, user.c_str(), pass);
3603
3369
drizzle_con_set_db(con, db.c_str());
3604
while((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
3370
while (drizzle_return_t ret= drizzle_con_connect(con))
3615
3381
ret == DRIZZLE_RETURN_COULD_NOT_CONNECT) &&
3616
3382
failed_attempts < opt_max_connect_retries)
3618
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3619
opt_max_connect_retries, ret, drizzle_con_error(con));
3620
usleep(connection_retry_sleep);
3384
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts, opt_max_connect_retries, ret, drizzle_con_error(con));
3624
3389
if (failed_attempts > 0)
3625
die("Could not open connection '%s' after %d attempts: %d %s", name,
3626
failed_attempts, ret, drizzle_con_error(con));
3390
die("Could not open connection '%s' after %d attempts: %d %s", name, failed_attempts, ret, drizzle_con_error(con));
3628
die("Could not open connection '%s': %d %s", name, ret,
3629
drizzle_con_error(con));
3392
die("Could not open connection '%s': %d %s", name, ret, drizzle_con_error(con));
3631
3394
failed_attempts++;
3692
3453
drizzle_con_set_tcp(con, host, port);
3693
3454
drizzle_con_set_auth(con, user, pass);
3694
3455
drizzle_con_set_db(con, db);
3695
if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
3456
if (drizzle_return_t ret= drizzle_con_connect(con))
3697
3458
if (ret == DRIZZLE_RETURN_HANDSHAKE_FAILED)
3699
3460
var_set_errno(drizzle_con_error_code(con));
3700
handle_error(command, drizzle_con_error_code(con), drizzle_con_error(con),
3701
drizzle_con_sqlstate(con), &ds_res);
3461
handle_error(command, drizzle_con_error_code(con), drizzle_con_error(con), drizzle_con_sqlstate(con), &ds_res);
3705
3465
var_set_errno(ret);
3706
3466
handle_error(command, ret, drizzle_con_error(con), "", &ds_res);
3709
3468
return 0; /* Not connected */
3712
3470
var_set_errno(0);
3713
3471
handle_no_error(command);
3714
3472
return 1; /* Connected */
3791
3546
char buff[FN_REFLEN];
3792
3547
internal::fn_format(buff, ds_sock.c_str(), TMPDIR, "", 0);
3794
ds_sock.append(buff);
3799
con_options= ds_options.c_str();
3553
const char* con_options= ds_options.c_str();
3800
3554
while (*con_options)
3803
3556
/* Step past any spaces in beginning of option*/
3804
3557
while (*con_options && my_isspace(charset_info, *con_options))
3806
3559
/* Find end of this option */
3560
const char* end= con_options;
3808
3561
while (*end && !my_isspace(charset_info, *end))
3810
die("Illegal option to connect: %.*s",
3811
(int) (end - con_options), con_options);
3563
die("Illegal option to connect: %.*s", (int) (end - con_options), con_options);
3812
3564
/* Process next option */
3813
3565
con_options= end;
3816
if (find_connection_by_name(ds_connection_name.c_str()))
3568
if (find_ptr2(g_connections, ds_connection_name))
3817
3569
die("Connection %s already exists", ds_connection_name.c_str());
3819
if (next_con != g_connections + sizeof(g_connections) / sizeof(st_connection) - 1)
3825
if (!(con_slot= find_connection_by_name("-closed_connection-")))
3826
die("Connection limit exhausted, you can have max %d connections",
3827
(int) (sizeof(g_connections)/sizeof(st_connection)));
3830
if ((con_slot->drizzle= drizzle_create(NULL)) == NULL)
3831
die("Failed on drizzle_create()");
3832
if (!drizzle_con_create(con_slot->drizzle, &con_slot->con))
3833
die("Failed on drizzle_con_create()");
3834
drizzle_con_add_options(&con_slot->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
3571
st_connection* con_slot= new st_connection;
3836
3573
/* Use default db name */
3837
if (ds_database.length() == 0)
3838
ds_database.append(opt_db);
3574
if (ds_database.empty())
3575
ds_database= opt_db;
3840
3577
/* Special database to allow one to connect without a database name */
3841
if (ds_database.length() && !strcmp(ds_database.c_str(),"*NO-ONE*"))
3578
if (ds_database == "*NO-ONE*")
3842
3579
ds_database.clear();
3844
if (connect_n_handle_errors(command, &con_slot->con,
3845
ds_host.c_str(),ds_user.c_str(),
3846
ds_password.c_str(), ds_database.c_str(),
3847
con_port, ds_sock.c_str()))
3581
if (connect_n_handle_errors(command, *con_slot, ds_host.c_str(), ds_user.c_str(),
3582
ds_password.c_str(), ds_database.c_str(), con_port, ds_sock.c_str()))
3849
con_slot->name= strdup(ds_connection_name.c_str());
3584
g_connections[ds_connection_name]= con_slot;
3850
3585
cur_con= con_slot;
3852
if (con_slot == next_con)
3853
next_con++; /* if we used the next_con slot, advance the pointer */
3856
3588
/* Update $drizzleclient_get_server_version to that of current connection */
3857
var_set_drizzleclient_get_server_version(&cur_con->con);
3589
var_set_drizzleclient_get_server_version(*cur_con);
3863
static int do_done(st_command* command)
3593
static void do_done(st_command* command)
3865
3595
/* Check if empty block stack */
3866
3596
if (cur_block == block_stack)
4496
4216
internal::fn_format(buff, fname, "", "", MY_UNPACK_FILENAME);
4218
int flags= O_WRONLY | O_CREAT;
4499
4220
flags|= O_TRUNC;
4500
if ((fd= internal::my_open(buff, flags,
4501
MYF(MY_WME | MY_FFNF))) < 0)
4221
int fd= internal::my_open(buff, flags, MYF(MY_WME | MY_FFNF));
4502
4223
die("Could not open '%s' for writing: errno = %d", buff, errno);
4503
4224
if (append && lseek(fd, 0, SEEK_END) == MY_FILEPOS_ERROR)
4504
4225
die("Could not find end of file '%s': errno = %d", buff, errno);
4594
4314
Values may be converted with 'replace_column'
4597
static void append_result(string *ds, drizzle_result_st *res)
4317
static void append_result(string *ds, drizzle::result_c& res)
4600
uint32_t num_fields= drizzle_result_column_count(res);
4601
drizzle_column_st *column;
4604
while ((row = drizzle_row_next(res)))
4319
uint32_t num_fields= res.column_count();
4320
while (drizzle_row_t row = res.row_next())
4607
lengths = drizzle_row_field_sizes(res);
4608
drizzle_column_seek(res, 0);
4609
for (i = 0; i < num_fields; i++)
4322
size_t* lengths = res.row_field_sizes();
4324
for (uint32_t i = 0; i < num_fields; i++)
4611
column= drizzle_column_next(res);
4612
if (row[i] && (drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_TINY))
4326
drizzle_column_st* column= res.column_next();
4327
if (row[i] && drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_TINY)
4614
4329
if (boost::lexical_cast<uint32_t>(row[i]))
4616
if ((drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_UNSIGNED))
4331
if (drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_UNSIGNED)
4618
4333
append_field(ds, i, column, "YES", 3, false);
4651
4364
Append metadata for fields to output
4654
static void append_metadata(string *ds, drizzle_result_st *res)
4367
static void append_metadata(string *ds, drizzle::result_c& res)
4656
drizzle_column_st *column;
4657
4369
ds->append("Catalog\tDatabase\tTable\tTable_alias\tColumn\t"
4658
4370
"Column_alias\tType\tLength\tMax length\tIs_null\t"
4659
4371
"Flags\tDecimals\tCharsetnr\n");
4661
drizzle_column_seek(res, 0);
4662
while ((column= drizzle_column_next(res)))
4374
while (drizzle_column_st* column= res.column_next())
4664
ds->append(drizzle_column_catalog(column),
4665
strlen(drizzle_column_catalog(column)));
4666
ds->append("\t", 1);
4376
ds->append(drizzle_column_catalog(column), strlen(drizzle_column_catalog(column)));
4667
4378
ds->append(drizzle_column_db(column), strlen(drizzle_column_db(column)));
4668
ds->append("\t", 1);
4669
ds->append(drizzle_column_orig_table(column),
4670
strlen(drizzle_column_orig_table(column)));
4671
ds->append("\t", 1);
4672
ds->append(drizzle_column_table(column),
4673
strlen(drizzle_column_table(column)));
4674
ds->append("\t", 1);
4675
ds->append(drizzle_column_orig_name(column),
4676
strlen(drizzle_column_orig_name(column)));
4677
ds->append("\t", 1);
4678
ds->append(drizzle_column_name(column),
4679
strlen(drizzle_column_name(column)));
4680
ds->append("\t", 1);
4380
ds->append(drizzle_column_orig_table(column), strlen(drizzle_column_orig_table(column)));
4382
ds->append(drizzle_column_table(column), strlen(drizzle_column_table(column)));
4384
ds->append(drizzle_column_orig_name(column), strlen(drizzle_column_orig_name(column)));
4386
ds->append(drizzle_column_name(column), strlen(drizzle_column_name(column)));
4681
4388
replace_append_uint(ds, drizzle_column_type_drizzle(column));
4682
ds->append("\t", 1);
4683
4390
replace_append_uint(ds, drizzle_column_size(column));
4684
ds->append("\t", 1);
4685
if (drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_TINY)
4687
replace_append_uint(ds, 1);
4691
replace_append_uint(ds, drizzle_column_max_size(column));
4693
ds->append("\t", 1);
4694
ds->append((char*) ((drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NOT_NULL) ? "N" : "Y"), 1);
4695
ds->append("\t", 1);
4392
replace_append_uint(ds, drizzle_column_type(column) == DRIZZLE_COLUMN_TYPE_TINY ? 1 : drizzle_column_max_size(column));
4394
ds->append((drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NOT_NULL) ? "N" : "Y", 1);
4696
4396
replace_append_uint(ds, drizzle_column_flags(column));
4697
ds->append("\t", 1);
4698
4398
replace_append_uint(ds, drizzle_column_decimals(column));
4699
ds->append("\t", 1);
4700
4400
replace_append_uint(ds, drizzle_column_charset(column));
4701
ds->append("\n", 1);
4726
4426
Display the table headings with the names tab separated
4729
static void append_table_headings(string *ds, drizzle_result_st *res)
4429
static void append_table_headings(string& ds, drizzle::result_c& res)
4731
4431
uint32_t col_idx= 0;
4732
drizzle_column_st *column;
4733
drizzle_column_seek(res, 0);
4734
while ((column= drizzle_column_next(res)))
4433
while (drizzle_column_st* column= res.column_next())
4737
ds->append("\t", 1);
4738
replace_append(ds, drizzle_column_name(column));
4437
replace_append(&ds, drizzle_column_name(column));
4741
ds->append("\n", 1);
4748
4447
Number of warnings appended to ds
4751
static int append_warnings(string *ds, drizzle_con_st *con,
4752
drizzle_result_st *res)
4450
static int append_warnings(string& ds, drizzle::connection_c& con, drizzle::result_c& res)
4755
drizzle_result_st warn_res;
4756
drizzle_return_t ret;
4759
if (!(count= drizzle_result_warning_count(res)))
4762
if (drizzle_query_str(con, &warn_res, "SHOW WARNINGS", &ret) == NULL ||
4763
ret != DRIZZLE_RETURN_OK)
4765
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4766
die("Error running query \"SHOW WARNINGS\": %s", drizzle_result_error(&warn_res));
4768
die("Error running query \"SHOW WARNINGS\": %s", drizzle_con_error(con));
4771
if (drizzle_result_column_count(&warn_res) == 0 ||
4772
drizzle_result_buffer(&warn_res) != DRIZZLE_RETURN_OK)
4773
die("Warning count is %u but didn't get any warnings", count);
4775
append_result(ds, &warn_res);
4776
drizzle_result_free(&warn_res);
4452
uint32_t count= drizzle_result_warning_count(&res.b_);
4456
drizzle::result_c warn_res;
4457
dt_query(con, warn_res, "show warnings");
4458
append_result(&ds, warn_res);
4792
4473
ds output buffer where to store result form query
4795
static void run_query_normal(st_connection *cn,
4476
static void run_query_normal(st_connection& cn,
4796
4477
st_command* command,
4797
4478
int flags, char *query, int query_len,
4798
string *ds, string *ds_warnings)
4479
string *ds, string& ds_warnings)
4800
drizzle_result_st res;
4801
4481
drizzle_return_t ret;
4802
drizzle_con_st *con= &cn->con;
4482
drizzle_con_st *con= cn;
4805
4485
drizzle_con_add_options(con, DRIZZLE_CON_NO_RESULT_READ);
4487
drizzle::result_c res;
4807
4488
if (flags & QUERY_SEND_FLAG)
4810
4491
* Send the query
4813
(void) drizzle_query(con, &res, query, query_len, &ret);
4494
(void) drizzle_query(con, &res.b_, query, query_len, &ret);
4814
4495
if (ret != DRIZZLE_RETURN_OK)
4816
4497
if (ret == DRIZZLE_RETURN_ERROR_CODE ||
4817
4498
ret == DRIZZLE_RETURN_HANDSHAKE_FAILED)
4819
err= drizzle_result_error_code(&res);
4820
handle_error(command, err, drizzle_result_error(&res),
4821
drizzle_result_sqlstate(&res), ds);
4822
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4823
drizzle_result_free(&res);
4500
err= res.error_code();
4501
handle_error(command, err, res.error(), drizzle_result_sqlstate(&res.b_), ds);
4838
4516
* Read the result packet
4840
if (drizzle_result_read(con, &res, &ret) == NULL ||
4518
if (drizzle_result_read(con, &res.b_, &ret) == NULL ||
4841
4519
ret != DRIZZLE_RETURN_OK)
4843
4521
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4845
handle_error(command, drizzle_result_error_code(&res),
4846
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
4523
handle_error(command, res.error_code(), res.error(), drizzle_result_sqlstate(&res.b_), ds);
4850
4526
handle_error(command, ret, drizzle_con_error(con), "", ds);
4851
drizzle_result_free(&res);
4857
4532
Store the result of the query if it will return any fields
4859
if (drizzle_result_column_count(&res) &&
4860
(ret= drizzle_result_buffer(&res)) != DRIZZLE_RETURN_OK)
4534
if (res.column_count() &&
4535
(ret= drizzle_result_buffer(&res.b_)) != DRIZZLE_RETURN_OK)
4862
4537
if (ret == DRIZZLE_RETURN_ERROR_CODE)
4864
handle_error(command, drizzle_result_error_code(&res),
4865
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
4539
handle_error(command, res.error_code(), res.error(), drizzle_result_sqlstate(&res.b_), ds);
4869
4542
handle_error(command, ret, drizzle_con_error(con), "", ds);
4870
drizzle_result_free(&res);
4902
4574
if (!disable_warnings)
4904
4576
drizzle_con_remove_options(con, DRIZZLE_CON_NO_RESULT_READ);
4905
if (append_warnings(ds_warnings, con, &res) || ds_warnings->length())
4577
if (append_warnings(ds_warnings, cn, res) || not ds_warnings.empty())
4907
4579
ds->append("Warnings:\n", 10);
4908
ds->append(ds_warnings->c_str(), ds_warnings->length());
4912
4584
if (!disable_info)
4913
append_info(ds, affected_rows, drizzle_result_info(&res));
4585
append_info(ds, affected_rows, drizzle_result_info(&res.b_));
4916
drizzle_result_free(&res);
4919
4590
/* If we come here the query is both executed and read successfully */
4963
4630
abort_not_supported_test
4965
4632
if (err_errno == DRIZZLE_RETURN_SERVER_GONE)
4966
die("require query '%s' failed: %d: %s", command->query,
4967
err_errno, err_error);
4633
die("require query '%s' failed: %d: %s", command->query, err_errno, err_error);
4969
4635
/* Abort the run of this test, pass the failed query as reason */
4970
abort_not_supported_test("Query '%s' failed, required functionality " \
4971
"not supported", command->query);
4636
abort_not_supported_test("Query '%s' failed, required functionality not supported", command->query);
4974
4639
if (command->abort_on_error)
4975
4640
die("query '%s' failed: %d: %s", command->query, err_errno, err_error);
4977
for (i= 0 ; (uint32_t) i < command->expected_errors.count ; i++)
4643
for (; i < command->expected_errors.count; i++)
4979
4645
if (((command->expected_errors.err[i].type == ERR_ERRNO) &&
4980
4646
(command->expected_errors.err[i].code.errnum == err_errno)) ||
5043
4707
void handle_no_error(st_command* command)
5047
4709
if (command->expected_errors.err[0].type == ERR_ERRNO &&
5048
4710
command->expected_errors.err[0].code.errnum != 0)
5050
4712
/* Error code we wanted was != 0, i.e. not an expected success */
5051
die("query '%s' succeeded - should have failed with errno %d...",
5052
command->query, command->expected_errors.err[0].code.errnum);
4713
die("query '%s' succeeded - should have failed with errno %d...", command->query, command->expected_errors.err[0].code.errnum);
5054
4715
else if (command->expected_errors.err[0].type == ERR_SQLSTATE &&
5055
4716
strcmp(command->expected_errors.err[0].code.sqlstate,"00000") != 0)
5057
4718
/* SQLSTATE we wanted was != "00000", i.e. not an expected success */
5058
die("query '%s' succeeded - should have failed with sqlstate %s...",
5059
command->query, command->expected_errors.err[0].code.sqlstate);
4719
die("query '%s' succeeded - should have failed with sqlstate %s...", command->query, command->expected_errors.err[0].code.sqlstate);
5114
4767
Create a temporary dynamic string to contain the output from
5117
if (! command->require_file.empty())
4771
string* ds= command->require_file.empty() ? &ds_res : &ds_result;
5126
4773
Log the query into the output buffer
5128
4775
if (!disable_query_log && (flags & QUERY_SEND_FLAG))
5130
replace_append_mem(ds, query, query_len);
4777
replace_append_mem(*ds, query, query_len);
5131
4778
ds->append(delimiter, delimiter_length);
5132
4779
ds->append("\n");
4782
string* save_ds= NULL;
5135
4784
if (display_result_sorted)
5147
4796
Always run with normal C API if it's not a complete
5150
run_query_normal(cn, command, flags, query, query_len,
4800
run_query_normal(cn, command, flags, query, query_len, ds, ds_warnings);
5153
4802
if (display_result_sorted)
5155
4804
/* Sort the result set and append it to result */
5156
append_sorted(save_ds, &ds_sorted);
4805
append_sorted(*save_ds, ds_sorted);
5163
4812
and the output should be checked against an already
5164
4813
existing file which has been specified using --require or --result
5166
check_require(ds, command->require_file);
4815
check_require(*ds, command->require_file);
5173
4820
/****************************************************************************/
5175
static void get_command_type(struct st_command* command)
4822
static void get_command_type(st_command* command)
5181
4824
if (*command->query == '}')
5183
4826
command->type = Q_END_BLOCK;
5187
save= command->query[command->first_word_len];
4830
char save= command->query[command->first_word_len];
5188
4831
command->query[command->first_word_len]= 0;
5189
type= command_typelib.find_type(command->query, TYPELIB::e_default);
4832
uint32_t type= command_typelib.find_type(command->query, TYPELIB::e_default);
5190
4833
command->query[command->first_word_len]= save;
5596
5229
cur_file->file_name= strdup("<stdin>");
5597
5230
cur_file->lineno= 1;
5599
cur_con= g_connections;
5600
if ((cur_con->drizzle= drizzle_create(NULL)) == NULL)
5601
die("Failed in drizzle_create()");
5602
if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5603
die("Failed in drizzle_con_create()");
5604
drizzle_con_add_options(&cur_con->con, use_drizzle_protocol ? DRIZZLE_CON_EXPERIMENTAL : DRIZZLE_CON_MYSQL);
5606
cur_con->name = strdup("default");
5607
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5232
cur_con= safe_connect("default", opt_host, opt_user, opt_pass, opt_db, opt_port);
5233
g_connections["default"] = cur_con;
5610
5235
fill_global_error_names();
6125
5749
struct st_replace *init_replace(const char **from, const char **to, uint32_t count,
6126
5750
char *word_end_chars);
6128
void replace_strings_append(struct st_replace *rep, string* ds,
6129
const char *from, int len);
5752
void replace_strings_append(struct st_replace *rep, string& ds, const char *from, int len);
6131
5754
st_replace *glob_replace= NULL;
6132
5755
// boost::scoped_ptr<st_replace> glob_replace;
6226
5846
if (!(rep_str = ((REPLACE_STRING*) rep_pos))->replace_string)
6228
5848
/* No match found */
6229
ds->append(start, from - start - 1);
5849
ds.append(start, from - start - 1);
6233
5853
/* Append part of original string before replace string */
6234
ds->append(start, (from - rep_str->to_offset) - start);
5854
ds.append(start, (from - rep_str->to_offset) - start);
6236
5856
/* Append replace string */
6237
ds->append(rep_str->replace_string,
6238
strlen(rep_str->replace_string));
5857
ds.append(rep_str->replace_string, strlen(rep_str->replace_string));
6240
5859
if (!*(from-=rep_str->from_offset) && rep_pos->found != 2)
6882
6501
rep_str=(REPLACE_STRING*) (replace+sets.count);
6883
6502
to_array= (char **) (rep_str+found_sets+1);
6884
6503
to_pos=(char *) (to_array+count);
6885
for (i=0 ; i < count ; i++)
6504
for (i=0; i < count; i++)
6887
6506
to_array[i]=to_pos;
6888
6507
to_pos=strcpy(to_pos,to[i])+strlen(to[i])+1;
6890
6509
rep_str[0].found=1;
6891
6510
rep_str[0].replace_string=0;
6892
for (i=1 ; i <= found_sets ; i++)
6511
for (i=1; i <= found_sets; i++)
6894
6513
const char *pos= from[found_set[i-1].table_offset];
6895
6514
rep_str[i].found= !memcmp(pos, "\\^", 3) ? 2 : 1;
7148
6767
replace_strings_append(glob_replace, ds, v, len);
7155
6774
/* Append zero-terminated string to ds, with optional replace */
7156
6775
void replace_append(string *ds, const char *val)
7158
replace_append_mem(ds, val, strlen(val));
6777
replace_append_mem(*ds, val, strlen(val));
7161
6780
/* Append uint32_t to ds, with optional replace */
7185
void append_sorted(string* ds, string *ds_input)
6804
void append_sorted(string& ds, const string& ds_input)
7187
6806
priority_queue<string, vector<string>, greater<string> > lines;
7189
if (ds_input->empty())
6808
if (ds_input.empty())
7190
6809
return; /* No input */
7192
unsigned long eol_pos= 0;
7194
eol_pos= ds_input->find_first_of('\n', 0);
6811
unsigned long eol_pos= ds_input.find_first_of('\n', 0);
7195
6812
if (eol_pos == string::npos)
7196
6813
return; // We should have at least one header here
7198
ds->append(ds_input->substr(0, eol_pos+1));
6815
ds.append(ds_input.substr(0, eol_pos+1));
7200
6817
unsigned long start_pos= eol_pos+1;
7202
6819
/* Insert line(s) in array */
7205
eol_pos= ds_input->find_first_of('\n', start_pos);
6822
eol_pos= ds_input.find_first_of('\n', start_pos);
7206
6823
/* Find end of line */
7207
lines.push(ds_input->substr(start_pos, eol_pos-start_pos+1));
6824
lines.push(ds_input.substr(start_pos, eol_pos-start_pos+1));
7208
6825
start_pos= eol_pos+1;
7210
6827
} while ( eol_pos != string::npos);
7212
6829
/* Create new result */
7213
while (!lines.empty()) {
7214
ds->append(lines.top());
6830
while (!lines.empty())
6832
ds.append(lines.top());
7221
6837
static void free_all_replace()