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)
399
cli_advanced_command(DRIZZLE *drizzle, enum enum_server_command command,
400
const unsigned char *header, uint32_t header_length,
401
const unsigned char *arg, uint32_t arg_length, bool skip_check)
400
NET *net= &mysql->net;
403
NET *net= &drizzle->net;
401
404
my_bool result= 1;
402
405
init_sigpipe_variables
403
406
my_bool stmt_skip= false;
405
408
/* Don't give sigpipe errors if the client doesn't want them */
409
set_sigpipe(drizzle);
408
if (mysql->net.vio == 0)
409
{ /* Do reconnect if possible */
410
if (mysql_reconnect(mysql) || stmt_skip)
411
if (drizzle->net.vio == 0)
412
{ /* Do reconnect if possible */
413
if (drizzle_reconnect(drizzle) || stmt_skip)
413
if (mysql->status != MYSQL_STATUS_READY ||
414
mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
416
if (drizzle->status != DRIZZLE_STATUS_READY ||
417
drizzle->server_status & SERVER_MORE_RESULTS_EXISTS)
416
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
419
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
420
423
net_clear_error(net);
422
mysql->affected_rows= ~(uint64_t) 0;
425
drizzle->affected_rows= ~(uint64_t) 0;
424
427
We don't want to clear the protocol buffer on COM_QUIT, because if
425
428
the previous command was a shutdown command, we may have the
426
429
response for the COM_QUIT already in the communication buffer
428
net_clear(&mysql->net, (command != COM_QUIT));
431
net_clear(&drizzle->net, (command != COM_QUIT));
430
433
if (net_write_command(net,(uchar) command, header, header_length,
433
436
if (net->last_errno == ER_NET_PACKET_TOO_LARGE)
435
set_mysql_error(mysql, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
438
set_drizzle_error(drizzle, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
439
if (mysql_reconnect(mysql) || stmt_skip)
442
if (drizzle_reconnect(drizzle) || stmt_skip)
441
444
if (net_write_command(net,(uchar) command, header, header_length,
444
set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate);
447
set_drizzle_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
450
result= ((mysql->packet_length=cli_safe_read(mysql)) == packet_error ?
453
result= ((drizzle->packet_length=cli_safe_read(drizzle)) == packet_error ?
453
reset_sigpipe(mysql);
456
reset_sigpipe(drizzle);
457
void free_old_query(MYSQL *mysql)
460
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;
463
free_root(&drizzle->field_alloc,MYF(0));
464
init_alloc_root(&drizzle->field_alloc,8192,0); /* Assume rowlength < 8192 */
466
drizzle->field_count= 0; /* For API */
467
drizzle->warning_count= 0;
600
603
groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0;
602
605
load_defaults(filename, groups, &argc, &argv);
603
if (argc != 1) /* If some default option */
606
if (argc != 1) /* If some default option */
605
608
char **option=argv;
606
609
while (*++option)
608
611
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));
613
char *end=strcend(*option,'=');
618
*end=0; /* Remove '=' */
620
/* Change all '_' in variable name to '-' */
621
for (end= *option ; *(end= strcend(end,'_')) ; )
623
switch (find_type(*option+2,&option_types,2)) {
626
options->port=atoi(opt_arg);
631
my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR));
632
options->unix_socket=my_strdup(opt_arg,MYF(MY_WME));
635
case 3: /* compress */
637
options->client_flag|= CLIENT_COMPRESS;
639
case 4: /* password */
642
my_free(options->password,MYF(MY_ALLOW_ZERO_PTR));
643
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 */
647
options->protocol = DRIZZLE_PROTOCOL_PIPE;
648
case 20: /* connect_timeout */
649
case 6: /* timeout */
651
options->connect_timeout=atoi(opt_arg);
656
my_free(options->user,MYF(MY_ALLOW_ZERO_PTR));
657
options->user=my_strdup(opt_arg,MYF(MY_WME));
660
case 8: /* init-command */
661
add_init_command(options,opt_arg);
666
my_free(options->host,MYF(MY_ALLOW_ZERO_PTR));
667
options->host=my_strdup(opt_arg,MYF(MY_WME));
670
case 10: /* database */
673
my_free(options->db,MYF(MY_ALLOW_ZERO_PTR));
674
options->db=my_strdup(opt_arg,MYF(MY_WME));
677
case 12: /* return-found-rows */
678
options->client_flag|=CLIENT_FOUND_ROWS;
680
case 13: /* Ignore SSL options */
683
case 17: /* charset-lib */
684
my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR));
686
case 17: /* charset-lib */
687
my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR));
685
688
options->charset_dir = my_strdup(opt_arg, MYF(MY_WME));
688
my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR));
691
my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR));
689
692
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;
694
case 19: /* Interactive-timeout */
695
options->client_flag|= CLIENT_INTERACTIVE;
698
if (!opt_arg || atoi(opt_arg) != 0)
699
options->client_flag|= CLIENT_LOCAL_FILES;
701
options->client_flag&= ~CLIENT_LOCAL_FILES;
704
options->client_flag&= ~CLIENT_LOCAL_FILES;
703
case 24: /* max-allowed-packet */
706
case 24: /* max-allowed-packet */
705
options->max_allowed_packet= atoi(opt_arg);
708
options->max_allowed_packet= atoi(opt_arg);
707
710
case 25: /* protocol */
708
711
if ((options->protocol= find_type(opt_arg,
709
&sql_protocol_typelib,0)) <= 0)
712
&sql_protocol_typelib,0)) <= 0)
711
714
fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg);
1020
1023
*lengths++=len;
1023
*prev_pos=0; /* Terminate prev field */
1026
*prev_pos=0; /* Terminate prev field */
1026
row[field]=(char*) prev_pos+1; /* End of last field */
1027
*prev_pos=0; /* Terminate last field */
1029
row[field]=(char*) prev_pos+1; /* End of last field */
1030
*prev_pos=0; /* Terminate last field */
1032
1035
/****************************************************************************
1033
Init MySQL structure or allocate one
1036
Init DRIZZLE structure or allocate one
1034
1037
****************************************************************************/
1037
mysql_init(MYSQL *mysql)
1040
drizzle_create(DRIZZLE *ptr)
1039
if (mysql_server_init(0, NULL, NULL))
1043
if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL))))
1045
set_mysql_error(NULL, CR_OUT_OF_MEMORY, unknown_sqlstate);
1043
if (!drizzle_client_init)
1045
drizzle_client_init=true;
1046
org_my_init_done=my_init_done;
1048
/* Will init threads */
1056
drizzle_port = MYSQL_PORT;
1058
struct servent *serv_ptr;
1062
if builder specifically requested a default port, use that
1063
(even if it coincides with our factory default).
1064
only if they didn't do we check /etc/services (and, failing
1065
on that, fall back to the factory default of 4427).
1066
either default can be overridden by the environment variable
1067
MYSQL_TCP_PORT, which in turn can be overridden with command
1071
#if MYSQL_PORT_DEFAULT == 0
1072
if ((serv_ptr = getservbyname("drizzle", "tcp")))
1073
drizzle_port = (uint) ntohs((ushort) serv_ptr->s_port);
1075
if ((env = getenv("DRIZZLE_TCP_PORT")))
1076
drizzle_port =(uint) atoi(env);
1079
if (!drizzle_unix_port)
1082
drizzle_unix_port = (char*) MYSQL_UNIX_ADDR;
1083
if ((env = getenv("DRIZZLE_UNIX_PORT")))
1084
drizzle_unix_port = env;
1086
#if defined(SIGPIPE)
1087
(void) signal(SIGPIPE, SIG_IGN);
1091
/* Init if new thread */
1092
if (my_thread_init())
1097
ptr= (DRIZZLE *) malloc(sizeof(DRIZZLE));
1101
set_drizzle_error(NULL, CR_OUT_OF_MEMORY, unknown_sqlstate);
1104
memset(ptr, 0, sizeof(DRIZZLE));
1051
bzero((char*) (mysql), sizeof(*(mysql)));
1052
mysql->options.connect_timeout= CONNECT_TIMEOUT;
1053
mysql->charset=default_client_charset_info;
1054
strmov(mysql->net.sqlstate, not_error_sqlstate);
1109
memset(ptr, 0, sizeof(DRIZZLE));
1112
ptr->options.connect_timeout= CONNECT_TIMEOUT;
1113
ptr->charset=default_client_charset_info;
1114
strcpy(ptr->net.sqlstate, not_error_sqlstate);
1057
1117
Only enable LOAD DATA INFILE by default if configured with
1058
1118
--enable-local-infile
1061
#if defined(ENABLED_LOCAL_INFILE) && !defined(MYSQL_SERVER)
1062
mysql->options.client_flag|= CLIENT_LOCAL_FILES;
1121
#if defined(ENABLED_LOCAL_INFILE) && !defined(DRIZZLE_SERVER)
1122
ptr->options.client_flag|= CLIENT_LOCAL_FILES;
1065
1125
#ifdef HAVE_SMEM
1066
mysql->options.shared_memory_base_name= (char*) def_shared_memory_base_name;
1126
ptr->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 */
1129
ptr->options.methods_to_use= DRIZZLE_OPT_GUESS_CONNECTION;
1130
ptr->options.report_data_truncation= true; /* default */
1073
1133
By default we don't reconnect because it could silently corrupt data (after
1074
1134
reconnection you potentially lose table locks, user variables, session
1075
1135
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.
1136
drizzle_reconnect()).
1137
This is a change: < 5.0.3 drizzle->reconnect was set to 1 by default.
1078
1138
How this change impacts existing apps:
1079
1139
- existing apps which relyed on the default will see a behaviour change;
1080
they will have to set reconnect=1 after mysql_real_connect().
1140
they will have to set reconnect=1 after drizzle_connect().
1081
1141
- 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())
1142
could do it was by setting drizzle.reconnect to 1 after drizzle_connect())
1083
1143
will not see a behaviour change.
1084
1144
- existing apps which explicitely asked for no reconnection
1085
(mysql.reconnect=0) will not see a behaviour change.
1145
(drizzle.reconnect=0) will not see a behaviour change.
1087
mysql->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.
1154
Free all memory and resources used by the client library
1157
When calling this there should not be any other threads using
1160
To make things simpler when used with windows dll's (which calls this
1161
function automaticly), it's safe to call this function multiple times.
1165
void STDCALL drizzle_server_end()
1167
if (!drizzle_client_init)
1170
finish_client_errs();
1173
/* If library called my_init(), free memory allocated by it */
1174
if (!org_my_init_done)
1181
drizzle_thread_end();
1184
drizzle_client_init= org_my_init_done= 0;
1185
#ifdef EMBEDDED_SERVER
1188
fclose(stderror_file);
1196
Fill in SSL part of DRIZZLE structure and set 'use_ssl' flag.
1197
NB! Errors are not reported until you do drizzle_connect.
1098
1200
#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 !
1203
Note that the drizzle argument must be initialized with drizzle_init()
1204
before calling drizzle_connect !
1105
static bool cli_read_query_result(MYSQL *mysql);
1106
static MYSQL_RES *cli_use_result(MYSQL *mysql);
1207
static bool cli_read_query_result(DRIZZLE *drizzle);
1208
static DRIZZLE_RES *cli_use_result(DRIZZLE *drizzle);
1108
static MYSQL_METHODS client_methods=
1210
static DRIZZLE_METHODS client_methods=
1110
1212
cli_read_query_result, /* read_query_result */
1111
1213
cli_advanced_command, /* advanced_command */
1128
int mysql_init_character_set(MYSQL *mysql)
1230
int drizzle_init_character_set(DRIZZLE *drizzle)
1130
1232
const char *default_collation_name;
1132
1234
/* Set character set */
1133
if (!mysql->options.charset_name)
1235
if (!drizzle->options.charset_name)
1135
1237
default_collation_name= MYSQL_DEFAULT_COLLATION_NAME;
1136
if (!(mysql->options.charset_name=
1238
if (!(drizzle->options.charset_name=
1137
1239
my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME))))
1141
1243
default_collation_name= NULL;
1144
1246
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,
1247
if (drizzle->options.charset_dir)
1248
charsets_dir=drizzle->options.charset_dir;
1249
drizzle->charset=get_charset_by_csname(drizzle->options.charset_name,
1148
1250
MY_CS_PRIMARY, MYF(MY_WME));
1149
if (mysql->charset && default_collation_name)
1251
if (drizzle->charset && default_collation_name)
1151
1253
CHARSET_INFO *collation;
1153
1255
get_charset_by_name(default_collation_name, MYF(MY_WME))))
1155
if (!my_charset_same(mysql->charset, collation))
1257
if (!my_charset_same(drizzle->charset, collation))
1157
my_printf_error(ER_UNKNOWN_ERROR,
1259
my_printf_error(ER_UNKNOWN_ERROR,
1158
1260
"COLLATION %s is not valid for CHARACTER SET %s",
1160
default_collation_name, mysql->options.charset_name);
1161
mysql->charset= NULL;
1262
default_collation_name, drizzle->options.charset_name);
1263
drizzle->charset= NULL;
1165
mysql->charset= collation;
1267
drizzle->charset= collation;
1169
mysql->charset= NULL;
1271
drizzle->charset= NULL;
1171
1273
charsets_dir= save;
1174
if (!mysql->charset)
1276
if (!drizzle->charset)
1176
if (mysql->options.charset_dir)
1177
set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
1278
if (drizzle->options.charset_dir)
1279
set_drizzle_extended_error(drizzle, CR_CANT_READ_CHARSET, unknown_sqlstate,
1178
1280
ER(CR_CANT_READ_CHARSET),
1179
mysql->options.charset_name,
1180
mysql->options.charset_dir);
1281
drizzle->options.charset_name,
1282
drizzle->options.charset_dir);
1183
1285
char cs_dir_name[FN_REFLEN];
1184
1286
get_charsets_dir(cs_dir_name);
1185
set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
1287
set_drizzle_extended_error(drizzle, CR_CANT_READ_CHARSET, unknown_sqlstate,
1186
1288
ER(CR_CANT_READ_CHARSET),
1187
mysql->options.charset_name,
1289
drizzle->options.charset_name,
1198
CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
1300
CLI_DRIZZLE_CONNECT(DRIZZLE *drizzle,const char *host, const char *user,
1199
1301
const char *passwd, const char *db,
1200
1302
uint32_t port, const char *unix_socket, uint32_t client_flag)
1202
1304
char buff[NAME_LEN+USERNAME_LENGTH+100];
1203
1305
char *end,*host_info=NULL;
1204
1306
uint32_t pkt_length;
1205
NET *net= &mysql->net;
1307
NET *net= &drizzle->net;
1206
1308
struct sockaddr_un UNIXaddr;
1207
1309
init_sigpipe_variables
1209
1311
/* 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 */
1312
set_sigpipe(drizzle);
1313
drizzle->methods= &client_methods;
1314
net->vio = 0; /* If something goes wrong */
1315
drizzle->client_flag=0; /* For handshake */
1215
1317
/* use default options */
1216
if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
1318
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;
1320
drizzle_read_default_options(&drizzle->options,
1321
(drizzle->options.my_cnf_file ?
1322
drizzle->options.my_cnf_file : "my"),
1323
drizzle->options.my_cnf_group);
1324
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1325
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1326
drizzle->options.my_cnf_file=drizzle->options.my_cnf_group=0;
1227
1329
/* Some empty-string-tests are done because of ODBC */
1228
1330
if (!host || !host[0])
1229
host=mysql->options.host;
1331
host=drizzle->options.host;
1230
1332
if (!user || !user[0])
1232
user=mysql->options.user;
1334
user=drizzle->options.user;
1238
passwd=mysql->options.password;
1340
passwd=drizzle->options.password;
1242
1344
if (!db || !db[0])
1243
db=mysql->options.db;
1345
db=drizzle->options.db;
1245
port=mysql->options.port;
1347
port=drizzle->options.port;
1246
1348
if (!unix_socket)
1247
unix_socket=mysql->options.unix_socket;
1349
unix_socket=drizzle->options.unix_socket;
1249
mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
1351
drizzle->server_status=SERVER_STATUS_AUTOCOMMIT;
1252
1354
Part 0: Grab a socket and connect it to the server
1254
1356
#if defined(HAVE_SMEM)
1255
if ((!mysql->options.protocol ||
1256
mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
1357
if ((!drizzle->options.protocol ||
1358
drizzle->options.protocol == DRIZZLE_PROTOCOL_MEMORY) &&
1257
1359
(!host || !strcmp(host,LOCAL_HOST)))
1259
if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) ==
1260
INVALID_HANDLE_VALUE)
1361
if ((create_shared_memory(drizzle,net, drizzle->options.connect_timeout)) ==
1362
INVALID_HANDLE_VALUE)
1262
if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY)
1364
if (drizzle->options.protocol == DRIZZLE_PROTOCOL_MEMORY)
1266
1368
Try also with PIPE or TCP/IP. Clear the error from
1451
1553
/* Check if version of protocol matches current one */
1453
mysql->protocol_version= net->read_pos[0];
1454
if (mysql->protocol_version != PROTOCOL_VERSION)
1555
drizzle->protocol_version= net->read_pos[0];
1556
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,
1558
set_drizzle_extended_error(drizzle, CR_VERSION_ERROR, unknown_sqlstate,
1559
ER(CR_VERSION_ERROR), drizzle->protocol_version,
1458
1560
PROTOCOL_VERSION);
1461
1563
end=strend((char*) net->read_pos+1);
1462
mysql->thread_id=uint4korr(end+1);
1564
drizzle->thread_id=uint4korr(end+1);
1465
1567
Scramble is split into two parts because old clients does not understand
1466
1568
long scrambles; here goes the first part.
1468
strmake(mysql->scramble, end, SCRAMBLE_LENGTH_323);
1570
strmake(drizzle->scramble, end, SCRAMBLE_LENGTH_323);
1469
1571
end+= SCRAMBLE_LENGTH_323+1;
1471
1573
if (pkt_length >= (uint) (end+1 - (char*) net->read_pos))
1472
mysql->server_capabilities=uint2korr(end);
1574
drizzle->server_capabilities=uint2korr(end);
1473
1575
if (pkt_length >= (uint) (end+18 - (char*) net->read_pos))
1475
1577
/* New protocol with 16 bytes to describe server characteristics */
1476
mysql->server_language=end[2];
1477
mysql->server_status=uint2korr(end+3);
1578
drizzle->server_language=end[2];
1579
drizzle->server_status=uint2korr(end+3);
1480
if (pkt_length >= (uint) (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 -
1582
if (pkt_length >= (uint) (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 -
1481
1583
(char *) net->read_pos))
1482
strmake(mysql->scramble+SCRAMBLE_LENGTH_323, end,
1584
strmake(drizzle->scramble+SCRAMBLE_LENGTH_323, end,
1483
1585
SCRAMBLE_LENGTH-SCRAMBLE_LENGTH_323);
1485
mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION;
1587
drizzle->server_capabilities&= ~CLIENT_SECURE_CONNECTION;
1487
if (mysql->options.secure_auth && passwd[0] &&
1488
!(mysql->server_capabilities & CLIENT_SECURE_CONNECTION))
1589
if (drizzle->options.secure_auth && passwd[0] &&
1590
!(drizzle->server_capabilities & CLIENT_SECURE_CONNECTION))
1490
set_mysql_error(mysql, CR_SECURE_AUTH, unknown_sqlstate);
1592
set_drizzle_error(drizzle, CR_SECURE_AUTH, unknown_sqlstate);
1494
if (mysql_init_character_set(mysql))
1596
if (drizzle_init_character_set(drizzle))
1497
1599
/* Save connection information */
1498
1600
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))))
1601
&drizzle->host_info, (uint) strlen(host_info)+1,
1602
&drizzle->host, (uint) strlen(host)+1,
1603
&drizzle->unix_socket,unix_socket ?
1604
(uint) strlen(unix_socket)+1 : (uint) 1,
1605
&drizzle->server_version,
1606
(uint) (end - (char*) net->read_pos),
1608
!(drizzle->user=my_strdup(user,MYF(0))) ||
1609
!(drizzle->passwd=my_strdup(passwd,MYF(0))))
1509
set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1611
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
1512
strmov(mysql->host_info,host_info);
1513
strmov(mysql->host,host);
1614
strmov(drizzle->host_info,host_info);
1615
strmov(drizzle->host,host);
1514
1616
if (unix_socket)
1515
strmov(mysql->unix_socket,unix_socket);
1617
strmov(drizzle->unix_socket,unix_socket);
1517
mysql->unix_socket=0;
1518
strmov(mysql->server_version,(char*) net->read_pos+1);
1619
drizzle->unix_socket=0;
1620
strmov(drizzle->server_version,(char*) net->read_pos+1);
1522
1624
Part 2: format and send client info to the server for access check
1525
client_flag|=mysql->options.client_flag;
1627
client_flag|=drizzle->options.client_flag;
1526
1628
client_flag|=CLIENT_CAPABILITIES;
1527
1629
if (client_flag & CLIENT_MULTI_STATEMENTS)
1528
1630
client_flag|= CLIENT_MULTI_RESULTS;
1576
1678
*end++= '\0'; /* empty password */
1578
1680
/* Add database if needed */
1579
if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB))
1681
if (db && (drizzle->server_capabilities & CLIENT_CONNECT_WITH_DB))
1581
1683
end= strmake(end, db, NAME_LEN) + 1;
1582
mysql->db= my_strdup(db,MYF(MY_WME));
1684
drizzle->db= my_strdup(db,MYF(MY_WME));
1585
1687
/* Write authentication package */
1586
1688
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,
1690
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1589
1691
ER(CR_SERVER_LOST_EXTENDED),
1590
1692
"sending authentication information",
1596
1698
Part 3: Authorization data's been sent. Now server can reply with
1597
1699
OK-packet, or re-request scrambled password.
1600
if ((pkt_length=cli_safe_read(mysql)) == packet_error)
1702
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,
1704
if (drizzle->net.last_errno == CR_SERVER_LOST)
1705
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1604
1706
ER(CR_SERVER_LOST_EXTENDED),
1605
1707
"reading authorization packet",
1610
if (client_flag & CLIENT_COMPRESS) /* We will use compression */
1712
if (client_flag & CLIENT_COMPRESS) /* We will use compression */
1611
1713
net->compress=1;
1614
if (db && mysql_select_db(mysql, db))
1716
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,
1718
if (drizzle->net.last_errno == CR_SERVER_LOST)
1719
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1618
1720
ER(CR_SERVER_LOST_EXTENDED),
1619
1721
"Setting intital database",
1624
if (mysql->options.init_commands)
1726
if (drizzle->options.init_commands)
1626
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
1728
DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1627
1729
char **ptr= (char**)init_commands->buffer;
1628
1730
char **end_command= ptr + init_commands->elements;
1630
my_bool reconnect=mysql->reconnect;
1732
my_bool reconnect=drizzle->reconnect;
1733
drizzle->reconnect=0;
1633
1735
for (; ptr < end_command; ptr++)
1636
if (mysql_real_query(mysql,*ptr, (ulong) strlen(*ptr)))
1738
if (drizzle_real_query(drizzle,*ptr, (ulong) strlen(*ptr)))
1740
if (drizzle->fields)
1640
if (!(res= cli_use_result(mysql)))
1642
mysql_free_result(res);
1742
if (!(res= cli_use_result(drizzle)))
1744
drizzle_free_result(res);
1645
mysql->reconnect=reconnect;
1747
drizzle->reconnect=reconnect;
1648
reset_sigpipe(mysql);
1750
reset_sigpipe(drizzle);
1652
reset_sigpipe(mysql);
1754
reset_sigpipe(drizzle);
1654
1756
/* Free alloced memory */
1656
mysql_close_free(mysql);
1757
end_server(drizzle);
1758
drizzle_close_free(drizzle);
1657
1759
if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS))
1658
mysql_close_free_options(mysql);
1760
drizzle_close_free_options(drizzle);
1664
my_bool mysql_reconnect(MYSQL *mysql)
1766
my_bool drizzle_reconnect(DRIZZLE *drizzle)
1768
DRIZZLE tmp_drizzle;
1669
if (!mysql->reconnect ||
1670
(mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info)
1771
if (!drizzle->reconnect ||
1772
(drizzle->server_status & SERVER_STATUS_IN_TRANS) || !drizzle->host_info)
1672
1774
/* 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;
1775
drizzle->server_status&= ~SERVER_STATUS_IN_TRANS;
1776
set_drizzle_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
1779
drizzle_create(&tmp_drizzle);
1780
tmp_drizzle.options= drizzle->options;
1781
tmp_drizzle.options.my_cnf_file= tmp_drizzle.options.my_cnf_group= 0;
1783
if (!drizzle_connect(&tmp_drizzle,drizzle->host,drizzle->user,drizzle->passwd,
1784
drizzle->db, drizzle->port, drizzle->unix_socket,
1785
drizzle->client_flag | CLIENT_REMEMBER_OPTIONS))
1787
drizzle->net.last_errno= tmp_drizzle.net.last_errno;
1788
strmov(drizzle->net.last_error, tmp_drizzle.net.last_error);
1789
strmov(drizzle->net.sqlstate, tmp_drizzle.net.sqlstate);
1792
if (drizzle_set_character_set(&tmp_drizzle, drizzle->charset->csname))
1794
bzero((char*) &tmp_drizzle.options,sizeof(tmp_drizzle.options));
1795
drizzle_close(&tmp_drizzle);
1796
drizzle->net.last_errno= tmp_drizzle.net.last_errno;
1797
strmov(drizzle->net.last_error, tmp_drizzle.net.last_error);
1798
strmov(drizzle->net.sqlstate, tmp_drizzle.net.sqlstate);
1802
tmp_drizzle.reconnect= 1;
1803
tmp_drizzle.free_me= drizzle->free_me;
1805
/* Don't free options as these are now used in tmp_drizzle */
1806
bzero((char*) &drizzle->options,sizeof(drizzle->options));
1808
drizzle_close(drizzle);
1809
*drizzle=tmp_drizzle;
1810
net_clear(&drizzle->net, 1);
1811
drizzle->affected_rows= ~(uint64_t) 0;
1716
1818
**************************************************************************/
1719
mysql_select_db(MYSQL *mysql, const char *db)
1821
drizzle_select_db(DRIZZLE *drizzle, const char *db)
1723
if ((error=simple_command(mysql,COM_INIT_DB, (const uchar*) db,
1825
if ((error=simple_command(drizzle,COM_INIT_DB, (const uchar*) db,
1724
1826
(ulong) strlen(db),0)))
1726
my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
1727
mysql->db=my_strdup(db,MYF(MY_WME));
1828
my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1829
drizzle->db=my_strdup(db,MYF(MY_WME));
1732
1834
/*************************************************************************
1733
1835
Send a QUIT to the server and close the connection
1734
If handle is alloced by mysql connect free it.
1836
If handle is alloced by DRIZZLE connect free it.
1735
1837
*************************************************************************/
1737
static void mysql_close_free_options(MYSQL *mysql)
1839
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)
1841
my_free(drizzle->options.user,MYF(MY_ALLOW_ZERO_PTR));
1842
my_free(drizzle->options.host,MYF(MY_ALLOW_ZERO_PTR));
1843
my_free(drizzle->options.password,MYF(MY_ALLOW_ZERO_PTR));
1844
my_free(drizzle->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
1845
my_free(drizzle->options.db,MYF(MY_ALLOW_ZERO_PTR));
1846
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1847
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1848
my_free(drizzle->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
1849
my_free(drizzle->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
1850
my_free(drizzle->options.client_ip,MYF(MY_ALLOW_ZERO_PTR));
1851
if (drizzle->options.init_commands)
1751
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
1853
DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1752
1854
char **ptr= (char**)init_commands->buffer;
1753
1855
char **end= ptr + init_commands->elements;
1754
1856
for (; ptr<end; ptr++)
1757
1859
my_free((char*)init_commands,MYF(MY_WME));
1759
1861
#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));
1862
if (drizzle->options.shared_memory_base_name != def_shared_memory_base_name)
1863
my_free(drizzle->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
1762
1864
#endif /* HAVE_SMEM */
1763
bzero((char*) &mysql->options,sizeof(mysql->options));
1865
bzero((char*) &drizzle->options,sizeof(drizzle->options));
1768
static void mysql_close_free(MYSQL *mysql)
1870
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;
1872
my_free((uchar*) drizzle->host_info,MYF(MY_ALLOW_ZERO_PTR));
1873
my_free(drizzle->user,MYF(MY_ALLOW_ZERO_PTR));
1874
my_free(drizzle->passwd,MYF(MY_ALLOW_ZERO_PTR));
1875
my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1876
my_free(drizzle->info_buffer,MYF(MY_ALLOW_ZERO_PTR));
1877
drizzle->info_buffer= 0;
1777
1879
/* Clear pointers for better safety */
1778
mysql->host_info= mysql->user= mysql->passwd= mysql->db= 0;
1880
drizzle->host_info= drizzle->user= drizzle->passwd= drizzle->db= 0;
1782
void STDCALL mysql_close(MYSQL *mysql)
1884
void STDCALL drizzle_close(DRIZZLE *drizzle)
1784
if (mysql) /* Some simple safety */
1886
if (drizzle) /* Some simple safety */
1786
1888
/* If connection is still up, send a QUIT message */
1787
if (mysql->net.vio != 0)
1889
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 */
1891
free_old_query(drizzle);
1892
drizzle->status=DRIZZLE_STATUS_READY; /* Force command */
1893
drizzle->reconnect=0;
1894
simple_command(drizzle,COM_QUIT,(uchar*) 0,0,1);
1895
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));
1897
drizzle_close_free_options(drizzle);
1898
drizzle_close_free(drizzle);
1899
if (drizzle->free_me)
1900
my_free((uchar*) drizzle,MYF(0));
1804
static bool cli_read_query_result(MYSQL *mysql)
1906
static bool cli_read_query_result(DRIZZLE *drizzle)
1807
1909
ulong field_count;
1910
DRIZZLE_DATA *fields;
1811
if ((length = cli_safe_read(mysql)) == packet_error)
1913
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*/
1915
free_old_query(drizzle); /* Free old result */
1916
#ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/
1817
pos=(uchar*) mysql->net.read_pos;
1919
pos=(uchar*) drizzle->net.read_pos;
1818
1920
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;
1922
drizzle->affected_rows= net_field_length_ll(&pos);
1923
drizzle->insert_id= net_field_length_ll(&pos);
1924
if (protocol_41(drizzle))
1926
drizzle->server_status=uint2korr(pos); pos+=2;
1927
drizzle->warning_count=uint2korr(pos); pos+=2;
1929
else if (drizzle->server_capabilities & CLIENT_TRANSACTIONS)
1931
/* DRIZZLE 4.0 protocol */
1932
drizzle->server_status=uint2korr(pos); pos+=2;
1933
drizzle->warning_count= 0;
1935
if (pos < drizzle->net.read_pos+length && net_field_length(&pos))
1936
drizzle->info=(char*) pos;
1837
1939
#ifdef MYSQL_CLIENT
1838
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
1940
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
1842
if (!(mysql->options.client_flag & CLIENT_LOCAL_FILES))
1944
if (!(drizzle->options.client_flag & CLIENT_LOCAL_FILES))
1844
set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
1946
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)
1950
error= handle_local_infile(drizzle,(char*) pos);
1951
if ((length= cli_safe_read(drizzle)) == packet_error || error)
1851
goto get_info; /* Get info packet */
1953
goto get_info; /* Get info packet */
1854
if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT))
1855
mysql->server_status|= SERVER_STATUS_IN_TRANS;
1956
if (!(drizzle->server_status & SERVER_STATUS_AUTOCOMMIT))
1957
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;
1959
if (!(fields=cli_read_rows(drizzle,(DRIZZLE_FIELD*)0, protocol_41(drizzle) ? 7:5)))
1961
if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,
1962
(uint) field_count,0,
1963
drizzle->server_capabilities)))
1965
drizzle->status= DRIZZLE_STATUS_GET_RESULT;
1966
drizzle->field_count= (uint) field_count;
1870
1972
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
1973
Needs to be followed by drizzle_read_query_result() when we want to
1872
1974
finish processing it.
1875
1977
int32_t STDCALL
1876
mysql_send_query(MYSQL* mysql, const char* query, uint32_t length)
1978
drizzle_send_query(DRIZZLE *drizzle, const char* query, uint32_t length)
1878
return(simple_command(mysql, COM_QUERY, (uchar*) query, length, 1));
1980
return(simple_command(drizzle, COM_QUERY, (uchar*) query, length, 1));
1882
1984
int32_t STDCALL
1883
mysql_real_query(MYSQL *mysql, const char *query, uint32_t length)
1985
drizzle_real_query(DRIZZLE *drizzle, const char *query, uint32_t length)
1885
if (mysql_send_query(mysql,query,length))
1987
if (drizzle_send_query(drizzle,query,length))
1887
return((int) (*mysql->methods->read_query_result)(mysql));
1989
return((int) (*drizzle->methods->read_query_result)(drizzle));
1891
1993
/**************************************************************************
1892
1994
Alloc result struct for buffered results. All rows are read to buffer.
1893
mysql_data_seek may be used.
1995
drizzle_data_seek may be used.
1894
1996
**************************************************************************/
1896
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql)
1998
DRIZZLE_RES * STDCALL drizzle_store_result(DRIZZLE *drizzle)
2000
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 */
2002
if (!drizzle->fields)
2004
if (drizzle->status != DRIZZLE_STATUS_GET_RESULT)
2006
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
2009
drizzle->status=DRIZZLE_STATUS_READY; /* server is ready */
2010
if (!(result=(DRIZZLE_RES*) my_malloc((uint) (sizeof(DRIZZLE_RES)+
2012
drizzle->field_count),
2013
MYF(MY_WME | MY_ZEROFILL))))
2015
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
2018
result->methods= drizzle->methods;
2019
result->eof= 1; /* Marker for buffered */
1918
2020
result->lengths= (uint32_t*) (result+1);
1919
2021
if (!(result->data=
1920
(*mysql->methods->read_rows)(mysql,mysql->fields,mysql->field_count)))
2022
(*drizzle->methods->read_rows)(drizzle,drizzle->fields,drizzle->field_count)))
1922
2024
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;
2027
drizzle->affected_rows= result->row_count= result->data->rows;
2028
result->data_cursor= result->data->data;
2029
result->fields= drizzle->fields;
2030
result->field_alloc= drizzle->field_alloc;
2031
result->field_count= drizzle->field_count;
1930
2032
/* 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 */
2033
drizzle->fields=0; /* fields is now in result */
2034
clear_alloc_root(&drizzle->field_alloc);
2035
/* just in case this was mistakenly called after drizzle_stmt_execute() */
2036
drizzle->unbuffered_fetch_owner= 0;
2037
return(result); /* Data fetched */
1939
2041
/**************************************************************************
1940
2042
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.
2043
when calling to drizzle_fetch_row.
2044
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
2046
No other queries may be specified with the same DRIZZLE handle.
2047
There shouldn't be much processing per row because DRIZZLE server shouldn't
1946
2048
have to wait for the client (and will not wait more than 30 sec/packet).
1947
2049
**************************************************************************/
1949
static MYSQL_RES * cli_use_result(MYSQL *mysql)
2051
static DRIZZLE_RES * cli_use_result(DRIZZLE *drizzle)
2053
DRIZZLE_RES *result;
2055
if (!drizzle->fields)
1955
if (mysql->status != MYSQL_STATUS_GET_RESULT)
2057
if (drizzle->status != DRIZZLE_STATUS_GET_RESULT)
1957
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
2059
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))))
2062
if (!(result=(DRIZZLE_RES*) my_malloc(sizeof(*result)+
2063
sizeof(ulong)*drizzle->field_count,
2064
MYF(MY_WME | MY_ZEROFILL))))
1964
2066
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 */
2067
result->methods= drizzle->methods;
2068
if (!(result->row=(DRIZZLE_ROW)
2069
my_malloc(sizeof(result->row[0])*(drizzle->field_count+1), MYF(MY_WME))))
2070
{ /* Ptrs: to one row */
1969
2071
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;
2074
result->fields= drizzle->fields;
2075
result->field_alloc= drizzle->field_alloc;
2076
result->field_count= drizzle->field_count;
1975
2077
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 */
2078
result->handle= drizzle;
2079
result->current_row= 0;
2080
drizzle->fields=0; /* fields is now in result */
2081
clear_alloc_root(&drizzle->field_alloc);
2082
drizzle->status=DRIZZLE_STATUS_USE_RESULT;
2083
drizzle->unbuffered_fetch_owner= &result->unbuffered_fetch_cancelled;
2084
return(result); /* Data is read to be fetched */
2056
mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
2158
drizzle_options(DRIZZLE *drizzle,enum drizzle_option option, const void *arg)
2058
2160
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 ?*/
2161
case DRIZZLE_OPT_CONNECT_TIMEOUT:
2162
drizzle->options.connect_timeout= *(uint*) arg;
2164
case DRIZZLE_OPT_READ_TIMEOUT:
2165
drizzle->options.read_timeout= *(uint*) arg;
2167
case DRIZZLE_OPT_WRITE_TIMEOUT:
2168
drizzle->options.write_timeout= *(uint*) arg;
2170
case DRIZZLE_OPT_COMPRESS:
2171
drizzle->options.compress= 1; /* Remember for connect */
2172
drizzle->options.client_flag|= CLIENT_COMPRESS;
2174
case DRIZZLE_OPT_NAMED_PIPE: /* This option is depricated */
2175
drizzle->options.protocol=DRIZZLE_PROTOCOL_PIPE; /* Force named pipe */
2177
case DRIZZLE_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
2076
2178
if (!arg || test(*(uint*) arg))
2077
mysql->options.client_flag|= CLIENT_LOCAL_FILES;
2179
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:
2181
drizzle->options.client_flag&= ~CLIENT_LOCAL_FILES;
2183
case DRIZZLE_INIT_COMMAND:
2184
add_init_command(&drizzle->options,arg);
2186
case DRIZZLE_READ_DEFAULT_FILE:
2187
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
2188
drizzle->options.my_cnf_file=my_strdup(arg,MYF(MY_WME));
2190
case DRIZZLE_READ_DEFAULT_GROUP:
2191
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
2192
drizzle->options.my_cnf_group=my_strdup(arg,MYF(MY_WME));
2194
case DRIZZLE_SET_CHARSET_DIR:
2195
my_free(drizzle->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
2196
drizzle->options.charset_dir=my_strdup(arg,MYF(MY_WME));
2198
case DRIZZLE_SET_CHARSET_NAME:
2199
my_free(drizzle->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
2200
drizzle->options.charset_name=my_strdup(arg,MYF(MY_WME));
2202
case DRIZZLE_OPT_PROTOCOL:
2203
drizzle->options.protocol= *(uint*) arg;
2205
case DRIZZLE_SHARED_MEMORY_BASE_NAME:
2104
2206
#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));
2207
if (drizzle->options.shared_memory_base_name != def_shared_memory_base_name)
2208
my_free(drizzle->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
2209
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:
2212
case DRIZZLE_OPT_USE_REMOTE_CONNECTION:
2213
case DRIZZLE_OPT_USE_EMBEDDED_CONNECTION:
2214
case DRIZZLE_OPT_GUESS_CONNECTION:
2215
drizzle->options.methods_to_use= option;
2217
case DRIZZLE_SET_CLIENT_IP:
2218
drizzle->options.client_ip= my_strdup(arg, MYF(MY_WME));
2220
case DRIZZLE_SECURE_AUTH:
2221
drizzle->options.secure_auth= *(my_bool *) arg;
2223
case DRIZZLE_REPORT_DATA_TRUNCATION:
2224
drizzle->options.report_data_truncation= test(*(my_bool *) arg);
2226
case DRIZZLE_OPT_RECONNECT:
2227
drizzle->reconnect= *(my_bool *) arg;
2229
case DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT:
2128
2230
if (*(my_bool*) arg)
2129
mysql->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
2231
drizzle->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
2131
mysql->options.client_flag&= ~CLIENT_SSL_VERIFY_SERVER_CERT;
2233
drizzle->options.client_flag&= ~CLIENT_SSL_VERIFY_SERVER_CERT;