562
static void show_query(DRIZZLE *drizzle, const char* query)
561
static void show_query(drizzle_con_st *con, const char* query)
563
drizzle_result_st res;
564
drizzle_return_t ret;
570
if (drizzleclient_query(drizzle, query))
569
if (drizzle_query_str(con, &res, query, &ret) == NULL ||
570
ret != DRIZZLE_RETURN_OK)
572
log_msg("Error running query '%s': %d %s",
573
query, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
572
if (ret == DRIZZLE_RETURN_ERROR_CODE)
574
log_msg("Error running query '%s': %d %s",
575
query, drizzle_result_error_code(&res),
576
drizzle_result_error(&res));
577
drizzle_result_free(&res);
581
log_msg("Error running query '%s': %d %s",
582
query, ret, drizzle_con_error(con));
577
if ((res= drizzleclient_store_result(drizzle)) == NULL)
587
if (drizzle_result_column_count(&res) == 0 ||
588
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
579
590
/* No result set returned */
591
drizzle_result_free(&res);
586
598
unsigned int row_num= 0;
587
unsigned int num_fields= drizzleclient_num_fields(res);
588
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
599
unsigned int num_fields= drizzle_result_column_count(&res);
600
drizzle_column_st *column;
590
602
fprintf(stderr, "=== %s ===\n", query);
591
while ((row= drizzleclient_fetch_row(res)))
603
while ((row= drizzle_row_next(&res)))
593
uint32_t *lengths= drizzleclient_fetch_lengths(res);
605
size_t *lengths= drizzle_row_field_sizes(&res);
596
608
fprintf(stderr, "---- %d. ----\n", row_num);
609
drizzle_column_seek(&res, 0);
597
610
for(i= 0; i < num_fields; i++)
612
column= drizzle_column_next(&res);
599
613
fprintf(stderr, "%s\t%.*s\n",
614
drizzle_column_name(column),
601
615
(int)lengths[i], row[i] ? row[i] : "NULL");
627
static void show_warnings_before_error(DRIZZLE *drizzle)
641
static void show_warnings_before_error(drizzle_con_st *con)
643
drizzle_result_st res;
644
drizzle_return_t ret;
630
645
const char* query= "SHOW WARNINGS";
636
if (drizzleclient_query(drizzle, query))
650
if (drizzle_query_str(con, &res, query, &ret) == NULL ||
651
ret != DRIZZLE_RETURN_OK)
638
log_msg("Error running query '%s': %d %s",
639
query, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
653
if (ret == DRIZZLE_RETURN_ERROR_CODE)
655
log_msg("Error running query '%s': %d %s",
656
query, drizzle_result_error_code(&res),
657
drizzle_result_error(&res));
658
drizzle_result_free(&res);
662
log_msg("Error running query '%s': %d %s",
663
query, ret, drizzle_con_error(con));
643
if ((res= drizzleclient_store_result(drizzle)) == NULL)
668
if (drizzle_result_column_count(&res) == 0 ||
669
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
645
671
/* No result set returned */
672
drizzle_result_free(&res);
649
if (drizzleclient_num_rows(res) <= 1)
676
if (drizzle_result_row_count(&res) <= 1)
651
678
/* Don't display the last row, it's "last error" */
656
683
unsigned int row_num= 0;
657
unsigned int num_fields= drizzleclient_num_fields(res);
684
unsigned int num_fields= drizzle_result_column_count(&res);
659
686
fprintf(stderr, "\nWarnings from just before the error:\n");
660
while ((row= drizzleclient_fetch_row(res)))
687
while ((row= drizzle_row_next(&res)))
663
uint32_t *lengths= drizzleclient_fetch_lengths(res);
690
size_t *lengths= drizzle_row_field_sizes(&res);
665
if (++row_num >= drizzleclient_num_rows(res))
692
if (++row_num >= drizzle_result_row_count(&res))
667
694
/* Don't display the last row, it's "last error" */
1818
1847
/* Eval the query, thus replacing all environment variables */
1819
1848
do_eval(&ds_query, query, end, false);
1821
if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1822
die("Error running query '%s': %d %s", ds_query.c_str(),
1823
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
1824
if (!(res= drizzleclient_store_result(drizzle)))
1850
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(),
1852
ret != DRIZZLE_RETURN_OK)
1854
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1856
die("Error running query '%s': %d %s", ds_query.c_str(),
1857
drizzle_result_error_code(&res), drizzle_result_error(&res));
1858
drizzle_result_free(&res);
1862
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
1863
drizzle_con_error(con));
1866
if (drizzle_result_column_count(&res) == 0 ||
1867
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
1825
1868
die("Query '%s' didn't return a result set", ds_query.c_str());
1827
if ((row= drizzleclient_fetch_row(res)) && row[0])
1870
if ((row= drizzle_row_next(&res)) && row[0])
1830
1873
Concatenate all fields in the first row with tab in between
1913
1957
ds_query.append(unstripped_query);
1915
1959
/* Run the query */
1916
if (drizzleclient_real_query(drizzle, ds_query.c_str(), ds_query.length()))
1917
die("Error running query '%s': %d %s", ds_query.c_str(),
1918
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
1919
if (!(res= drizzleclient_store_result(drizzle)))
1960
if (drizzle_query(con, &res, ds_query.c_str(), ds_query.length(),
1962
ret != DRIZZLE_RETURN_OK)
1964
if (ret == DRIZZLE_RETURN_ERROR_CODE)
1966
die("Error running query '%s': %d %s", ds_query.c_str(),
1967
drizzle_result_error_code(&res), drizzle_result_error(&res));
1968
drizzle_result_free(&res);
1972
die("Error running query '%s': %d %s", ds_query.c_str(), ret,
1973
drizzle_con_error(con));
1976
if (drizzle_result_column_count(&res) == 0 ||
1977
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
1920
1978
die("Query '%s' didn't return a result set", ds_query.c_str());
1923
1981
/* Find column number from the given column name */
1925
uint32_t num_fields= drizzleclient_num_fields(res);
1926
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
1983
uint32_t num_fields= drizzle_result_column_count(&res);
1984
drizzle_column_st *column;
1928
1986
for (i= 0; i < num_fields; i++)
1930
if (strcmp(fields[i].name, ds_col.c_str()) == 0 &&
1931
strlen(fields[i].name) == ds_col.length())
1988
column= drizzle_column_next(&res);
1989
if (strcmp(drizzle_column_name(column), ds_col.c_str()) == 0 &&
1990
strlen(drizzle_column_name(column)) == ds_col.length())
2968
3030
do_wait_for_slave_to_stop(struct st_command *)
2970
3032
static int SLAVE_POLL_INTERVAL= 300000;
2971
DRIZZLE *drizzle= &cur_con->drizzle;
3033
drizzle_con_st *con= &cur_con->con;
2974
DRIZZLE_RES *res= NULL;
3036
drizzle_result_st res;
3037
drizzle_return_t ret;
2978
if (drizzleclient_query(drizzle,"show status like 'Slave_running'") ||
2979
!(res=drizzleclient_store_result(drizzle)))
3041
if (drizzle_query_str(con,&res,"show status like 'Slave_running'",
3042
&ret) == NULL || ret != DRIZZLE_RETURN_OK)
3044
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3046
die("Query failed while probing slave for stop: %s",
3047
drizzle_result_error(&res));
3048
drizzle_result_free(&res);
3052
die("Query failed while probing slave for stop: %s",
3053
drizzle_con_error(con));
3057
if (drizzle_result_column_count(&res) == 0 ||
3058
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
2980
3060
die("Query failed while probing slave for stop: %s",
2981
drizzleclient_error(drizzle));
2982
if (!(row=drizzleclient_fetch_row(res)) || !row[1])
3061
drizzle_con_error(con));
3064
if (!(row=drizzle_row_next(&res)) || !row[1])
2984
drizzleclient_free_result(res);
3066
drizzle_result_free(&res);
2985
3067
die("Strange result from query while probing slave for stop");
2987
3069
done = !strcmp(row[1],"OFF");
2988
drizzleclient_free_result(res);
3070
drizzle_result_free(&res);
2991
3073
usleep(SLAVE_POLL_INTERVAL);
3011
3094
wait_for_position:
3013
if (drizzleclient_query(drizzle, query_buf))
3014
die("failed in '%s': %d: %s", query_buf, drizzleclient_errno(drizzle),
3015
drizzleclient_error(drizzle));
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)))
3021
drizzleclient_free_result(res);
3096
if (drizzle_query_str(con, &res, query_buf, &ret) == NULL ||
3097
ret != DRIZZLE_RETURN_OK)
3099
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3101
die("failed in '%s': %d: %s", query_buf, drizzle_result_error_code(&res),
3102
drizzle_result_error(&res));
3103
drizzle_result_free(&res);
3106
die("failed in '%s': %d: %s", query_buf, ret, drizzle_con_error(con));
3109
if (drizzle_result_column_count(&res) == 0 ||
3110
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3111
die("drizzle_result_buffer() returned NULL for '%s'", query_buf);
3113
if (!(row= drizzle_row_next(&res)))
3115
drizzle_result_free(&res);
3022
3116
die("empty result in %s", query_buf);
3027
3121
It may be that the slave SQL thread has not started yet, though START
3028
3122
SLAVE has been issued ?
3030
drizzleclient_free_result(res);
3124
drizzle_result_free(&res);
3031
3125
if (tries++ == 30)
3033
show_query(drizzle, "SHOW MASTER STATUS");
3034
show_query(drizzle, "SHOW SLAVE STATUS");
3127
show_query(con, "SHOW MASTER STATUS");
3128
show_query(con, "SHOW SLAVE STATUS");
3035
3129
die("could not sync with master ('%s' returned NULL)", query_buf);
3037
3131
sleep(1); /* So at most we will wait 30 seconds and make 31 tries */
3038
3132
goto wait_for_position;
3040
drizzleclient_free_result(res);
3134
drizzle_result_free(&res);
3068
3162
static int do_save_master_pos(void)
3072
DRIZZLE *drizzle= &cur_con->drizzle;
3164
drizzle_result_st res;
3165
drizzle_return_t ret;
3167
drizzle_con_st *con= &cur_con->con;
3073
3168
const char *query;
3076
if (drizzleclient_query(drizzle, query= "show master status"))
3077
die("failed in 'show master status': %d %s",
3078
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3171
if (drizzle_query_str(con, &res, query= "show master status", &ret) == NULL ||
3172
ret != DRIZZLE_RETURN_OK)
3174
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3176
die("failed in '%s': %d: %s", query, drizzle_result_error_code(&res),
3177
drizzle_result_error(&res));
3178
drizzle_result_free(&res);
3181
die("failed in '%s': %d: %s", query, ret, drizzle_con_error(con));
3080
if (!(res = drizzleclient_store_result(drizzle)))
3184
if (drizzle_result_column_count(&res) == 0 ||
3185
drizzle_result_buffer(&res) != DRIZZLE_RETURN_OK)
3081
3186
die("drizzleclient_store_result() retuned NULL for '%s'", query);
3082
if (!(row = drizzleclient_fetch_row(res)))
3187
if (!(row = drizzle_row_next(&res)))
3083
3188
die("empty result in show master status");
3084
3189
strncpy(master_pos.file, row[0], sizeof(master_pos.file)-1);
3085
3190
master_pos.pos = strtoul(row[1], (char**) 0, 10);
3086
drizzleclient_free_result(res);
3191
drizzle_result_free(&res);
3288
3393
SQLSTATE string
3289
- Must be SQLSTATE_LENGTH long
3394
- Must be DRIZZLE_MAX_SQLSTATE_SIZE long
3290
3395
- May contain only digits[0-9] and _uppercase_ letters
3292
3397
p++; /* Step past the S */
3293
if ((end - p) != SQLSTATE_LENGTH)
3294
die("The sqlstate must be exactly %d chars long", SQLSTATE_LENGTH);
3398
if ((end - p) != DRIZZLE_MAX_SQLSTATE_SIZE)
3399
die("The sqlstate must be exactly %d chars long", DRIZZLE_MAX_SQLSTATE_SIZE);
3296
3401
/* Check sqlstate string validity */
3297
3402
while (*p && p < end)
3559
static void safe_connect(DRIZZLE *drizzle, const char *name, const char *host,
3560
const char *user, const char *pass, const char *db,
3657
static void safe_connect(drizzle_con_st *con, const char *name,
3658
const char *host, const char *user, const char *pass,
3659
const char *db, int port)
3563
3661
int failed_attempts= 0;
3564
3662
static uint32_t connection_retry_sleep= 100000; /* Microseconds */
3567
while(!drizzleclient_connect(drizzle, host, user, pass, db, port, NULL,
3568
CLIENT_MULTI_STATEMENTS | CLIENT_REMEMBER_OPTIONS))
3663
drizzle_return_t ret;
3665
drizzle_con_set_tcp(con, host, port);
3666
drizzle_con_set_auth(con, user, pass);
3667
drizzle_con_set_db(con, db);
3668
while((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
3575
3675
on protocol/connection type
3578
if ((drizzleclient_errno(drizzle) == CR_CONN_HOST_ERROR ||
3579
drizzleclient_errno(drizzle) == CR_CONNECTION_ERROR) &&
3678
if ((ret == DRIZZLE_RETURN_GETADDRINFO ||
3679
ret == DRIZZLE_RETURN_COULD_NOT_CONNECT) &&
3580
3680
failed_attempts < opt_max_connect_retries)
3582
3682
verbose_msg("Connect attempt %d/%d failed: %d: %s", failed_attempts,
3583
opt_max_connect_retries, drizzleclient_errno(drizzle),
3584
drizzleclient_error(drizzle));
3683
opt_max_connect_retries, ret, drizzle_con_error(con));
3585
3684
usleep(connection_retry_sleep);
3589
3688
if (failed_attempts > 0)
3590
3689
die("Could not open connection '%s' after %d attempts: %d %s", name,
3591
failed_attempts, drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3690
failed_attempts, ret, drizzle_con_error(con));
3593
die("Could not open connection '%s': %d %s", name,
3594
drizzleclient_errno(drizzle), drizzleclient_error(drizzle));
3692
die("Could not open connection '%s': %d %s", name, ret,
3693
drizzle_con_error(con));
3596
3695
failed_attempts++;
3625
3724
static int connect_n_handle_errors(struct st_command *command,
3626
DRIZZLE *con, const char* host,
3725
drizzle_con_st *con, const char* host,
3627
3726
const char* user, const char* pass,
3628
3727
const char* db, int port, const char* sock)
3729
drizzle_return_t ret;
3631
3731
/* Only log if an error is expected */
3632
3732
if (!command->abort_on_error &&
3653
3753
ds_res.append(delimiter);
3654
3754
ds_res.append("\n");
3656
if (!drizzleclient_connect(con, host, user, pass, db, port, 0,
3657
CLIENT_MULTI_STATEMENTS))
3756
drizzle_con_set_tcp(con, host, port);
3757
drizzle_con_set_auth(con, user, pass);
3758
drizzle_con_set_db(con, db);
3759
if ((ret= drizzle_con_connect(con)) != DRIZZLE_RETURN_OK)
3659
var_set_errno(drizzleclient_errno(con));
3660
handle_error(command, drizzleclient_errno(con), drizzleclient_error(con),
3661
drizzleclient_sqlstate(con), &ds_res);
3761
if (ret == DRIZZLE_RETURN_ERROR_CODE)
3763
var_set_errno(drizzle_con_error_code(con));
3764
handle_error(command, drizzle_con_error_code(con), drizzle_con_error(con),
3765
drizzle_con_sqlstate(con), &ds_res);
3770
handle_error(command, ret, drizzle_con_error(con), "", &ds_res);
3662
3773
return 0; /* Not connected */
3786
3897
(int) (sizeof(connections)/sizeof(struct st_connection)));
3789
if (!drizzleclient_create(&con_slot->drizzle))
3790
die("Failed on drizzleclient_create()");
3791
if (opt_compress || con_compress)
3792
drizzleclient_options(&con_slot->drizzle, DRIZZLE_OPT_COMPRESS, NULL);
3900
if ((con_slot->drizzle= drizzle_create(NULL)) == NULL)
3901
die("Failed on drizzle_create()");
3902
if (!drizzle_con_create(con_slot->drizzle, &con_slot->con))
3903
die("Failed on drizzle_con_create()");
3795
3905
/* Use default db name */
3796
3906
if (ds_database.length() == 0)
3800
3910
if (ds_database.length() && !strcmp(ds_database.c_str(),"*NO-ONE*"))
3801
3911
ds_database.clear();
3803
if (connect_n_handle_errors(command, &con_slot->drizzle,
3913
if (connect_n_handle_errors(command, &con_slot->con,
3804
3914
ds_host.c_str(),ds_user.c_str(),
3805
3915
ds_password.c_str(), ds_database.c_str(),
3806
3916
con_port, ds_sock.c_str()))
4816
4926
Values may be converted with 'replace_column'
4819
static void append_result(string *ds, DRIZZLE_RES *res)
4929
static void append_result(string *ds, drizzle_result_st *res)
4822
uint32_t num_fields= drizzleclient_num_fields(res);
4823
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
4932
uint32_t num_fields= drizzle_result_column_count(res);
4933
drizzle_column_st *column;
4826
while ((row = drizzleclient_fetch_row(res)))
4936
while ((row = drizzle_row_next(res)))
4829
lengths = drizzleclient_fetch_lengths(res);
4939
lengths = drizzle_row_field_sizes(res);
4940
drizzle_column_seek(res, 0);
4830
4941
for (i = 0; i < num_fields; i++)
4831
append_field(ds, i, &fields[i],
4943
column= drizzle_column_next(res);
4944
append_field(ds, i, column,
4832
4945
(const char*)row[i], lengths[i], !row[i]);
4833
4947
if (!display_result_vertically)
4834
4948
ds->append("\n");
4841
4955
Append metadata for fields to output
4844
static void append_metadata(string *ds,
4845
const DRIZZLE_FIELD *field,
4846
uint32_t num_fields)
4958
static void append_metadata(string *ds, drizzle_result_st *res)
4848
const DRIZZLE_FIELD *field_end;
4960
drizzle_column_st *column;
4849
4961
ds->append("Catalog\tDatabase\tTable\tTable_alias\tColumn\t"
4850
4962
"Column_alias\tType\tLength\tMax length\tIs_null\t"
4851
4963
"Flags\tDecimals\tCharsetnr\n");
4853
for (field_end= field+num_fields ;
4965
drizzle_column_seek(res, 0);
4966
while ((column= drizzle_column_next(res)))
4857
ds->append(field->catalog,
4858
field->catalog_length);
4859
ds->append("\t", 1);
4860
ds->append(field->db, field->db_length);
4861
ds->append("\t", 1);
4862
ds->append(field->org_table,
4863
field->org_table_length);
4864
ds->append("\t", 1);
4865
ds->append(field->table,
4866
field->table_length);
4867
ds->append("\t", 1);
4868
ds->append(field->org_name,
4869
field->org_name_length);
4870
ds->append("\t", 1);
4871
ds->append(field->name, field->name_length);
4872
ds->append("\t", 1);
4873
replace_append_uint(ds, field->type);
4874
ds->append("\t", 1);
4875
replace_append_uint(ds, field->length);
4876
ds->append("\t", 1);
4877
replace_append_uint(ds, field->max_length);
4878
ds->append("\t", 1);
4879
ds->append((char*) ((field->flags & NOT_NULL_FLAG) ?
4881
ds->append("\t", 1);
4882
replace_append_uint(ds, field->flags);
4883
ds->append("\t", 1);
4884
replace_append_uint(ds, field->decimals);
4885
ds->append("\t", 1);
4886
replace_append_uint(ds, field->charsetnr);
4968
ds->append(drizzle_column_catalog(column),
4969
strlen(drizzle_column_catalog(column)));
4970
ds->append("\t", 1);
4971
ds->append(drizzle_column_db(column), strlen(drizzle_column_db(column)));
4972
ds->append("\t", 1);
4973
ds->append(drizzle_column_orig_table(column),
4974
strlen(drizzle_column_orig_table(column)));
4975
ds->append("\t", 1);
4976
ds->append(drizzle_column_table(column),
4977
strlen(drizzle_column_table(column)));
4978
ds->append("\t", 1);
4979
ds->append(drizzle_column_orig_name(column),
4980
strlen(drizzle_column_orig_name(column)));
4981
ds->append("\t", 1);
4982
ds->append(drizzle_column_name(column),
4983
strlen(drizzle_column_name(column)));
4984
ds->append("\t", 1);
4985
replace_append_uint(ds, drizzle_column_type_drizzle(column));
4986
ds->append("\t", 1);
4987
replace_append_uint(ds, drizzle_column_size(column));
4988
ds->append("\t", 1);
4989
replace_append_uint(ds, drizzle_column_max_size(column));
4990
ds->append("\t", 1);
4991
ds->append((char*) ((drizzle_column_flags(column) & DRIZZLE_COLUMN_FLAGS_NOT_NULL) ? "N" : "Y"), 1);
4992
ds->append("\t", 1);
4993
replace_append_uint(ds, drizzle_column_flags(column));
4994
ds->append("\t", 1);
4995
replace_append_uint(ds, drizzle_column_decimals(column));
4996
ds->append("\t", 1);
4997
replace_append_uint(ds, drizzle_column_charset(column));
4887
4998
ds->append("\n", 1);
4912
5023
Display the table headings with the names tab separated
4915
static void append_table_headings(string *ds,
4916
const DRIZZLE_FIELD *field,
4917
uint32_t num_fields)
5026
static void append_table_headings(string *ds, drizzle_result_st *res)
4920
for (col_idx= 0; col_idx < num_fields; col_idx++)
5028
uint32_t col_idx= 0;
5029
drizzle_column_st *column;
5030
drizzle_column_seek(res, 0);
5031
while ((column= drizzle_column_next(res)))
4923
5034
ds->append("\t", 1);
4924
replace_append(ds, field[col_idx].name);
5035
replace_append(ds, drizzle_column_name(column));
4926
5038
ds->append("\n", 1);
4933
5045
Number of warnings appended to ds
4936
static int append_warnings(string *ds, DRIZZLE *drizzle)
5048
static int append_warnings(string *ds, drizzle_con_st *con,
5049
drizzle_result_st *res)
4938
5051
uint32_t count;
4939
DRIZZLE_RES *warn_res;
4942
if (!(count= drizzleclient_warning_count(drizzle)))
5052
drizzle_result_st warn_res;
5053
drizzle_return_t ret;
5056
if (!(count= drizzle_result_warning_count(res)))
4946
If one day we will support execution of multi-statements
4947
through PS API we should not issue SHOW WARNINGS until
4948
we have not read all results...
4950
assert(!drizzleclient_more_results(drizzle));
4952
if (drizzleclient_real_query(drizzle, "SHOW WARNINGS", 13))
4953
die("Error running query \"SHOW WARNINGS\": %s", drizzleclient_error(drizzle));
4955
if (!(warn_res= drizzleclient_store_result(drizzle)))
4956
die("Warning count is %u but didn't get any warnings",
4959
append_result(ds, warn_res);
5059
if (drizzle_query_str(con, &warn_res, "SHOW WARNINGS", &ret) == NULL ||
5060
ret != DRIZZLE_RETURN_OK)
5062
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5063
die("Error running query \"SHOW WARNINGS\": %s", drizzle_result_error(&warn_res));
5065
die("Error running query \"SHOW WARNINGS\": %s", drizzle_con_error(con));
5068
if (drizzle_result_column_count(&warn_res) == 0 ||
5069
drizzle_result_buffer(&warn_res) != DRIZZLE_RETURN_OK)
5070
die("Warning count is %u but didn't get any warnings", count);
5072
append_result(ds, &warn_res);
5073
drizzle_result_free(&warn_res);
4980
5094
int flags, char *query, int query_len,
4981
5095
string *ds, string *ds_warnings)
4983
DRIZZLE_RES *res= 0;
4984
DRIZZLE *drizzle= &cn->drizzle;
4985
int err= 0, counter= 0;
5097
drizzle_result_st res;
5098
drizzle_return_t ret;
5099
drizzle_con_st *con= &cn->con;
5102
drizzle_con_add_options(con, DRIZZLE_CON_NO_RESULT_READ);
4987
5104
if (flags & QUERY_SEND_FLAG)
4990
5107
* Send the query
4992
if (do_send_query(cn, query, query_len, flags))
5110
(void) drizzle_query(con, &res, query, query_len, &ret);
5111
if (ret != DRIZZLE_RETURN_OK)
4994
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
4995
drizzleclient_sqlstate(drizzle), ds);
5113
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5115
err= drizzle_result_error_code(&res);
5116
handle_error(command, err, drizzle_result_error(&res),
5117
drizzle_result_sqlstate(&res), ds);
5118
drizzle_result_free(&res);
5122
handle_error(command, ret, drizzle_con_error(con), "", ds);
4999
5128
if (!(flags & QUERY_REAP_FLAG))
5005
When on first result set, call drizzleclient_read_query_result to retrieve
5006
answer to the query sent earlier
5008
if ((counter==0) && drizzleclient_read_query_result(drizzle))
5133
* Read the result packet
5135
if (drizzle_result_read(con, &res, &ret) == NULL ||
5136
ret != DRIZZLE_RETURN_OK)
5010
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5011
drizzleclient_sqlstate(drizzle), ds);
5138
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5140
handle_error(command, drizzle_result_error_code(&res),
5141
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
5145
handle_error(command, ret, drizzle_con_error(con), "", ds);
5146
drizzle_result_free(&res);
5017
5152
Store the result of the query if it will return any fields
5019
if (drizzleclient_field_count(drizzle) && ((res= drizzleclient_store_result(drizzle)) == 0))
5154
if (drizzle_result_column_count(&res) &&
5155
(ret= drizzle_result_buffer(&res)) != DRIZZLE_RETURN_OK)
5021
handle_error(command, drizzleclient_errno(drizzle), drizzleclient_error(drizzle),
5022
drizzleclient_sqlstate(drizzle), ds);
5157
if (ret == DRIZZLE_RETURN_ERROR_CODE)
5159
handle_error(command, drizzle_result_error_code(&res),
5160
drizzle_result_error(&res), drizzle_result_sqlstate(&res),
5164
handle_error(command, ret, drizzle_con_error(con), "", ds);
5165
drizzle_result_free(&res);
5028
5172
uint64_t affected_rows= 0; /* Ok to be undef if 'disable_info' is set */
5174
if (drizzle_result_column_count(&res))
5032
const DRIZZLE_FIELD *fields= drizzleclient_fetch_fields(res);
5033
uint32_t num_fields= drizzleclient_num_fields(res);
5035
5176
if (display_metadata)
5036
append_metadata(ds, fields, num_fields);
5177
append_metadata(ds, &res);
5038
5179
if (!display_result_vertically)
5039
append_table_headings(ds, fields, num_fields);
5180
append_table_headings(ds, &res);
5041
append_result(ds, res);
5182
append_result(ds, &res);
5046
5187
query to find the warnings
5048
5189
if (!disable_info)
5049
affected_rows= drizzleclient_affected_rows(drizzle);
5190
affected_rows= drizzle_result_affected_rows(&res);
5052
5193
Add all warnings to the result. We can't do this if we are in
5053
5194
the middle of processing results from multi-statement, because
5054
5195
this will break protocol.
5056
if (!disable_warnings && !drizzleclient_more_results(drizzle))
5197
if (!disable_warnings)
5058
if (append_warnings(ds_warnings, drizzle) || ds_warnings->length())
5199
drizzle_con_remove_options(con, DRIZZLE_CON_NO_RESULT_READ);
5200
if (append_warnings(ds_warnings, con, &res) || ds_warnings->length())
5060
5202
ds->append("Warnings:\n", 10);
5061
5203
ds->append(ds_warnings->c_str(), ds_warnings->length());
5065
5207
if (!disable_info)
5066
append_info(ds, affected_rows, drizzleclient_info(drizzle));
5208
append_info(ds, affected_rows, drizzle_result_info(&res));
5071
drizzleclient_free_result(res);
5075
} while (!(err= drizzleclient_next_result(drizzle)));
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);
5211
drizzle_result_free(&res);
5083
assert(err == -1); /* Successful and there are no more results */
5085
5214
/* If we come here the query is both executed and read successfully */
5086
5215
handle_no_error(command);
5520
5649
cur_file->lineno= 1;
5522
5651
cur_con= connections;
5523
if (!( drizzleclient_create(&cur_con->drizzle)))
5524
die("Failed in drizzleclient_create()");
5526
drizzleclient_options(&cur_con->drizzle,DRIZZLE_OPT_COMPRESS,NULL);
5652
if ((cur_con->drizzle= drizzle_create(NULL)) == NULL)
5653
die("Failed in drizzle_create()");
5654
if (!( drizzle_con_create(cur_con->drizzle, &cur_con->con)))
5655
die("Failed in drizzle_con_create()");
5528
5657
if (!(cur_con->name = strdup("default")))
5529
5658
die("Out of memory");
5531
safe_connect(&cur_con->drizzle, cur_con->name, opt_host, opt_user, opt_pass,
5660
safe_connect(&cur_con->con, cur_con->name, opt_host, opt_user, opt_pass,
5532
5661
opt_db, opt_port);
5534
5663
/* Use all time until exit if no explicit 'start_timer' */