The world's most popular open source database
#include <protocol.h>
Inheritance diagram for Protocol:


Public Types | |
| SEND_NUM_ROWS = 1 | |
| SEND_DEFAULTS = 2 | |
| SEND_EOF = 4 | |
| enum | { SEND_NUM_ROWS = 1, SEND_DEFAULTS = 2, SEND_EOF = 4 } |
Public Member Functions | |
| Protocol () | |
| Protocol (THD *thd_arg) | |
| virtual | ~Protocol () |
| void | init (THD *thd_arg) |
| virtual bool | send_fields (List< Item > *list, uint flags) |
| bool | store (I_List< i_string > *str_list) |
| bool | store (const char *from, CHARSET_INFO *cs) |
| String * | storage_packet () |
| void | free () |
| virtual bool | write () |
| bool | store (uint32 from) |
| bool | store (longlong from) |
| bool | store (ulonglong from) |
| bool | store (String *str) |
| virtual bool | prepare_for_send (List< Item > *item_list) |
| virtual bool | flush () |
| virtual void | prepare_for_resend ()=0 |
| virtual bool | store_null ()=0 |
| virtual bool | store_tiny (longlong from)=0 |
| virtual bool | store_short (longlong from)=0 |
| virtual bool | store_long (longlong from)=0 |
| virtual bool | store_longlong (longlong from, bool unsigned_flag)=0 |
| virtual bool | store_decimal (const my_decimal *)=0 |
| virtual bool | store (const char *from, uint length, CHARSET_INFO *cs)=0 |
| virtual bool | store (const char *from, uint length, CHARSET_INFO *fromcs, CHARSET_INFO *tocs)=0 |
| virtual bool | store (float from, uint32 decimals, String *buffer)=0 |
| virtual bool | store (double from, uint32 decimals, String *buffer)=0 |
| virtual bool | store (TIME *time)=0 |
| virtual bool | store_date (TIME *time)=0 |
| virtual bool | store_time (TIME *time)=0 |
| virtual bool | store (Field *field)=0 |
| void | remove_last_row () |
Protected Member Functions | |
| enum enum_field_types *field_types uint field_count bool | net_store_data (const char *from, uint length) |
| bool | store_string_aux (const char *from, uint length, CHARSET_INFO *fromcs, CHARSET_INFO *tocs) |
Protected Attributes | |
| THD * | thd |
| String * | packet |
| String * | convert |
| uint | field_pos |
Definition at line 27 of file protocol.h.
| anonymous enum |
| Protocol::Protocol | ( | ) | [inline] |
| Protocol::Protocol | ( | THD * | thd_arg | ) | [inline] |
Definition at line 50 of file protocol.h.
References init().
00050 { init(thd_arg); }
Here is the call graph for this function:

| virtual Protocol::~Protocol | ( | ) | [inline, virtual] |
| bool Protocol::flush | ( | ) | [virtual] |
Definition at line 511 of file protocol.cc.
References net_flush(), and thd.
Referenced by mysqld_dump_create_info().
00512 { 00513 #ifndef EMBEDDED_LIBRARY 00514 return net_flush(&thd->net); 00515 #else 00516 return 0; 00517 #endif 00518 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void Protocol::free | ( | ) | [inline] |
Definition at line 60 of file protocol.h.
References String::free(), and packet.
Referenced by mysql_ha_read().
Here is the call graph for this function:

Here is the caller graph for this function:

| void Protocol::init | ( | THD * | thd_arg | ) |
Definition at line 500 of file protocol.cc.
References convert, packet, and thd.
Referenced by Protocol().
00501 { 00502 thd=thd_arg; 00503 packet= &thd->packet; 00504 convert= &thd->convert_buffer; 00505 #ifndef DBUG_OFF 00506 field_types= 0; 00507 #endif 00508 }
Here is the caller graph for this function:

Definition at line 35 of file protocol.cc.
References memcpy, net_store_length(), and to.
Referenced by Protocol_simple::store(), Protocol_simple::store_date(), Protocol_simple::store_decimal(), Protocol_simple::store_long(), Protocol_simple::store_longlong(), Protocol_simple::store_short(), store_string_aux(), Protocol_simple::store_time(), and Protocol_simple::store_tiny().
00039 { 00040 ulong packet_length=packet->length(); 00041 /* 00042 The +9 comes from that strings of length longer than 16M require 00043 9 bytes to be stored (see net_store_length). 00044 */ 00045 if (packet_length+9+length > packet->alloced_length() && 00046 packet->realloc(packet_length+9+length)) 00047 return 1; 00048 char *to=(char*) net_store_length((char*) packet->ptr()+packet_length, 00049 (ulonglong) length); 00050 memcpy(to,from,length); 00051 packet->length((uint) (to+length-packet->ptr())); 00052 return 0; 00053 }
Here is the call graph for this function:

Here is the caller graph for this function:

| virtual void Protocol::prepare_for_resend | ( | ) | [pure virtual] |
Implemented in Protocol_simple, and Protocol_prep.
Referenced by Event_scheduler::dump_internal_status(), mysql_admin_table(), mysql_checksum_table(), mysql_ha_read(), mysql_show_grants(), mysql_xa_recover(), mysqld_dump_create_info(), mysqld_list_processes(), mysqld_show_authors(), mysqld_show_column_types(), mysqld_show_contributors(), mysqld_show_create(), mysqld_show_create_db(), mysqld_show_privileges(), mysqld_show_warnings(), print_field_values(), send_answer_1(), send_check_errmsg(), send_variant_2_list(), Events::show_create_event(), sp_head::show_create_function(), sp_head::show_create_procedure(), show_handlerton(), sp_head::show_routine_code(), show_routine_grants(), and stat_print().
Here is the caller graph for this function:

Reimplemented in Protocol_prep.
Definition at line 71 of file protocol.h.
References base_list::elements.
Referenced by Protocol_prep::prepare_for_send(), and send_fields().
00072 { 00073 field_count=item_list->elements; 00074 return 0; 00075 }
Here is the caller graph for this function:

| void Protocol::remove_last_row | ( | ) | [inline] |
Definition at line 541 of file protocol.cc.
References Send_field::charsetnr, CLIENT_LONG_FLAG, CLIENT_PROTOCOL_41, Send_field::col_name, DTCollation::collation, Item::collation, count, Send_field::db_name, DBUG_ENTER, DBUG_RETURN, Send_field::decimals, ER, ER_OUT_OF_RESOURCES, err, Send_field::flags, int(), int2store, int3store, int4store, Send_field::length, String::length(), list(), Item::make_field(), charset_info_st::mbmaxlen, charset_info_st::mbminlen, my_charset_bin, my_message(), my_net_write(), MYF, MYSQL_TYPE_BLOB, MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VARCHAR, net_store_length(), NULL, charset_info_st::number, Send_field::org_col_name, Send_field::org_table_name, pos(), Protocol_simple::prepare_for_resend(), prepare_for_send(), String::ptr(), String::realloc(), Item::send(), SEND_DEFAULTS, SEND_EOF, SEND_NUM_ROWS, storage_packet(), Protocol_simple::store(), STRING_WITH_LEN, strlen(), system_charset_info, Send_field::table_name, thd, Send_field::type, and write_eof_packet().
Referenced by Event_scheduler::dump_internal_status(), ha_show_status(), mysql_admin_table(), mysql_checksum_table(), mysql_ha_read(), mysql_show_grants(), mysql_xa_recover(), mysqld_list_processes(), mysqld_show_authors(), mysqld_show_column_types(), mysqld_show_contributors(), mysqld_show_create(), mysqld_show_create_db(), mysqld_show_privileges(), mysqld_show_storage_engines(), send_answer_1(), send_header_2(), Events::show_create_event(), sp_head::show_create_function(), sp_head::show_create_procedure(), and sp_head::show_routine_code().
00542 { 00543 List_iterator_fast<Item> it(*list); 00544 Item *item; 00545 char buff[80]; 00546 String tmp((char*) buff,sizeof(buff),&my_charset_bin); 00547 Protocol_simple prot(thd); 00548 String *local_packet= prot.storage_packet(); 00549 CHARSET_INFO *thd_charset= thd->variables.character_set_results; 00550 DBUG_ENTER("send_fields"); 00551 00552 if (flags & SEND_NUM_ROWS) 00553 { // Packet with number of elements 00554 char *pos=net_store_length(buff, (uint) list->elements); 00555 (void) my_net_write(&thd->net, buff,(uint) (pos-buff)); 00556 } 00557 00558 #ifndef DBUG_OFF 00559 field_types= (enum_field_types*) thd->alloc(sizeof(field_types) * 00560 list->elements); 00561 uint count= 0; 00562 #endif 00563 00564 while ((item=it++)) 00565 { 00566 char *pos; 00567 CHARSET_INFO *cs= system_charset_info; 00568 Send_field field; 00569 item->make_field(&field); 00570 00571 /* Keep things compatible for old clients */ 00572 if (field.type == MYSQL_TYPE_VARCHAR) 00573 field.type= MYSQL_TYPE_VAR_STRING; 00574 00575 prot.prepare_for_resend(); 00576 00577 if (thd->client_capabilities & CLIENT_PROTOCOL_41) 00578 { 00579 if (prot.store(STRING_WITH_LEN("def"), cs, thd_charset) || 00580 prot.store(field.db_name, (uint) strlen(field.db_name), 00581 cs, thd_charset) || 00582 prot.store(field.table_name, (uint) strlen(field.table_name), 00583 cs, thd_charset) || 00584 prot.store(field.org_table_name, (uint) strlen(field.org_table_name), 00585 cs, thd_charset) || 00586 prot.store(field.col_name, (uint) strlen(field.col_name), 00587 cs, thd_charset) || 00588 prot.store(field.org_col_name, (uint) strlen(field.org_col_name), 00589 cs, thd_charset) || 00590 local_packet->realloc(local_packet->length()+12)) 00591 goto err; 00592 /* Store fixed length fields */ 00593 pos= (char*) local_packet->ptr()+local_packet->length(); 00594 *pos++= 12; // Length of packed fields 00595 if (item->collation.collation == &my_charset_bin || thd_charset == NULL) 00596 { 00597 /* No conversion */ 00598 int2store(pos, field.charsetnr); 00599 int4store(pos+2, field.length); 00600 } 00601 else 00602 { 00603 /* With conversion */ 00604 uint max_char_len; 00605 int2store(pos, thd_charset->number); 00606 /* 00607 For TEXT/BLOB columns, field_length describes the maximum data 00608 length in bytes. There is no limit to the number of characters 00609 that a TEXT column can store, as long as the data fits into 00610 the designated space. 00611 For the rest of textual columns, field_length is evaluated as 00612 char_count * mbmaxlen, where character count is taken from the 00613 definition of the column. In other words, the maximum number 00614 of characters here is limited by the column definition. 00615 */ 00616 max_char_len= (field.type >= (int) MYSQL_TYPE_TINY_BLOB && 00617 field.type <= (int) MYSQL_TYPE_BLOB) ? 00618 field.length / item->collation.collation->mbminlen : 00619 field.length / item->collation.collation->mbmaxlen; 00620 int4store(pos+2, max_char_len * thd_charset->mbmaxlen); 00621 } 00622 pos[6]= field.type; 00623 int2store(pos+7,field.flags); 00624 pos[9]= (char) field.decimals; 00625 pos[10]= 0; // For the future 00626 pos[11]= 0; // For the future 00627 pos+= 12; 00628 } 00629 else 00630 { 00631 if (prot.store(field.table_name, (uint) strlen(field.table_name), 00632 cs, thd_charset) || 00633 prot.store(field.col_name, (uint) strlen(field.col_name), 00634 cs, thd_charset) || 00635 local_packet->realloc(local_packet->length()+10)) 00636 goto err; 00637 pos= (char*) local_packet->ptr()+local_packet->length(); 00638 00639 #ifdef TO_BE_DELETED_IN_6 00640 if (!(thd->client_capabilities & CLIENT_LONG_FLAG)) 00641 { 00642 pos[0]=3; 00643 int3store(pos+1,field.length); 00644 pos[4]=1; 00645 pos[5]=field.type; 00646 pos[6]=2; 00647 pos[7]= (char) field.flags; 00648 pos[8]= (char) field.decimals; 00649 pos+= 9; 00650 } 00651 else 00652 #endif 00653 { 00654 pos[0]=3; 00655 int3store(pos+1,field.length); 00656 pos[4]=1; 00657 pos[5]=field.type; 00658 pos[6]=3; 00659 int2store(pos+7,field.flags); 00660 pos[9]= (char) field.decimals; 00661 pos+= 10; 00662 } 00663 } 00664 local_packet->length((uint) (pos - local_packet->ptr())); 00665 if (flags & SEND_DEFAULTS) 00666 item->send(&prot, &tmp); // Send default value 00667 if (prot.write()) 00668 break; /* purecov: inspected */ 00669 #ifndef DBUG_OFF 00670 field_types[count++]= field.type; 00671 #endif 00672 } 00673 00674 if (flags & SEND_EOF) 00675 write_eof_packet(thd, &thd->net); 00676 DBUG_RETURN(prepare_for_send(list)); 00677 00678 err: 00679 my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), 00680 MYF(0)); /* purecov: inspected */ 00681 DBUG_RETURN(1); /* purecov: inspected */ 00682 }
Here is the call graph for this function:

Here is the caller graph for this function:

| String* Protocol::storage_packet | ( | ) | [inline] |
Definition at line 59 of file protocol.h.
References packet.
Referenced by mysqld_dump_create_info(), and send_fields().
00059 { return packet; }
Here is the caller graph for this function:

Implemented in Protocol_simple, and Protocol_prep.
Implemented in Protocol_simple, and Protocol_prep.
Implemented in Protocol_simple, and Protocol_prep.
Implemented in Protocol_simple, and Protocol_prep.
| virtual bool Protocol::store | ( | const char * | from, | |
| uint | length, | |||
| CHARSET_INFO * | fromcs, | |||
| CHARSET_INFO * | tocs | |||
| ) | [pure virtual] |
Implemented in Protocol_simple, and Protocol_prep.
| virtual bool Protocol::store | ( | const char * | from, | |
| uint | length, | |||
| CHARSET_INFO * | cs | |||
| ) | [pure virtual] |
Implemented in Protocol_simple, and Protocol_prep.
Definition at line 68 of file protocol.h.
References String::charset(), String::length(), String::ptr(), and store().
Here is the call graph for this function:

Definition at line 66 of file protocol.h.
References store_longlong().
00067 { return store_longlong((longlong) from, 1); }
Here is the call graph for this function:

Definition at line 64 of file protocol.h.
References store_longlong().
00065 { return store_longlong((longlong) from, 0); }
Here is the call graph for this function:

Definition at line 62 of file protocol.h.
References store_long().
00063 { return store_long((longlong) from); }
Here is the call graph for this function:

| bool Protocol::store | ( | const char * | from, | |
| CHARSET_INFO * | cs | |||
| ) |
Definition at line 708 of file protocol.cc.
References store(), store_null(), and strlen().
00709 { 00710 if (!from) 00711 return store_null(); 00712 uint length= strlen(from); 00713 return store(from, length, cs); 00714 }
Here is the call graph for this function:

Definition at line 721 of file protocol.cc.
References String::append(), buf, String::charset(), String::length(), my_charset_bin, String::ptr(), and i_string::ptr.
Referenced by Event_scheduler::dump_internal_status(), mysql_admin_table(), mysql_checksum_table(), mysql_show_grants(), mysql_xa_recover(), mysqld_list_processes(), mysqld_show_authors(), mysqld_show_column_types(), mysqld_show_contributors(), mysqld_show_create(), mysqld_show_create_db(), mysqld_show_privileges(), mysqld_show_warnings(), print_field_values(), Item_ref::send(), Item_field::send(), Item::send(), send_answer_1(), Field_datetime::send_binary(), Field_timestamp::send_binary(), Field_double::send_binary(), Field_float::send_binary(), Field::send_binary(), send_check_errmsg(), send_variant_2_list(), Events::show_create_event(), sp_head::show_create_function(), sp_head::show_create_procedure(), show_handlerton(), sp_head::show_routine_code(), show_routine_grants(), stat_print(), and store().
00722 { 00723 char buf[256]; 00724 String tmp(buf, sizeof(buf), &my_charset_bin); 00725 uint32 len; 00726 I_List_iterator<i_string> it(*str_list); 00727 i_string* s; 00728 00729 tmp.length(0); 00730 while ((s=it++)) 00731 { 00732 tmp.append(s->ptr); 00733 tmp.append(','); 00734 } 00735 if ((len= tmp.length())) 00736 len--; // Remove last ',' 00737 return store((char*) tmp.ptr(), len, tmp.charset()); 00738 }
Here is the call graph for this function:

Here is the caller graph for this function:

Implemented in Protocol_simple, and Protocol_prep.
Referenced by Item::send(), Field_newdate::send_binary(), and Field_date::send_binary().
Here is the caller graph for this function:

| virtual bool Protocol::store_decimal | ( | const my_decimal * | ) | [pure virtual] |
Implemented in Protocol_simple, and Protocol_prep.

