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)
401
cli_advanced_command(DRIZZLE *drizzle, enum enum_server_command command,
402
const unsigned char *header, uint32_t header_length,
403
const unsigned char *arg, uint32_t arg_length, bool skip_check)
400
NET *net= &mysql->net;
405
NET *net= &drizzle->net;
401
406
my_bool result= 1;
402
407
init_sigpipe_variables
403
408
my_bool stmt_skip= false;
405
410
/* Don't give sigpipe errors if the client doesn't want them */
411
set_sigpipe(drizzle);
408
if (mysql->net.vio == 0)
409
{ /* Do reconnect if possible */
410
if (mysql_reconnect(mysql) || stmt_skip)
413
if (drizzle->net.vio == 0)
414
{ /* Do reconnect if possible */
415
if (drizzle_reconnect(drizzle) || stmt_skip)
413
if (mysql->status != MYSQL_STATUS_READY ||
414
mysql->server_status & SERVER_MORE_RESULTS_EXISTS)
418
if (drizzle->status != DRIZZLE_STATUS_READY ||
419
drizzle->server_status & SERVER_MORE_RESULTS_EXISTS)
416
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
421
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
420
425
net_clear_error(net);
422
mysql->affected_rows= ~(uint64_t) 0;
427
drizzle->affected_rows= ~(uint64_t) 0;
424
429
We don't want to clear the protocol buffer on COM_QUIT, because if
425
430
the previous command was a shutdown command, we may have the
426
431
response for the COM_QUIT already in the communication buffer
428
net_clear(&mysql->net, (command != COM_QUIT));
433
net_clear(&drizzle->net, (command != COM_QUIT));
430
435
if (net_write_command(net,(uchar) command, header, header_length,
433
438
if (net->last_errno == ER_NET_PACKET_TOO_LARGE)
435
set_mysql_error(mysql, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
440
set_drizzle_error(drizzle, CR_NET_PACKET_TOO_LARGE, unknown_sqlstate);
439
if (mysql_reconnect(mysql) || stmt_skip)
444
if (drizzle_reconnect(drizzle) || stmt_skip)
441
446
if (net_write_command(net,(uchar) command, header, header_length,
444
set_mysql_error(mysql, CR_SERVER_GONE_ERROR, unknown_sqlstate);
449
set_drizzle_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
450
result= ((mysql->packet_length=cli_safe_read(mysql)) == packet_error ?
455
result= ((drizzle->packet_length=cli_safe_read(drizzle)) == packet_error ?
453
reset_sigpipe(mysql);
458
reset_sigpipe(drizzle);
457
void free_old_query(MYSQL *mysql)
462
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;
465
free_root(&drizzle->field_alloc,MYF(0));
466
init_alloc_root(&drizzle->field_alloc,8192,0); /* Assume rowlength < 8192 */
468
drizzle->field_count= 0; /* For API */
469
drizzle->warning_count= 0;
600
605
groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0;
602
607
load_defaults(filename, groups, &argc, &argv);
603
if (argc != 1) /* If some default option */
608
if (argc != 1) /* If some default option */
605
610
char **option=argv;
606
611
while (*++option)
608
613
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));
615
char *end=strcend(*option,'=');
620
*end=0; /* Remove '=' */
622
/* Change all '_' in variable name to '-' */
623
for (end= *option ; *(end= strcend(end,'_')) ; )
625
switch (find_type(*option+2,&option_types,2)) {
628
options->port=atoi(opt_arg);
633
my_free(options->unix_socket,MYF(MY_ALLOW_ZERO_PTR));
634
options->unix_socket=my_strdup(opt_arg,MYF(MY_WME));
637
case 3: /* compress */
639
options->client_flag|= CLIENT_COMPRESS;
641
case 4: /* password */
644
my_free(options->password,MYF(MY_ALLOW_ZERO_PTR));
645
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 */
649
options->protocol = DRIZZLE_PROTOCOL_PIPE;
650
case 20: /* connect_timeout */
651
case 6: /* timeout */
653
options->connect_timeout=atoi(opt_arg);
658
my_free(options->user,MYF(MY_ALLOW_ZERO_PTR));
659
options->user=my_strdup(opt_arg,MYF(MY_WME));
662
case 8: /* init-command */
663
add_init_command(options,opt_arg);
668
my_free(options->host,MYF(MY_ALLOW_ZERO_PTR));
669
options->host=my_strdup(opt_arg,MYF(MY_WME));
672
case 10: /* database */
675
my_free(options->db,MYF(MY_ALLOW_ZERO_PTR));
676
options->db=my_strdup(opt_arg,MYF(MY_WME));
679
case 12: /* return-found-rows */
680
options->client_flag|=CLIENT_FOUND_ROWS;
682
case 13: /* Ignore SSL options */
683
case 17: /* charset-lib */
684
my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR));
688
case 17: /* charset-lib */
689
my_free(options->charset_dir,MYF(MY_ALLOW_ZERO_PTR));
685
690
options->charset_dir = my_strdup(opt_arg, MYF(MY_WME));
688
my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR));
693
my_free(options->charset_name,MYF(MY_ALLOW_ZERO_PTR));
689
694
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;
696
case 19: /* Interactive-timeout */
697
options->client_flag|= CLIENT_INTERACTIVE;
700
if (!opt_arg || atoi(opt_arg) != 0)
701
options->client_flag|= CLIENT_LOCAL_FILES;
703
options->client_flag&= ~CLIENT_LOCAL_FILES;
706
options->client_flag&= ~CLIENT_LOCAL_FILES;
703
case 24: /* max-allowed-packet */
708
case 24: /* max-allowed-packet */
705
options->max_allowed_packet= atoi(opt_arg);
710
options->max_allowed_packet= atoi(opt_arg);
707
712
case 25: /* protocol */
708
713
if ((options->protocol= find_type(opt_arg,
709
&sql_protocol_typelib,0)) <= 0)
714
&sql_protocol_typelib,0)) <= 0)
711
716
fprintf(stderr, "Unknown option to protocol: %s\n", opt_arg);
1020
1025
*lengths++=len;
1023
*prev_pos=0; /* Terminate prev field */
1028
*prev_pos=0; /* Terminate prev field */
1026
row[field]=(char*) prev_pos+1; /* End of last field */
1027
*prev_pos=0; /* Terminate last field */
1031
row[field]=(char*) prev_pos+1; /* End of last field */
1032
*prev_pos=0; /* Terminate last field */
1032
1037
/****************************************************************************
1033
Init MySQL structure or allocate one
1038
Init DRIZZLE structure or allocate one
1034
1039
****************************************************************************/
1037
mysql_init(MYSQL *mysql)
1042
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);
1045
if (!drizzle_client_init)
1047
drizzle_client_init=true;
1048
org_my_init_done=my_init_done;
1050
/* Will init threads */
1058
drizzle_port = MYSQL_PORT;
1060
struct servent *serv_ptr;
1064
if builder specifically requested a default port, use that
1065
(even if it coincides with our factory default).
1066
only if they didn't do we check /etc/services (and, failing
1067
on that, fall back to the factory default of 4427).
1068
either default can be overridden by the environment variable
1069
MYSQL_TCP_PORT, which in turn can be overridden with command
1073
#if MYSQL_PORT_DEFAULT == 0
1074
if ((serv_ptr = getservbyname("drizzle", "tcp")))
1075
drizzle_port = (uint) ntohs((ushort) serv_ptr->s_port);
1077
if ((env = getenv("DRIZZLE_TCP_PORT")))
1078
drizzle_port =(uint) atoi(env);
1081
if (!drizzle_unix_port)
1084
drizzle_unix_port = (char*) MYSQL_UNIX_ADDR;
1085
if ((env = getenv("DRIZZLE_UNIX_PORT")))
1086
drizzle_unix_port = env;
1088
#if defined(SIGPIPE)
1089
(void) signal(SIGPIPE, SIG_IGN);
1093
/* Init if new thread */
1094
if (my_thread_init())
1099
ptr= (DRIZZLE *) malloc(sizeof(DRIZZLE));
1103
set_drizzle_error(NULL, CR_OUT_OF_MEMORY, unknown_sqlstate);
1106
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);
1111
memset(ptr, 0, sizeof(DRIZZLE));
1114
ptr->options.connect_timeout= CONNECT_TIMEOUT;
1115
ptr->charset=default_client_charset_info;
1116
strcpy(ptr->net.sqlstate, not_error_sqlstate);
1057
1119
Only enable LOAD DATA INFILE by default if configured with
1058
1120
--enable-local-infile
1061
#if defined(ENABLED_LOCAL_INFILE) && !defined(MYSQL_SERVER)
1062
mysql->options.client_flag|= CLIENT_LOCAL_FILES;
1123
#if defined(ENABLED_LOCAL_INFILE) && !defined(DRIZZLE_SERVER)
1124
ptr->options.client_flag|= CLIENT_LOCAL_FILES;
1065
1127
#ifdef HAVE_SMEM
1066
mysql->options.shared_memory_base_name= (char*) def_shared_memory_base_name;
1128
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 */
1131
ptr->options.methods_to_use= DRIZZLE_OPT_GUESS_CONNECTION;
1132
ptr->options.report_data_truncation= true; /* default */
1073
1135
By default we don't reconnect because it could silently corrupt data (after
1074
1136
reconnection you potentially lose table locks, user variables, session
1075
1137
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.
1138
drizzle_reconnect()).
1139
This is a change: < 5.0.3 drizzle->reconnect was set to 1 by default.
1078
1140
How this change impacts existing apps:
1079
1141
- existing apps which relyed on the default will see a behaviour change;
1080
they will have to set reconnect=1 after mysql_real_connect().
1142
they will have to set reconnect=1 after drizzle_connect().
1081
1143
- 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())
1144
could do it was by setting drizzle.reconnect to 1 after drizzle_connect())
1083
1145
will not see a behaviour change.
1084
1146
- existing apps which explicitely asked for no reconnection
1085
(mysql.reconnect=0) will not see a behaviour change.
1147
(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.
1156
Free all memory and resources used by the client library
1159
When calling this there should not be any other threads using
1162
To make things simpler when used with windows dll's (which calls this
1163
function automaticly), it's safe to call this function multiple times.
1167
void STDCALL drizzle_server_end()
1169
if (!drizzle_client_init)
1172
finish_client_errs();
1175
/* If library called my_init(), free memory allocated by it */
1176
if (!org_my_init_done)
1183
drizzle_thread_end();
1186
drizzle_client_init= org_my_init_done= 0;
1187
#ifdef EMBEDDED_SERVER
1190
fclose(stderror_file);
1198
Fill in SSL part of DRIZZLE structure and set 'use_ssl' flag.
1199
NB! Errors are not reported until you do drizzle_connect.
1098
1202
#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 !
1205
Note that the drizzle argument must be initialized with drizzle_init()
1206
before calling drizzle_connect !
1105
static bool cli_read_query_result(MYSQL *mysql);
1106
static MYSQL_RES *cli_use_result(MYSQL *mysql);
1209
static bool cli_read_query_result(DRIZZLE *drizzle);
1210
static DRIZZLE_RES *cli_use_result(DRIZZLE *drizzle);
1108
static MYSQL_METHODS client_methods=
1212
static DRIZZLE_METHODS client_methods=
1110
1214
cli_read_query_result, /* read_query_result */
1111
1215
cli_advanced_command, /* advanced_command */
1128
int mysql_init_character_set(MYSQL *mysql)
1232
int drizzle_init_character_set(DRIZZLE *drizzle)
1130
1234
const char *default_collation_name;
1132
1236
/* Set character set */
1133
if (!mysql->options.charset_name)
1237
if (!drizzle->options.charset_name)
1135
1239
default_collation_name= MYSQL_DEFAULT_COLLATION_NAME;
1136
if (!(mysql->options.charset_name=
1240
if (!(drizzle->options.charset_name=
1137
1241
my_strdup(MYSQL_DEFAULT_CHARSET_NAME,MYF(MY_WME))))
1141
1245
default_collation_name= NULL;
1144
1248
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,
1249
if (drizzle->options.charset_dir)
1250
charsets_dir=drizzle->options.charset_dir;
1251
drizzle->charset=get_charset_by_csname(drizzle->options.charset_name,
1148
1252
MY_CS_PRIMARY, MYF(MY_WME));
1149
if (mysql->charset && default_collation_name)
1253
if (drizzle->charset && default_collation_name)
1151
1255
CHARSET_INFO *collation;
1153
1257
get_charset_by_name(default_collation_name, MYF(MY_WME))))
1155
if (!my_charset_same(mysql->charset, collation))
1259
if (!my_charset_same(drizzle->charset, collation))
1157
my_printf_error(ER_UNKNOWN_ERROR,
1261
my_printf_error(ER_UNKNOWN_ERROR,
1158
1262
"COLLATION %s is not valid for CHARACTER SET %s",
1160
default_collation_name, mysql->options.charset_name);
1161
mysql->charset= NULL;
1264
default_collation_name, drizzle->options.charset_name);
1265
drizzle->charset= NULL;
1165
mysql->charset= collation;
1269
drizzle->charset= collation;
1169
mysql->charset= NULL;
1273
drizzle->charset= NULL;
1171
1275
charsets_dir= save;
1174
if (!mysql->charset)
1278
if (!drizzle->charset)
1176
if (mysql->options.charset_dir)
1177
set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
1280
if (drizzle->options.charset_dir)
1281
set_drizzle_extended_error(drizzle, CR_CANT_READ_CHARSET, unknown_sqlstate,
1178
1282
ER(CR_CANT_READ_CHARSET),
1179
mysql->options.charset_name,
1180
mysql->options.charset_dir);
1283
drizzle->options.charset_name,
1284
drizzle->options.charset_dir);
1183
1287
char cs_dir_name[FN_REFLEN];
1184
1288
get_charsets_dir(cs_dir_name);
1185
set_mysql_extended_error(mysql, CR_CANT_READ_CHARSET, unknown_sqlstate,
1289
set_drizzle_extended_error(drizzle, CR_CANT_READ_CHARSET, unknown_sqlstate,
1186
1290
ER(CR_CANT_READ_CHARSET),
1187
mysql->options.charset_name,
1291
drizzle->options.charset_name,
1198
CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user,
1302
CLI_DRIZZLE_CONNECT(DRIZZLE *drizzle,const char *host, const char *user,
1199
1303
const char *passwd, const char *db,
1200
1304
uint32_t port, const char *unix_socket, uint32_t client_flag)
1202
1306
char buff[NAME_LEN+USERNAME_LENGTH+100];
1203
1307
char *end,*host_info=NULL;
1204
1308
uint32_t pkt_length;
1205
NET *net= &mysql->net;
1309
NET *net= &drizzle->net;
1206
1310
struct sockaddr_un UNIXaddr;
1207
1311
init_sigpipe_variables
1209
1313
/* 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 */
1314
set_sigpipe(drizzle);
1315
drizzle->methods= &client_methods;
1316
net->vio = 0; /* If something goes wrong */
1317
drizzle->client_flag=0; /* For handshake */
1215
1319
/* use default options */
1216
if (mysql->options.my_cnf_file || mysql->options.my_cnf_group)
1320
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;
1322
drizzle_read_default_options(&drizzle->options,
1323
(drizzle->options.my_cnf_file ?
1324
drizzle->options.my_cnf_file : "my"),
1325
drizzle->options.my_cnf_group);
1326
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1327
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1328
drizzle->options.my_cnf_file=drizzle->options.my_cnf_group=0;
1227
1331
/* Some empty-string-tests are done because of ODBC */
1228
1332
if (!host || !host[0])
1229
host=mysql->options.host;
1333
host=drizzle->options.host;
1230
1334
if (!user || !user[0])
1232
user=mysql->options.user;
1336
user=drizzle->options.user;
1238
passwd=mysql->options.password;
1342
passwd=drizzle->options.password;
1242
1346
if (!db || !db[0])
1243
db=mysql->options.db;
1347
db=drizzle->options.db;
1245
port=mysql->options.port;
1349
port=drizzle->options.port;
1246
1350
if (!unix_socket)
1247
unix_socket=mysql->options.unix_socket;
1351
unix_socket=drizzle->options.unix_socket;
1249
mysql->server_status=SERVER_STATUS_AUTOCOMMIT;
1353
drizzle->server_status=SERVER_STATUS_AUTOCOMMIT;
1252
1356
Part 0: Grab a socket and connect it to the server
1254
1358
#if defined(HAVE_SMEM)
1255
if ((!mysql->options.protocol ||
1256
mysql->options.protocol == MYSQL_PROTOCOL_MEMORY) &&
1359
if ((!drizzle->options.protocol ||
1360
drizzle->options.protocol == DRIZZLE_PROTOCOL_MEMORY) &&
1257
1361
(!host || !strcmp(host,LOCAL_HOST)))
1259
if ((create_shared_memory(mysql,net, mysql->options.connect_timeout)) ==
1260
INVALID_HANDLE_VALUE)
1363
if ((create_shared_memory(drizzle,net, drizzle->options.connect_timeout)) ==
1364
INVALID_HANDLE_VALUE)
1262
if (mysql->options.protocol == MYSQL_PROTOCOL_MEMORY)
1366
if (drizzle->options.protocol == DRIZZLE_PROTOCOL_MEMORY)
1266
1370
Try also with PIPE or TCP/IP. Clear the error from
1451
1555
/* Check if version of protocol matches current one */
1453
mysql->protocol_version= net->read_pos[0];
1454
if (mysql->protocol_version != PROTOCOL_VERSION)
1557
drizzle->protocol_version= net->read_pos[0];
1558
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,
1560
set_drizzle_extended_error(drizzle, CR_VERSION_ERROR, unknown_sqlstate,
1561
ER(CR_VERSION_ERROR), drizzle->protocol_version,
1458
1562
PROTOCOL_VERSION);
1461
1565
end=strend((char*) net->read_pos+1);
1462
mysql->thread_id=uint4korr(end+1);
1566
drizzle->thread_id=uint4korr(end+1);
1465
1569
Scramble is split into two parts because old clients does not understand
1466
1570
long scrambles; here goes the first part.
1468
strmake(mysql->scramble, end, SCRAMBLE_LENGTH_323);
1572
strmake(drizzle->scramble, end, SCRAMBLE_LENGTH_323);
1469
1573
end+= SCRAMBLE_LENGTH_323+1;
1471
1575
if (pkt_length >= (uint) (end+1 - (char*) net->read_pos))
1472
mysql->server_capabilities=uint2korr(end);
1576
drizzle->server_capabilities=uint2korr(end);
1473
1577
if (pkt_length >= (uint) (end+18 - (char*) net->read_pos))
1475
1579
/* New protocol with 16 bytes to describe server characteristics */
1476
mysql->server_language=end[2];
1477
mysql->server_status=uint2korr(end+3);
1580
drizzle->server_language=end[2];
1581
drizzle->server_status=uint2korr(end+3);
1480
if (pkt_length >= (uint) (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 -
1584
if (pkt_length >= (uint) (end + SCRAMBLE_LENGTH - SCRAMBLE_LENGTH_323 + 1 -
1481
1585
(char *) net->read_pos))
1482
strmake(mysql->scramble+SCRAMBLE_LENGTH_323, end,
1586
strmake(drizzle->scramble+SCRAMBLE_LENGTH_323, end,
1483
1587
SCRAMBLE_LENGTH-SCRAMBLE_LENGTH_323);
1485
mysql->server_capabilities&= ~CLIENT_SECURE_CONNECTION;
1589
drizzle->server_capabilities&= ~CLIENT_SECURE_CONNECTION;
1487
if (mysql->options.secure_auth && passwd[0] &&
1488
!(mysql->server_capabilities & CLIENT_SECURE_CONNECTION))
1591
if (drizzle->options.secure_auth && passwd[0] &&
1592
!(drizzle->server_capabilities & CLIENT_SECURE_CONNECTION))
1490
set_mysql_error(mysql, CR_SECURE_AUTH, unknown_sqlstate);
1594
set_drizzle_error(drizzle, CR_SECURE_AUTH, unknown_sqlstate);
1494
if (mysql_init_character_set(mysql))
1598
if (drizzle_init_character_set(drizzle))
1497
1601
/* Save connection information */
1498
1602
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))))
1603
&drizzle->host_info, (uint) strlen(host_info)+1,
1604
&drizzle->host, (uint) strlen(host)+1,
1605
&drizzle->unix_socket,unix_socket ?
1606
(uint) strlen(unix_socket)+1 : (uint) 1,
1607
&drizzle->server_version,
1608
(uint) (end - (char*) net->read_pos),
1610
!(drizzle->user=my_strdup(user,MYF(0))) ||
1611
!(drizzle->passwd=my_strdup(passwd,MYF(0))))
1509
set_mysql_error(mysql, CR_OUT_OF_MEMORY, unknown_sqlstate);
1613
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
1512
strmov(mysql->host_info,host_info);
1513
strmov(mysql->host,host);
1616
strmov(drizzle->host_info,host_info);
1617
strmov(drizzle->host,host);
1514
1618
if (unix_socket)
1515
strmov(mysql->unix_socket,unix_socket);
1619
strmov(drizzle->unix_socket,unix_socket);
1517
mysql->unix_socket=0;
1518
strmov(mysql->server_version,(char*) net->read_pos+1);
1621
drizzle->unix_socket=0;
1622
strmov(drizzle->server_version,(char*) net->read_pos+1);
1522
1626
Part 2: format and send client info to the server for access check
1525
client_flag|=mysql->options.client_flag;
1629
client_flag|=drizzle->options.client_flag;
1526
1630
client_flag|=CLIENT_CAPABILITIES;
1527
1631
if (client_flag & CLIENT_MULTI_STATEMENTS)
1528
1632
client_flag|= CLIENT_MULTI_RESULTS;
1576
1680
*end++= '\0'; /* empty password */
1578
1682
/* Add database if needed */
1579
if (db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB))
1683
if (db && (drizzle->server_capabilities & CLIENT_CONNECT_WITH_DB))
1581
1685
end= strmake(end, db, NAME_LEN) + 1;
1582
mysql->db= my_strdup(db,MYF(MY_WME));
1686
drizzle->db= my_strdup(db,MYF(MY_WME));
1585
1689
/* Write authentication package */
1586
1690
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,
1692
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1589
1693
ER(CR_SERVER_LOST_EXTENDED),
1590
1694
"sending authentication information",
1596
1700
Part 3: Authorization data's been sent. Now server can reply with
1597
1701
OK-packet, or re-request scrambled password.
1600
if ((pkt_length=cli_safe_read(mysql)) == packet_error)
1704
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,
1706
if (drizzle->net.last_errno == CR_SERVER_LOST)
1707
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1604
1708
ER(CR_SERVER_LOST_EXTENDED),
1605
1709
"reading authorization packet",
1610
if (client_flag & CLIENT_COMPRESS) /* We will use compression */
1714
if (client_flag & CLIENT_COMPRESS) /* We will use compression */
1611
1715
net->compress=1;
1614
if (db && mysql_select_db(mysql, db))
1718
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,
1720
if (drizzle->net.last_errno == CR_SERVER_LOST)
1721
set_drizzle_extended_error(drizzle, CR_SERVER_LOST, unknown_sqlstate,
1618
1722
ER(CR_SERVER_LOST_EXTENDED),
1619
1723
"Setting intital database",
1624
if (mysql->options.init_commands)
1728
if (drizzle->options.init_commands)
1626
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
1730
DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1627
1731
char **ptr= (char**)init_commands->buffer;
1628
1732
char **end_command= ptr + init_commands->elements;
1630
my_bool reconnect=mysql->reconnect;
1734
my_bool reconnect=drizzle->reconnect;
1735
drizzle->reconnect=0;
1633
1737
for (; ptr < end_command; ptr++)
1636
if (mysql_real_query(mysql,*ptr, (ulong) strlen(*ptr)))
1740
if (drizzle_real_query(drizzle,*ptr, (ulong) strlen(*ptr)))
1742
if (drizzle->fields)
1640
if (!(res= cli_use_result(mysql)))
1642
mysql_free_result(res);
1744
if (!(res= cli_use_result(drizzle)))
1746
drizzle_free_result(res);
1645
mysql->reconnect=reconnect;
1749
drizzle->reconnect=reconnect;
1648
reset_sigpipe(mysql);
1752
reset_sigpipe(drizzle);
1652
reset_sigpipe(mysql);
1756
reset_sigpipe(drizzle);
1654
1758
/* Free alloced memory */
1656
mysql_close_free(mysql);
1759
end_server(drizzle);
1760
drizzle_close_free(drizzle);
1657
1761
if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS))
1658
mysql_close_free_options(mysql);
1762
drizzle_close_free_options(drizzle);
1664
my_bool mysql_reconnect(MYSQL *mysql)
1768
my_bool drizzle_reconnect(DRIZZLE *drizzle)
1770
DRIZZLE tmp_drizzle;
1669
if (!mysql->reconnect ||
1670
(mysql->server_status & SERVER_STATUS_IN_TRANS) || !mysql->host_info)
1773
if (!drizzle->reconnect ||
1774
(drizzle->server_status & SERVER_STATUS_IN_TRANS) || !drizzle->host_info)
1672
1776
/* 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;
1777
drizzle->server_status&= ~SERVER_STATUS_IN_TRANS;
1778
set_drizzle_error(drizzle, CR_SERVER_GONE_ERROR, unknown_sqlstate);
1781
drizzle_create(&tmp_drizzle);
1782
tmp_drizzle.options= drizzle->options;
1783
tmp_drizzle.options.my_cnf_file= tmp_drizzle.options.my_cnf_group= 0;
1785
if (!drizzle_connect(&tmp_drizzle,drizzle->host,drizzle->user,drizzle->passwd,
1786
drizzle->db, drizzle->port, drizzle->unix_socket,
1787
drizzle->client_flag | CLIENT_REMEMBER_OPTIONS))
1789
drizzle->net.last_errno= tmp_drizzle.net.last_errno;
1790
strmov(drizzle->net.last_error, tmp_drizzle.net.last_error);
1791
strmov(drizzle->net.sqlstate, tmp_drizzle.net.sqlstate);
1794
if (drizzle_set_character_set(&tmp_drizzle, drizzle->charset->csname))
1796
memset((char*) &tmp_drizzle.options, 0, sizeof(tmp_drizzle.options));
1797
drizzle_close(&tmp_drizzle);
1798
drizzle->net.last_errno= tmp_drizzle.net.last_errno;
1799
strmov(drizzle->net.last_error, tmp_drizzle.net.last_error);
1800
strmov(drizzle->net.sqlstate, tmp_drizzle.net.sqlstate);
1804
tmp_drizzle.reconnect= 1;
1805
tmp_drizzle.free_me= drizzle->free_me;
1807
/* Don't free options as these are now used in tmp_drizzle */
1808
memset((char*) &drizzle->options, 0, sizeof(drizzle->options));
1810
drizzle_close(drizzle);
1811
*drizzle=tmp_drizzle;
1812
net_clear(&drizzle->net, 1);
1813
drizzle->affected_rows= ~(uint64_t) 0;
1716
1820
**************************************************************************/
1719
mysql_select_db(MYSQL *mysql, const char *db)
1823
drizzle_select_db(DRIZZLE *drizzle, const char *db)
1723
if ((error=simple_command(mysql,COM_INIT_DB, (const uchar*) db,
1827
if ((error=simple_command(drizzle,COM_INIT_DB, (const uchar*) db,
1724
1828
(ulong) strlen(db),0)))
1726
my_free(mysql->db,MYF(MY_ALLOW_ZERO_PTR));
1727
mysql->db=my_strdup(db,MYF(MY_WME));
1830
my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1831
drizzle->db=my_strdup(db,MYF(MY_WME));
1732
1836
/*************************************************************************
1733
1837
Send a QUIT to the server and close the connection
1734
If handle is alloced by mysql connect free it.
1838
If handle is alloced by DRIZZLE connect free it.
1735
1839
*************************************************************************/
1737
static void mysql_close_free_options(MYSQL *mysql)
1841
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)
1843
my_free(drizzle->options.user,MYF(MY_ALLOW_ZERO_PTR));
1844
my_free(drizzle->options.host,MYF(MY_ALLOW_ZERO_PTR));
1845
my_free(drizzle->options.password,MYF(MY_ALLOW_ZERO_PTR));
1846
my_free(drizzle->options.unix_socket,MYF(MY_ALLOW_ZERO_PTR));
1847
my_free(drizzle->options.db,MYF(MY_ALLOW_ZERO_PTR));
1848
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
1849
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
1850
my_free(drizzle->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
1851
my_free(drizzle->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
1852
my_free(drizzle->options.client_ip,MYF(MY_ALLOW_ZERO_PTR));
1853
if (drizzle->options.init_commands)
1751
DYNAMIC_ARRAY *init_commands= mysql->options.init_commands;
1855
DYNAMIC_ARRAY *init_commands= drizzle->options.init_commands;
1752
1856
char **ptr= (char**)init_commands->buffer;
1753
1857
char **end= ptr + init_commands->elements;
1754
1858
for (; ptr<end; ptr++)
1757
1861
my_free((char*)init_commands,MYF(MY_WME));
1759
1863
#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));
1864
if (drizzle->options.shared_memory_base_name != def_shared_memory_base_name)
1865
my_free(drizzle->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
1762
1866
#endif /* HAVE_SMEM */
1763
bzero((char*) &mysql->options,sizeof(mysql->options));
1867
memset((char*) &drizzle->options, 0, sizeof(drizzle->options));
1768
static void mysql_close_free(MYSQL *mysql)
1872
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;
1874
my_free((uchar*) drizzle->host_info,MYF(MY_ALLOW_ZERO_PTR));
1875
my_free(drizzle->user,MYF(MY_ALLOW_ZERO_PTR));
1876
my_free(drizzle->passwd,MYF(MY_ALLOW_ZERO_PTR));
1877
my_free(drizzle->db,MYF(MY_ALLOW_ZERO_PTR));
1878
my_free(drizzle->info_buffer,MYF(MY_ALLOW_ZERO_PTR));
1879
drizzle->info_buffer= 0;
1777
1881
/* Clear pointers for better safety */
1778
mysql->host_info= mysql->user= mysql->passwd= mysql->db= 0;
1882
drizzle->host_info= drizzle->user= drizzle->passwd= drizzle->db= 0;
1782
void STDCALL mysql_close(MYSQL *mysql)
1886
void STDCALL drizzle_close(DRIZZLE *drizzle)
1784
if (mysql) /* Some simple safety */
1888
if (drizzle) /* Some simple safety */
1786
1890
/* If connection is still up, send a QUIT message */
1787
if (mysql->net.vio != 0)
1891
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 */
1893
free_old_query(drizzle);
1894
drizzle->status=DRIZZLE_STATUS_READY; /* Force command */
1895
drizzle->reconnect=0;
1896
simple_command(drizzle,COM_QUIT,(uchar*) 0,0,1);
1897
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));
1899
drizzle_close_free_options(drizzle);
1900
drizzle_close_free(drizzle);
1901
if (drizzle->free_me)
1902
my_free((uchar*) drizzle,MYF(0));
1804
static bool cli_read_query_result(MYSQL *mysql)
1908
static bool cli_read_query_result(DRIZZLE *drizzle)
1807
1911
ulong field_count;
1912
DRIZZLE_DATA *fields;
1811
if ((length = cli_safe_read(mysql)) == packet_error)
1915
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*/
1917
free_old_query(drizzle); /* Free old result */
1918
#ifdef MYSQL_CLIENT /* Avoid warn of unused labels*/
1817
pos=(uchar*) mysql->net.read_pos;
1921
pos=(uchar*) drizzle->net.read_pos;
1818
1922
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;
1924
drizzle->affected_rows= net_field_length_ll(&pos);
1925
drizzle->insert_id= net_field_length_ll(&pos);
1926
if (protocol_41(drizzle))
1928
drizzle->server_status=uint2korr(pos); pos+=2;
1929
drizzle->warning_count=uint2korr(pos); pos+=2;
1931
else if (drizzle->server_capabilities & CLIENT_TRANSACTIONS)
1933
/* DRIZZLE 4.0 protocol */
1934
drizzle->server_status=uint2korr(pos); pos+=2;
1935
drizzle->warning_count= 0;
1937
if (pos < drizzle->net.read_pos+length && net_field_length(&pos))
1938
drizzle->info=(char*) pos;
1837
1941
#ifdef MYSQL_CLIENT
1838
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
1942
if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */
1842
if (!(mysql->options.client_flag & CLIENT_LOCAL_FILES))
1946
if (!(drizzle->options.client_flag & CLIENT_LOCAL_FILES))
1844
set_mysql_error(mysql, CR_MALFORMED_PACKET, unknown_sqlstate);
1948
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)
1952
error= handle_local_infile(drizzle,(char*) pos);
1953
if ((length= cli_safe_read(drizzle)) == packet_error || error)
1851
goto get_info; /* Get info packet */
1955
goto get_info; /* Get info packet */
1854
if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT))
1855
mysql->server_status|= SERVER_STATUS_IN_TRANS;
1958
if (!(drizzle->server_status & SERVER_STATUS_AUTOCOMMIT))
1959
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;
1961
if (!(fields=cli_read_rows(drizzle,(DRIZZLE_FIELD*)0, protocol_41(drizzle) ? 7:5)))
1963
if (!(drizzle->fields=unpack_fields(fields,&drizzle->field_alloc,
1964
(uint) field_count,0,
1965
drizzle->server_capabilities)))
1967
drizzle->status= DRIZZLE_STATUS_GET_RESULT;
1968
drizzle->field_count= (uint) field_count;
1870
1974
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
1975
Needs to be followed by drizzle_read_query_result() when we want to
1872
1976
finish processing it.
1875
1979
int32_t STDCALL
1876
mysql_send_query(MYSQL* mysql, const char* query, uint32_t length)
1980
drizzle_send_query(DRIZZLE *drizzle, const char* query, uint32_t length)
1878
return(simple_command(mysql, COM_QUERY, (uchar*) query, length, 1));
1982
return(simple_command(drizzle, COM_QUERY, (uchar*) query, length, 1));
1882
1986
int32_t STDCALL
1883
mysql_real_query(MYSQL *mysql, const char *query, uint32_t length)
1987
drizzle_real_query(DRIZZLE *drizzle, const char *query, uint32_t length)
1885
if (mysql_send_query(mysql,query,length))
1989
if (drizzle_send_query(drizzle,query,length))
1887
return((int) (*mysql->methods->read_query_result)(mysql));
1991
return((int) (*drizzle->methods->read_query_result)(drizzle));
1891
1995
/**************************************************************************
1892
1996
Alloc result struct for buffered results. All rows are read to buffer.
1893
mysql_data_seek may be used.
1997
drizzle_data_seek may be used.
1894
1998
**************************************************************************/
1896
MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql)
2000
DRIZZLE_RES * STDCALL drizzle_store_result(DRIZZLE *drizzle)
2002
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 */
2004
if (!drizzle->fields)
2006
if (drizzle->status != DRIZZLE_STATUS_GET_RESULT)
2008
set_drizzle_error(drizzle, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
2011
drizzle->status=DRIZZLE_STATUS_READY; /* server is ready */
2012
if (!(result=(DRIZZLE_RES*) my_malloc((uint) (sizeof(DRIZZLE_RES)+
2014
drizzle->field_count),
2015
MYF(MY_WME | MY_ZEROFILL))))
2017
set_drizzle_error(drizzle, CR_OUT_OF_MEMORY, unknown_sqlstate);
2020
result->methods= drizzle->methods;
2021
result->eof= 1; /* Marker for buffered */
1918
2022
result->lengths= (uint32_t*) (result+1);
1919
2023
if (!(result->data=
1920
(*mysql->methods->read_rows)(mysql,mysql->fields,mysql->field_count)))
2024
(*drizzle->methods->read_rows)(drizzle,drizzle->fields,drizzle->field_count)))
1922
2026
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;
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 */
2029
drizzle->affected_rows= result->row_count= result->data->rows;
2030
result->data_cursor= result->data->data;
2031
result->fields= drizzle->fields;
2032
result->field_alloc= drizzle->field_alloc;
2033
result->field_count= drizzle->field_count;
2034
/* The rest of result members is zeroed in malloc */
2035
drizzle->fields=0; /* fields is now in result */
2036
clear_alloc_root(&drizzle->field_alloc);
2037
/* just in case this was mistakenly called after drizzle_stmt_execute() */
2038
drizzle->unbuffered_fetch_owner= 0;
2039
return(result); /* Data fetched */
1939
2043
/**************************************************************************
1940
2044
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.
2045
when calling to drizzle_fetch_row.
2046
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
2048
No other queries may be specified with the same DRIZZLE handle.
2049
There shouldn't be much processing per row because DRIZZLE server shouldn't
1946
2050
have to wait for the client (and will not wait more than 30 sec/packet).
1947
2051
**************************************************************************/
1949
static MYSQL_RES * cli_use_result(MYSQL *mysql)
2053
static DRIZZLE_RES * cli_use_result(DRIZZLE *drizzle)
2055
DRIZZLE_RES *result;
2057
if (!drizzle->fields)
1955
if (mysql->status != MYSQL_STATUS_GET_RESULT)
2059
if (drizzle->status != DRIZZLE_STATUS_GET_RESULT)
1957
set_mysql_error(mysql, CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate);
2061
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))))
2064
if (!(result=(DRIZZLE_RES*) my_malloc(sizeof(*result)+
2065
sizeof(ulong)*drizzle->field_count,
2066
MYF(MY_WME | MY_ZEROFILL))))
1964
2068
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 */
2069
result->methods= drizzle->methods;
2070
if (!(result->row=(DRIZZLE_ROW)
2071
my_malloc(sizeof(result->row[0])*(drizzle->field_count+1), MYF(MY_WME))))
2072
{ /* Ptrs: to one row */
1969
2073
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;
2076
result->fields= drizzle->fields;
2077
result->field_alloc= drizzle->field_alloc;
2078
result->field_count= drizzle->field_count;
1975
2079
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 */
2080
result->handle= drizzle;
2081
result->current_row= 0;
2082
drizzle->fields=0; /* fields is now in result */
2083
clear_alloc_root(&drizzle->field_alloc);
2084
drizzle->status=DRIZZLE_STATUS_USE_RESULT;
2085
drizzle->unbuffered_fetch_owner= &result->unbuffered_fetch_cancelled;
2086
return(result); /* Data is read to be fetched */
2056
mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg)
2160
drizzle_options(DRIZZLE *drizzle,enum drizzle_option option, const void *arg)
2058
2162
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 ?*/
2163
case DRIZZLE_OPT_CONNECT_TIMEOUT:
2164
drizzle->options.connect_timeout= *(uint*) arg;
2166
case DRIZZLE_OPT_READ_TIMEOUT:
2167
drizzle->options.read_timeout= *(uint*) arg;
2169
case DRIZZLE_OPT_WRITE_TIMEOUT:
2170
drizzle->options.write_timeout= *(uint*) arg;
2172
case DRIZZLE_OPT_COMPRESS:
2173
drizzle->options.compress= 1; /* Remember for connect */
2174
drizzle->options.client_flag|= CLIENT_COMPRESS;
2176
case DRIZZLE_OPT_NAMED_PIPE: /* This option is depricated */
2177
drizzle->options.protocol=DRIZZLE_PROTOCOL_PIPE; /* Force named pipe */
2179
case DRIZZLE_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/
2076
2180
if (!arg || test(*(uint*) arg))
2077
mysql->options.client_flag|= CLIENT_LOCAL_FILES;
2181
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:
2183
drizzle->options.client_flag&= ~CLIENT_LOCAL_FILES;
2185
case DRIZZLE_INIT_COMMAND:
2186
add_init_command(&drizzle->options,arg);
2188
case DRIZZLE_READ_DEFAULT_FILE:
2189
my_free(drizzle->options.my_cnf_file,MYF(MY_ALLOW_ZERO_PTR));
2190
drizzle->options.my_cnf_file=my_strdup(arg,MYF(MY_WME));
2192
case DRIZZLE_READ_DEFAULT_GROUP:
2193
my_free(drizzle->options.my_cnf_group,MYF(MY_ALLOW_ZERO_PTR));
2194
drizzle->options.my_cnf_group=my_strdup(arg,MYF(MY_WME));
2196
case DRIZZLE_SET_CHARSET_DIR:
2197
my_free(drizzle->options.charset_dir,MYF(MY_ALLOW_ZERO_PTR));
2198
drizzle->options.charset_dir=my_strdup(arg,MYF(MY_WME));
2200
case DRIZZLE_SET_CHARSET_NAME:
2201
my_free(drizzle->options.charset_name,MYF(MY_ALLOW_ZERO_PTR));
2202
drizzle->options.charset_name=my_strdup(arg,MYF(MY_WME));
2204
case DRIZZLE_OPT_PROTOCOL:
2205
drizzle->options.protocol= *(uint*) arg;
2207
case DRIZZLE_SHARED_MEMORY_BASE_NAME:
2104
2208
#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));
2209
if (drizzle->options.shared_memory_base_name != def_shared_memory_base_name)
2210
my_free(drizzle->options.shared_memory_base_name,MYF(MY_ALLOW_ZERO_PTR));
2211
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:
2214
case DRIZZLE_OPT_USE_REMOTE_CONNECTION:
2215
case DRIZZLE_OPT_USE_EMBEDDED_CONNECTION:
2216
case DRIZZLE_OPT_GUESS_CONNECTION:
2217
drizzle->options.methods_to_use= option;
2219
case DRIZZLE_SET_CLIENT_IP:
2220
drizzle->options.client_ip= my_strdup(arg, MYF(MY_WME));
2222
case DRIZZLE_SECURE_AUTH:
2223
drizzle->options.secure_auth= *(my_bool *) arg;
2225
case DRIZZLE_REPORT_DATA_TRUNCATION:
2226
drizzle->options.report_data_truncation= test(*(my_bool *) arg);
2228
case DRIZZLE_OPT_RECONNECT:
2229
drizzle->reconnect= *(my_bool *) arg;
2231
case DRIZZLE_OPT_SSL_VERIFY_SERVER_CERT:
2128
2232
if (*(my_bool*) arg)
2129
mysql->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
2233
drizzle->options.client_flag|= CLIENT_SSL_VERIFY_SERVER_CERT;
2131
mysql->options.client_flag&= ~CLIENT_SSL_VERIFY_SERVER_CERT;
2235
drizzle->options.client_flag&= ~CLIENT_SSL_VERIFY_SERVER_CERT;