396
cli_advanced_command(MYSQL *mysql, enum enum_server_command command,
397
const unsigned char *header, uint32_t header_length,
398
const unsigned char *arg, uint32_t arg_length, bool skip_check)
396
cli_advanced_command(DRIZZLE *drizzle, enum enum_server_command command,
397
const unsigned char *header, uint32_t header_length,
398
const unsigned char *arg, uint32_t arg_length, bool skip_check)
400
NET *net= &mysql->net;
400
NET *net= &drizzle->net;
401
401
my_bool result= 1;
402
402
init_sigpipe_variables
403
403
my_bool stmt_skip= false;
405
405
/* Don't give sigpipe errors if the client doesn't want them */
406
set_sigpipe(drizzle);
408
if (mysql->net.vio == 0)
409
{ /* Do reconnect if possible */
410
if (mysql_reconnect(mysql) || stmt_skip)
408
if (drizzle->net.vio == 0)
409
{ /* Do reconnect if possible */
410
if (drizzle_reconnect(drizzle) || stmt_skip)
413
if (mysql->status != MYSQL_STATUS_READY ||
414
mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
413
if (drizzle->status != DRIZZLE_STATUS_READY ||
414
drizzle->server_status & SERVER_MORE_RESULTS_EXISTS)
416
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
416
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
420
420
net_clear_error(net);
422
mysql->affected_rows= ~(uint64_t) 0;
422
drizzle->affected_rows= ~(uint64_t) 0;
424
424
We don't want to clear the protocol buffer on COM_QUIT, because if
425
425
the previous command was a shutdown command, we may have the
426
426
response for the COM_QUIT already in the communication buffer
428
net_clear(&mysql->net, (command != COM_QUIT));
428
net_clear(&drizzle->net, (command != COM_QUIT));
430
430
if (net_write_command(net,(uchar) command, header, header_length,
433
433
if (net->last_errno == ER_NET_PACKET_TOO_LARGE)
435
set_mysql_error(mysql, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
435
set_drizzle_error(drizzle, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
439
if (mysql_reconnect(mysql) || stmt_skip)
439
if (drizzle_reconnect(drizzle) || stmt_skip)
441
441
if (net_write_command(net,(uchar) command, header, header_length,
444
set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate);
444
set_drizzle_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
450
result= ((mysql->packet_length=cli_safe_read(mysql)) == packet_error ?
450
result= ((drizzle->packet_length=cli_safe_read(drizzle)) == packet_error ?
453
reset_sigpipe(mysql);
453
reset_sigpipe(drizzle);
457
void free_old_query(MYSQL *mysql)
457
void free_old_query(DRIZZLE *drizzle)
460
free_root(&mysql->field_alloc,MYF(0));
461
init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */
463
mysql->field_count= 0; /* For API */
464
mysql->warning_count= 0;
460
free_root(&drizzle->field_alloc,MYF(0));
461
init_alloc_root(&drizzle->field_alloc,8192,0); /* Assume rowlength < 8192 */
463
drizzle->field_count= 0; /* For API */
464
drizzle->warning_count= 0;
600
600
groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0;
602
602
load_defaults(filename, groups, &argc, &argv);
603
if (argc != 1) /* If some default option */
603
if (argc != 1) /* If some default option */
605
605
char **option=argv;
606
606
while (*++option)
608
608
if (option[0][0] == '-' && option[0][1] == '-')
610
char *end=strcend(*option,'=');
615
*end=0; /* Remove '=' */
617
/* Change all '_' in variable name to '-' */
618
for (end= *option ; *(end= strcend(end,'_')) ; )
620
switch (find_type(*option+2,&option_types,2)) {
623
options->port=atoi(opt_arg);
628
my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR));
629
options->unix_socket=my_strdup(opt_arg,MYF(MY_WME));
632
case 3: /* compress */
634
options->client_flag|= CLIENT_COMPRESS;
636
case 4: /* password */
639
my_free(options->password,MYF(MY_ALLOW_ZERO_PTR));
640
options->password=my_strdup(opt_arg,MYF(MY_WME));
610
char *end=strcend(*option,'=');
615
*end=0; /* Remove '=' */
617
/* Change all '_' in variable name to '-' */
618
for (end= *option ; *(end= strcend(end,'_')) ; )
620
switch (find_type(*option+2,&option_types,2)) {
623
options->port=atoi(opt_arg);
628
my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR));
629
options->unix_socket=my_strdup(opt_arg,MYF(MY_WME));
632
case 3: /* compress */
634
options->client_flag|= CLIENT_COMPRESS;
636
case 4: /* password */
639
my_free(options->password,MYF(MY_ALLOW_ZERO_PTR));
640
options->password=my_strdup(opt_arg,MYF(MY_WME));
644
options->protocol = MYSQL_PROTOCOL_PIPE;
645
case 20: /* connect_timeout */
646
case 6: /* timeout */
648
options->connect_timeout=atoi(opt_arg);
653
my_free(options->user,MYF(MY_ALLOW_ZERO_PTR));
654
options->user=my_strdup(opt_arg,MYF(MY_WME));
657
case 8: /* init-command */
658
add_init_command(options,opt_arg);
663
my_free(options->host,MYF(MY_ALLOW_ZERO_PTR));
664
options->host=my_strdup(opt_arg,MYF(MY_WME));
667
case 10: /* database */
670
my_free(options->db,MYF(MY_ALLOW_ZERO_PTR));
671
options->db=my_strdup(opt_arg,MYF(MY_WME));
674
case 12: /* return-found-rows */
675
options->client_flag|=CLIENT_FOUND_ROWS;
677
case 13: /* Ignore SSL options */
644
options->protocol = DRIZZLE_PROTOCOL_PIPE;
645
case 20: /* connect_timeout */
646
case 6: /* timeout */
648
options->connect_timeout=atoi(opt_arg);
653
my_free(options->user,MYF(MY_ALLOW_ZERO_PTR));
654
options->user=my_strdup(opt_arg,MYF(MY_WME));
657
case 8: /* init-command */
658
add_init_command(options,opt_arg);
663
my_free(options->host,MYF(MY_ALLOW_ZERO_PTR));
664
options->host=my_strdup(opt_arg,MYF(MY_WME));
667
case 10: /* database */
670
my_free(options->db,MYF(MY_ALLOW_ZERO_PTR));
671
options->db=my_strdup(opt_arg,MYF(MY_WME));
674
case 12: /* return-found-rows */
675
options->client_flag|=CLIENT_FOUND_ROWS;
677
case 13: /* Ignore SSL options */
683
case 17: /* charset-lib */
684
my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR));
683
case 17: /* charset-lib */
684
my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR));
685
685
options->charset_dir = my_strdup(opt_arg, MYF(MY_WME));
688
my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR));
688
my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR));
689
689
options->charset_name = my_strdup(opt_arg, MYF(MY_WME));
691
case 19: /* Interactive-timeout */
692
options->client_flag|= CLIENT_INTERACTIVE;
695
if (!opt_arg || atoi(opt_arg) != 0)
696
options->client_flag|= CLIENT_LOCAL_FILES;
698
options->client_flag&= ~CLIENT_LOCAL_FILES;
701
options->client_flag&= ~CLIENT_LOCAL_FILES;
691
case 19: /* Interactive-timeout */
692
options->client_flag|= CLIENT_INTERACTIVE;
695
if (!opt_arg || atoi(opt_arg) != 0)
696
options->client_flag|= CLIENT_LOCAL_FILES;
698
options->client_flag&= ~CLIENT_LOCAL_FILES;
701
options->client_flag&= ~CLIENT_LOCAL_FILES;
703
case 24: /* max-allowed-packet */
703
case 24: /* max-allowed-packet */
705
options->max_allowed_packet= atoi(opt_arg);
705
options->max_allowed_packet= atoi(opt_arg);
707
707
case 25: /* protocol */
708
708
if ((options->protocol= find_type(opt_arg,
709
&sql_protocol_typelib,0)) <= 0)
709
&sql_protocol_typelib,0)) <= 0)
711
711
fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg);
1061
1061
#if defined(ENABLED_LOCAL_INFILE) && !defined(MYSQL_SERVER)
1062
mysql->options.client_flag|= CLIENT_LOCAL_FILES;
1062
drizzle->options.client_flag|= CLIENT_LOCAL_FILES;
1065
1065
#ifdef HAVE_SMEM
1066
mysql->options.shared_memory_base_name= (char*) def_shared_memory_base_name;
1066
drizzle->options.shared_memory_base_name= (char*) def_shared_memory_base_name;
1069
mysql->options.methods_to_use= MYSQL_OPT_GUESS_CONNECTION;
1070
mysql->options.report_data_truncation= true; /* default */
1069
drizzle->options.methods_to_use= DRIZZLE_OPT_GUESS_CONNECTION;
1070
drizzle->options.report_data_truncation= true; /* default */
1073
1073
By default we don't reconnect because it could silently corrupt data (after
1074
1074
reconnection you potentially lose table locks, user variables, session
1075
1075
variables (transactions but they are specifically dealt with in
1077
This is a change: < 5.0.3 mysql->reconnect was set to 1 by default.
1076
drizzle_reconnect()).
1077
This is a change: < 5.0.3 drizzle->reconnect was set to 1 by default.
1078
1078
How this change impacts existing apps:
1079
1079
- existing apps which relyed on the default will see a behaviour change;
1080
they will have to set reconnect=1 after mysql_real_connect().
1080
they will have to set reconnect=1 after drizzle_connect().
1081
1081
- existing apps which explicitely asked for reconnection (the only way they
1082
could do it was by setting mysql.reconnect to 1 after mysql_real_connect())
1082
could do it was by setting drizzle.reconnect to 1 after drizzle_connect())
1083
1083
will not see a behaviour change.
1084
1084
- existing apps which explicitely asked for no reconnection
1085
(mysql.reconnect=0) will not see a behaviour change.
1085
(drizzle.reconnect=0) will not see a behaviour change.
1087
mysql->reconnect= 0;
1087
drizzle->reconnect= 0;
1094
Fill in SSL part of MYSQL structure and set 'use_ssl' flag.
1095
NB! Errors are not reported until you do mysql_real_connect.
1094
Fill in SSL part of DRIZZLE structure and set 'use_ssl' flag.
1095
NB! Errors are not reported until you do drizzle_connect.
1098
1098
#define strdup_if_not_null(A) (A) == 0 ? 0 : my_strdup((A),MYF(MY_WME))
1101
Note that the mysql argument must be initialized with mysql_init()
1102
before calling mysql_real_connect !
1101
Note that the drizzle argument must be initialized with drizzle_init()
1102
before calling drizzle_connect !
1105
static bool cli_read_query_result(MYSQL *mysql);
1106
static MYSQL_RES *cli_use_result(MYSQL *mysql);
1105
static bool cli_read_query_result(DRIZZLE *drizzle);
1106
static DRIZZLE_RES *cli_use_result(DRIZZLE *drizzle);
1108
static MYSQL_METHODS client_methods=
1108
static DRIZZLE_METHODS client_methods=
1110
1110
cli_read_query_result, /* read_query_result */
1111
1111
cli_advanced_command, /* advanced_command */
1128
int mysql_init_character_set(MYSQL *mysql)
1128
int drizzle_init_character_set(DRIZZLE *drizzle)
1130
1130
const char *default_collation_name;
1132
1132
/* Set character set */
1133
if (!mysql->options.charset_name)
1133
if (!drizzle->options.charset_name)
1135
1135
default_collation_name= MYSQL_DEFAULT_COLLATION_NAME;
1136
if (!(mysql->options.charset_name=
1136
if (!(drizzle->options.charset_name=
1137
1137
my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME))))
1141
1141
default_collation_name= NULL;
1144
1144
const char *save= charsets_dir;
1145
if (mysql->options.charset_dir)
1146
charsets_dir=mysql->options.charset_dir;
1147
mysql->charset=get_charset_by_csname(mysql->options.charset_name,
1145
if (drizzle->options.charset_dir)
1146
charsets_dir=drizzle->options.charset_dir;
1147
drizzle->charset=get_charset_by_csname(drizzle->options.charset_name,
1148
1148
MY_CS_PRIMARY, MYF(MY_WME));
1149
if (mysql->charset && default_collation_name)
1149
if (drizzle->charset && default_collation_name)
1151
1151
CHARSET_INFO *collation;
1153
1153
get_charset_by_name(default_collation_name, MYF(MY_WME))))
1155
if (!my_charset_same(mysql->charset, collation))
1155
if (!my_charset_same(drizzle->charset, collation))
1157
my_printf_error(ER_UNKNOWN_ERROR,
1157
my_printf_error(ER_UNKNOWN_ERROR,
1158
1158
"COLLATION %s is not valid for CHARACTER SET %s",
1160
default_collation_name, mysql->options.charset_name);
1161
mysql->charset= NULL;
1160
default_collation_name, drizzle->options.charset_name);
1161
drizzle->charset= NULL;
1165
mysql->charset= collation;
1165
drizzle->charset= collation;
1169
mysql->charset= NULL;
1169
drizzle->charset= NULL;
1171
1171
charsets_dir= save;
1174
if (!mysql->charset)
1174
if (!drizzle->charset)
1176
if (mysql->options.charset_dir)
1177
set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
1176
if (drizzle->options.charset_dir)
1177
set_drizzle_extended_error(drizzle, CR_CANT_READ_CHARSET, unknown_sqlstate,
1178
1178
ER(CR_CANT_READ_CHARSET),
1179
mysql->options.charset_name,
1180
mysql->options.charset_dir);
1179
drizzle->options.charset_name,
1180
drizzle->options.charset_dir);
1183
1183
char cs_dir_name[FN_REFLEN];
1184
1184
get_charsets_dir(cs_dir_name);
1185
set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
1185
set_drizzle_extended_error(drizzle, CR_CANT_READ_CHARSET, unknown_sqlstate,
1186
1186
ER(CR_CANT_READ_CHARSET),
1187
mysql->options.charset_name,
1187
drizzle->options.charset_name,
1198
CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
1198
CLI_DRIZZLE_CONNECT(DRIZZLE *drizzle,const char *host, const char *user,
1199
1199
const char *passwd, const char *db,
1200
1200
uint32_t port, const char *unix_socket, uint32_t client_flag)
1202
1202
char buff[NAME_LEN+USERNAME_LENGTH+100];
1203
1203
char *end,*host_info=NULL;
1204
1204
uint32_t pkt_length;
1205
NET *net= &mysql->net;
1205
NET *net= &drizzle->net;
1206
1206
struct sockaddr_un UNIXaddr;
1207
1207
init_sigpipe_variables
1209
1209
/* Don't give sigpipe errors if the client doesn't want them */
1211
mysql->methods= &client_methods;
1212
net->vio = 0; /* If something goes wrong */
1213
mysql->client_flag=0; /* For handshake */
1210
set_sigpipe(drizzle);
1211
drizzle->methods= &client_methods;
1212
net->vio = 0; /* If something goes wrong */
1213
drizzle->client_flag=0; /* For handshake */
1215
1215
/* use default options */
1216
if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
1216
if (drizzle->options.my_cnf_file || drizzle->options.my_cnf_group)
1218
mysql_read_default_options(&mysql->options,
1219
(mysql->options.my_cnf_file ?
1220
mysql->options.my_cnf_file : "my"),
1221
mysql->options.my_cnf_group);
1222
my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1223
my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1224
mysql->options.my_cnf_file=mysql->options.my_cnf_group=0;
1218
drizzle_read_default_options(&drizzle->options,
1219
(drizzle->options.my_cnf_file ?
1220
drizzle->options.my_cnf_file : "my"),
1221
drizzle->options.my_cnf_group);
1222
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1223
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1224
drizzle->options.my_cnf_file=drizzle->options.my_cnf_group=0;
1227
1227
/* Some empty-string-tests are done because of ODBC */
1228
1228
if (!host || !host[0])
1229
host=mysql->options.host;
1229
host=drizzle->options.host;
1230
1230
if (!user || !user[0])
1232
user=mysql->options.user;
1232
user=drizzle->options.user;
1238
passwd=mysql->options.password;
1238
passwd=drizzle->options.password;
1242
1242
if (!db || !db[0])
1243
db=mysql->options.db;
1243
db=drizzle->options.db;
1245
port=mysql->options.port;
1245
port=drizzle->options.port;
1246
1246
if (!unix_socket)
1247
unix_socket=mysql->options.unix_socket;
1247
unix_socket=drizzle->options.unix_socket;
1249
mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
1249
drizzle->server_status=SERVER_STATUS_AUTOCOMMIT;
1252
1252
Part 0: Grab a socket and connect it to the server
1254
1254
#if defined(HAVE_SMEM)
1255
if ((!mysql->options.protocol ||
1256
mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
1255
if ((!drizzle->options.protocol ||
1256
drizzle->options.protocol == DRIZZLE_PROTOCOL_MEMORY) &&
1257
1257
(!host || !strcmp(host,LOCAL_HOST)))
1259
if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) ==
1260
INVALID_HANDLE_VALUE)
1259
if ((create_shared_memory(drizzle,net, drizzle->options.connect_timeout)) ==
1260
INVALID_HANDLE_VALUE)
1262
if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY)
1262
if (drizzle->options.protocol == DRIZZLE_PROTOCOL_MEMORY)
1266
1266
Try also with PIPE or TCP/IP. Clear the error from
1451
1451
/* Check if version of protocol matches current one */
1453
mysql->protocol_version= net->read_pos[0];
1454
if (mysql->protocol_version != PROTOCOL_VERSION)
1453
drizzle->protocol_version= net->read_pos[0];
1454
if (drizzle->protocol_version != PROTOCOL_VERSION)
1456
set_mysql_extended_error(mysql, CR_VERSION_ERROR, unknown_sqlstate,
1457
ER(CR_VERSION_ERROR), mysql->protocol_version,
1456
set_drizzle_extended_error(drizzle, CR_VERSION_ERROR, unknown_sqlstate,
1457
ER(CR_VERSION_ERROR), drizzle->protocol_version,
1458
1458
PROTOCOL_VERSION);
1461
1461
end=strend((char*) net->read_pos+1);
1462
mysql->thread_id=uint4korr(end+1);
1462
drizzle->thread_id=uint4korr(end+1);
1465
1465
Scramble is split into two parts because old clients does not understand
1466
1466
long scrambles; here goes the first part.
1468
strmake(mysql->scramble, end, SCRAMBLE_LENGTH_323);
1468
strmake(drizzle->scramble, end, SCRAMBLE_LENGTH_323);
1469
1469
end+= SCRAMBLE_LENGTH_323+1;
1471
1471
if (pkt_length >= (uint) (end+1 - (char*) net->read_pos))
1472
mysql->server_capabilities=uint2korr(end);
1472
drizzle->server_capabilities=uint2korr(end);
1473
1473
if (pkt_length >= (uint) (end+18 - (char*) net->read_pos))
1475
1475
/* New protocol with 16 bytes to describe server characteristics */
1476
mysql->server_language=end[2];
1477
mysql->server_status=uint2korr(end+3);
1476
drizzle->server_language=end[2];
1477
drizzle->server_status=uint2korr(end+3);
1480
if (pkt_length >= (uint) (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 -
1480
if (pkt_length >= (uint) (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 -
1481
1481
(char *) net->read_pos))
1482
strmake(mysql->scramble+SCRAMBLE_LENGTH_323, end,
1482
strmake(drizzle->scramble+SCRAMBLE_LENGTH_323, end,
1483
1483
SCRAMBLE_LENGTH-SCRAMBLE_LENGTH_323);
1485
mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION;
1485
drizzle->server_capabilities&= ~CLIENT_SECURE_CONNECTION;
1487
if (mysql->options.secure_auth && passwd[0] &&
1488
!(mysql->server_capabilities & CLIENT_SECURE_CONNECTION))
1487
if (drizzle->options.secure_auth && passwd[0] &&
1488
!(drizzle->server_capabilities & CLIENT_SECURE_CONNECTION))
1490
set_mysql_error(mysql, CR_SECURE_AUTH, unknown_sqlstate);
1490
set_drizzle_error(drizzle, CR_SECURE_AUTH, unknown_sqlstate);
1494
if (mysql_init_character_set(mysql))
1494
if (drizzle_init_character_set(drizzle))
1497
1497
/* Save connection information */
1498
1498
if (!my_multi_malloc(MYF(0),
1499
&mysql->host_info, (uint) strlen(host_info)+1,
1500
&mysql->host, (uint) strlen(host)+1,
1501
&mysql->unix_socket,unix_socket ?
1502
(uint) strlen(unix_socket)+1 : (uint) 1,
1503
&mysql->server_version,
1504
(uint) (end - (char*) net->read_pos),
1506
!(mysql->user=my_strdup(user,MYF(0))) ||
1507
!(mysql->passwd=my_strdup(passwd,MYF(0))))
1499
&drizzle->host_info, (uint) strlen(host_info)+1,
1500
&drizzle->host, (uint) strlen(host)+1,
1501
&drizzle->unix_socket,unix_socket ?
1502
(uint) strlen(unix_socket)+1 : (uint) 1,
1503
&drizzle->server_version,
1504
(uint) (end - (char*) net->read_pos),
1506
!(drizzle->user=my_strdup(user,MYF(0))) ||
1507
!(drizzle->passwd=my_strdup(passwd,MYF(0))))
1509
set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1509
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
1512
strmov(mysql->host_info,host_info);
1513
strmov(mysql->host,host);
1512
strmov(drizzle->host_info,host_info);
1513
strmov(drizzle->host,host);
1514
1514
if (unix_socket)
1515
strmov(mysql->unix_socket,unix_socket);
1515
strmov(drizzle->unix_socket,unix_socket);
1517
mysql->unix_socket=0;
1518
strmov(mysql->server_version,(char*) net->read_pos+1);
1517
drizzle->unix_socket=0;
1518
strmov(drizzle->server_version,(char*) net->read_pos+1);
1522
1522
Part 2: format and send client info to the server for access check
1525
client_flag|=mysql->options.client_flag;
1525
client_flag|=drizzle->options.client_flag;
1526
1526
client_flag|=CLIENT_CAPABILITIES;
1527
1527
if (client_flag & CLIENT_MULTI_STATEMENTS)
1528
1528
client_flag|= CLIENT_MULTI_RESULTS;
1576
1576
*end++= '\0'; /* empty password */
1578
1578
/* Add database if needed */
1579
if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB))
1579
if (db && (drizzle->server_capabilities & CLIENT_CONNECT_WITH_DB))
1581
1581
end= strmake(end, db, NAME_LEN) + 1;
1582
mysql->db= my_strdup(db,MYF(MY_WME));
1582
drizzle->db= my_strdup(db,MYF(MY_WME));
1585
1585
/* Write authentication package */
1586
1586
if (my_net_write(net, (uchar*) buff, (size_t) (end-buff)) || net_flush(net))
1588
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
1588
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1589
1589
ER(CR_SERVER_LOST_EXTENDED),
1590
1590
"sending authentication information",
1596
1596
Part 3: Authorization data's been sent. Now server can reply with
1597
1597
OK-packet, or re-request scrambled password.
1600
if ((pkt_length=cli_safe_read(mysql)) == packet_error)
1600
if ((pkt_length=cli_safe_read(drizzle)) == packet_error)
1602
if (mysql->net.last_errno == CR_SERVER_LOST)
1603
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
1602
if (drizzle->net.last_errno == CR_SERVER_LOST)
1603
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1604
1604
ER(CR_SERVER_LOST_EXTENDED),
1605
1605
"reading authorization packet",
1610
if (client_flag & CLIENT_COMPRESS) /* We will use compression */
1610
if (client_flag & CLIENT_COMPRESS) /* We will use compression */
1611
1611
net->compress=1;
1614
if (db && mysql_select_db(mysql, db))
1614
if (db && drizzle_select_db(drizzle, db))
1616
if (mysql->net.last_errno == CR_SERVER_LOST)
1617
set_mysql_extended_error(mysql, CR_SERVER_LOST, unknown_sqlstate,
1616
if (drizzle->net.last_errno == CR_SERVER_LOST)
1617
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1618
1618
ER(CR_SERVER_LOST_EXTENDED),
1619
1619
"Setting intital database",
1624
if (mysql->options.init_commands)
1624
if (drizzle->options.init_commands)
1626
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
1626
DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1627
1627
char **ptr= (char**)init_commands->buffer;
1628
1628
char **end_command= ptr + init_commands->elements;
1630
my_bool reconnect=mysql->reconnect;
1630
my_bool reconnect=drizzle->reconnect;
1631
drizzle->reconnect=0;
1633
1633
for (; ptr < end_command; ptr++)
1636
if (mysql_real_query(mysql,*ptr, (ulong) strlen(*ptr)))
1636
if (drizzle_real_query(drizzle,*ptr, (ulong) strlen(*ptr)))
1638
if (drizzle->fields)
1640
if (!(res= cli_use_result(mysql)))
1642
mysql_free_result(res);
1640
if (!(res= cli_use_result(drizzle)))
1642
drizzle_free_result(res);
1645
mysql->reconnect=reconnect;
1645
drizzle->reconnect=reconnect;
1648
reset_sigpipe(mysql);
1648
reset_sigpipe(drizzle);
1652
reset_sigpipe(mysql);
1652
reset_sigpipe(drizzle);
1654
1654
/* Free alloced memory */
1656
mysql_close_free(mysql);
1655
end_server(drizzle);
1656
drizzle_close_free(drizzle);
1657
1657
if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS))
1658
mysql_close_free_options(mysql);
1658
drizzle_close_free_options(drizzle);
1664
my_bool mysql_reconnect(MYSQL *mysql)
1664
my_bool drizzle_reconnect(DRIZZLE *drizzle)
1666
DRIZZLE tmp_drizzle;
1669
if (!mysql->reconnect ||
1670
(mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info)
1669
if (!drizzle->reconnect ||
1670
(drizzle->server_status & SERVER_STATUS_IN_TRANS) || !drizzle->host_info)
1672
1672
/* Allow reconnect next time */
1673
mysql->server_status&= ~SERVER_STATUS_IN_TRANS;
1674
set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate);
1677
mysql_init(&tmp_mysql);
1678
tmp_mysql.options= mysql->options;
1679
tmp_mysql.options.my_cnf_file= tmp_mysql.options.my_cnf_group= 0;
1681
if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd,
1682
mysql->db, mysql->port, mysql->unix_socket,
1683
mysql->client_flag | CLIENT_REMEMBER_OPTIONS))
1685
mysql->net.last_errno= tmp_mysql.net.last_errno;
1686
strmov(mysql->net.last_error, tmp_mysql.net.last_error);
1687
strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate);
1690
if (mysql_set_character_set(&tmp_mysql, mysql->charset->csname))
1692
bzero((char*) &tmp_mysql.options,sizeof(tmp_mysql.options));
1693
mysql_close(&tmp_mysql);
1694
mysql->net.last_errno= tmp_mysql.net.last_errno;
1695
strmov(mysql->net.last_error, tmp_mysql.net.last_error);
1696
strmov(mysql->net.sqlstate, tmp_mysql.net.sqlstate);
1700
tmp_mysql.reconnect= 1;
1701
tmp_mysql.free_me= mysql->free_me;
1703
/* Don't free options as these are now used in tmp_mysql */
1704
bzero((char*) &mysql->options,sizeof(mysql->options));
1708
net_clear(&mysql->net, 1);
1709
mysql->affected_rows= ~(uint64_t) 0;
1673
drizzle->server_status&= ~SERVER_STATUS_IN_TRANS;
1674
set_drizzle_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
1677
drizzle_init(&tmp_drizzle);
1678
tmp_drizzle.options= drizzle->options;
1679
tmp_drizzle.options.my_cnf_file= tmp_drizzle.options.my_cnf_group= 0;
1681
if (!drizzle_connect(&tmp_drizzle,drizzle->host,drizzle->user,drizzle->passwd,
1682
drizzle->db, drizzle->port, drizzle->unix_socket,
1683
drizzle->client_flag | CLIENT_REMEMBER_OPTIONS))
1685
drizzle->net.last_errno= tmp_drizzle.net.last_errno;
1686
strmov(drizzle->net.last_error, tmp_drizzle.net.last_error);
1687
strmov(drizzle->net.sqlstate, tmp_drizzle.net.sqlstate);
1690
if (drizzle_set_character_set(&tmp_drizzle, drizzle->charset->csname))
1692
bzero((char*) &tmp_drizzle.options,sizeof(tmp_drizzle.options));
1693
drizzle_close(&tmp_drizzle);
1694
drizzle->net.last_errno= tmp_drizzle.net.last_errno;
1695
strmov(drizzle->net.last_error, tmp_drizzle.net.last_error);
1696
strmov(drizzle->net.sqlstate, tmp_drizzle.net.sqlstate);
1700
tmp_drizzle.reconnect= 1;
1701
tmp_drizzle.free_me= drizzle->free_me;
1703
/* Don't free options as these are now used in tmp_drizzle */
1704
bzero((char*) &drizzle->options,sizeof(drizzle->options));
1706
drizzle_close(drizzle);
1707
*drizzle=tmp_drizzle;
1708
net_clear(&drizzle->net, 1);
1709
drizzle->affected_rows= ~(uint64_t) 0;
1716
1716
**************************************************************************/
1719
mysql_select_db(MYSQL *mysql, const char *db)
1719
drizzle_select_db(DRIZZLE *drizzle, const char *db)
1723
if ((error=simple_command(mysql,COM_INIT_DB, (const uchar*) db,
1723
if ((error=simple_command(drizzle,COM_INIT_DB, (const uchar*) db,
1724
1724
(ulong) strlen(db),0)))
1726
my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
1727
mysql->db=my_strdup(db,MYF(MY_WME));
1726
my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1727
drizzle->db=my_strdup(db,MYF(MY_WME));
1732
1732
/*************************************************************************
1733
1733
Send a QUIT to the server and close the connection
1734
If handle is alloced by mysql connect free it.
1734
If handle is alloced by DRIZZLE connect free it.
1735
1735
*************************************************************************/
1737
static void mysql_close_free_options(MYSQL *mysql)
1737
static void drizzle_close_free_options(DRIZZLE *drizzle)
1739
my_free(mysql->options.user,MYF(MY_ALLOW_ZERO_PTR));
1740
my_free(mysql->options.host,MYF(MY_ALLOW_ZERO_PTR));
1741
my_free(mysql->options.password,MYF(MY_ALLOW_ZERO_PTR));
1742
my_free(mysql->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
1743
my_free(mysql->options.db,MYF(MY_ALLOW_ZERO_PTR));
1744
my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1745
my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1746
my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
1747
my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
1748
my_free(mysql->options.client_ip,MYF(MY_ALLOW_ZERO_PTR));
1749
if (mysql->options.init_commands)
1739
my_free(drizzle->options.user,MYF(MY_ALLOW_ZERO_PTR));
1740
my_free(drizzle->options.host,MYF(MY_ALLOW_ZERO_PTR));
1741
my_free(drizzle->options.password,MYF(MY_ALLOW_ZERO_PTR));
1742
my_free(drizzle->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
1743
my_free(drizzle->options.db,MYF(MY_ALLOW_ZERO_PTR));
1744
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1745
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1746
my_free(drizzle->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
1747
my_free(drizzle->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
1748
my_free(drizzle->options.client_ip,MYF(MY_ALLOW_ZERO_PTR));
1749
if (drizzle->options.init_commands)
1751
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
1751
DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1752
1752
char **ptr= (char**)init_commands->buffer;
1753
1753
char **end= ptr + init_commands->elements;
1754
1754
for (; ptr<end; ptr++)
1757
1757
my_free((char*)init_commands,MYF(MY_WME));
1759
1759
#ifdef HAVE_SMEM
1760
if (mysql->options.shared_memory_base_name != def_shared_memory_base_name)
1761
my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
1760
if (drizzle->options.shared_memory_base_name != def_shared_memory_base_name)
1761
my_free(drizzle->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
1762
1762
#endif /* HAVE_SMEM */
1763
bzero((char*) &mysql->options,sizeof(mysql->options));
1763
bzero((char*) &drizzle->options,sizeof(drizzle->options));
1768
static void mysql_close_free(MYSQL *mysql)
1768
static void drizzle_close_free(DRIZZLE *drizzle)
1770
my_free((uchar*) mysql->host_info,MYF(MY_ALLOW_ZERO_PTR));
1771
my_free(mysql->user,MYF(MY_ALLOW_ZERO_PTR));
1772
my_free(mysql->passwd,MYF(MY_ALLOW_ZERO_PTR));
1773
my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
1774
my_free(mysql->info_buffer,MYF(MY_ALLOW_ZERO_PTR));
1775
mysql->info_buffer= 0;
1770
my_free((uchar*) drizzle->host_info,MYF(MY_ALLOW_ZERO_PTR));
1771
my_free(drizzle->user,MYF(MY_ALLOW_ZERO_PTR));
1772
my_free(drizzle->passwd,MYF(MY_ALLOW_ZERO_PTR));
1773
my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1774
my_free(drizzle->info_buffer,MYF(MY_ALLOW_ZERO_PTR));
1775
drizzle->info_buffer= 0;
1777
1777
/* Clear pointers for better safety */
1778
mysql->host_info= mysql->user= mysql->passwd= mysql->db= 0;
1778
drizzle->host_info= drizzle->user= drizzle->passwd= drizzle->db= 0;
1782
void STDCALL mysql_close(MYSQL *mysql)
1782
void STDCALL drizzle_close(DRIZZLE *drizzle)
1784
if (mysql) /* Some simple safety */
1784
if (drizzle) /* Some simple safety */
1786
1786
/* If connection is still up, send a QUIT message */
1787
if (mysql->net.vio != 0)
1787
if (drizzle->net.vio != 0)
1789
free_old_query(mysql);
1790
mysql->status=MYSQL_STATUS_READY; /* Force command */
1792
simple_command(mysql,COM_QUIT,(uchar*) 0,0,1);
1793
end_server(mysql); /* Sets mysql->net.vio= 0 */
1789
free_old_query(drizzle);
1790
drizzle->status=DRIZZLE_STATUS_READY; /* Force command */
1791
drizzle->reconnect=0;
1792
simple_command(drizzle,COM_QUIT,(uchar*) 0,0,1);
1793
end_server(drizzle); /* Sets drizzle->net.vio= 0 */
1795
mysql_close_free_options(mysql);
1796
mysql_close_free(mysql);
1798
my_free((uchar*) mysql,MYF(0));
1795
drizzle_close_free_options(drizzle);
1796
drizzle_close_free(drizzle);
1797
if (drizzle->free_me)
1798
my_free((uchar*) drizzle,MYF(0));
1804
static bool cli_read_query_result(MYSQL *mysql)
1804
static bool cli_read_query_result(DRIZZLE *drizzle)
1807
1807
ulong field_count;
1808
DRIZZLE_DATA *fields;
1811
if ((length = cli_safe_read(mysql)) == packet_error)
1811
if ((length = cli_safe_read(drizzle)) == packet_error)
1813
free_old_query(mysql); /* Free old result */
1814
#ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/
1813
free_old_query(drizzle); /* Free old result */
1814
#ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/
1817
pos=(uchar*) mysql->net.read_pos;
1817
pos=(uchar*) drizzle->net.read_pos;
1818
1818
if ((field_count= net_field_length(&pos)) == 0)
1820
mysql->affected_rows= net_field_length_ll(&pos);
1821
mysql->insert_id= net_field_length_ll(&pos);
1822
if (protocol_41(mysql))
1824
mysql->server_status=uint2korr(pos); pos+=2;
1825
mysql->warning_count=uint2korr(pos); pos+=2;
1827
else if (mysql->server_capabilities & CLIENT_TRANSACTIONS)
1829
/* MySQL 4.0 protocol */
1830
mysql->server_status=uint2korr(pos); pos+=2;
1831
mysql->warning_count= 0;
1833
if (pos < mysql->net.read_pos+length && net_field_length(&pos))
1834
mysql->info=(char*) pos;
1820
drizzle->affected_rows= net_field_length_ll(&pos);
1821
drizzle->insert_id= net_field_length_ll(&pos);
1822
if (protocol_41(drizzle))
1824
drizzle->server_status=uint2korr(pos); pos+=2;
1825
drizzle->warning_count=uint2korr(pos); pos+=2;
1827
else if (drizzle->server_capabilities & CLIENT_TRANSACTIONS)
1829
/* DRIZZLE 4.0 protocol */
1830
drizzle->server_status=uint2korr(pos); pos+=2;
1831
drizzle->warning_count= 0;
1833
if (pos < drizzle->net.read_pos+length && net_field_length(&pos))
1834
drizzle->info=(char*) pos;
1837
1837
#ifdef MYSQL_CLIENT
1838
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
1838
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
1842
if (!(mysql->options.client_flag & CLIENT_LOCAL_FILES))
1842
if (!(drizzle->options.client_flag & CLIENT_LOCAL_FILES))
1844
set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
1844
set_drizzle_error(drizzle, CR_MALFORMED_PACKET, unknown_sqlstate);
1848
error= handle_local_infile(mysql,(char*) pos);
1849
if ((length= cli_safe_read(mysql)) == packet_error || error)
1848
error= handle_local_infile(drizzle,(char*) pos);
1849
if ((length= cli_safe_read(drizzle)) == packet_error || error)
1851
goto get_info; /* Get info packet */
1851
goto get_info; /* Get info packet */
1854
if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT))
1855
mysql->server_status|= SERVER_STATUS_IN_TRANS;
1854
if (!(drizzle->server_status & SERVER_STATUS_AUTOCOMMIT))
1855
drizzle->server_status|= SERVER_STATUS_IN_TRANS;
1857
if (!(fields=cli_read_rows(mysql,(MYSQL_FIELD*)0, protocol_41(mysql) ? 7:5)))
1859
if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,
1860
(uint) field_count,0,
1861
mysql->server_capabilities)))
1863
mysql->status= MYSQL_STATUS_GET_RESULT;
1864
mysql->field_count= (uint) field_count;
1857
if (!(fields=cli_read_rows(drizzle,(DRIZZLE_FIELD*)0, protocol_41(drizzle) ? 7:5)))
1859
if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,
1860
(uint) field_count,0,
1861
drizzle->server_capabilities)))
1863
drizzle->status= DRIZZLE_STATUS_GET_RESULT;
1864
drizzle->field_count= (uint) field_count;
1870
1870
Send the query and return so we can do something else.
1871
Needs to be followed by mysql_read_query_result() when we want to
1871
Needs to be followed by drizzle_read_query_result() when we want to
1872
1872
finish processing it.
1875
1875
int32_t STDCALL
1876
mysql_send_query(MYSQL* mysql, const char* query, uint32_t length)
1876
drizzle_send_query(DRIZZLE *drizzle, const char* query, uint32_t length)
1878
return(simple_command(mysql, COM_QUERY, (uchar*) query, length, 1));
1878
return(simple_command(drizzle, COM_QUERY, (uchar*) query, length, 1));
1882
1882
int32_t STDCALL
1883
mysql_real_query(MYSQL *mysql, const char *query, uint32_t length)
1883
drizzle_real_query(DRIZZLE *drizzle, const char *query, uint32_t length)
1885
if (mysql_send_query(mysql,query,length))
1885
if (drizzle_send_query(drizzle,query,length))
1887
return((int) (*mysql->methods->read_query_result)(mysql));
1887
return((int) (*drizzle->methods->read_query_result)(drizzle));
1891
1891
/**************************************************************************
1892
1892
Alloc result struct for buffered results. All rows are read to buffer.
1893
mysql_data_seek may be used.
1893
drizzle_data_seek may be used.
1894
1894
**************************************************************************/
1896
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql)
1896
DRIZZLE_RES * STDCALL drizzle_store_result(DRIZZLE *drizzle)
1898
DRIZZLE_RES *result;
1902
if (mysql->status != MYSQL_STATUS_GET_RESULT)
1904
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
1907
mysql->status=MYSQL_STATUS_READY; /* server is ready */
1908
if (!(result=(MYSQL_RES*) my_malloc((uint) (sizeof(MYSQL_RES)+
1910
mysql->field_count),
1911
MYF(MY_WME | MY_ZEROFILL))))
1913
set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1916
result->methods= mysql->methods;
1917
result->eof= 1; /* Marker for buffered */
1900
if (!drizzle->fields)
1902
if (drizzle->status != DRIZZLE_STATUS_GET_RESULT)
1904
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
1907
drizzle->status=DRIZZLE_STATUS_READY; /* server is ready */
1908
if (!(result=(DRIZZLE_RES*) my_malloc((uint) (sizeof(DRIZZLE_RES)+
1910
drizzle->field_count),
1911
MYF(MY_WME | MY_ZEROFILL))))
1913
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
1916
result->methods= drizzle->methods;
1917
result->eof= 1; /* Marker for buffered */
1918
1918
result->lengths= (uint32_t*) (result+1);
1919
1919
if (!(result->data=
1920
(*mysql->methods->read_rows)(mysql,mysql->fields,mysql->field_count)))
1920
(*drizzle->methods->read_rows)(drizzle,drizzle->fields,drizzle->field_count)))
1922
1922
my_free((uchar*) result,MYF(0));
1925
mysql->affected_rows= result->row_count= result->data->rows;
1926
result->data_cursor= result->data->data;
1927
result->fields= mysql->fields;
1928
result->field_alloc= mysql->field_alloc;
1929
result->field_count= mysql->field_count;
1925
drizzle->affected_rows= result->row_count= result->data->rows;
1926
result->data_cursor= result->data->data;
1927
result->fields= drizzle->fields;
1928
result->field_alloc= drizzle->field_alloc;
1929
result->field_count= drizzle->field_count;
1930
1930
/* The rest of result members is bzeroed in malloc */
1931
mysql->fields=0; /* fields is now in result */
1932
clear_alloc_root(&mysql->field_alloc);
1933
/* just in case this was mistakenly called after mysql_stmt_execute() */
1934
mysql->unbuffered_fetch_owner= 0;
1935
return(result); /* Data fetched */
1931
drizzle->fields=0; /* fields is now in result */
1932
clear_alloc_root(&drizzle->field_alloc);
1933
/* just in case this was mistakenly called after drizzle_stmt_execute() */
1934
drizzle->unbuffered_fetch_owner= 0;
1935
return(result); /* Data fetched */
1939
1939
/**************************************************************************
1940
1940
Alloc struct for use with unbuffered reads. Data is fetched by domand
1941
when calling to mysql_fetch_row.
1942
mysql_data_seek is a noop.
1941
when calling to drizzle_fetch_row.
1942
DRIZZLE_DATA_seek is a noop.
1944
No other queries may be specified with the same MYSQL handle.
1945
There shouldn't be much processing per row because mysql server shouldn't
1944
No other queries may be specified with the same DRIZZLE handle.
1945
There shouldn't be much processing per row because DRIZZLE server shouldn't
1946
1946
have to wait for the client (and will not wait more than 30 sec/packet).
1947
1947
**************************************************************************/
1949
static MYSQL_RES * cli_use_result(MYSQL *mysql)
1949
static DRIZZLE_RES * cli_use_result(DRIZZLE *drizzle)
1951
DRIZZLE_RES *result;
1953
if (!drizzle->fields)
1955
if (mysql->status != MYSQL_STATUS_GET_RESULT)
1955
if (drizzle->status != DRIZZLE_STATUS_GET_RESULT)
1957
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
1957
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
1960
if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+
1961
sizeof(ulong)*mysql->field_count,
1962
MYF(MY_WME | MY_ZEROFILL))))
1960
if (!(result=(DRIZZLE_RES*) my_malloc(sizeof(*result)+
1961
sizeof(ulong)*drizzle->field_count,
1962
MYF(MY_WME | MY_ZEROFILL))))
1964
1964
result->lengths=(uint32_t*) (result+1);
1965
result->methods= mysql->methods;
1966
if (!(result->row=(MYSQL_ROW)
1967
my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME))))
1968
{ /* Ptrs: to one row */
1965
result->methods= drizzle->methods;
1966
if (!(result->row=(DRIZZLE_ROW)
1967
my_malloc(sizeof(result->row[0])*(drizzle->field_count+1), MYF(MY_WME))))
1968
{ /* Ptrs: to one row */
1969
1969
my_free((uchar*) result,MYF(0));
1972
result->fields= mysql->fields;
1973
result->field_alloc= mysql->field_alloc;
1974
result->field_count= mysql->field_count;
1972
result->fields= drizzle->fields;
1973
result->field_alloc= drizzle->field_alloc;
1974
result->field_count= drizzle->field_count;
1975
1975
result->current_field=0;
1976
result->handle= mysql;
1977
result->current_row= 0;
1978
mysql->fields=0; /* fields is now in result */
1979
clear_alloc_root(&mysql->field_alloc);
1980
mysql->status=MYSQL_STATUS_USE_RESULT;
1981
mysql->unbuffered_fetch_owner= &result->unbuffered_fetch_cancelled;
1982
return(result); /* Data is read to be fetched */
1976
result->handle= drizzle;
1977
result->current_row= 0;
1978
drizzle->fields=0; /* fields is now in result */
1979
clear_alloc_root(&drizzle->field_alloc);
1980
drizzle->status=DRIZZLE_STATUS_USE_RESULT;
1981
drizzle->unbuffered_fetch_owner= &result->unbuffered_fetch_cancelled;
1982
return(result); /* Data is read to be fetched */
2056
mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
2056
drizzle_options(DRIZZLE *drizzle,enum drizzle_option option, const void *arg)
2058
2058
switch (option) {
2059
case MYSQL_OPT_CONNECT_TIMEOUT:
2060
mysql->options.connect_timeout= *(uint*) arg;
2062
case MYSQL_OPT_READ_TIMEOUT:
2063
mysql->options.read_timeout= *(uint*) arg;
2065
case MYSQL_OPT_WRITE_TIMEOUT:
2066
mysql->options.write_timeout= *(uint*) arg;
2068
case MYSQL_OPT_COMPRESS:
2069
mysql->options.compress= 1; /* Remember for connect */
2070
mysql->options.client_flag|= CLIENT_COMPRESS;
2072
case MYSQL_OPT_NAMED_PIPE: /* This option is depricated */
2073
mysql->options.protocol=MYSQL_PROTOCOL_PIPE; /* Force named pipe */
2075
case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
2059
case DRIZZLE_OPT_CONNECT_TIMEOUT:
2060
drizzle->options.connect_timeout= *(uint*) arg;
2062
case DRIZZLE_OPT_READ_TIMEOUT:
2063
drizzle->options.read_timeout= *(uint*) arg;
2065
case DRIZZLE_OPT_WRITE_TIMEOUT:
2066
drizzle->options.write_timeout= *(uint*) arg;
2068
case DRIZZLE_OPT_COMPRESS:
2069
drizzle->options.compress= 1; /* Remember for connect */
2070
drizzle->options.client_flag|= CLIENT_COMPRESS;
2072
case DRIZZLE_OPT_NAMED_PIPE: /* This option is depricated */
2073
drizzle->options.protocol=DRIZZLE_PROTOCOL_PIPE; /* Force named pipe */
2075
case DRIZZLE_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
2076
2076
if (!arg || test(*(uint*) arg))
2077
mysql->options.client_flag|= CLIENT_LOCAL_FILES;
2077
drizzle->options.client_flag|= CLIENT_LOCAL_FILES;
2079
mysql->options.client_flag&= ~CLIENT_LOCAL_FILES;
2081
case MYSQL_INIT_COMMAND:
2082
add_init_command(&mysql->options,arg);
2084
case MYSQL_READ_DEFAULT_FILE:
2085
my_free(mysql->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
2086
mysql->options.my_cnf_file=my_strdup(arg,MYF(MY_WME));
2088
case MYSQL_READ_DEFAULT_GROUP:
2089
my_free(mysql->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
2090
mysql->options.my_cnf_group=my_strdup(arg,MYF(MY_WME));
2092
case MYSQL_SET_CHARSET_DIR:
2093
my_free(mysql->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
2094
mysql->options.charset_dir=my_strdup(arg,MYF(MY_WME));
2096
case MYSQL_SET_CHARSET_NAME:
2097
my_free(mysql->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
2098
mysql->options.charset_name=my_strdup(arg,MYF(MY_WME));
2100
case MYSQL_OPT_PROTOCOL:
2101
mysql->options.protocol= *(uint*) arg;
2103
case MYSQL_SHARED_MEMORY_BASE_NAME:
2079
drizzle->options.client_flag&= ~CLIENT_LOCAL_FILES;
2081
case DRIZZLE_INIT_COMMAND:
2082
add_init_command(&drizzle->options,arg);
2084
case DRIZZLE_READ_DEFAULT_FILE:
2085
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
2086
drizzle->options.my_cnf_file=my_strdup(arg,MYF(MY_WME));
2088
case DRIZZLE_READ_DEFAULT_GROUP:
2089
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
2090
drizzle->options.my_cnf_group=my_strdup(arg,MYF(MY_WME));
2092
case DRIZZLE_SET_CHARSET_DIR:
2093
my_free(drizzle->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
2094
drizzle->options.charset_dir=my_strdup(arg,MYF(MY_WME));
2096
case DRIZZLE_SET_CHARSET_NAME:
2097
my_free(drizzle->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
2098
drizzle->options.charset_name=my_strdup(arg,MYF(MY_WME));
2100
case DRIZZLE_OPT_PROTOCOL:
2101
drizzle->options.protocol= *(uint*) arg;
2103
case DRIZZLE_SHARED_MEMORY_BASE_NAME:
2104
2104
#ifdef HAVE_SMEM
2105
if (mysql->options.shared_memory_base_name != def_shared_memory_base_name)
2106
my_free(mysql->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
2107
mysql->options.shared_memory_base_name=my_strdup(arg,MYF(MY_WME));
2105
if (drizzle->options.shared_memory_base_name != def_shared_memory_base_name)
2106
my_free(drizzle->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
2107
drizzle->options.shared_memory_base_name=my_strdup(arg,MYF(MY_WME));
2110
case MYSQL_OPT_USE_REMOTE_CONNECTION:
2111
case MYSQL_OPT_USE_EMBEDDED_CONNECTION:
2112
case MYSQL_OPT_GUESS_CONNECTION:
2113
mysql->options.methods_to_use= option;
2115
case MYSQL_SET_CLIENT_IP:
2116
mysql->options.client_ip= my_strdup(arg, MYF(MY_WME));
2118
case MYSQL_SECURE_AUTH:
2119
mysql->options.secure_auth= *(my_bool *) arg;
2121
case MYSQL_REPORT_DATA_TRUNCATION:
2122
mysql->options.report_data_truncation= test(*(my_bool *) arg);
2124
case MYSQL_OPT_RECONNECT:
2125
mysql->reconnect= *(my_bool *) arg;
2127
case MYSQL_OPT_SSL_VERIFY_SERVER_CERT:
2110
case DRIZZLE_OPT_USE_REMOTE_CONNECTION:
2111
case DRIZZLE_OPT_USE_EMBEDDED_CONNECTION:
2112
case DRIZZLE_OPT_GUESS_CONNECTION:
2113
drizzle->options.methods_to_use= option;
2115
case DRIZZLE_SET_CLIENT_IP:
2116
drizzle->options.client_ip= my_strdup(arg, MYF(MY_WME));
2118
case DRIZZLE_SECURE_AUTH:
2119
drizzle->options.secure_auth= *(my_bool *) arg;
2121
case DRIZZLE_REPORT_DATA_TRUNCATION:
2122
drizzle->options.report_data_truncation= test(*(my_bool *) arg);
2124
case DRIZZLE_OPT_RECONNECT:
2125
drizzle->reconnect= *(my_bool *) arg;
2127
case DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT:
2128
2128
if (*(my_bool*) arg)
2129
mysql->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
2129
drizzle->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
2131
mysql->options.client_flag&= ~CLIENT_SSL_VERIFY_SERVER_CERT;
2131
drizzle->options.client_flag&= ~CLIENT_SSL_VERIFY_SERVER_CERT;