summaryrefslogtreecommitdiff
path: root/sql/protocol.cc
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2017-05-04 16:05:21 +0400
committerAlexander Barkov <bar@mariadb.org>2017-05-04 16:05:21 +0400
commitfe127562e2bfa0306d0a32eeb886764af577019d (patch)
tree1f886c2642f9d288e60d97899de575a94d43f2cd /sql/protocol.cc
parentae5b31fe52e272a2cebbdf9bf8c230d622dc8ec3 (diff)
downloadmariadb-git-fe127562e2bfa0306d0a32eeb886764af577019d.tar.gz
MDEV-12687 Split Item::send() into virtual method in Type_handler
Diffstat (limited to 'sql/protocol.cc')
-rw-r--r--sql/protocol.cc22
1 files changed, 11 insertions, 11 deletions
diff --git a/sql/protocol.cc b/sql/protocol.cc
index 340b3a2176a..33742dc01a2 100644
--- a/sql/protocol.cc
+++ b/sql/protocol.cc
@@ -791,8 +791,7 @@ bool Protocol::send_result_set_metadata(List<Item> *list, uint flags)
{
List_iterator_fast<Item> it(*list);
Item *item;
- uchar buff[MAX_FIELD_WIDTH];
- String tmp((char*) buff,sizeof(buff),&my_charset_bin);
+ ValueBuffer<MAX_FIELD_WIDTH> tmp;
Protocol_text prot(thd);
String *local_packet= prot.storage_packet();
CHARSET_INFO *thd_charset= thd->variables.character_set_results;
@@ -800,7 +799,9 @@ bool Protocol::send_result_set_metadata(List<Item> *list, uint flags)
if (flags & SEND_NUM_ROWS)
{ // Packet with number of elements
+ uchar buff[MAX_INT_WIDTH];
uchar *pos= net_store_length(buff, list->elements);
+ DBUG_ASSERT(pos <= buff + sizeof(buff));
if (my_net_write(&thd->net, buff, (size_t) (pos-buff)))
DBUG_RETURN(1);
}
@@ -968,15 +969,20 @@ bool Protocol::write()
bool Protocol::send_result_set_row(List<Item> *row_items)
{
- char buffer[MAX_FIELD_WIDTH];
- String str_buffer(buffer, sizeof (buffer), &my_charset_bin);
List_iterator_fast<Item> it(*row_items);
DBUG_ENTER("Protocol::send_result_set_row");
for (Item *item= it++; item; item= it++)
{
- if (item->send(this, &str_buffer))
+ /*
+ ValueBuffer::m_string can be altered during Item::send().
+ It's important to declare value_buffer inside the loop,
+ to have ValueBuffer::m_string point to ValueBuffer::buffer
+ on every iteration.
+ */
+ ValueBuffer<MAX_FIELD_WIDTH> value_buffer;
+ if (item->send(this, &value_buffer))
{
// If we're out of memory, reclaim some, to help us recover.
this->free();
@@ -985,12 +991,6 @@ bool Protocol::send_result_set_row(List<Item> *row_items)
/* Item::send() may generate an error. If so, abort the loop. */
if (thd->is_error())
DBUG_RETURN(TRUE);
-
- /*
- Reset str_buffer to its original state, as it may have been altered in
- Item::send().
- */
- str_buffer.set(buffer, sizeof(buffer), &my_charset_bin);
}
DBUG_RETURN(FALSE);