同步操作将从 nwsuafzq/MySQLAdvisor 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; version 2 of the License.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *//**@fileLow level functions for storing data to be send to the MySQL client.The actual communction is handled by the net_xxx functions in net_serv.cc*/#include "sql_priv.h"#include "unireg.h" // REQUIRED: for other includes#include "protocol.h"#include "sql_class.h" // THD#include <stdarg.h>using std::min;using std::max;static const unsigned int PACKET_BUFFER_EXTRA_ALLOC= 1024;/* Declared non-static only because of the embedded library. */bool net_send_error_packet(THD *, uint, const char *, const char *);/* Declared non-static only because of the embedded library. */bool net_send_ok(THD *, uint, uint, ulonglong, ulonglong, const char *);/* Declared non-static only because of the embedded library. */bool net_send_eof(THD *thd, uint server_status, uint statement_warn_count);#ifndef EMBEDDED_LIBRARYstatic bool write_eof_packet(THD *, NET *, uint, uint);#endif#ifndef EMBEDDED_LIBRARYbool Protocol::net_store_data(const uchar *from, size_t length)#elsebool Protocol_binary::net_store_data(const uchar *from, size_t length)#endif{ulong packet_length=packet->length();/*The +9 comes from that strings of length longer than 16M require9 bytes to be stored (see net_store_length).*/if (packet_length+9+length > packet->alloced_length() &&packet->realloc(packet_length+9+length))return 1;uchar *to= net_store_length((uchar*) packet->ptr()+packet_length, length);memcpy(to,from,length);packet->length((uint) (to+length-(uchar*) packet->ptr()));return 0;}/*net_store_data() - extended version with character set conversion.It is optimized for short strings whose length afterconversion is garanteed to be less than 251, which accupiesexactly one byte to store length. It allows not to usethe "convert" member as a temporary buffer, conversionis done directly to the "packet" member.The limit 251 is good enough to optimize send_result_set_metadata()because column, table, database names fit into this limit.*/#ifndef EMBEDDED_LIBRARYbool Protocol::net_store_data(const uchar *from, size_t length,const CHARSET_INFO *from_cs,const CHARSET_INFO *to_cs){uint dummy_errors;/* Calculate maxumum possible result length */uint conv_length= to_cs->mbmaxlen * length / from_cs->mbminlen;if (conv_length > 250){/*For strings with conv_length greater than 250 byteswe don't know how many bytes we will need to store length: one or two,because we don't know result length until conversion is done.For example, when converting from utf8 (mbmaxlen=3) to latin1,conv_length=300 means that the result length can vary between 100 to 300.length=100 needs one byte, length=300 needs to bytes.Thus conversion directly to "packet" is not worthy.Let's use "convert" as a temporary buffer.*/return (convert->copy((const char*) from, length, from_cs,to_cs, &dummy_errors) ||net_store_data((const uchar*) convert->ptr(), convert->length()));}ulong packet_length= packet->length();ulong new_length= packet_length + conv_length + 1;if (new_length > packet->alloced_length() && packet->realloc(new_length))return 1;char *length_pos= (char*) packet->ptr() + packet_length;char *to= length_pos + 1;to+= copy_and_convert(to, conv_length, to_cs,(const char*) from, length, from_cs, &dummy_errors);net_store_length((uchar*) length_pos, to - length_pos - 1);packet->length((uint) (to - packet->ptr()));return 0;}#endif/**Send a error string to client.Design note:net_printf_error and net_send_error are low-level functionsthat shall be used only when a new connection is beingestablished or at server startup.For SIGNAL/RESIGNAL and GET DIAGNOSTICS functionality it'scritical that every error that can be intercepted is issued in oneplace only, my_message_sql.@param thd Thread handler@param sql_errno The error code to send@param err A pointer to the error message@return@retval FALSE The message was sent to the client@retval TRUE An error occurred and the message wasn't sent properly*/bool net_send_error(THD *thd, uint sql_errno, const char *err,const char* sqlstate){bool error;DBUG_ENTER("net_send_error");DBUG_ASSERT(sql_errno);DBUG_ASSERT(err);DBUG_PRINT("enter",("sql_errno: %d err: %s", sql_errno, err));if (sqlstate == NULL)sqlstate= mysql_errno_to_sqlstate(sql_errno);/*It's one case when we can push an error even though thereis an OK or EOF already.*/thd->get_stmt_da()->set_overwrite_status(true);/* Abort multi-result sets */thd->server_status&= ~SERVER_MORE_RESULTS_EXISTS;error= net_send_error_packet(thd, sql_errno, err, sqlstate);thd->get_stmt_da()->set_overwrite_status(false);DBUG_RETURN(error);}/**Return ok to the client.The ok packet has the following structure:- 0 : Marker (1 byte)- affected_rows : Stored in 1-9 bytes- id : Stored in 1-9 bytes- server_status : Copy of thd->server_status; Can be used by clientto check if we are inside an transaction.New in 4.0 protocol- warning_count : Stored in 2 bytes; New in 4.1 protocol- message : Stored as packed length (1-9 bytes) + message.Is not stored if no message.@param thd Thread handler@param server_status The server status@param statement_warn_count Total number of warnings@param affected_rows Number of rows changed by statement@param id Auto_increment id for first row (if used)@param message Message to send to the client (Used by mysql_status)@return@retval FALSE The message was successfully sent@retval TRUE An error occurred and the messages wasn't sent properly*/#ifndef EMBEDDED_LIBRARYboolnet_send_ok(THD *thd,uint server_status, uint statement_warn_count,ulonglong affected_rows, ulonglong id, const char *message){NET *net= &thd->net;uchar buff[MYSQL_ERRMSG_SIZE+10],*pos;bool error= FALSE;DBUG_ENTER("net_send_ok");if (! net->vio) // hack for re-parsing queries{DBUG_PRINT("info", ("vio present: NO"));DBUG_RETURN(FALSE);}buff[0]=0; // No fieldspos=net_store_length(buff+1,affected_rows);pos=net_store_length(pos, id);if (thd->client_capabilities & CLIENT_PROTOCOL_41){DBUG_PRINT("info",("affected_rows: %lu id: %lu status: %u warning_count: %u",(ulong) affected_rows,(ulong) id,(uint) (server_status & 0xffff),(uint) statement_warn_count));int2store(pos, server_status);pos+=2;/* We can only return up to 65535 warnings in two bytes */uint tmp= min(statement_warn_count, 65535U);int2store(pos, tmp);pos+= 2;}else if (net->return_status) // For 4.0 protocol{int2store(pos, server_status);pos+=2;}thd->get_stmt_da()->set_overwrite_status(true);if (message && message[0])pos= net_store_data(pos, (uchar*) message, strlen(message));error= my_net_write(net, buff, (size_t) (pos-buff));if (!error)error= net_flush(net);thd->get_stmt_da()->set_overwrite_status(false);DBUG_PRINT("info", ("OK sent, so no more error sending allowed"));DBUG_RETURN(error);}static uchar eof_buff[1]= { (uchar) 254 }; /* Marker for end of fields *//**Send eof (= end of result set) to the client.The eof packet has the following structure:- 254 : Marker (1 byte)- warning_count : Stored in 2 bytes; New in 4.1 protocol- status_flag : Stored in 2 bytes;For flags like SERVER_MORE_RESULTS_EXISTS.Note that the warning count will not be sent if 'no_flush' is set aswe don't want to report the warning count until all data is sent to theclient.@param thd Thread handler@param server_status The server status@param statement_warn_count Total number of warnings@return@retval FALSE The message was successfully sent@retval TRUE An error occurred and the message wasn't sent properly*/boolnet_send_eof(THD *thd, uint server_status, uint statement_warn_count){NET *net= &thd->net;bool error= FALSE;DBUG_ENTER("net_send_eof");/* Set to TRUE if no active vio, to work well in case of --init-file */if (net->vio != 0){thd->get_stmt_da()->set_overwrite_status(true);error= write_eof_packet(thd, net, server_status, statement_warn_count);if (!error)error= net_flush(net);thd->get_stmt_da()->set_overwrite_status(false);DBUG_PRINT("info", ("EOF sent, so no more error sending allowed"));}DBUG_RETURN(error);}/**Format EOF packet according to the current protocol andwrite it to the network output buffer.@param thd The thread handler@param net The network handler@param server_status The server status@param statement_warn_count The number of warnings@return@retval FALSE The message was sent successfully@retval TRUE An error occurred and the messages wasn't sent properly*/static bool write_eof_packet(THD *thd, NET *net,uint server_status,uint statement_warn_count){bool error;if (thd->client_capabilities & CLIENT_PROTOCOL_41){uchar buff[5];/*Don't send warn count during SP execution, as the warn_listis cleared between substatements, and mysqltest gets confused*/uint tmp= min(statement_warn_count, 65535U);buff[0]= 254;int2store(buff+1, tmp);/*The following test should never be true, but it's better to do itbecause if 'is_fatal_error' is set the server is not going to executeother queries (see the if test in dispatch_command / COM_QUERY)*/if (thd->is_fatal_error)server_status&= ~SERVER_MORE_RESULTS_EXISTS;int2store(buff + 3, server_status);error= my_net_write(net, buff, 5);}elseerror= my_net_write(net, eof_buff, 1);return error;}/**@param thd Thread handler@param sql_errno The error code to send@param err A pointer to the error message@return@retval FALSE The message was successfully sent@retval TRUE An error occurred and the messages wasn't sent properly*/bool net_send_error_packet(THD *thd, uint sql_errno, const char *err,const char* sqlstate){NET *net= &thd->net;uint length;/*buff[]: sql_errno:2 + ('#':1 + SQLSTATE_LENGTH:5) + MYSQL_ERRMSG_SIZE:512*/uint error;char converted_err[MYSQL_ERRMSG_SIZE];char buff[2+1+SQLSTATE_LENGTH+MYSQL_ERRMSG_SIZE], *pos;DBUG_ENTER("send_error_packet");if (net->vio == 0){if (thd->bootstrap){/* In bootstrap it's ok to print on stderr */fprintf(stderr,"ERROR: %d %s\n",sql_errno,err);}DBUG_RETURN(FALSE);}int2store(buff,sql_errno);pos= buff+2;if (thd->client_capabilities & CLIENT_PROTOCOL_41){/* The first # is to make the protocol backward compatible */buff[2]= '#';pos= strmov(buff+3, sqlstate);}convert_error_message(converted_err, sizeof(converted_err),thd->variables.character_set_results,err, strlen(err), system_charset_info, &error);/* Converted error message is always null-terminated. */length= (uint) (strmake(pos, converted_err, MYSQL_ERRMSG_SIZE - 1) - buff);DBUG_RETURN(net_write_command(net,(uchar) 255, (uchar*) "", 0, (uchar*) buff,length));}#endif /* EMBEDDED_LIBRARY *//**Faster net_store_length when we know that length is less than 65536.We keep a separate version for that range because it's widely used inlibmysql.uint is used as agrument type because of MySQL type conventions:- uint for 0..65536- ulong for 0..4294967296- ulonglong for bigger numbers.*/static uchar *net_store_length_fast(uchar *packet, uint length){if (length < 251){*packet=(uchar) length;return packet+1;}*packet++=252;int2store(packet,(uint) length);return packet+2;}/**Send the status of the current statement execution over network.@param thd in fact, carries two parameters, NET for the transport andDiagnostics_area as the source of status information.In MySQL, there are two types of SQL statements: those that returna result set and those that return status information only.If a statement returns a result set, it consists of 3 parts:- result set meta-data- variable number of result set rows (can be 0)- followed and terminated by EOF or ERROR packetOnce the client has seen the meta-data information, it alwaysexpects an EOF or ERROR to terminate the result set. If ERROR isreceived, the result set rows are normally discarded (this is upto the client implementation, libmysql at least does discard them).EOF, on the contrary, means "successfully evaluated the entireresult set". Since we don't know how many rows belong to a resultset until it's evaluated, EOF/ERROR is the indicator of the endof the row stream. Note, that we can not buffer result set rowson the server -- there may be an arbitrary number of rows. Butwe do buffer the last packet (EOF/ERROR) in the Diagnostics_area anddelay sending it till the very end of execution (here), to be able tochange EOF to an ERROR if commit failed or some other error occurredduring the last cleanup steps taken after execution.A statement that does not return a result set doesn't send resultset meta-data either. Instead it returns one of:- OK packet- ERROR packet.Similarly to the EOF/ERROR of the previous statement type, OK/ERRORpacket is "buffered" in the diagnostics area and sent to the clientin the end of statement.@note This method defines a template, but delegates actualsending of data to virtual Protocol::send_{ok,eof,error}. Thisallows for implementation of protocols that "intercept" ok/eof/errormessages, and store them in memory, etc, instead of sending tothe client.@pre The diagnostics area is assigned or disabled. It can not be empty-- we assume that every SQL statement or COM_* commandgenerates OK, ERROR, or EOF status.@post The status information is encoded to protocol format and sent to theclient.@return We conventionally return void, since the only type of errorthat can happen here is a NET (transport) error, and that onewill become visible when we attempt to read from the NET thenext command.Diagnostics_area::is_sent is set for debugging purposes only.*/void Protocol::end_statement(){DBUG_ENTER("Protocol::end_statement");DBUG_ASSERT(! thd->get_stmt_da()->is_sent());bool error= FALSE;/* Can not be true, but do not take chances in production. */if (thd->get_stmt_da()->is_sent())DBUG_VOID_RETURN;switch (thd->get_stmt_da()->status()) {case Diagnostics_area::DA_ERROR:/* The query failed, send error to log and abort bootstrap. */error= send_error(thd->get_stmt_da()->sql_errno(),thd->get_stmt_da()->message(),thd->get_stmt_da()->get_sqlstate());break;case Diagnostics_area::DA_EOF:error= send_eof(thd->server_status,thd->get_stmt_da()->statement_warn_count());break;case Diagnostics_area::DA_OK:error= send_ok(thd->server_status,thd->get_stmt_da()->statement_warn_count(),thd->get_stmt_da()->affected_rows(),thd->get_stmt_da()->last_insert_id(),thd->get_stmt_da()->message());break;case Diagnostics_area::DA_DISABLED:break;case Diagnostics_area::DA_EMPTY:default:DBUG_ASSERT(0);error= send_ok(thd->server_status, 0, 0, 0, NULL);break;}if (!error)thd->get_stmt_da()->set_is_sent(true);DBUG_VOID_RETURN;}/**A default implementation of "OK" packet response to the client.Currently this implementation is re-used by both network-orientedprotocols -- the binary and text one. They do not differin their OK packet format, which allows for a significant simplificationon client side.*/bool Protocol::send_ok(uint server_status, uint statement_warn_count,ulonglong affected_rows, ulonglong last_insert_id,const char *message){DBUG_ENTER("Protocol::send_ok");const bool retval=net_send_ok(thd, server_status, statement_warn_count,affected_rows, last_insert_id, message);DBUG_RETURN(retval);}/**A default implementation of "EOF" packet response to the client.Binary and text protocol do not differ in their EOF packet format.*/bool Protocol::send_eof(uint server_status, uint statement_warn_count){DBUG_ENTER("Protocol::send_eof");const bool retval= net_send_eof(thd, server_status, statement_warn_count);DBUG_RETURN(retval);}/**A default implementation of "ERROR" packet response to the client.Binary and text protocol do not differ in ERROR packet format.*/bool Protocol::send_error(uint sql_errno, const char *err_msg,const char *sql_state){DBUG_ENTER("Protocol::send_error");const bool retval= net_send_error_packet(thd, sql_errno, err_msg, sql_state);DBUG_RETURN(retval);}/****************************************************************************Functions used by the protocol functions (like net_send_ok) to storestrings and numbers in the header result packet.****************************************************************************//* The following will only be used for short strings < 65K */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;}uchar *net_store_data(uchar *to,int32 from){char buff[20];uint length=(uint) (int10_to_str(from,buff,10)-buff);to=net_store_length_fast(to,length);memcpy(to,buff,length);return to+length;}uchar *net_store_data(uchar *to,longlong from){char buff[22];uint length=(uint) (longlong10_to_str(from,buff,10)-buff);to=net_store_length_fast(to,length);memcpy(to,buff,length);return to+length;}/*****************************************************************************Default Protocol functions*****************************************************************************/void Protocol::init(THD *thd_arg){thd=thd_arg;packet= &thd->packet;convert= &thd->convert_buffer;#ifndef DBUG_OFFfield_types= 0;#endif}/**Finish the result set with EOF packet, as is expected by the client,if there is an error evaluating the next row and a continue handlerfor the error.*/void Protocol::end_partial_result_set(THD *thd_arg){net_send_eof(thd_arg, thd_arg->server_status, 0 /* no warnings, we're inside SP */);}bool Protocol::flush(){#ifndef EMBEDDED_LIBRARYbool error;thd->get_stmt_da()->set_overwrite_status(true);error= net_flush(&thd->net);thd->get_stmt_da()->set_overwrite_status(false);return error;#elsereturn 0;#endif}#ifndef EMBEDDED_LIBRARYbool Protocol::write(){DBUG_ENTER("Protocol::write");DBUG_RETURN(my_net_write(&thd->net, (uchar*) packet->ptr(),packet->length()));}#endif /* EMBEDDED_LIBRARY *//**Send \0円 end terminated string.@param from NullS or \0円 terminated string@noteIn most cases one should use store(from, length) instead of this function@retval0 ok@retval1 error*/bool Protocol::store(const char *from, const CHARSET_INFO *cs){if (!from)return store_null();uint length= strlen(from);return store(from, length, cs);}/**Send a set of strings as one long string with ',' in between.*/bool Protocol::store(I_List<i_string>* str_list){char buf[256];String tmp(buf, sizeof(buf), &my_charset_bin);uint32 len;I_List_iterator<i_string> it(*str_list);i_string* s;tmp.length(0);while ((s=it++)){tmp.append(s->ptr);tmp.append(',');}if ((len= tmp.length()))len--; // Remove last ','return store((char*) tmp.ptr(), len, tmp.charset());}/****************************************************************************Functions to handle the simple (default) protocol where everything isThis protocol is the one that is used by default between the MySQL serverand client when you are not using prepared statements.All data are sent as 'packed-string-length' followed by 'string-data'****************************************************************************/#ifndef EMBEDDED_LIBRARYvoid Protocol_text::prepare_for_resend(){packet->length(0);#ifndef DBUG_OFFfield_pos= 0;#endif}bool Protocol_text::store_null(){#ifndef DBUG_OFFfield_pos++;#endifchar buff[1];buff[0]= (char)251;return packet->append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC);}#endif/**Auxilary function to convert string to the given character setand store in network buffer.*/bool Protocol::store_string_aux(const char *from, size_t length,const CHARSET_INFO *fromcs,const CHARSET_INFO *tocs){/* 'tocs' is set 0 when client issues SET character_set_results=NULL */if (tocs && !my_charset_same(fromcs, tocs) &&fromcs != &my_charset_bin &&tocs != &my_charset_bin){/* Store with conversion */return net_store_data((uchar*) from, length, fromcs, tocs);}/* Store without conversion */return net_store_data((uchar*) from, length);}bool Protocol_text::store(const char *from, size_t length,const CHARSET_INFO *fromcs,const CHARSET_INFO *tocs){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_DECIMAL ||field_types[field_pos] == MYSQL_TYPE_BIT ||field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL ||(field_types[field_pos] >= MYSQL_TYPE_ENUM &&field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));field_pos++;#endifreturn store_string_aux(from, length, fromcs, tocs);}bool Protocol_text::store(const char *from, size_t length,const CHARSET_INFO *fromcs){const CHARSET_INFO *tocs= this->thd->variables.character_set_results;#ifndef DBUG_OFFDBUG_PRINT("info", ("Protocol_text::store field %u (%u): %.*s", field_pos,field_count, (int) length, (length == 0 ? "" : from)));DBUG_ASSERT(field_pos < field_count);DBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_DECIMAL ||field_types[field_pos] == MYSQL_TYPE_BIT ||field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL ||field_types[field_pos] == MYSQL_TYPE_NEWDATE ||(field_types[field_pos] >= MYSQL_TYPE_ENUM &&field_types[field_pos] <= MYSQL_TYPE_GEOMETRY));field_pos++;#endifreturn store_string_aux(from, length, fromcs, tocs);}bool Protocol_text::store_tiny(longlong from){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 || field_types[field_pos] == MYSQL_TYPE_TINY);field_pos++;#endifchar buff[20];return net_store_data((uchar*) buff,(size_t) (int10_to_str((int) from, buff, -10) - buff));}bool Protocol_text::store_short(longlong from){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_YEAR ||field_types[field_pos] == MYSQL_TYPE_SHORT);field_pos++;#endifchar buff[20];return net_store_data((uchar*) buff,(size_t) (int10_to_str((int) from, buff, -10) -buff));}bool Protocol_text::store_long(longlong from){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_INT24 ||field_types[field_pos] == MYSQL_TYPE_LONG);field_pos++;#endifchar buff[20];return net_store_data((uchar*) buff,(size_t) (int10_to_str((long int)from, buff,(from <0)?-10:10)-buff));}bool Protocol_text::store_longlong(longlong from, bool unsigned_flag){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_LONGLONG);field_pos++;#endifchar buff[22];return net_store_data((uchar*) buff,(size_t) (longlong10_to_str(from,buff,unsigned_flag ? 10 : -10)-buff));}bool Protocol_text::store_decimal(const my_decimal *d){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL);field_pos++;#endifchar buff[DECIMAL_MAX_STR_LENGTH + 1];String str(buff, sizeof(buff), &my_charset_bin);(void) my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);return net_store_data((uchar*) str.ptr(), str.length());}bool Protocol_text::store(float from, uint32 decimals, String *buffer){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_FLOAT);field_pos++;#endifbuffer->set_real((double) from, decimals, thd->charset());return net_store_data((uchar*) buffer->ptr(), buffer->length());}bool Protocol_text::store(double from, uint32 decimals, String *buffer){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_DOUBLE);field_pos++;#endifbuffer->set_real(from, decimals, thd->charset());return net_store_data((uchar*) buffer->ptr(), buffer->length());}/**@todoSecond_part format ("%06") needs to change whenwe support 0-6 decimals for time.*/bool Protocol_text::store(MYSQL_TIME *tm, uint decimals){#ifndef DBUG_OFFfield_pos++;#endifchar buff[MAX_DATE_STRING_REP_LENGTH];uint length= my_datetime_to_str(tm, buff, decimals);return net_store_data((uchar*) buff, length);}bool Protocol_text::store_date(MYSQL_TIME *tm){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_DATE);field_pos++;#endifchar buff[MAX_DATE_STRING_REP_LENGTH];size_t length= my_date_to_str(tm, buff);return net_store_data((uchar*) buff, length);}bool Protocol_text::store_time(MYSQL_TIME *tm, uint decimals){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_TIME);field_pos++;#endifchar buff[MAX_DATE_STRING_REP_LENGTH];uint length= my_time_to_str(tm, buff, decimals);return net_store_data((uchar*) buff, length);}/****************************************************************************Functions to handle the binary protocol used with prepared statementsData format:[ok:1] reserved ok packet[null_field:(field_count+7+2)/8] reserved to send null data. The size iscalculated using:bit_fields= (field_count+7+2)/8;2 bits are reserved for identifying typeof package.[[length]data] data field (the length applies only forstring/binary/time/timestamp fields andrest of them are not sent as they havethe default length that client understandsbased on the field type[..]..[[length]data] data****************************************************************************/bool Protocol_binary::prepare_for_send(uint num_columns){Protocol::prepare_for_send(num_columns);bit_fields= (field_count+9)/8;return packet->alloc(bit_fields+1);/* prepare_for_resend will be called after this one */}void Protocol_binary::prepare_for_resend(){packet->length(bit_fields+1);memset(const_cast<char*>(packet->ptr()), 0, 1+bit_fields);field_pos=0;}bool Protocol_binary::store(const char *from, size_t length,const CHARSET_INFO *fromcs){const CHARSET_INFO *tocs= thd->variables.character_set_results;field_pos++;return store_string_aux(from, length, fromcs, tocs);}bool Protocol_binary::store(const char *from, size_t length,const CHARSET_INFO *fromcs,const CHARSET_INFO *tocs){field_pos++;return store_string_aux(from, length, fromcs, tocs);}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 */char *to= (char*) packet->ptr()+offset;*to= (char) ((uchar) *to | (uchar) bit);field_pos++;return 0;}bool Protocol_binary::store_tiny(longlong from){char buff[1];field_pos++;buff[0]= (uchar) from;return packet->append(buff, sizeof(buff), PACKET_BUFFER_EXTRA_ALLOC);}bool Protocol_binary::store_short(longlong from){field_pos++;char *to= packet->prep_append(2, PACKET_BUFFER_EXTRA_ALLOC);if (!to)return 1;int2store(to, (int) from);return 0;}bool Protocol_binary::store_long(longlong from){field_pos++;char *to= packet->prep_append(4, PACKET_BUFFER_EXTRA_ALLOC);if (!to)return 1;int4store(to, from);return 0;}bool Protocol_binary::store_longlong(longlong from, bool unsigned_flag){field_pos++;char *to= packet->prep_append(8, PACKET_BUFFER_EXTRA_ALLOC);if (!to)return 1;int8store(to, from);return 0;}bool Protocol_binary::store_decimal(const my_decimal *d){#ifndef DBUG_OFFDBUG_ASSERT(field_types == 0 ||field_types[field_pos] == MYSQL_TYPE_NEWDECIMAL);field_pos++;#endifchar buff[DECIMAL_MAX_STR_LENGTH + 1];String str(buff, sizeof(buff), &my_charset_bin);(void) my_decimal2string(E_DEC_FATAL_ERROR, d, 0, 0, 0, &str);return store(str.ptr(), str.length(), str.charset());}bool Protocol_binary::store(float from, uint32 decimals, String *buffer){field_pos++;char *to= packet->prep_append(4, PACKET_BUFFER_EXTRA_ALLOC);if (!to)return 1;float4store(to, from);return 0;}bool Protocol_binary::store(double from, uint32 decimals, String *buffer){field_pos++;char *to= packet->prep_append(8, PACKET_BUFFER_EXTRA_ALLOC);if (!to)return 1;float8store(to, from);return 0;}bool Protocol_binary::store(MYSQL_TIME *tm, uint precision){char buff[12],*pos;uint length;field_pos++;pos= buff+1;int2store(pos, tm->year);pos[2]= (uchar) tm->month;pos[3]= (uchar) tm->day;pos[4]= (uchar) tm->hour;pos[5]= (uchar) tm->minute;pos[6]= (uchar) tm->second;int4store(pos+7, tm->second_part);if (tm->second_part)length=11;else if (tm->hour || tm->minute || tm->second)length=7;else if (tm->year || tm->month || tm->day)length=4;elselength=0;buff[0]=(char) length; // Length is stored firstreturn packet->append(buff, length+1, PACKET_BUFFER_EXTRA_ALLOC);}bool Protocol_binary::store_date(MYSQL_TIME *tm){tm->hour= tm->minute= tm->second=0;tm->second_part= 0;return Protocol_binary::store(tm, 0);}bool Protocol_binary::store_time(MYSQL_TIME *tm, uint precision){char buff[13], *pos;uint length;field_pos++;pos= buff+1;pos[0]= tm->neg ? 1 : 0;if (tm->hour >= 24){/* Fix if we come from Item::send */uint days= tm->hour/24;tm->hour-= days*24;tm->day+= days;}int4store(pos+1, tm->day);pos[5]= (uchar) tm->hour;pos[6]= (uchar) tm->minute;pos[7]= (uchar) tm->second;int4store(pos+8, tm->second_part);if (tm->second_part)length=12;else if (tm->hour || tm->minute || tm->second || tm->day)length=8;elselength=0;buff[0]=(char) length; // Length is stored firstreturn packet->append(buff, length+1, PACKET_BUFFER_EXTRA_ALLOC);}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。