38
38
Function called by drizzleclient_net_init() to set some check variables
42
void drizzleclient_net_local_init(NET *net)
44
net->max_packet= (uint32_t) global_system_variables.net_buffer_length;
46
drizzleclient_net_set_read_timeout(net,
47
(uint32_t)global_system_variables.net_read_timeout);
48
drizzleclient_net_set_write_timeout(net,
49
(uint32_t)global_system_variables.net_write_timeout);
51
net->retry_count= (uint32_t) global_system_variables.net_retry_count;
52
net->max_packet_size= cmax(global_system_variables.net_buffer_length,
53
global_system_variables.max_allowed_packet);
57
41
static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;
59
43
static void write_eof_packet(Session *session, NET *net,
153
137
bool ProtocolOldLibdrizzle::netStoreData(const unsigned char *from, size_t length,
154
138
const CHARSET_INFO * const from_cs,
155
const CHARSET_INFO * const to_cs)
139
const CHARSET_INFO * const to_cs)
157
141
uint32_t dummy_errors;
158
142
/* Calculate maxumum possible result length */
199
183
The ok packet has the following structure:
201
185
- 0 : Marker (1 byte)
202
- affected_rows : Stored in 1-9 bytes
203
- id : Stored in 1-9 bytes
204
- server_status : Copy of session->server_status; Can be used by client
186
- affected_rows : Stored in 1-9 bytes
187
- id : Stored in 1-9 bytes
188
- server_status : Copy of session->server_status; Can be used by client
205
189
to check if we are inside an transaction.
206
190
New in 4.0 protocol
207
- warning_count : Stored in 2 bytes; New in 4.1 protocol
208
- message : Stored as packed length (1-9 bytes) + message.
191
- warning_count : Stored in 2 bytes; New in 4.1 protocol
192
- message : Stored as packed length (1-9 bytes) + message.
209
193
Is not stored if no message.
211
@param session Thread handler
212
@param affected_rows Number of rows changed by statement
213
@param id Auto_increment id for first row (if used)
214
@param message Message to send to the client (Used by mysql_status)
195
@param session Thread handler
196
@param affected_rows Number of rows changed by statement
197
@param id Auto_increment id for first row (if used)
198
@param message Message to send to the client (Used by mysql_status)
222
206
unsigned char buff[DRIZZLE_ERRMSG_SIZE+10],*pos;
224
if (!net->vio) // hack for re-parsing queries
208
if (!net->vio) // hack for re-parsing queries
229
buff[0]=0; // No fields
213
buff[0]=0; // No fields
230
214
pos=drizzleclient_net_store_length(buff+1,affected_rows);
231
215
pos=drizzleclient_net_store_length(pos, id);
232
216
int2store(pos, server_status);
258
242
const char *message= NULL;
261
if (!net.vio) // hack for re-parsing queries
245
if (!net.vio) // hack for re-parsing queries
266
buff[0]=0; // No fields
250
buff[0]=0; // No fields
267
251
if (session->main_da.status() == Diagnostics_area::DA_OK)
269
253
pos=drizzleclient_net_store_length(buff+1,session->main_da.affected_rows());
307
291
The eof packet has the following structure:
309
- 254 (DRIZZLE_PROTOCOL_NO_MORE_DATA) : Marker (1 byte)
310
- warning_count : Stored in 2 bytes; New in 4.1 protocol
311
- status_flag : Stored in 2 bytes;
293
- 254 (DRIZZLE_PROTOCOL_NO_MORE_DATA) : Marker (1 byte)
294
- warning_count : Stored in 2 bytes; New in 4.1 protocol
295
- status_flag : Stored in 2 bytes;
312
296
For flags like SERVER_MORE_RESULTS_EXISTS.
314
298
Note that the warning count will not be sent if 'no_flush' is set as
315
299
we don't want to report the warning count until all data is sent to the
318
@param session Thread handler
319
@param no_flush Set to 1 if there will be more data to the client,
302
@param session Thread handler
303
@param no_flush Set to 1 if there will be more data to the client,
320
304
like in send_fields().
375
359
drizzleclient_net_write(net, buff, 5);
378
void ProtocolOldLibdrizzle::sendErrorPacket(uint32_t sql_errno, const char *err)
362
void ProtocolOldLibdrizzle::sendError(uint32_t sql_errno, const char *err)
384
368
unsigned char buff[2+1+SQLSTATE_LENGTH+DRIZZLE_ERRMSG_SIZE], *pos;
371
assert(err && err[0]);
374
It's one case when we can push an error even though there
375
is an OK or EOF already.
377
session->main_da.can_overwrite_status= true;
379
/* Abort multi-result sets */
380
session->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
383
Send a error string to client.
385
For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it's
386
critical that every error that can be intercepted is issued in one
387
place only, my_message_sql.
386
390
if (net.vio == 0)
403
407
err= (char*) buff;
405
409
drizzleclient_net_write_command(&net,(unsigned char) 255, (unsigned char*) "", 0, (unsigned char*) err, length);
410
Send a error string to client.
413
net_printf_error and net_send_error are low-level functions
414
that shall be used only when a new connection is being
415
established or at server startup.
417
For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it's
418
critical that every error that can be intercepted is issued in one
419
place only, my_message_sql.
421
void ProtocolOldLibdrizzle::sendError(uint32_t sql_errno, const char *err)
424
assert(err && err[0]);
427
It's one case when we can push an error even though there
428
is an OK or EOF already.
430
session->main_da.can_overwrite_status= true;
432
/* Abort multi-result sets */
433
session->server_status&= ~SERVER_MORE_RESULTS_EXISTS;
435
sendErrorPacket(sql_errno, err);
437
411
session->main_da.can_overwrite_status= false;
466
440
Sum fields has table name empty and field_name.
468
@param Session Thread data object
469
@param list List of items to send to client
470
@param flag Bit mask with the following functions:
442
@param Session Thread data object
443
@param list List of items to send to client
444
@param flag Bit mask with the following functions:
471
445
- 1 send number of rows
472
446
- 2 send default values
473
447
- 4 don't write eof packet
478
1 Error (Note that in this case the error is not sent to the
452
1 Error (Note that in this case the error is not sent to the
481
455
bool ProtocolOldLibdrizzle::send_fields(List<Item> *list, uint32_t flags)
488
462
const CHARSET_INFO * const session_charset= default_charset_info;
490
464
if (flags & SEND_NUM_ROWS)
491
{ // Packet with number of elements
465
{ // Packet with number of elements
492
466
unsigned char *pos= drizzleclient_net_store_length(buff, list->elements);
493
467
(void) drizzleclient_net_write(&net, buff, (size_t) (pos-buff));
520
494
/* Store fixed length fields */
521
495
pos= (char*) local_packet->ptr()+local_packet->length();
522
*pos++= 12; // Length of packed fields
496
*pos++= 12; // Length of packed fields
523
497
if (item->collation.collation == &my_charset_bin || session_charset == NULL)
525
499
/* No conversion */
547
521
pos[6]= field.type;
548
522
int2store(pos+7,field.flags);
549
523
pos[9]= (char) field.decimals;
550
pos[10]= 0; // For the future
551
pos[11]= 0; // For the future
524
pos[10]= 0; // For the future
525
pos[11]= 0; // For the future
554
528
local_packet->length((uint32_t) (pos - local_packet->ptr()));
555
529
if (flags & SEND_DEFAULTS)
556
item->send(this, &tmp); // Send default value
530
item->send(this, &tmp); // Send default value
558
break; /* purecov: inspected */
532
break; /* purecov: inspected */
561
535
if (flags & SEND_EOF)
573
547
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES),
574
MYF(0)); /* purecov: inspected */
575
return(1); /* purecov: inspected */
548
MYF(0)); /* purecov: inspected */
549
return(1); /* purecov: inspected */
587
561
Send \\0 end terminated string.
589
@param from NULL or \\0 terminated string
563
@param from NULL or \\0 terminated string
592
566
In most cases one should use store(from, length) instead of this function
600
574
bool ProtocolOldLibdrizzle::store(const char *from, const CHARSET_INFO * const cs)
604
578
uint32_t length= strlen(from);
605
579
return store(from, length, cs);
627
601
if ((len= tmp.length()))
628
len--; // Remove last ','
602
len--; // Remove last ','
629
603
return store((char*) tmp.ptr(), len, tmp.charset());
785
759
bool ProtocolOldLibdrizzle::storeStringAux(const char *from, size_t length,
786
760
const CHARSET_INFO * const fromcs,
787
const CHARSET_INFO * const tocs)
761
const CHARSET_INFO * const tocs)
789
763
/* 'tocs' is set 0 when client issues SET character_set_results=NULL */
790
764
if (tocs && !my_charset_same(fromcs, tocs) &&
802
776
bool ProtocolOldLibdrizzle::store(const char *from, size_t length,
803
777
const CHARSET_INFO * const fromcs,
804
const CHARSET_INFO * const tocs)
778
const CHARSET_INFO * const tocs)
806
780
return storeStringAux(from, length, fromcs, tocs);
818
bool ProtocolOldLibdrizzle::store_tiny(int64_t from)
821
return netStoreData((unsigned char*) buff,
822
(size_t) (int10_to_str((int) from, buff, -10) - buff));
826
bool ProtocolOldLibdrizzle::store_short(int64_t from)
829
return netStoreData((unsigned char*) buff,
830
(size_t) (int10_to_str((int) from, buff, -10) -
835
bool ProtocolOldLibdrizzle::store_long(int64_t from)
838
return netStoreData((unsigned char*) buff,
839
(size_t) (int10_to_str((long int)from, buff,
840
(from <0)?-10:10)-buff));
844
bool ProtocolOldLibdrizzle::store_int64_t(int64_t from, bool unsigned_flag)
792
bool ProtocolOldLibdrizzle::store(int32_t from)
795
return netStoreData((unsigned char*) buff,
796
(size_t) (int10_to_str(from, buff, -10) - buff));
799
bool ProtocolOldLibdrizzle::store(uint32_t from)
802
return netStoreData((unsigned char*) buff,
803
(size_t) (int10_to_str(from, buff, 10) - buff));
806
bool ProtocolOldLibdrizzle::store(int64_t from)
847
809
return netStoreData((unsigned char*) buff,
848
(size_t) (int64_t10_to_str(from,buff,
849
unsigned_flag ? 10 : -10)-
810
(size_t) (int64_t10_to_str(from, buff, -10) - buff));
813
bool ProtocolOldLibdrizzle::store(uint64_t from)
816
return netStoreData((unsigned char*) buff,
817
(size_t) (int64_t10_to_str(from, buff, 10) - buff));
877
844
bool ProtocolOldLibdrizzle::store(Field *field)
879
846
if (field->is_null())
881
848
char buff[MAX_FIELD_WIDTH];
882
849
String str(buff,sizeof(buff), &my_charset_bin);
883
850
const CHARSET_INFO * const tocs= default_charset_info;
901
length= sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d",
909
length+= sprintf(buff+length, ".%06d",
910
(int)tm->second_part);
911
return netStoreData((unsigned char*) buff, length);
915
bool ProtocolOldLibdrizzle::store_date(DRIZZLE_TIME *tm)
917
char buff[MAX_DATE_STRING_REP_LENGTH];
918
size_t length= my_date_to_str(tm, buff);
919
return netStoreData((unsigned char*) buff, length);
925
Second_part format ("%06") needs to change when
926
we support 0-6 decimals for time.
929
bool ProtocolOldLibdrizzle::store_time(DRIZZLE_TIME *tm)
933
uint32_t day= (tm->year || tm->month) ? 0 : tm->day;
934
length= sprintf(buff, "%s%02ld:%02d:%02d",
936
(long) day*24L+(long) tm->hour,
940
length+= sprintf(buff+length, ".%06d", (int)tm->second_part);
870
switch (tm->time_type)
872
case DRIZZLE_TIMESTAMP_DATETIME:
873
length= sprintf(buff, "%04d-%02d-%02d %02d:%02d:%02d",
881
length+= sprintf(buff+length, ".%06d", (int)tm->second_part);
884
case DRIZZLE_TIMESTAMP_DATE:
885
length= sprintf(buff, "%04d-%02d-%02d",
891
case DRIZZLE_TIMESTAMP_TIME:
892
day= (tm->year || tm->month) ? 0 : tm->day;
893
length= sprintf(buff, "%s%02ld:%02d:%02d", tm->neg ? "-" : "",
894
(long) day*24L+(long) tm->hour, (int) tm->minute,
897
length+= sprintf(buff+length, ".%06d", (int)tm->second_part);
900
case DRIZZLE_TIMESTAMP_NONE:
901
case DRIZZLE_TIMESTAMP_ERROR:
941
907
return netStoreData((unsigned char*) buff, length);
1017
983
, (unsigned char*) buff
1018
984
, (size_t) (end-buff))
1019
|| (pkt_len= drizzleclient_net_read(&net)) == packet_error
985
|| (pkt_len= drizzleclient_net_read(&net)) == packet_error
1020
986
|| pkt_len < MIN_HANDSHAKE_SIZE)
1022
988
my_error(ER_HANDSHAKE_ERROR, MYF(0), session->security_ctx.ip.c_str());
1110
1076
static int init(void *p)
1112
ProtocolFactory **factory= (ProtocolFactory **)p;
1078
ProtocolFactory **factory= static_cast<ProtocolFactory **>(p);
1113
1079
*factory= new ProtocolFactoryOldLibdrizzle;
1117
1083
static int deinit(void *p)
1119
ProtocolFactoryOldLibdrizzle *factory= (ProtocolFactoryOldLibdrizzle *)p;
1085
ProtocolFactoryOldLibdrizzle *factory= static_cast<ProtocolFactoryOldLibdrizzle *>(p);
1120
1086
delete factory;