diff options
Diffstat (limited to 'sql/protocol.cc')
-rw-r--r-- | sql/protocol.cc | 134 |
1 files changed, 87 insertions, 47 deletions
diff --git a/sql/protocol.cc b/sql/protocol.cc index 48ef9ecb71e..882fd5268b1 100644 --- a/sql/protocol.cc +++ b/sql/protocol.cc @@ -27,6 +27,23 @@ #include <stdarg.h> #include <assert.h> +#ifndef EMBEDDED_LIBRARY +bool Protocol::net_store_data(const char *from, uint length) +{ + ulong packet_length=packet->length(); + if (packet_length+5+length > packet->alloced_length() && + packet->realloc(packet_length+5+length)) + return 1; + char *to=(char*) net_store_length((char*) packet->ptr()+packet_length, + (ulonglong) length); + memcpy(to,from,length); + packet->length((uint) (to+length-packet->ptr())); + return 0; +} + +#endif + + /* Send a error string to client */ void send_error(THD *thd, uint sql_errno, const char *err) @@ -39,7 +56,9 @@ void send_error(THD *thd, uint sql_errno, const char *err) err ? err : net->last_error[0] ? net->last_error : "NULL")); +#ifndef EMBEDDED_LIBRARY query_cache_abort(net); +#endif thd->query_error= 1; // needed to catch query errors during replication if (!err) { @@ -56,6 +75,12 @@ void send_error(THD *thd, uint sql_errno, const char *err) } } } + +#ifdef EMBEDDED_LIBRARY + net->last_errno= sql_errno; + strmake(net->last_error, err, sizeof(net->last_error)-1); +#else + if (net->vio == 0) { if (thd->bootstrap) @@ -78,6 +103,7 @@ void send_error(THD *thd, uint sql_errno, const char *err) set_if_smaller(length,MYSQL_ERRMSG_SIZE-1); } VOID(net_write_command(net,(uchar) 255, "", 0, (char*) err,length)); +#endif /* EMBEDDED_LIBRARY*/ thd->fatal_error=0; // Error message is given thd->net.report_error= 0; DBUG_VOID_RETURN; @@ -88,6 +114,7 @@ void send_error(THD *thd, uint sql_errno, const char *err) This is used by mysqld.cc, which doesn't have a THD */ +#ifndef EMBEDDED_LIBRARY void net_send_error(NET *net, uint sql_errno, const char *err) { char buff[2]; @@ -100,7 +127,7 @@ void net_send_error(NET *net, uint sql_errno, const char *err) net_write_command(net,(uchar) 255, buff, 2, err, length); DBUG_VOID_RETURN; } - +#endif /* Send a warning to the end user @@ -137,14 +164,22 @@ net_printf(THD *thd, uint errcode, ...) { va_list args; uint length,offset; - const char *format,*text_pos; + const char *format; +#ifndef EMBEDDED_LIBRARY + const char *text_pos; +#else + char text_pos[500]; +#endif int head_length= NET_HEADER_SIZE; NET *net= &thd->net; + DBUG_ENTER("net_printf"); DBUG_PRINT("enter",("message: %u",errcode)); thd->query_error= 1; // needed to catch query errors during replication +#ifndef EMBEDDED_LIBRARY query_cache_abort(net); // Safety +#endif va_start(args,errcode); /* The following is needed to make net_printf() work with 0 argument for @@ -160,13 +195,16 @@ net_printf(THD *thd, uint errcode, ...) errcode= ER_UNKNOWN_ERROR; } offset= net->return_errno ? 2 : 0; +#ifndef EMBEDDED_LIBRARY text_pos=(char*) net->buff+head_length+offset+1; +#endif (void) vsprintf(my_const_cast(char*) (text_pos),format,args); length=(uint) strlen((char*) text_pos); if (length >= sizeof(net->last_error)) length=sizeof(net->last_error)-1; /* purecov: inspected */ va_end(args); +#ifndef EMBEDDED_LIBRARY if (net->vio == 0) { if (thd->bootstrap) @@ -187,10 +225,36 @@ net_printf(THD *thd, uint errcode, ...) if (offset) int2store(text_pos-2, errcode); VOID(net_real_write(net,(char*) net->buff,length+head_length+1+offset)); +#else + net->last_errno= errcode; + strmake(net->last_error, text_pos, length); +#endif thd->fatal_error=0; // Error message is given DBUG_VOID_RETURN; } +/* + Function called by my_net_init() to set some check variables +*/ + +#ifndef EMBEDDED_LIBRARY +extern "C" { +void my_net_local_init(NET *net) +{ + net->max_packet= (uint) global_system_variables.net_buffer_length; + net->read_timeout= (uint) global_system_variables.net_read_timeout; + net->write_timeout=(uint) global_system_variables.net_write_timeout; + net->retry_count= (uint) global_system_variables.net_retry_count; + net->max_packet_size= max(global_system_variables.net_buffer_length, + global_system_variables.max_allowed_packet); +} +} + +#else /* EMBEDDED_LIBRARY */ +void my_net_local_init(NET *net __attribute__(unused)) +{ +} +#endif /* EMBEDDED_LIBRARY */ /* Return ok to the client. @@ -217,6 +281,7 @@ net_printf(THD *thd, uint errcode, ...) If net->no_send_ok return without sending packet */ +#ifndef EMBEDDED_LIBRARY void send_ok(THD *thd, ha_rows affected_rows, ulonglong id, const char *message) @@ -302,6 +367,7 @@ send_eof(THD *thd, bool no_flush) } DBUG_VOID_RETURN; } +#endif /* EMBEDDED_LIBRARY */ /**************************************************************************** @@ -356,23 +422,6 @@ char *net_store_length(char *pkg, uint length) } -/* - Used internally for storing strings in packet -*/ - -static bool net_store_data(String *packet, const char *from, uint length) -{ - ulong packet_length=packet->length(); - if (packet_length+5+length > packet->alloced_length() && - packet->realloc(packet_length+5+length)) - return 1; - char *to=(char*) net_store_length((char*) packet->ptr()+packet_length, - (ulonglong) length); - memcpy(to,from,length); - packet->length((uint) (to+length-packet->ptr())); - return 0; -} - /**************************************************************************** Functions used by the protocol functions (like send_ok) to store strings and numbers in the header result packet. @@ -409,19 +458,6 @@ char *net_store_data(char *to,longlong from) Function called by my_net_init() to set some check variables */ -extern "C" { -void my_net_local_init(NET *net) -{ - net->max_packet= (uint) global_system_variables.net_buffer_length; - net->read_timeout= (uint) global_system_variables.net_read_timeout; - net->write_timeout=(uint) global_system_variables.net_write_timeout; - net->retry_count= (uint) global_system_variables.net_retry_count; - net->max_packet_size= max(global_system_variables.net_buffer_length, - global_system_variables.max_allowed_packet); -} -} - - /***************************************************************************** Default Protocol functions *****************************************************************************/ @@ -458,6 +494,7 @@ void Protocol::init(THD *thd_arg) 1 Error (Note that in this case the error is not sent to the client) */ +#ifndef EMBEDDED_LIBRARY bool Protocol::send_fields(List<Item> *list, uint flag) { List_iterator_fast<Item> it(*list); @@ -540,7 +577,6 @@ err: DBUG_RETURN(1); /* purecov: inspected */ } - bool Protocol::write() { DBUG_ENTER("Protocol::write"); @@ -548,6 +584,9 @@ bool Protocol::write() } +#endif /* EMBEDDED_LIBRARY */ + + /* Send \0 end terminated string @@ -605,6 +644,7 @@ bool Protocol::store(I_List<i_string>* str_list) ****************************************************************************/ +#ifndef EMBEDDED_LIBRARY void Protocol_simple::prepare_for_resend() { packet->length(0); @@ -612,6 +652,7 @@ void Protocol_simple::prepare_for_resend() field_pos= 0; #endif } +#endif bool Protocol_simple::store_null() { @@ -634,7 +675,7 @@ bool Protocol_simple::store(const char *from, uint length) #endif if (convert) return convert->store(packet, from, length); - return net_store_data(packet, from, length); + return net_store_data(from, length); } @@ -644,7 +685,7 @@ bool Protocol_simple::store_tiny(longlong from) DBUG_ASSERT(field_types == 0 || field_types[field_pos++] == MYSQL_TYPE_TINY); #endif char buff[20]; - return net_store_data(packet,(char*) buff, + return net_store_data((char*) buff, (uint) (int10_to_str((int) from,buff, -10)-buff)); } @@ -655,7 +696,7 @@ bool Protocol_simple::store_short(longlong from) field_types[field_pos++] == MYSQL_TYPE_SHORT); #endif char buff[20]; - return net_store_data(packet,(char*) buff, + return net_store_data((char*) buff, (uint) (int10_to_str((int) from,buff, -10)-buff)); } @@ -665,7 +706,7 @@ bool Protocol_simple::store_long(longlong from) DBUG_ASSERT(field_types == 0 || field_types[field_pos++] == MYSQL_TYPE_LONG); #endif char buff[20]; - return net_store_data(packet,(char*) buff, + return net_store_data((char*) buff, (uint) (int10_to_str((int) from,buff, -10)-buff)); } @@ -677,7 +718,7 @@ bool Protocol_simple::store_longlong(longlong from, bool unsigned_flag) field_types[field_pos++] == MYSQL_TYPE_LONGLONG); #endif char buff[22]; - return net_store_data(packet,(char*) buff, + return net_store_data((char*) buff, (uint) (longlong10_to_str(from,buff, unsigned_flag ? 10 : -10)- buff)); @@ -691,7 +732,7 @@ bool Protocol_simple::store(float from, uint32 decimals, String *buffer) field_types[field_pos++] == MYSQL_TYPE_FLOAT); #endif buffer->set((double) from, decimals, thd->variables.thd_charset); - return net_store_data(packet,(char*) buffer->ptr(), buffer->length()); + return net_store_data((char*) buffer->ptr(), buffer->length()); } bool Protocol_simple::store(double from, uint32 decimals, String *buffer) @@ -701,7 +742,7 @@ bool Protocol_simple::store(double from, uint32 decimals, String *buffer) field_types[field_pos++] == MYSQL_TYPE_DOUBLE); #endif buffer->set(from, decimals, thd->variables.thd_charset); - return net_store_data(packet,(char*) buffer->ptr(), buffer->length()); + return net_store_data((char*) buffer->ptr(), buffer->length()); } @@ -717,7 +758,7 @@ bool Protocol_simple::store(Field *field) field->val_str(&tmp,&tmp); if (convert) return convert->store(packet, tmp.ptr(), tmp.length()); - return net_store_data(packet, tmp.ptr(), tmp.length()); + return net_store_data(tmp.ptr(), tmp.length()); } @@ -738,7 +779,7 @@ bool Protocol_simple::store(TIME *tm) (int) tm->hour, (int) tm->minute, (int) tm->second)); - return net_store_data(packet, (char*) buff, length); + return net_store_data((char*) buff, length); } @@ -754,7 +795,7 @@ bool Protocol_simple::store_date(TIME *tm) (int) tm->year, (int) tm->month, (int) tm->day)); - return net_store_data(packet, (char*) buff, length); + return net_store_data((char*) buff, length); } @@ -771,7 +812,7 @@ bool Protocol_simple::store_time(TIME *tm) (long) tm->day*3600L+(long) tm->hour, (int) tm->minute, (int) tm->second)); - return net_store_data(packet, (char*) buff, length); + return net_store_data((char*) buff, length); } @@ -795,7 +836,7 @@ bool Protocol_simple::store_time(TIME *tm) bool Protocol_prep::prepare_for_send(List<Item> *item_list) { - field_count= item_list->elements; + Protocol::prepare_for_send(item_list); bit_fields= (field_count+9)/8; if (packet->alloc(bit_fields+1)) return 1; @@ -823,10 +864,9 @@ bool Protocol_prep::store(const char *from,uint length) field_pos++; if (convert) return convert->store(packet, from, length); - return net_store_data(packet, from, length); + return net_store_data(from, length); } - bool Protocol_prep::store_null() { uint offset= (field_pos+2)/8+1, bit= (1 << ((field_pos+2) & 7)); |