MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
emb_qcache.h
1 /* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #include "sql_cache.h" /* Query_cache_block */
17 
19 {
20  uchar *cur_data;
21  uchar *data_end;
22  Query_cache_block *block;
23  uint headers_len;
24 public:
25 #ifndef DBUG_OFF
26  Query_cache_block *first_block;
27  uint stored_size;
28 #endif
29  Querycache_stream(Query_cache_block *ini_block, uint ini_headers_len) :
30  block(ini_block), headers_len(ini_headers_len)
31  {
32  cur_data= ((uchar*)block)+headers_len;
33  data_end= cur_data + (block->used-headers_len);
34 #ifndef DBUG_OFF
35  first_block= ini_block;
36  stored_size= 0;
37 #endif
38  }
39  void use_next_block(bool writing)
40  {
41  /*
42  This shouldn't be called if there is only one block, or to loop
43  around to the first block again. That means we're trying to write
44  more data than we allocated space for.
45  */
46  DBUG_ASSERT(block->next != block);
47  DBUG_ASSERT(block->next != first_block);
48 
49  block= block->next;
50  /*
51  While writing, update the type of each block as we write to it.
52  While reading, make sure that the block is of the expected type.
53  */
54  if (writing)
55  block->type= Query_cache_block::RES_CONT;
56  else
57  DBUG_ASSERT(block->type == Query_cache_block::RES_CONT);
58 
59  cur_data= ((uchar*)block)+headers_len;
60  data_end= cur_data + (block->used-headers_len);
61  }
62 
63  void store_uchar(uchar c);
64  void store_short(ushort s);
65  void store_int(uint i);
66  void store_ll(ulonglong ll);
67  void store_str_only(const char *str, uint str_len);
68  void store_str(const char *str, uint str_len);
69  void store_safe_str(const char *str, uint str_len);
70 
71  uchar load_uchar();
72  ushort load_short();
73  uint load_int();
74  ulonglong load_ll();
75  void load_str_only(char *buffer, uint str_len);
76  char *load_str(MEM_ROOT *alloc, uint *str_len);
77  int load_safe_str(MEM_ROOT *alloc, char **str, uint *str_len);
78  int load_column(MEM_ROOT *alloc, char **column);
79 };
80 
81 uint emb_count_querycache_size(THD *thd);
82 int emb_load_querycache_result(THD *thd, Querycache_stream *src);
83 void emb_store_querycache_result(Querycache_stream *dst, THD* thd);
84 bool net_send_eof(THD *thd, uint server_status, uint total_warn_count);