summaryrefslogtreecommitdiff
path: root/sql/sql_parse.cc
diff options
context:
space:
mode:
authorTatjana Azundris Nuernberg <tatjana.nuernberg@oracle.com>2011-10-10 15:34:29 +0100
committerTatjana Azundris Nuernberg <tatjana.nuernberg@oracle.com>2011-10-10 15:34:29 +0100
commit2a8a76537ff7486286b463084da2f6d9ac905d40 (patch)
tree051108b8abaf436cda3123271518e2ace579674f /sql/sql_parse.cc
parent12f5e01403cf8cb3601b23632ff5d9a952496327 (diff)
parente02c3d7fb7e59bcede73392ab0da5a5228859e0f (diff)
downloadmariadb-git-2a8a76537ff7486286b463084da2f6d9ac905d40.tar.gz
auto-merge
Diffstat (limited to 'sql/sql_parse.cc')
-rw-r--r--sql/sql_parse.cc21
1 files changed, 19 insertions, 2 deletions
diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc
index b5864fef19d..55509a31f77 100644
--- a/sql/sql_parse.cc
+++ b/sql/sql_parse.cc
@@ -1912,13 +1912,30 @@ bool alloc_query(THD *thd, const char *packet, uint packet_length)
pos--;
packet_length--;
}
- /* We must allocate some extra memory for query cache */
+ /* We must allocate some extra memory for query cache
+
+ The query buffer layout is:
+ buffer :==
+ <statement> The input statement(s)
+ '\0' Terminating null char (1 byte)
+ <length> Length of following current database name (size_t)
+ <db_name> Name of current database
+ <flags> Flags struct
+ */
if (! (query= (char*) thd->memdup_w_gap(packet,
packet_length,
- 1 + thd->db_length +
+ 1 + sizeof(size_t) + thd->db_length +
QUERY_CACHE_FLAGS_SIZE)))
return TRUE;
query[packet_length]= '\0';
+ /*
+ Space to hold the name of the current database is allocated. We
+ also store this length, in case current database is changed during
+ execution. We might need to reallocate the 'query' buffer
+ */
+ size_t *len = (size_t *) (query + packet_length + 1);
+ *len= thd->db_length;
+
thd->set_query(query, packet_length);
/* Reclaim some memory */