diff options
Diffstat (limited to 'sql/protocol.cc')
-rw-r--r-- | sql/protocol.cc | 196 |
1 files changed, 107 insertions, 89 deletions
diff --git a/sql/protocol.cc b/sql/protocol.cc index ced6d78519a..2ed241c4c98 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -33,9 +33,9 @@ static void write_eof_packet(THD *thd, NET *net); #endif #ifndef EMBEDDED_LIBRARY -bool Protocol::net_store_data(const char *from, uint length) +bool Protocol::net_store_data(const uchar *from, size_t length) #else -bool Protocol_prep::net_store_data(const char *from, uint length) +bool Protocol_binary::net_store_data(const uchar *from, size_t length) #endif { ulong packet_length=packet->length(); @@ -46,10 +46,9 @@ bool Protocol_prep::net_store_data(const char *from, uint length) if (packet_length+9+length > packet->alloced_length() && packet->realloc(packet_length+9+length)) return 1; - char *to=(char*) net_store_length((char*) packet->ptr()+packet_length, - length); + uchar *to= net_store_length((uchar*) packet->ptr()+packet_length, length); memcpy(to,from,length); - packet->length((uint) (to+length-packet->ptr())); + packet->length((uint) (to+length-(uchar*) packet->ptr())); return 0; } @@ -80,6 +79,7 @@ void net_send_error(THD *thd, uint sql_errno, const char *err) if (net && net->no_send_error) { thd->clear_error(); + thd->is_fatal_error= 0; // Error message is given DBUG_PRINT("info", ("sending error messages prohibited")); DBUG_VOID_RETURN; } @@ -112,7 +112,7 @@ void net_send_error(THD *thd, uint sql_errno, const char *err) net_send_error_packet(thd, sql_errno, err); - thd->is_fatal_error=0; // Error message is given + thd->is_fatal_error= 0; // Error message is given thd->net.report_error= 0; /* Abort multi-result sets */ @@ -157,6 +157,7 @@ net_printf_error(THD *thd, uint errcode, ...) if (net && net->no_send_error) { thd->clear_error(); + thd->is_fatal_error= 0; // Error message is given DBUG_PRINT("info", ("sending error messages prohibited")); DBUG_VOID_RETURN; } @@ -225,7 +226,7 @@ net_printf_error(THD *thd, uint errcode, ...) memcpy(pos+3, mysql_errno_to_sqlstate(errcode), SQLSTATE_LENGTH); } } - VOID(net_real_write(net,(char*) net->buff,length+head_length+1+offset)); + VOID(net_real_write(net, net->buff, length+head_length+1+offset)); #else net->last_errno= errcode; strmake(net->last_error, text_pos, length); @@ -269,7 +270,7 @@ void send_ok(THD *thd, ha_rows affected_rows, ulonglong id, const char *message) { NET *net= &thd->net; - char buff[MYSQL_ERRMSG_SIZE+10],*pos; + uchar buff[MYSQL_ERRMSG_SIZE+10],*pos; DBUG_ENTER("send_ok"); if (net->no_send_ok || !net->vio) // hack for re-parsing queries @@ -305,8 +306,8 @@ send_ok(THD *thd, ha_rows affected_rows, ulonglong id, const char *message) pos+=2; } if (message) - pos=net_store_data((char*) pos, message, strlen(message)); - VOID(my_net_write(net,buff,(uint) (pos-buff))); + pos= net_store_data(pos, (uchar*) message, strlen(message)); + VOID(my_net_write(net, buff, (size_t) (pos-buff))); VOID(net_flush(net)); /* We can't anymore send an error to the client */ thd->net.report_error= 0; @@ -316,7 +317,7 @@ send_ok(THD *thd, ha_rows affected_rows, ulonglong id, const char *message) DBUG_VOID_RETURN; } -static char eof_buff[1]= { (char) 254 }; /* Marker for end of fields */ +static uchar eof_buff[1]= { (uchar) 254 }; /* Marker for end of fields */ /* Send eof (= end of result set) to the client @@ -381,7 +382,7 @@ static void write_eof_packet(THD *thd, NET *net) if (thd->is_fatal_error) thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS; int2store(buff+3, thd->server_status); - VOID(my_net_write(net, (char*) buff, 5)); + VOID(my_net_write(net, buff, 5)); } else VOID(my_net_write(net, eof_buff, 1)); @@ -409,7 +410,7 @@ void net_send_error_packet(THD *thd, uint sql_errno, const char *err) { NET *net= &thd->net; uint length; - char buff[MYSQL_ERRMSG_SIZE+2], *pos; + uchar buff[MYSQL_ERRMSG_SIZE+2], *pos; DBUG_ENTER("send_error_packet"); @@ -431,17 +432,19 @@ void net_send_error_packet(THD *thd, uint sql_errno, const char *err) { /* The first # is to make the protocol backward compatible */ buff[2]= '#'; - pos= strmov(buff+3, mysql_errno_to_sqlstate(sql_errno)); + pos= (uchar*) strmov((char*) buff+3, mysql_errno_to_sqlstate(sql_errno)); } - length= (uint) (strmake(pos, err, MYSQL_ERRMSG_SIZE-1) - buff); - err=buff; + length= (uint) (strmake((char*) pos, err, MYSQL_ERRMSG_SIZE-1) - + (char*) buff); + err= (char*) buff; } else { length=(uint) strlen(err); set_if_smaller(length,MYSQL_ERRMSG_SIZE-1); } - VOID(net_write_command(net,(uchar) 255, "", 0, (char*) err,length)); + VOID(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) err, + length)); DBUG_VOID_RETURN; } @@ -457,17 +460,16 @@ void net_send_error_packet(THD *thd, uint sql_errno, const char *err) ulonglong for bigger numbers. */ -static char *net_store_length_fast(char *pkg, uint length) +static uchar *net_store_length_fast(uchar *packet, uint length) { - uchar *packet=(uchar*) pkg; if (length < 251) { *packet=(uchar) length; - return (char*) packet+1; + return packet+1; } *packet++=252; int2store(packet,(uint) length); - return (char*) packet+2; + return packet+2; } @@ -478,14 +480,14 @@ static char *net_store_length_fast(char *pkg, uint length) /* The following will only be used for short strings < 65K */ -char *net_store_data(char *to,const char *from, uint length) +uchar *net_store_data(uchar *to, const uchar *from, size_t length) { to=net_store_length_fast(to,length); memcpy(to,from,length); return to+length; } -char *net_store_data(char *to,int32 from) +uchar *net_store_data(uchar *to,int32 from) { char buff[20]; uint length=(uint) (int10_to_str(from,buff,10)-buff); @@ -494,7 +496,7 @@ char *net_store_data(char *to,int32 from) return to+length; } -char *net_store_data(char *to,longlong from) +uchar *net_store_data(uchar *to,longlong from) { char buff[22]; uint length=(uint) (longlong10_to_str(from,buff,10)-buff); @@ -553,17 +555,17 @@ bool Protocol::send_fields(List<Item> *list, uint flags) { List_iterator_fast<Item> it(*list); Item *item; - char buff[80]; + uchar buff[80]; String tmp((char*) buff,sizeof(buff),&my_charset_bin); - Protocol_simple prot(thd); + Protocol_text prot(thd); String *local_packet= prot.storage_packet(); CHARSET_INFO *thd_charset= thd->variables.character_set_results; DBUG_ENTER("send_fields"); if (flags & SEND_NUM_ROWS) { // Packet with number of elements - char *pos=net_store_length(buff, list->elements); - (void) my_net_write(&thd->net, buff,(uint) (pos-buff)); + uchar *pos= net_store_length(buff, list->elements); + (void) my_net_write(&thd->net, buff, (size_t) (pos-buff)); } #ifndef DBUG_OFF @@ -696,7 +698,8 @@ err: bool Protocol::write() { DBUG_ENTER("Protocol::write"); - DBUG_RETURN(my_net_write(&thd->net, packet->ptr(), packet->length())); + DBUG_RETURN(my_net_write(&thd->net, (uchar*) packet->ptr(), + packet->length())); } #endif /* EMBEDDED_LIBRARY */ @@ -758,7 +761,7 @@ bool Protocol::store(I_List<i_string>* str_list) ****************************************************************************/ #ifndef EMBEDDED_LIBRARY -void Protocol_simple::prepare_for_resend() +void Protocol_text::prepare_for_resend() { packet->length(0); #ifndef DBUG_OFF @@ -766,7 +769,7 @@ void Protocol_simple::prepare_for_resend() #endif } -bool Protocol_simple::store_null() +bool Protocol_text::store_null() { #ifndef DBUG_OFF field_pos++; @@ -783,7 +786,7 @@ bool Protocol_simple::store_null() and store in network buffer. */ -bool Protocol::store_string_aux(const char *from, uint length, +bool Protocol::store_string_aux(const char *from, size_t length, CHARSET_INFO *fromcs, CHARSET_INFO *tocs) { /* 'tocs' is set 0 when client issues SET character_set_results=NULL */ @@ -792,15 +795,15 @@ bool Protocol::store_string_aux(const char *from, uint length, tocs != &my_charset_bin) { uint dummy_errors; - return convert->copy(from, length, fromcs, tocs, &dummy_errors) || - net_store_data(convert->ptr(), convert->length()); + return (convert->copy(from, length, fromcs, tocs, &dummy_errors) || + net_store_data((uchar*) convert->ptr(), convert->length())); } - return net_store_data(from, length); + return net_store_data((uchar*) from, length); } -bool Protocol_simple::store(const char *from, uint length, - CHARSET_INFO *fromcs, CHARSET_INFO *tocs) +bool Protocol_text::store(const char *from, size_t length, + CHARSET_INFO *fromcs, CHARSET_INFO *tocs) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -815,8 +818,8 @@ bool Protocol_simple::store(const char *from, uint length, } -bool Protocol_simple::store(const char *from, uint length, - CHARSET_INFO *fromcs) +bool Protocol_text::store(const char *from, size_t length, + CHARSET_INFO *fromcs) { CHARSET_INFO *tocs= this->thd->variables.character_set_results; #ifndef DBUG_OFF @@ -832,19 +835,19 @@ bool Protocol_simple::store(const char *from, uint length, } -bool Protocol_simple::store_tiny(longlong from) +bool Protocol_text::store_tiny(longlong from) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || field_types[field_pos] == MYSQL_TYPE_TINY); field_pos++; #endif char buff[20]; - return net_store_data((char*) buff, - (uint) (int10_to_str((int) from,buff, -10)-buff)); + return net_store_data((uchar*) buff, + (size_t) (int10_to_str((int) from, buff, -10) - buff)); } -bool Protocol_simple::store_short(longlong from) +bool Protocol_text::store_short(longlong from) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -853,12 +856,13 @@ bool Protocol_simple::store_short(longlong from) field_pos++; #endif char buff[20]; - return net_store_data((char*) buff, - (uint) (int10_to_str((int) from,buff, -10)-buff)); + return net_store_data((uchar*) buff, + (size_t) (int10_to_str((int) from, buff, -10) - + buff)); } -bool Protocol_simple::store_long(longlong from) +bool Protocol_text::store_long(longlong from) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -867,12 +871,13 @@ bool Protocol_simple::store_long(longlong from) field_pos++; #endif char buff[20]; - return net_store_data((char*) buff, - (uint) (int10_to_str((long int)from,buff, (from <0)?-10:10)-buff)); + return net_store_data((uchar*) buff, + (size_t) (int10_to_str((long int)from, buff, + (from <0)?-10:10)-buff)); } -bool Protocol_simple::store_longlong(longlong from, bool unsigned_flag) +bool Protocol_text::store_longlong(longlong from, bool unsigned_flag) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -880,14 +885,14 @@ bool Protocol_simple::store_longlong(longlong from, bool unsigned_flag) field_pos++; #endif char buff[22]; - return net_store_data((char*) buff, - (uint) (longlong10_to_str(from,buff, - unsigned_flag ? 10 : -10)- - buff)); + return net_store_data((uchar*) buff, + (size_t) (longlong10_to_str(from,buff, + unsigned_flag ? 10 : -10)- + buff)); } -bool Protocol_simple::store_decimal(const my_decimal *d) +bool Protocol_text::store_decimal(const my_decimal *d) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -897,35 +902,35 @@ bool Protocol_simple::store_decimal(const my_decimal *d) char buff[DECIMAL_MAX_STR_LENGTH]; String str(buff, sizeof(buff), &my_charset_bin); (void) my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str); - return net_store_data(str.ptr(), str.length()); + return net_store_data((uchar*) str.ptr(), str.length()); } -bool Protocol_simple::store(float from, uint32 decimals, String *buffer) +bool Protocol_text::store(float from, uint32 decimals, String *buffer) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || field_types[field_pos] == MYSQL_TYPE_FLOAT); field_pos++; #endif - buffer->set((double) from, decimals, thd->charset()); - return net_store_data((char*) buffer->ptr(), buffer->length()); + buffer->set_real((double) from, decimals, thd->charset()); + return net_store_data((uchar*) buffer->ptr(), buffer->length()); } -bool Protocol_simple::store(double from, uint32 decimals, String *buffer) +bool Protocol_text::store(double from, uint32 decimals, String *buffer) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || field_types[field_pos] == MYSQL_TYPE_DOUBLE); field_pos++; #endif - buffer->set(from, decimals, thd->charset()); - return net_store_data((char*) buffer->ptr(), buffer->length()); + buffer->set_real(from, decimals, thd->charset()); + return net_store_data((uchar*) buffer->ptr(), buffer->length()); } -bool Protocol_simple::store(Field *field) +bool Protocol_text::store(Field *field) { if (field->is_null()) return store_null(); @@ -935,8 +940,19 @@ bool Protocol_simple::store(Field *field) char buff[MAX_FIELD_WIDTH]; String str(buff,sizeof(buff), &my_charset_bin); CHARSET_INFO *tocs= this->thd->variables.character_set_results; +#ifndef DBUG_OFF + TABLE *table= field->table; + my_bitmap_map *old_map= 0; + if (table->file) + old_map= dbug_tmp_use_all_columns(table, table->read_set); +#endif field->val_str(&str); +#ifndef DBUG_OFF + if (old_map) + dbug_tmp_restore_column_map(table->read_set, old_map); +#endif + return store_string_aux(str.ptr(), str.length(), str.charset(), tocs); } @@ -948,7 +964,7 @@ bool Protocol_simple::store(Field *field) */ -bool Protocol_simple::store(MYSQL_TIME *tm) +bool Protocol_text::store(MYSQL_TIME *tm) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -966,12 +982,13 @@ bool Protocol_simple::store(MYSQL_TIME *tm) (int) tm->minute, (int) tm->second)); if (tm->second_part) - length+= my_sprintf(buff+length,(buff+length, ".%06d", (int)tm->second_part)); - return net_store_data((char*) buff, length); + length+= my_sprintf(buff+length,(buff+length, ".%06d", + (int)tm->second_part)); + return net_store_data((uchar*) buff, length); } -bool Protocol_simple::store_date(MYSQL_TIME *tm) +bool Protocol_text::store_date(MYSQL_TIME *tm) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -979,8 +996,8 @@ bool Protocol_simple::store_date(MYSQL_TIME *tm) field_pos++; #endif char buff[MAX_DATE_STRING_REP_LENGTH]; - int length= my_date_to_str(tm, buff); - return net_store_data(buff, (uint) length); + size_t length= my_date_to_str(tm, buff); + return net_store_data((uchar*) buff, length); } @@ -990,7 +1007,7 @@ bool Protocol_simple::store_date(MYSQL_TIME *tm) we support 0-6 decimals for time. */ -bool Protocol_simple::store_time(MYSQL_TIME *tm) +bool Protocol_text::store_time(MYSQL_TIME *tm) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -1007,7 +1024,7 @@ bool Protocol_simple::store_time(MYSQL_TIME *tm) (int) tm->second)); if (tm->second_part) length+= my_sprintf(buff+length,(buff+length, ".%06d", (int)tm->second_part)); - return net_store_data((char*) buff, length); + return net_store_data((uchar*) buff, length); } @@ -1030,7 +1047,7 @@ bool Protocol_simple::store_time(MYSQL_TIME *tm) [..]..[[length]data] data ****************************************************************************/ -bool Protocol_prep::prepare_for_send(List<Item> *item_list) +bool Protocol_binary::prepare_for_send(List<Item> *item_list) { Protocol::prepare_for_send(item_list); bit_fields= (field_count+9)/8; @@ -1041,29 +1058,30 @@ bool Protocol_prep::prepare_for_send(List<Item> *item_list) } -void Protocol_prep::prepare_for_resend() +void Protocol_binary::prepare_for_resend() { packet->length(bit_fields+1); - bzero((char*) packet->ptr(), 1+bit_fields); + bzero((uchar*) packet->ptr(), 1+bit_fields); field_pos=0; } -bool Protocol_prep::store(const char *from, uint length, CHARSET_INFO *fromcs) +bool Protocol_binary::store(const char *from, size_t length, + CHARSET_INFO *fromcs) { CHARSET_INFO *tocs= thd->variables.character_set_results; field_pos++; return store_string_aux(from, length, fromcs, tocs); } -bool Protocol_prep::store(const char *from,uint length, - CHARSET_INFO *fromcs, CHARSET_INFO *tocs) +bool Protocol_binary::store(const char *from, size_t length, + CHARSET_INFO *fromcs, CHARSET_INFO *tocs) { field_pos++; return store_string_aux(from, length, fromcs, tocs); } -bool Protocol_prep::store_null() +bool Protocol_binary::store_null() { uint offset= (field_pos+2)/8+1, bit= (1 << ((field_pos+2) & 7)); /* Room for this as it's allocated in prepare_for_send */ @@ -1074,7 +1092,7 @@ bool Protocol_prep::store_null() } -bool Protocol_prep::store_tiny(longlong from) +bool Protocol_binary::store_tiny(longlong from) { char buff[1]; field_pos++; @@ -1083,7 +1101,7 @@ bool Protocol_prep::store_tiny(longlong from) } -bool Protocol_prep::store_short(longlong from) +bool Protocol_binary::store_short(longlong from) { field_pos++; char *to= packet->prep_append(2, PACKET_BUFFER_EXTRA_ALLOC); @@ -1094,7 +1112,7 @@ bool Protocol_prep::store_short(longlong from) } -bool Protocol_prep::store_long(longlong from) +bool Protocol_binary::store_long(longlong from) { field_pos++; char *to= packet->prep_append(4, PACKET_BUFFER_EXTRA_ALLOC); @@ -1105,7 +1123,7 @@ bool Protocol_prep::store_long(longlong from) } -bool Protocol_prep::store_longlong(longlong from, bool unsigned_flag) +bool Protocol_binary::store_longlong(longlong from, bool unsigned_flag) { field_pos++; char *to= packet->prep_append(8, PACKET_BUFFER_EXTRA_ALLOC); @@ -1115,7 +1133,7 @@ bool Protocol_prep::store_longlong(longlong from, bool unsigned_flag) return 0; } -bool Protocol_prep::store_decimal(const my_decimal *d) +bool Protocol_binary::store_decimal(const my_decimal *d) { #ifndef DBUG_OFF DBUG_ASSERT(field_types == 0 || @@ -1128,7 +1146,7 @@ bool Protocol_prep::store_decimal(const my_decimal *d) return store(str.ptr(), str.length(), str.charset()); } -bool Protocol_prep::store(float from, uint32 decimals, String *buffer) +bool Protocol_binary::store(float from, uint32 decimals, String *buffer) { field_pos++; char *to= packet->prep_append(4, PACKET_BUFFER_EXTRA_ALLOC); @@ -1139,7 +1157,7 @@ bool Protocol_prep::store(float from, uint32 decimals, String *buffer) } -bool Protocol_prep::store(double from, uint32 decimals, String *buffer) +bool Protocol_binary::store(double from, uint32 decimals, String *buffer) { field_pos++; char *to= packet->prep_append(8, PACKET_BUFFER_EXTRA_ALLOC); @@ -1150,7 +1168,7 @@ bool Protocol_prep::store(double from, uint32 decimals, String *buffer) } -bool Protocol_prep::store(Field *field) +bool Protocol_binary::store(Field *field) { /* We should not increment field_pos here as send_binary() will call another @@ -1162,7 +1180,7 @@ bool Protocol_prep::store(Field *field) } -bool Protocol_prep::store(MYSQL_TIME *tm) +bool Protocol_binary::store(MYSQL_TIME *tm) { char buff[12],*pos; uint length; @@ -1188,15 +1206,15 @@ bool Protocol_prep::store(MYSQL_TIME *tm) return packet->append(buff, length+1, PACKET_BUFFER_EXTRA_ALLOC); } -bool Protocol_prep::store_date(MYSQL_TIME *tm) +bool Protocol_binary::store_date(MYSQL_TIME *tm) { tm->hour= tm->minute= tm->second=0; tm->second_part= 0; - return Protocol_prep::store(tm); + return Protocol_binary::store(tm); } -bool Protocol_prep::store_time(MYSQL_TIME *tm) +bool Protocol_binary::store_time(MYSQL_TIME *tm) { char buff[13], *pos; uint length; |