119
netStoreData() - extended version with character set conversion.
121
It is optimized for short strings whose length after
122
conversion is garanteed to be less than 251, which accupies
123
exactly one byte to store length. It allows not to use
124
the "convert" member as a temporary buffer, conversion
125
is done directly to the "packet" member.
126
The limit 251 is good enough to optimize send_fields()
127
because column, table, database names fit into this limit.
130
bool ProtocolOldLibdrizzle::netStoreData(const unsigned char *from, size_t length,
131
const CHARSET_INFO * const from_cs,
132
const CHARSET_INFO * const to_cs)
134
uint32_t dummy_errors;
135
/* Calculate maxumum possible result length */
136
uint32_t conv_length= to_cs->mbmaxlen * length / from_cs->mbminlen;
137
if (conv_length > 250)
140
For strings with conv_length greater than 250 bytes
141
we don't know how many bytes we will need to store length: one or two,
142
because we don't know result length until conversion is done.
143
For example, when converting from utf8 (mbmaxlen=3) to latin1,
144
conv_length=300 means that the result length can vary between 100 to 300.
145
length=100 needs one byte, length=300 needs to bytes.
147
Thus conversion directly to "packet" is not worthy.
148
Let's use "convert" as a temporary buffer.
150
return (convert->copy((const char*) from, length, from_cs,
151
to_cs, &dummy_errors) ||
152
netStoreData((const unsigned char*) convert->ptr(), convert->length()));
155
size_t packet_length= packet->length();
156
size_t new_length= packet_length + conv_length + 1;
158
if (new_length > packet->alloced_length() && packet->realloc(new_length))
161
char *length_pos= (char*) packet->ptr() + packet_length;
162
char *to= length_pos + 1;
164
to+= copy_and_convert(to, conv_length, to_cs,
165
(const char*) from, length, from_cs, &dummy_errors);
167
drizzleclient_net_store_length((unsigned char*) length_pos, to - length_pos - 1);
168
packet->length((uint32_t) (to - packet->ptr()));
174
119
Return ok to the client.
398
343
while ((item=it++))
401
const CHARSET_INFO * const cs= system_charset_info;
402
346
Send_field field;
403
347
item->make_field(&field);
405
349
prepareForResend();
407
if (store(STRING_WITH_LEN("def"), cs) ||
408
store(field.db_name, cs) ||
409
store(field.table_name, cs) ||
410
store(field.org_table_name, cs) ||
411
store(field.col_name, cs) ||
412
store(field.org_col_name, cs) ||
351
if (store(STRING_WITH_LEN("def")) ||
352
store(field.db_name) ||
353
store(field.table_name) ||
354
store(field.org_table_name) ||
355
store(field.col_name) ||
356
store(field.org_col_name) ||
413
357
packet->realloc(packet->length()+12))
416
360
/* Store fixed length fields */
417
361
pos= (char*) packet->ptr()+packet->length();
418
362
*pos++= 12; // Length of packed fields
419
if (item->collation.collation == &my_charset_bin)
422
int2store(pos, field.charsetnr);
423
int4store(pos+2, field.length);
427
/* With conversion */
428
uint32_t max_char_len;
429
int2store(pos, cs->number);
431
For TEXT/BLOB columns, field_length describes the maximum data
432
length in bytes. There is no limit to the number of characters
433
that a TEXT column can store, as long as the data fits into
434
the designated space.
435
For the rest of textual columns, field_length is evaluated as
436
char_count * mbmaxlen, where character count is taken from the
437
definition of the column. In other words, the maximum number
438
of characters here is limited by the column definition.
440
max_char_len= field.length / item->collation.collation->mbmaxlen;
441
int4store(pos+2, max_char_len * cs->mbmaxlen);
364
int2store(pos, field.charsetnr);
365
int4store(pos+2, field.length);
443
366
pos[6]= field.type;
444
367
int2store(pos+7,field.flags);
445
368
pos[9]= (char) field.decimals;
631
Auxilary function to convert string to the given character set
632
and store in network buffer.
635
bool ProtocolOldLibdrizzle::storeString(const char *from, size_t length,
636
const CHARSET_INFO * const fromcs,
637
const CHARSET_INFO * const tocs)
639
/* 'tocs' is set 0 when client issues SET character_set_results=NULL */
640
if (tocs && !my_charset_same(fromcs, tocs) &&
641
fromcs != &my_charset_bin &&
642
tocs != &my_charset_bin)
644
/* Store with conversion */
645
return netStoreData((unsigned char*) from, length, fromcs, tocs);
647
/* Store without conversion */
648
return netStoreData((unsigned char*) from, length);
652
bool ProtocolOldLibdrizzle::store(const char *from, size_t length,
653
const CHARSET_INFO * const fromcs)
655
const CHARSET_INFO * const tocs= default_charset_info;
656
return storeString(from, length, fromcs, tocs);
553
bool ProtocolOldLibdrizzle::store(const char *from, size_t length)
555
return netStoreData((const unsigned char *)from, length);
700
599
char buff[MAX_FIELD_WIDTH];
701
600
String str(buff,sizeof(buff), &my_charset_bin);
702
const CHARSET_INFO * const tocs= default_charset_info;
704
602
from->val_str(&str);
706
return storeString(str.ptr(), str.length(), str.charset(), tocs);
604
return netStoreData((const unsigned char *)str.ptr(), str.length());