MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fake_table.h
1 /* Copyright (c) 2012, 2013, 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 #ifndef FAKE_TABLE_H
17 #define FAKE_TABLE_H
18 
19 #include "sql_class.h"
20 
21 /*
22  A fake class to make setting up a TABLE object a little easier.
23 */
25 {
26 public:
27  Fake_TABLE_SHARE(uint number_of_columns)
28  {
29  static const char *fakepath= "fakepath";
30  fields= number_of_columns;
31  // fix if you plan to test with >32 columns.
32  column_bitmap_size= sizeof(int);
33  tmp_table= NO_TMP_TABLE;
34  db_low_byte_first= true;
35  path.str= const_cast<char*>(fakepath);
36  path.length= strlen(path.str);
37  }
38  ~Fake_TABLE_SHARE() {}
39 };
40 
41 /*
42  A fake class to make setting up a TABLE object a little easier. The
43  table has a local fake table share.
44 */
45 class Fake_TABLE: public TABLE
46 {
47  Fake_TABLE_SHARE table_share;
48  MY_BITMAP write_set_struct;
49  uint32 write_set_buf;
50  Field *field_array[32];
51 
52  void inititalize()
53  {
54  s= &table_share;
55  file= NULL;
56  in_use= current_thd;
57  null_row= '\0';
58  write_set= &write_set_struct;
59  read_set= NULL;
60  next_number_field= NULL; // No autoinc column
61 
62  EXPECT_EQ(0, bitmap_init(write_set, &write_set_buf, s->fields, false));
63 
64  static const char *table_name= "Fake";
65  for (uint i= 0; i < s->fields; ++i)
66  {
67  field[i]->table_name= &table_name;
68  field[i]->table= this;
69  field[i]->field_index= i;
70  }
71  const_table= true;
72  maybe_null= 0;
73  }
74 
75 public:
76  Fake_TABLE(Field *column1) : table_share(1)
77  {
78  field= field_array;
79  field[0]= column1;
80  inititalize();
81  }
82 
83  Fake_TABLE(Field *column1, Field *column2) : table_share(2)
84  {
85  field= field_array;
86  field[0]= column1;
87  field[1]= column2;
88  inititalize();
89  }
90 
91  Fake_TABLE(Field *column1, Field *column2, Field *column3)
92  : table_share(3)
93  {
94  field= field_array;
95  field[0]= column1;
96  field[1]= column2;
97  field[2]= column3;
98  inititalize();
99  }
100 
101  ~Fake_TABLE()
102  {
103  /*
104  This DTOR should be empty, since we inherit from TABLE,
105  which cannot have virtual member functions.
106  */
107  }
108 
109  void set_handler(handler *h) { file= h; }
110  TABLE_SHARE *get_share() { return &table_share; }
111 };
112 
113 #endif // FAKE_TABLE_H