~drizzle-trunk/drizzle/development

1999.4.1 by Brian Aker
First pass through, removing the need for us track the position in this
1
/* -*- mode: c++; c-basic-offset: 2; i/dent-tabs-mode: nil; -*-
1093.6.1 by Brian Aker
Refactor TableShare has to be behind class.
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
4
 *  Copyright (C) 2010 Brian Aker
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
5
 *  Copyright (C) 2009 Sun Microsystems, Inc.
1093.6.1 by Brian Aker
Refactor TableShare has to be behind class.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  (at your option) any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 */
21
22
/*
23
  This class is shared between different table objects. There is one
24
  instance of table share per one table in the database.
25
*/
26
27
/* Basic functions needed by many modules */
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
28
#include <config.h>
1223.3.1 by Monty Taylor
Replace HASH in table_share with drizzled::hash_map
29
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
30
#include <pthread.h>
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
31
#include <float.h>
32
33
#include <sys/types.h>
34
#include <sys/stat.h>
35
#include <fcntl.h>
36
1241.9.57 by Monty Taylor
Oy. Bigger change than I normally like - but this stuff is all intertwined.
37
38
#include <cassert>
1093.6.1 by Brian Aker
Refactor TableShare has to be behind class.
39
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
40
#include <drizzled/error.h>
41
#include <drizzled/gettext.h>
42
#include <drizzled/sql_base.h>
43
#include <drizzled/pthread_globals.h>
44
#include <drizzled/internal/my_pthread.h>
45
46
#include <drizzled/table.h>
47
#include <drizzled/table/shell.h>
48
49
#include <drizzled/session.h>
50
51
#include <drizzled/charset.h>
52
#include <drizzled/internal/m_string.h>
53
#include <drizzled/internal/my_sys.h>
54
55
#include <drizzled/item/string.h>
56
#include <drizzled/item/int.h>
57
#include <drizzled/item/decimal.h>
58
#include <drizzled/item/float.h>
59
#include <drizzled/item/null.h>
60
#include <drizzled/temporal.h>
61
62
#include <drizzled/field.h>
63
#include <drizzled/field/str.h>
64
#include <drizzled/field/num.h>
65
#include <drizzled/field/blob.h>
66
#include <drizzled/field/boolean.h>
67
#include <drizzled/field/enum.h>
68
#include <drizzled/field/null.h>
69
#include <drizzled/field/date.h>
70
#include <drizzled/field/decimal.h>
71
#include <drizzled/field/real.h>
72
#include <drizzled/field/double.h>
73
#include <drizzled/field/int32.h>
74
#include <drizzled/field/int64.h>
75
#include <drizzled/field/size.h>
76
#include <drizzled/field/num.h>
77
#include <drizzled/field/time.h>
78
#include <drizzled/field/epoch.h>
79
#include <drizzled/field/datetime.h>
80
#include <drizzled/field/microtime.h>
81
#include <drizzled/field/varstring.h>
82
#include <drizzled/field/uuid.h>
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
83
#include <drizzled/field/ipv6.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
84
#include <drizzled/plugin/storage_engine.h>
85
#include <drizzled/definition/cache.h>
86
#include <drizzled/typelib.h>
2198.1.1 by Olaf van der Spek
Remove unnecessary alter* includes
87
#include <drizzled/key.h>
2263.3.11 by Olaf van der Spek
Open Tables
88
#include <drizzled/open_tables_state.h>
2148.7.11 by Brian Aker
Remove some of the dependencies from session.h so that we make the include
89
1093.6.1 by Brian Aker
Refactor TableShare has to be behind class.
90
using namespace std;
91
2263.3.4 by Olaf van der Spek
Prefix global refresh_version
92
namespace drizzled {
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
93
1241.9.33 by Monty Taylor
Moved most of the global vars to set_var where they belong.
94
extern size_t table_def_size;
1093.6.1 by Brian Aker
Refactor TableShare has to be behind class.
95
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
96
static enum_field_types proto_field_type_to_drizzle_type(const message::Table::Field &field)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
97
{
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
98
  switch(field.type())
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
99
  {
100
  case message::Table::Field::INTEGER:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
101
    return DRIZZLE_TYPE_LONG;
102
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
103
  case message::Table::Field::DOUBLE:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
104
    return DRIZZLE_TYPE_DOUBLE;
105
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
106
  case message::Table::Field::EPOCH:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
107
    if (field.has_time_options() and field.time_options().microseconds())
108
      return DRIZZLE_TYPE_MICROTIME;
109
110
    return DRIZZLE_TYPE_TIMESTAMP;
111
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
112
  case message::Table::Field::BIGINT:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
113
    return DRIZZLE_TYPE_LONGLONG;
114
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
115
  case message::Table::Field::DATETIME:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
116
    return DRIZZLE_TYPE_DATETIME;
117
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
118
  case message::Table::Field::DATE:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
119
    return DRIZZLE_TYPE_DATE;
120
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
121
  case message::Table::Field::VARCHAR:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
122
    return DRIZZLE_TYPE_VARCHAR;
123
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
124
  case message::Table::Field::DECIMAL:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
125
    return DRIZZLE_TYPE_DECIMAL;
126
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
127
  case message::Table::Field::ENUM:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
128
    return DRIZZLE_TYPE_ENUM;
129
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
130
  case message::Table::Field::BLOB:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
131
    return DRIZZLE_TYPE_BLOB;
132
1996.2.1 by Brian Aker
uuid type code.
133
  case message::Table::Field::UUID:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
134
    return  DRIZZLE_TYPE_UUID;
135
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
136
  case message::Table::Field::IPV6:
137
    return  DRIZZLE_TYPE_IPV6;
138
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
139
  case message::Table::Field::BOOLEAN:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
140
    return DRIZZLE_TYPE_BOOLEAN;
141
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
142
  case message::Table::Field::TIME:
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
143
    return DRIZZLE_TYPE_TIME;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
144
  }
145
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
146
  abort();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
147
}
148
2440.2.20 by Olaf van der Spek
Use str_ref
149
static Item* default_value_item(enum_field_types field_type, const charset_info_st& charset, bool default_null, 
150
  const string& default_value, const string& default_bin_value)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
151
{
152
  if (default_null)
153
    return new Item_null();
154
2440.2.15 by Olaf van der Spek
Refactor
155
  switch (field_type)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
156
  {
157
  case DRIZZLE_TYPE_LONG:
158
  case DRIZZLE_TYPE_LONGLONG:
2221.12.12 by Stewart Smith
check for error in converting default_value to Item in default_value_item(). This means that INT DEFAULT 'aoeu' will properly error out.
159
    {
2440.2.15 by Olaf van der Spek
Refactor
160
      int error= 0;
2440.2.20 by Olaf van der Spek
Use str_ref
161
      Item* default_item= new Item_int(default_value.c_str(), (int64_t) internal::my_strtoll10(default_value.c_str(), NULL, &error), default_value.length());
2440.2.15 by Olaf van der Spek
Refactor
162
163
      if (error && error != -1) /* was an error and wasn't a negative number */
164
      {
165
        delete default_item;
166
        return NULL;
167
      }
168
      return default_item;
2221.12.12 by Stewart Smith
check for error in converting default_value to Item in default_value_item(). This means that INT DEFAULT 'aoeu' will properly error out.
169
    }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
170
  case DRIZZLE_TYPE_DOUBLE:
2440.2.20 by Olaf van der Spek
Use str_ref
171
    return new Item_float(default_value.c_str(), default_value.length());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
172
  case DRIZZLE_TYPE_NULL:
2440.2.15 by Olaf van der Spek
Refactor
173
    assert(false);
1976.3.1 by Brian Aker
Fixed a couple of assert() and added abort where program logic would corrupt
174
    abort();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
175
  case DRIZZLE_TYPE_TIMESTAMP:
176
  case DRIZZLE_TYPE_DATETIME:
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
177
  case DRIZZLE_TYPE_TIME:
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
178
  case DRIZZLE_TYPE_DATE:
179
  case DRIZZLE_TYPE_ENUM:
1996.2.1 by Brian Aker
uuid type code.
180
  case DRIZZLE_TYPE_UUID:
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
181
  case DRIZZLE_TYPE_IPV6:
2046.2.1 by Brian Aker
First pass on micro timestamp.
182
  case DRIZZLE_TYPE_MICROTIME:
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
183
  case DRIZZLE_TYPE_BOOLEAN:
2440.2.20 by Olaf van der Spek
Use str_ref
184
    // return new Item_string(*default_value, system_charset_info); // crash
185
    return new Item_string(default_value.data(), default_value.size(), system_charset_info);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
186
  case DRIZZLE_TYPE_VARCHAR:
187
  case DRIZZLE_TYPE_BLOB: /* Blob is here due to TINYTEXT. Feel the hate. */
2440.2.20 by Olaf van der Spek
Use str_ref
188
    return &charset== &my_charset_bin
189
      ? new Item_string(default_bin_value, &my_charset_bin)
190
      : new Item_string(default_value, system_charset_info);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
191
  case DRIZZLE_TYPE_DECIMAL:
2440.2.20 by Olaf van der Spek
Use str_ref
192
    return new Item_decimal(default_value.c_str(), default_value.length(), system_charset_info);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
193
  }
2440.2.15 by Olaf van der Spek
Refactor
194
  return NULL;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
195
}
196
197
198
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
199
/**
200
 * @todo
201
 *
202
 * Precache this stuff....
203
 */
204
bool TableShare::fieldInPrimaryKey(Field *in_field) const
205
{
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
206
  assert(getTableMessage());
1530.1.3 by Brian Aker
Style cleanup for table_share
207
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
208
  size_t num_indexes= getTableMessage()->indexes_size();
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
209
210
  for (size_t x= 0; x < num_indexes; ++x)
211
  {
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
212
    const message::Table::Index &index= getTableMessage()->indexes(x);
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
213
    if (index.is_primary())
214
    {
215
      size_t num_parts= index.index_part_size();
216
      for (size_t y= 0; y < num_parts; ++y)
217
      {
1999.4.1 by Brian Aker
First pass through, removing the need for us track the position in this
218
        if (index.index_part(y).fieldnr() == in_field->position())
1308.2.2 by Jay Pipes
Fixes transaction log/replication for multi-column primary keys. Changes CREATE SCHEMA to not use statement-base RAW_SQL and instead use a derived message::Statement subclass.
219
          return true;
220
      }
221
    }
222
  }
223
  return false;
224
}
225
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
226
TableShare::TableShare(const identifier::Table::Type type_arg) :
1608.2.2 by Brian Aker
Move constructors to .cc file.
227
  table_category(TABLE_UNKNOWN_CATEGORY),
228
  found_next_number_field(NULL),
229
  timestamp_field(NULL),
230
  key_info(NULL),
1672.3.3 by Brian Aker
Fix init of mem_root in Share.
231
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
1802.16.9 by Padraig O'Sullivan
Resolved bitset handling during temporary table creation. All tests pass again.
232
  all_set(),
1608.2.2 by Brian Aker
Move constructors to .cc file.
233
  block_size(0),
234
  version(0),
235
  timestamp_offset(0),
236
  reclength(0),
237
  stored_rec_length(0),
238
  max_rows(0),
2134.1.5 by Brian Aker
Flip name on variable (main to check for poor usage of it).
239
  _table_message(NULL),
1608.2.2 by Brian Aker
Move constructors to .cc file.
240
  storage_engine(NULL),
1608.2.4 by Brian Aker
Update for having share declared type.
241
  tmp_table(type_arg),
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
242
  _ref_count(0),
1608.2.2 by Brian Aker
Move constructors to .cc file.
243
  null_bytes(0),
244
  last_null_bit_pos(0),
2040.4.1 by Brian Aker
Update to time and field.
245
  _field_size(0),
1608.2.2 by Brian Aker
Move constructors to .cc file.
246
  rec_buff_length(0),
247
  keys(0),
248
  key_parts(0),
249
  max_key_length(0),
250
  max_unique_length(0),
251
  total_key_length(0),
252
  uniques(0),
253
  null_fields(0),
254
  blob_fields(0),
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
255
  has_variable_width(false),
1608.2.2 by Brian Aker
Move constructors to .cc file.
256
  db_create_options(0),
257
  db_options_in_use(0),
258
  db_record_offset(0),
259
  rowid_field_offset(0),
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
260
  primary_key(MAX_KEY),
1608.2.2 by Brian Aker
Move constructors to .cc file.
261
  next_number_index(0),
262
  next_number_key_offset(0),
263
  next_number_keypart(0),
264
  error(0),
265
  open_errno(0),
266
  errarg(0),
2134.1.4 by Brian Aker
Simple encapsulation for table.
267
  blob_ptr_size(portable_sizeof_char_ptr),
1608.2.2 by Brian Aker
Move constructors to .cc file.
268
  db_low_byte_first(false),
269
  keys_in_use(0),
2134.1.10 by Brian Aker
Move out event so that we don't incur it when using temp/internal tables.
270
  keys_for_keyread(0)
1608.2.2 by Brian Aker
Move constructors to .cc file.
271
{
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
272
  if (type_arg == message::Table::INTERNAL)
273
  {
2318.9.5 by Olaf van der Spek
Refactor build_table_filename
274
    string s= identifier::Table::build_tmptable_filename();
275
    private_key_for_cache.vectorPtr().assign(s.c_str(), s.c_str() + s.size() + 1);
1878.5.3 by Brian Aker
Update Key to work a bit faster.
276
    init(private_key_for_cache.vector(), private_key_for_cache.vector());
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
277
  }
278
  else
279
  {
280
    init("", "");
281
  }
1608.2.2 by Brian Aker
Move constructors to .cc file.
282
}
283
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
284
TableShare::TableShare(const identifier::Table &identifier, const identifier::Table::Key &key) :// Used by placeholder
1608.2.2 by Brian Aker
Move constructors to .cc file.
285
  table_category(TABLE_UNKNOWN_CATEGORY),
286
  found_next_number_field(NULL),
287
  timestamp_field(NULL),
288
  key_info(NULL),
1672.3.3 by Brian Aker
Fix init of mem_root in Share.
289
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
2134.1.3 by Brian Aker
Fix init/warnings for Table
290
  table_charset(0),
1802.16.9 by Padraig O'Sullivan
Resolved bitset handling during temporary table creation. All tests pass again.
291
  all_set(),
1608.2.2 by Brian Aker
Move constructors to .cc file.
292
  block_size(0),
293
  version(0),
294
  timestamp_offset(0),
295
  reclength(0),
296
  stored_rec_length(0),
297
  max_rows(0),
2134.1.5 by Brian Aker
Flip name on variable (main to check for poor usage of it).
298
  _table_message(NULL),
1608.2.2 by Brian Aker
Move constructors to .cc file.
299
  storage_engine(NULL),
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
300
  tmp_table(message::Table::INTERNAL),
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
301
  _ref_count(0),
1608.2.2 by Brian Aker
Move constructors to .cc file.
302
  null_bytes(0),
303
  last_null_bit_pos(0),
2040.4.1 by Brian Aker
Update to time and field.
304
  _field_size(0),
1608.2.2 by Brian Aker
Move constructors to .cc file.
305
  rec_buff_length(0),
306
  keys(0),
307
  key_parts(0),
308
  max_key_length(0),
309
  max_unique_length(0),
310
  total_key_length(0),
311
  uniques(0),
312
  null_fields(0),
313
  blob_fields(0),
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
314
  has_variable_width(false),
1608.2.2 by Brian Aker
Move constructors to .cc file.
315
  db_create_options(0),
316
  db_options_in_use(0),
317
  db_record_offset(0),
318
  rowid_field_offset(0),
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
319
  primary_key(MAX_KEY),
1608.2.2 by Brian Aker
Move constructors to .cc file.
320
  next_number_index(0),
321
  next_number_key_offset(0),
322
  next_number_keypart(0),
323
  error(0),
324
  open_errno(0),
325
  errarg(0),
2134.1.4 by Brian Aker
Simple encapsulation for table.
326
  blob_ptr_size(portable_sizeof_char_ptr),
1608.2.2 by Brian Aker
Move constructors to .cc file.
327
  db_low_byte_first(false),
328
  keys_in_use(0),
2134.1.10 by Brian Aker
Move out event so that we don't incur it when using temp/internal tables.
329
  keys_for_keyread(0)
1608.2.2 by Brian Aker
Move constructors to .cc file.
330
{
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
331
  assert(identifier.getKey() == key);
332
333
  private_key_for_cache= key;
334
335
  table_category=         TABLE_CATEGORY_TEMPORARY;
336
  tmp_table=              message::Table::INTERNAL;
337
2385.3.24 by Olaf van der Spek
Refactor
338
  db= str_ref(private_key_for_cache.vector());
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
339
2385.3.23 by Olaf van der Spek
Refactor
340
  table_name= str_ref(private_key_for_cache.vector() + strlen(private_key_for_cache.vector()) + 1);
2385.3.24 by Olaf van der Spek
Refactor
341
  path= str_ref("");
342
  normalized_path= str_ref("");
1937.4.1 by Andrew Hutchings
Make mixed case table names work again
343
344
  std::string tb_name(identifier.getTableName());
2318.7.21 by Olaf van der Spek
Use boost::to_lower
345
  boost::to_lower(tb_name);
2385.3.23 by Olaf van der Spek
Refactor
346
  assert(strcmp(tb_name.c_str(), table_name.data()) == 0);
2385.3.24 by Olaf van der Spek
Refactor
347
  assert(strcmp(identifier.getSchemaName().c_str(), db.data()) == 0);
1608.2.4 by Brian Aker
Update for having share declared type.
348
}
349
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
350
TableShare::TableShare(const identifier::Table &identifier) : // Just used during createTable()
1608.2.4 by Brian Aker
Update for having share declared type.
351
  table_category(TABLE_UNKNOWN_CATEGORY),
352
  found_next_number_field(NULL),
353
  timestamp_field(NULL),
354
  key_info(NULL),
1672.3.3 by Brian Aker
Fix init of mem_root in Share.
355
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
2134.1.3 by Brian Aker
Fix init/warnings for Table
356
  table_charset(0),
1802.16.9 by Padraig O'Sullivan
Resolved bitset handling during temporary table creation. All tests pass again.
357
  all_set(),
1608.2.4 by Brian Aker
Update for having share declared type.
358
  block_size(0),
359
  version(0),
360
  timestamp_offset(0),
361
  reclength(0),
362
  stored_rec_length(0),
363
  max_rows(0),
2134.1.5 by Brian Aker
Flip name on variable (main to check for poor usage of it).
364
  _table_message(NULL),
1608.2.4 by Brian Aker
Update for having share declared type.
365
  storage_engine(NULL),
366
  tmp_table(identifier.getType()),
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
367
  _ref_count(0),
1608.2.4 by Brian Aker
Update for having share declared type.
368
  null_bytes(0),
369
  last_null_bit_pos(0),
2040.4.1 by Brian Aker
Update to time and field.
370
  _field_size(0),
1608.2.4 by Brian Aker
Update for having share declared type.
371
  rec_buff_length(0),
372
  keys(0),
373
  key_parts(0),
374
  max_key_length(0),
375
  max_unique_length(0),
376
  total_key_length(0),
377
  uniques(0),
378
  null_fields(0),
379
  blob_fields(0),
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
380
  has_variable_width(false),
1608.2.4 by Brian Aker
Update for having share declared type.
381
  db_create_options(0),
382
  db_options_in_use(0),
383
  db_record_offset(0),
384
  rowid_field_offset(0),
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
385
  primary_key(MAX_KEY),
1608.2.4 by Brian Aker
Update for having share declared type.
386
  next_number_index(0),
387
  next_number_key_offset(0),
388
  next_number_keypart(0),
389
  error(0),
390
  open_errno(0),
391
  errarg(0),
2134.1.4 by Brian Aker
Simple encapsulation for table.
392
  blob_ptr_size(portable_sizeof_char_ptr),
1608.2.4 by Brian Aker
Update for having share declared type.
393
  db_low_byte_first(false),
394
  keys_in_use(0),
2134.1.10 by Brian Aker
Move out event so that we don't incur it when using temp/internal tables.
395
  keys_for_keyread(0)
1608.2.4 by Brian Aker
Update for having share declared type.
396
{
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
397
  private_key_for_cache= identifier.getKey();
398
  assert(identifier.getPath().size()); // Since we are doing a create table, this should be a positive value
399
  private_normalized_path.resize(identifier.getPath().size() + 1);
400
  memcpy(&private_normalized_path[0], identifier.getPath().c_str(), identifier.getPath().size());
401
1608.2.4 by Brian Aker
Update for having share declared type.
402
  {
2385.3.24 by Olaf van der Spek
Refactor
403
    table_category= TABLE_CATEGORY_TEMPORARY;
404
    tmp_table= message::Table::INTERNAL;
405
    db= str_ref(private_key_for_cache.vector());
406
    table_name= str_ref(db.data() + 1);
2385.3.30 by Olaf van der Spek
cppcheck
407
    path= private_normalized_path;
2385.3.24 by Olaf van der Spek
Refactor
408
    normalized_path= path;
1608.2.4 by Brian Aker
Update for having share declared type.
409
  }
410
}
411
412
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
413
/*
414
  Used for shares that will go into the cache.
415
*/
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
416
TableShare::TableShare(const identifier::Table::Type type_arg,
417
                       const identifier::Table &identifier,
2318.9.2 by Olaf van der Spek
Add const
418
                       const char *path_arg,
1608.2.2 by Brian Aker
Move constructors to .cc file.
419
                       uint32_t path_length_arg) :
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
420
  table_category(TABLE_UNKNOWN_CATEGORY),
421
  found_next_number_field(NULL),
422
  timestamp_field(NULL),
423
  key_info(NULL),
1672.3.3 by Brian Aker
Fix init of mem_root in Share.
424
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
2134.1.3 by Brian Aker
Fix init/warnings for Table
425
  table_charset(0),
1802.16.9 by Padraig O'Sullivan
Resolved bitset handling during temporary table creation. All tests pass again.
426
  all_set(),
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
427
  block_size(0),
428
  version(0),
429
  timestamp_offset(0),
430
  reclength(0),
431
  stored_rec_length(0),
432
  max_rows(0),
2134.1.5 by Brian Aker
Flip name on variable (main to check for poor usage of it).
433
  _table_message(NULL),
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
434
  storage_engine(NULL),
1608.2.4 by Brian Aker
Update for having share declared type.
435
  tmp_table(type_arg),
2069.4.4 by Brian Aker
Create a shared form of the instance which is a bit more heavier weight then
436
  _ref_count(0),
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
437
  null_bytes(0),
438
  last_null_bit_pos(0),
2040.4.1 by Brian Aker
Update to time and field.
439
  _field_size(0),
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
440
  rec_buff_length(0),
441
  keys(0),
442
  key_parts(0),
443
  max_key_length(0),
444
  max_unique_length(0),
445
  total_key_length(0),
446
  uniques(0),
447
  null_fields(0),
448
  blob_fields(0),
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
449
  has_variable_width(false),
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
450
  db_create_options(0),
451
  db_options_in_use(0),
452
  db_record_offset(0),
453
  rowid_field_offset(0),
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
454
  primary_key(MAX_KEY),
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
455
  next_number_index(0),
456
  next_number_key_offset(0),
457
  next_number_keypart(0),
458
  error(0),
459
  open_errno(0),
460
  errarg(0),
2134.1.4 by Brian Aker
Simple encapsulation for table.
461
  blob_ptr_size(portable_sizeof_char_ptr),
1502.1.22 by Brian Aker
Additional remove of memset on TableShare().
462
  db_low_byte_first(false),
463
  keys_in_use(0),
2134.1.10 by Brian Aker
Move out event so that we don't incur it when using temp/internal tables.
464
  keys_for_keyread(0)
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
465
{
2318.9.4 by Olaf van der Spek
Refactor tablename_to_filename
466
467
  private_key_for_cache= identifier.getKey();
468
  /*
469
    Let us use the fact that the key is "db/0/table_name/0" + optional
470
    part for temporary tables.
471
  */
2385.3.24 by Olaf van der Spek
Refactor
472
  db= str_ref(private_key_for_cache.vector());
473
  table_name= str_ref(db.data() + db.size() + 1);
2318.9.4 by Olaf van der Spek
Refactor tablename_to_filename
474
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
475
  std::string _path;
1502.1.12 by Brian Aker
Second pass through TableShare to new(). Partial hack in using bool for the
476
  if (path_arg)
477
  {
2318.9.4 by Olaf van der Spek
Refactor tablename_to_filename
478
    _path.assign(path_arg, path_length_arg);
1502.1.12 by Brian Aker
Second pass through TableShare to new(). Partial hack in using bool for the
479
  }
480
  else
481
  {
2385.3.24 by Olaf van der Spek
Refactor
482
    _path= identifier::Table::build_table_filename(db.data(), table_name.data(), false);
1502.1.12 by Brian Aker
Second pass through TableShare to new(). Partial hack in using bool for the
483
  }
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
484
2318.9.10 by Olaf van der Spek
Rename strmake to strdup (standard name)
485
  char* path_buff= mem_root.strdup(_path);
2385.3.25 by Olaf van der Spek
Refactor
486
  path= str_ref(path_buff, _path.length());
487
  normalized_path= str_ref(path_buff, _path.length());
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
488
2318.6.40 by Olaf van der Spek
Refactor
489
  version= g_refresh_version;
1502.1.11 by Brian Aker
This fixes TableShare such that for the cache we now correctly call new()
490
}
491
2385.3.24 by Olaf van der Spek
Refactor
492
void TableShare::init(const char *new_table_name, const char *new_path)
1608.2.2 by Brian Aker
Move constructors to .cc file.
493
{
2385.3.24 by Olaf van der Spek
Refactor
494
  table_category= TABLE_CATEGORY_TEMPORARY;
495
  tmp_table= message::Table::INTERNAL;
496
  db= str_ref("");
2385.3.23 by Olaf van der Spek
Refactor
497
  table_name= str_ref(new_table_name);
2385.3.24 by Olaf van der Spek
Refactor
498
  path= str_ref(new_path);
499
  normalized_path= str_ref(new_path);
1608.2.2 by Brian Aker
Move constructors to .cc file.
500
}
501
1619.1.1 by Brian Aker
Update for TableShare usage of key (remove a case where we had to build it).
502
TableShare::~TableShare() 
503
{
504
  storage_engine= NULL;
505
506
  mem_root.free_root(MYF(0));                 // Free's share
507
}
508
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
509
void TableShare::setIdentifier(const identifier::Table &identifier_arg)
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
510
{
511
  private_key_for_cache= identifier_arg.getKey();
512
513
  /*
514
    Let us use the fact that the key is "db/0/table_name/0" + optional
515
    part for temporary tables.
516
  */
2385.3.24 by Olaf van der Spek
Refactor
517
  db= str_ref(private_key_for_cache.vector());
518
  table_name= str_ref(db.data() + db.size() + 1);
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
519
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
520
  getTableMessage()->set_name(identifier_arg.getTableName());
521
  getTableMessage()->set_schema(identifier_arg.getSchemaName());
1618 by Brian Aker
This is a rollup set of patches for modifications to TableIdentifier to have
522
}
523
2224.4.1 by Brian Aker
parse_table_proto <-- const
524
bool TableShare::parse_table_proto(Session& session, const message::Table &table)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
525
{
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
526
  drizzled::error_t local_error= EE_OK;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
527
528
  if (! table.IsInitialized())
529
  {
2017.2.1 by Brian Aker
Cleanup error messages around bad table definitions.
530
    my_error(ER_CORRUPT_TABLE_DEFINITION, MYF(0),
531
             table.name().empty() ? " " :  table.name().c_str(),
532
             table.InitializationErrorString().c_str());
533
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
534
    return ER_CORRUPT_TABLE_DEFINITION;
535
  }
536
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
537
  setTableMessage(table);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
538
1574.1.2 by Brian Aker
Remove =this reference.
539
  storage_engine= plugin::StorageEngine::findByName(session, table.engine().name());
540
  assert(storage_engine); // We use an assert() here because we should never get this far and still have no suitable engine.
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
541
542
  message::Table::TableOptions table_options;
543
544
  if (table.has_options())
545
    table_options= table.options();
546
547
  uint32_t local_db_create_options= 0;
548
549
  if (table_options.pack_record())
550
    local_db_create_options|= HA_OPTION_PACK_RECORD;
551
552
  /* local_db_create_options was stored as 2 bytes in FRM
1530.1.3 by Brian Aker
Style cleanup for table_share
553
    Any HA_OPTION_ that doesn't fit into 2 bytes was silently truncated away.
554
  */
1574.1.2 by Brian Aker
Remove =this reference.
555
  db_create_options= (local_db_create_options & 0x0000FFFF);
556
  db_options_in_use= db_create_options;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
557
2318.9.5 by Olaf van der Spek
Refactor build_table_filename
558
  block_size= table_options.has_block_size() ? table_options.block_size() : 0;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
559
1638.1.5 by Stewart Smith
explicit collation in table proto (from review)
560
  table_charset= get_charset(table_options.collation_id());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
561
2134.1.3 by Brian Aker
Fix init/warnings for Table
562
  if (not table_charset)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
563
  {
2017.2.1 by Brian Aker
Cleanup error messages around bad table definitions.
564
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN_COLLATION, MYF(0),
565
             table_options.collation().c_str(),
566
             table.name().c_str());
1638.1.2 by Stewart Smith
fix error message for parsing invalid table collation to fit other forms of corruption by returning to the user session an appropriate error message.
567
2017.2.1 by Brian Aker
Cleanup error messages around bad table definitions.
568
    return ER_CORRUPT_TABLE_DEFINITION; // Historical
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
569
  }
570
1574.1.2 by Brian Aker
Remove =this reference.
571
  db_record_offset= 1;
572
573
  keys= table.indexes_size();
574
575
  key_parts= 0;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
576
  for (int indx= 0; indx < table.indexes_size(); indx++)
1574.1.2 by Brian Aker
Remove =this reference.
577
    key_parts+= table.indexes(indx).index_part_size();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
578
2385.3.25 by Olaf van der Spek
Refactor
579
  key_info= (KeyInfo*) mem().alloc(table.indexes_size() * sizeof(KeyInfo) +key_parts*sizeof(KeyPartInfo));
1534 by Brian Aker
Remove of KeyPartInfo
580
581
  KeyPartInfo *key_part;
582
583
  key_part= reinterpret_cast<KeyPartInfo*>
1574.1.2 by Brian Aker
Remove =this reference.
584
    (key_info+table.indexes_size());
585
586
2385.3.25 by Olaf van der Spek
Refactor
587
  ulong *rec_per_key= (ulong*) mem().alloc(sizeof(ulong*)*key_parts);
1574.1.2 by Brian Aker
Remove =this reference.
588
589
  KeyInfo* keyinfo= key_info;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
590
  for (int keynr= 0; keynr < table.indexes_size(); keynr++, keyinfo++)
591
  {
592
    message::Table::Index indx= table.indexes(keynr);
593
594
    keyinfo->table= 0;
595
    keyinfo->flags= 0;
596
597
    if (indx.is_unique())
598
      keyinfo->flags|= HA_NOSAME;
599
600
    if (indx.has_options())
601
    {
1537 by Brian Aker
Remove dead options/rename Option and remove the update that we no longer
602
      message::Table::Index::Options indx_options= indx.options();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
603
      if (indx_options.pack_key())
604
        keyinfo->flags|= HA_PACK_KEY;
605
606
      if (indx_options.var_length_key())
607
        keyinfo->flags|= HA_VAR_LENGTH_PART;
608
609
      if (indx_options.null_part_key())
610
        keyinfo->flags|= HA_NULL_PART_KEY;
611
612
      if (indx_options.binary_pack_key())
613
        keyinfo->flags|= HA_BINARY_PACK_KEY;
614
615
      if (indx_options.has_partial_segments())
616
        keyinfo->flags|= HA_KEY_HAS_PART_KEY_SEG;
617
618
      if (indx_options.auto_generated_key())
619
        keyinfo->flags|= HA_GENERATED_KEY;
620
621
      if (indx_options.has_key_block_size())
622
      {
623
        keyinfo->flags|= HA_USES_BLOCK_SIZE;
624
        keyinfo->block_size= indx_options.key_block_size();
625
      }
626
      else
627
      {
628
        keyinfo->block_size= 0;
629
      }
630
    }
631
632
    switch (indx.type())
633
    {
634
    case message::Table::Index::UNKNOWN_INDEX:
635
      keyinfo->algorithm= HA_KEY_ALG_UNDEF;
636
      break;
637
    case message::Table::Index::BTREE:
638
      keyinfo->algorithm= HA_KEY_ALG_BTREE;
639
      break;
640
    case message::Table::Index::HASH:
641
      keyinfo->algorithm= HA_KEY_ALG_HASH;
642
      break;
643
644
    default:
645
      /* TODO: suitable warning ? */
646
      keyinfo->algorithm= HA_KEY_ALG_UNDEF;
647
      break;
648
    }
649
650
    keyinfo->key_length= indx.key_length();
651
652
    keyinfo->key_parts= indx.index_part_size();
653
654
    keyinfo->key_part= key_part;
655
    keyinfo->rec_per_key= rec_per_key;
656
657
    for (unsigned int partnr= 0;
658
         partnr < keyinfo->key_parts;
659
         partnr++, key_part++)
660
    {
661
      message::Table::Index::IndexPart part;
662
      part= indx.index_part(partnr);
663
664
      *rec_per_key++= 0;
665
666
      key_part->field= NULL;
667
      key_part->fieldnr= part.fieldnr() + 1; // start from 1.
668
      key_part->null_bit= 0;
669
      /* key_part->null_offset is only set if null_bit (see later) */
670
      /* key_part->key_type= */ /* I *THINK* this may be okay.... */
671
      /* key_part->type ???? */
672
      key_part->key_part_flag= 0;
673
      if (part.has_in_reverse_order())
674
        key_part->key_part_flag= part.in_reverse_order()? HA_REVERSE_SORT : 0;
675
676
      key_part->length= part.compare_length();
677
1638.8.1 by Stewart Smith
make the compare_length() of index parts of VARCHAR and BLOB (i.e. those with charsets) be a length in characters instead of bytes. This makes the logic converting a table proto back into a CREATE TABLE statement remotely sane. This does mean that if we increase the number of bytes utf8_general_ci uses, engines may have issues with their on disk formats (if they're not too smart)
678
      int mbmaxlen= 1;
679
680
      if (table.field(part.fieldnr()).type() == message::Table::Field::VARCHAR
681
          || table.field(part.fieldnr()).type() == message::Table::Field::BLOB)
682
      {
683
        uint32_t collation_id;
684
685
        if (table.field(part.fieldnr()).string_options().has_collation_id())
686
          collation_id= table.field(part.fieldnr()).string_options().collation_id();
687
        else
688
          collation_id= table.options().collation_id();
689
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
690
        const charset_info_st *cs= get_charset(collation_id);
1638.8.1 by Stewart Smith
make the compare_length() of index parts of VARCHAR and BLOB (i.e. those with charsets) be a length in characters instead of bytes. This makes the logic converting a table proto back into a CREATE TABLE statement remotely sane. This does mean that if we increase the number of bytes utf8_general_ci uses, engines may have issues with their on disk formats (if they're not too smart)
691
692
        mbmaxlen= cs->mbmaxlen;
693
      }
694
      key_part->length*= mbmaxlen;
695
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
696
      key_part->store_length= key_part->length;
697
698
      /* key_part->offset is set later */
1577 by Brian Aker
Next bit of pack removal (this removes it from where we store it).
699
      key_part->key_type= 0;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
700
    }
701
2445.1.12 by Olaf van der Spek
Use str_ref
702
    if (not indx.has_comment())
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
703
    {
2445.1.12 by Olaf van der Spek
Use str_ref
704
      keyinfo->comment.clear();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
705
    }
706
    else
707
    {
708
      keyinfo->flags|= HA_USES_COMMENT;
2433.1.4 by Olaf van der Spek
Use assign(), data() and size()
709
      keyinfo->comment.assign(mem().strdup(indx.comment()), indx.comment().length());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
710
    }
711
2385.2.9 by Olaf van der Spek
Refactor
712
    keyinfo->name= mem().strdup(indx.name());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
713
1527.1.3 by Brian Aker
This is:
714
    addKeyName(string(keyinfo->name, indx.name().length()));
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
715
  }
716
1574.1.2 by Brian Aker
Remove =this reference.
717
  keys_for_keyread.reset();
718
  set_prefix(keys_in_use, keys);
719
2040.4.1 by Brian Aker
Update to time and field.
720
  _field_size= table.field_size();
1574.1.2 by Brian Aker
Remove =this reference.
721
2040.4.1 by Brian Aker
Update to time and field.
722
  setFields(_field_size + 1);
723
  _fields[_field_size]= NULL;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
724
725
  uint32_t local_null_fields= 0;
1574.1.2 by Brian Aker
Remove =this reference.
726
  reclength= 0;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
727
1938.4.3 by Brian Aker
Added generator for table_definition cache. Now no one can touch the guts :)
728
  std::vector<uint32_t> field_offsets;
729
  std::vector<uint32_t> field_pack_length;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
730
2040.4.1 by Brian Aker
Update to time and field.
731
  field_offsets.resize(_field_size);
732
  field_pack_length.resize(_field_size);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
733
734
  uint32_t interval_count= 0;
735
  uint32_t interval_parts= 0;
736
737
  uint32_t stored_columns_reclength= 0;
738
2040.4.1 by Brian Aker
Update to time and field.
739
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
740
  {
741
    message::Table::Field pfield= table.field(fieldnr);
2064.2.1 by Brian Aker
Fixes naming conventions and issues around notnull being "true" by default.
742
    if (pfield.constraints().is_nullable()) // Historical reference
743
    {
744
      local_null_fields++;
745
    }
746
    else if (not pfield.constraints().is_notnull())
747
    {
748
      local_null_fields++;
749
    }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
750
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
751
    enum_field_types drizzle_field_type= proto_field_type_to_drizzle_type(pfield);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
752
753
    field_offsets[fieldnr]= stored_columns_reclength;
754
755
    /* the below switch is very similar to
1530.1.3 by Brian Aker
Style cleanup for table_share
756
      CreateField::create_length_to_internal_length in field.cc
757
      (which should one day be replace by just this code)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
758
    */
759
    switch(drizzle_field_type)
760
    {
761
    case DRIZZLE_TYPE_BLOB:
762
    case DRIZZLE_TYPE_VARCHAR:
763
      {
764
        message::Table::Field::StringFieldOptions field_options= pfield.string_options();
765
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
766
        const charset_info_st *cs= get_charset(field_options.has_collation_id() ?
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
767
                                            field_options.collation_id() : 0);
768
769
        if (! cs)
770
          cs= default_charset_info;
771
772
        field_pack_length[fieldnr]= calc_pack_length(drizzle_field_type,
773
                                                     field_options.length() * cs->mbmaxlen);
774
      }
775
      break;
776
    case DRIZZLE_TYPE_ENUM:
777
      {
778
        message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
779
1782.4.4 by Brian Aker
Fix enum at being an intefer (which is what PG did, and it saves on
780
        field_pack_length[fieldnr]= 4;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
781
782
        interval_count++;
783
        interval_parts+= field_options.field_value_size();
784
      }
785
      break;
786
    case DRIZZLE_TYPE_DECIMAL:
787
      {
788
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
789
2030.1.2 by Brian Aker
First pass in refactoring of the name of my_decimal.
790
        field_pack_length[fieldnr]= class_decimal_get_binary_size(fo.precision(), fo.scale());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
791
      }
792
      break;
793
    default:
794
      /* Zero is okay here as length is fixed for other types. */
795
      field_pack_length[fieldnr]= calc_pack_length(drizzle_field_type, 0);
796
    }
797
1574.1.2 by Brian Aker
Remove =this reference.
798
    reclength+= field_pack_length[fieldnr];
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
799
    stored_columns_reclength+= field_pack_length[fieldnr];
800
  }
801
802
  /* data_offset added to stored_rec_length later */
1574.1.2 by Brian Aker
Remove =this reference.
803
  stored_rec_length= stored_columns_reclength;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
804
1574.1.2 by Brian Aker
Remove =this reference.
805
  null_fields= local_null_fields;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
806
807
  ulong null_bits= local_null_fields;
808
  if (! table_options.pack_record())
809
    null_bits++;
810
  ulong data_offset= (null_bits + 7)/8;
811
812
1574.1.2 by Brian Aker
Remove =this reference.
813
  reclength+= data_offset;
814
  stored_rec_length+= data_offset;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
815
816
  ulong local_rec_buff_length;
817
1574.1.2 by Brian Aker
Remove =this reference.
818
  local_rec_buff_length= ALIGN_SIZE(reclength + 1);
819
  rec_buff_length= local_rec_buff_length;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
820
1574.1.2 by Brian Aker
Remove =this reference.
821
  resizeDefaultValues(local_rec_buff_length);
822
  unsigned char* record= getDefaultValues();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
823
  int null_count= 0;
824
825
  if (! table_options.pack_record())
826
  {
827
    null_count++; // one bit for delete mark.
828
    *record|= 1;
829
  }
830
831
1574.1.7 by Brian Aker
Remove interval allocation via memroot.
832
  intervals.resize(interval_count);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
833
834
  /* Now fix the TYPELIBs for the intervals (enum values)
1530.1.3 by Brian Aker
Style cleanup for table_share
835
    and field names.
836
  */
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
837
838
  uint32_t interval_nr= 0;
839
2040.4.1 by Brian Aker
Update to time and field.
840
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
841
  {
842
    message::Table::Field pfield= table.field(fieldnr);
843
844
    /* enum typelibs */
845
    if (pfield.type() != message::Table::Field::ENUM)
846
      continue;
847
848
    message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
849
1579.3.14 by Stewart Smith
have a constant for the maximum number of enum elements
850
    if (field_options.field_value_size() > Field_enum::max_supported_elements)
1579.3.11 by Stewart Smith
Fix parsing the table proto message so that an error is returned (ER_CORRUPT_TABLE_DEFINITION) if there are too many elements for an ENUM column.
851
    {
2017.2.1 by Brian Aker
Cleanup error messages around bad table definitions.
852
      my_error(ER_CORRUPT_TABLE_DEFINITION_ENUM, MYF(0), table.name().c_str());
1579.3.11 by Stewart Smith
Fix parsing the table proto message so that an error is returned (ER_CORRUPT_TABLE_DEFINITION) if there are too many elements for an ENUM column.
853
2017.2.2 by Brian Aker
Additional encapsulation around the SE api.
854
      return ER_CORRUPT_TABLE_DEFINITION_ENUM; // Historical
1579.3.11 by Stewart Smith
Fix parsing the table proto message so that an error is returned (ER_CORRUPT_TABLE_DEFINITION) if there are too many elements for an ENUM column.
855
    }
856
857
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
858
    const charset_info_st *charset= get_charset(field_options.has_collation_id() ?
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
859
                                             field_options.collation_id() : 0);
860
861
    if (! charset)
862
      charset= default_charset_info;
863
1574.1.7 by Brian Aker
Remove interval allocation via memroot.
864
    TYPELIB *t= (&intervals[interval_nr]);
1574.1.2 by Brian Aker
Remove =this reference.
865
2385.3.25 by Olaf van der Spek
Refactor
866
    t->type_names= (const char**)mem().alloc((field_options.field_value_size() + 1) * sizeof(char*));
867
    t->type_lengths= (unsigned int*)mem().alloc((field_options.field_value_size() + 1) * sizeof(unsigned int));
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
868
869
    t->type_names[field_options.field_value_size()]= NULL;
870
    t->type_lengths[field_options.field_value_size()]= 0;
871
872
    t->count= field_options.field_value_size();
873
    t->name= NULL;
874
875
    for (int n= 0; n < field_options.field_value_size(); n++)
876
    {
2385.2.9 by Olaf van der Spek
Refactor
877
      t->type_names[n]= mem().strdup(field_options.field_value(n));
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
878
879
      /* 
880
       * Go ask the charset what the length is as for "" length=1
881
       * and there's stripping spaces or some other crack going on.
1530.1.3 by Brian Aker
Style cleanup for table_share
882
     */
2385.2.9 by Olaf van der Spek
Refactor
883
      t->type_lengths[n]= charset->cset->lengthsp(charset, t->type_names[n], field_options.field_value(n).length());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
884
    }
885
    interval_nr++;
886
  }
887
888
889
  /* and read the fields */
890
  interval_nr= 0;
891
2040.4.1 by Brian Aker
Update to time and field.
892
  bool use_hash= _field_size >= MAX_FIELDS_BEFORE_HASH;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
893
1574.1.2 by Brian Aker
Remove =this reference.
894
  unsigned char* null_pos= getDefaultValues();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
895
  int null_bit_pos= (table_options.pack_record()) ? 0 : 1;
896
2040.4.1 by Brian Aker
Update to time and field.
897
  for (unsigned int fieldnr= 0; fieldnr < _field_size; fieldnr++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
898
  {
899
    message::Table::Field pfield= table.field(fieldnr);
900
901
    Field::utype unireg_type= Field::NONE;
902
903
    if (pfield.has_numeric_options() &&
904
        pfield.numeric_options().is_autoincrement())
905
    {
906
      unireg_type= Field::NEXT_NUMBER;
907
    }
908
909
    if (pfield.has_options() &&
1638.3.2 by Stewart Smith
use default_expression and update_expression instead of default_value and update_value in the table proto for NOW()
910
        pfield.options().has_default_expression() &&
1638.3.3 by Stewart Smith
store CURRENT_TIMESTAMP instead of NOW() in the table proto as this is what we end up displaying in SHOW CREATE so more accurately represents what's going on. Although it could go either way (it totally does not matter), this paves the way for SHOW CREATE TABLE running through statement_transform.
911
        pfield.options().default_expression().compare("CURRENT_TIMESTAMP") == 0)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
912
    {
1638.3.2 by Stewart Smith
use default_expression and update_expression instead of default_value and update_value in the table proto for NOW()
913
      if (pfield.options().has_update_expression() &&
1638.3.3 by Stewart Smith
store CURRENT_TIMESTAMP instead of NOW() in the table proto as this is what we end up displaying in SHOW CREATE so more accurately represents what's going on. Although it could go either way (it totally does not matter), this paves the way for SHOW CREATE TABLE running through statement_transform.
914
          pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
915
      {
916
        unireg_type= Field::TIMESTAMP_DNUN_FIELD;
917
      }
1638.3.2 by Stewart Smith
use default_expression and update_expression instead of default_value and update_value in the table proto for NOW()
918
      else if (! pfield.options().has_update_expression())
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
919
      {
1530.1.3 by Brian Aker
Style cleanup for table_share
920
        unireg_type= Field::TIMESTAMP_DN_FIELD;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
921
      }
922
      else
1976.3.1 by Brian Aker
Fixed a couple of assert() and added abort where program logic would corrupt
923
      {
924
        assert(0); // Invalid update value.
925
        abort();
926
      }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
927
    }
928
    else if (pfield.has_options() &&
1638.3.2 by Stewart Smith
use default_expression and update_expression instead of default_value and update_value in the table proto for NOW()
929
             pfield.options().has_update_expression() &&
1638.3.3 by Stewart Smith
store CURRENT_TIMESTAMP instead of NOW() in the table proto as this is what we end up displaying in SHOW CREATE so more accurately represents what's going on. Although it could go either way (it totally does not matter), this paves the way for SHOW CREATE TABLE running through statement_transform.
930
             pfield.options().update_expression().compare("CURRENT_TIMESTAMP") == 0)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
931
    {
932
      unireg_type= Field::TIMESTAMP_UN_FIELD;
933
    }
934
2445.1.18 by Olaf van der Spek
Refactor
935
    str_ref comment;
936
    if (pfield.has_comment())
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
937
    {
2433.1.4 by Olaf van der Spek
Use assign(), data() and size()
938
      comment.assign(mem().strdup(pfield.comment()), pfield.comment().size());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
939
    }
940
941
    enum_field_types field_type;
942
2057.2.7 by Brian Aker
Remove need for committed type for microtime in proto.
943
    field_type= proto_field_type_to_drizzle_type(pfield);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
944
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
945
    const charset_info_st *charset= &my_charset_bin;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
946
2445.1.18 by Olaf van der Spek
Refactor
947
    if (field_type == DRIZZLE_TYPE_BLOB || field_type == DRIZZLE_TYPE_VARCHAR)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
948
    {
949
      message::Table::Field::StringFieldOptions field_options= pfield.string_options();
950
2445.1.18 by Olaf van der Spek
Refactor
951
      charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
952
2445.1.18 by Olaf van der Spek
Refactor
953
      if (not charset)
1530.1.3 by Brian Aker
Style cleanup for table_share
954
        charset= default_charset_info;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
955
    }
956
957
    if (field_type == DRIZZLE_TYPE_ENUM)
958
    {
959
      message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
960
2445.1.18 by Olaf van der Spek
Refactor
961
      charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
962
2445.1.18 by Olaf van der Spek
Refactor
963
      if (not charset)
1530.1.3 by Brian Aker
Style cleanup for table_share
964
        charset= default_charset_info;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
965
    }
966
967
    uint8_t decimals= 0;
2445.1.18 by Olaf van der Spek
Refactor
968
    if (field_type == DRIZZLE_TYPE_DECIMAL || field_type == DRIZZLE_TYPE_DOUBLE)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
969
    {
970
      message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
971
2445.1.18 by Olaf van der Spek
Refactor
972
      if (not pfield.has_numeric_options() || ! fo.has_scale())
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
973
      {
974
        /*
975
          We don't write the default to table proto so
976
          if no decimals specified for DOUBLE, we use the default.
977
        */
978
        decimals= NOT_FIXED_DEC;
979
      }
980
      else
981
      {
982
        if (fo.scale() > DECIMAL_MAX_SCALE)
983
        {
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
984
          local_error= ER_NOT_FORM_FILE;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
985
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
986
          return true;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
987
        }
988
        decimals= static_cast<uint8_t>(fo.scale());
989
      }
990
    }
991
992
    Item *default_value= NULL;
993
994
    if (pfield.options().has_default_value() ||
1638.7.1 by Stewart Smith
in the table proto, having default_null set to false explicitly (instead of just having it as a default) had a different behaviour than if it was not set and defaulting to NULL. This meant that you'd get empty defaults instead of no default. This only showed up in table_function tables.
995
        pfield.options().default_null()  ||
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
996
        pfield.options().has_default_bin_value())
997
    {
2440.2.20 by Olaf van der Spek
Use str_ref
998
      default_value= default_value_item(field_type, *charset, pfield.options().default_null(), pfield.options().default_value(), pfield.options().default_bin_value());
2221.12.12 by Stewart Smith
check for error in converting default_value to Item in default_value_item(). This means that INT DEFAULT 'aoeu' will properly error out.
999
      if (default_value == NULL)
1000
      {
1001
        my_error(ER_INVALID_DEFAULT, MYF(0), pfield.name().c_str());
1002
        return true;
1003
      }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1004
    }
1005
1006
1007
    uint32_t field_length= 0; //Assignment is for compiler complaint.
1008
1999.4.4 by Brian Aker
First pass through on timestamp.
1009
    // We set field_length in this loop.
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1010
    switch (field_type)
1011
    {
1012
    case DRIZZLE_TYPE_BLOB:
1013
    case DRIZZLE_TYPE_VARCHAR:
1530.1.3 by Brian Aker
Style cleanup for table_share
1014
      {
1015
        message::Table::Field::StringFieldOptions field_options= pfield.string_options();
1016
1017
        charset= get_charset(field_options.has_collation_id() ?
1018
                             field_options.collation_id() : 0);
1019
1020
        if (! charset)
1021
          charset= default_charset_info;
1022
1023
        field_length= field_options.length() * charset->mbmaxlen;
1024
      }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1025
      break;
1026
    case DRIZZLE_TYPE_DOUBLE:
1530.1.3 by Brian Aker
Style cleanup for table_share
1027
      {
1028
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1029
        if (!fo.has_precision() && !fo.has_scale())
1030
        {
1031
          field_length= DBL_DIG+7;
1032
        }
1033
        else
1034
        {
1035
          field_length= fo.precision();
1036
        }
1037
        if (field_length < decimals &&
1038
            decimals != NOT_FIXED_DEC)
1039
        {
1040
          my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
1041
          local_error= ER_M_BIGGER_THAN_D;
1042
          return true;
1530.1.3 by Brian Aker
Style cleanup for table_share
1043
        }
1044
        break;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1045
      }
1046
    case DRIZZLE_TYPE_DECIMAL:
1530.1.3 by Brian Aker
Style cleanup for table_share
1047
      {
1048
        message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1049
2030.1.2 by Brian Aker
First pass in refactoring of the name of my_decimal.
1050
        field_length= class_decimal_precision_to_length(fo.precision(), fo.scale(),
1530.1.3 by Brian Aker
Style cleanup for table_share
1051
                                                     false);
1052
        break;
1053
      }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1054
    case DRIZZLE_TYPE_DATETIME:
1055
      field_length= DateTime::MAX_STRING_LENGTH;
1056
      break;
1057
    case DRIZZLE_TYPE_DATE:
1058
      field_length= Date::MAX_STRING_LENGTH;
1059
      break;
1060
    case DRIZZLE_TYPE_ENUM:
1061
      {
1530.1.3 by Brian Aker
Style cleanup for table_share
1062
        field_length= 0;
1063
1064
        message::Table::Field::EnumerationValues fo= pfield.enumeration_values();
1065
1066
        for (int valnr= 0; valnr < fo.field_value_size(); valnr++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1067
        {
1530.1.3 by Brian Aker
Style cleanup for table_share
1068
          if (fo.field_value(valnr).length() > field_length)
1069
          {
1070
            field_length= charset->cset->numchars(charset,
1071
                                                  fo.field_value(valnr).c_str(),
1072
                                                  fo.field_value(valnr).c_str()
1073
                                                  + fo.field_value(valnr).length())
1074
              * charset->mbmaxlen;
1075
          }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1076
        }
1077
      }
1530.1.3 by Brian Aker
Style cleanup for table_share
1078
      break;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1079
    case DRIZZLE_TYPE_LONG:
1080
      {
1081
        uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1530.1.3 by Brian Aker
Style cleanup for table_share
1082
        field_length= MAX_INT_WIDTH+sign_len;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1083
      }
1084
      break;
1085
    case DRIZZLE_TYPE_LONGLONG:
2046.2.1 by Brian Aker
First pass on micro timestamp.
1086
      {
1087
        uint32_t sign_len= pfield.constraints().is_unsigned() ? 0 : 1;
1088
        field_length= MAX_BIGINT_WIDTH+sign_len;
1089
      }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1090
      break;
1996.2.1 by Brian Aker
uuid type code.
1091
    case DRIZZLE_TYPE_UUID:
1092
      field_length= field::Uuid::max_string_length();
1093
      break;
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
1094
    case DRIZZLE_TYPE_IPV6:
1095
      field_length= field::IPv6::max_string_length();
1096
      break;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
1097
    case DRIZZLE_TYPE_BOOLEAN:
1098
      field_length= field::Boolean::max_string_length();
2023.2.1 by Brian Aker
Merge in BOOL type.
1099
      break;
2046.2.1 by Brian Aker
First pass on micro timestamp.
1100
    case DRIZZLE_TYPE_MICROTIME:
1101
      field_length= field::Microtime::max_string_length();
1102
      break;
1999.4.4 by Brian Aker
First pass through on timestamp.
1103
    case DRIZZLE_TYPE_TIMESTAMP:
1999.4.9 by Brian Aker
Created EPOCH
1104
      field_length= field::Epoch::max_string_length();
1999.4.4 by Brian Aker
First pass through on timestamp.
1105
      break;
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
1106
    case DRIZZLE_TYPE_TIME:
2016.1.6 by Brian Aker
Additional cleanup for int32t time type
1107
      field_length= field::Time::max_string_length();
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
1108
      break;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1109
    case DRIZZLE_TYPE_NULL:
1110
      abort(); // Programming error
1111
    }
1112
2064.2.1 by Brian Aker
Fixes naming conventions and issues around notnull being "true" by default.
1113
    bool is_not_null= false;
1114
1115
    if (not pfield.constraints().is_nullable())
1116
    {
1117
      is_not_null= true;
1118
    }
1119
    else if (pfield.constraints().is_notnull())
1120
    {
1121
      is_not_null= true;
1122
    }
1123
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1124
    Field* f= make_field(pfield,
1125
                         record + field_offsets[fieldnr] + data_offset,
1996.2.1 by Brian Aker
uuid type code.
1126
                         field_length,
2064.2.1 by Brian Aker
Fixes naming conventions and issues around notnull being "true" by default.
1127
                         not is_not_null,
1996.2.1 by Brian Aker
uuid type code.
1128
                         null_pos,
1129
                         null_bit_pos,
1130
                         decimals,
1131
                         field_type,
1132
                         charset,
1133
                         MTYP_TYPENR(unireg_type),
1134
                         ((field_type == DRIZZLE_TYPE_ENUM) ?  &intervals[interval_nr++] : (TYPELIB*) 0),
2134.1.6 by Brian Aker
Merge in encapsulation of the table message from the main class.
1135
                         getTableMessage()->field(fieldnr).name().c_str());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1136
2040.4.1 by Brian Aker
Update to time and field.
1137
    _fields[fieldnr]= f;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1138
1996.2.1 by Brian Aker
uuid type code.
1139
    // Insert post make_field code here.
1140
    switch (field_type)
1141
    {
1142
    case DRIZZLE_TYPE_BLOB:
1143
    case DRIZZLE_TYPE_VARCHAR:
1144
    case DRIZZLE_TYPE_DOUBLE:
1145
    case DRIZZLE_TYPE_DECIMAL:
1146
    case DRIZZLE_TYPE_TIMESTAMP:
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
1147
    case DRIZZLE_TYPE_TIME:
1996.2.1 by Brian Aker
uuid type code.
1148
    case DRIZZLE_TYPE_DATETIME:
2046.2.1 by Brian Aker
First pass on micro timestamp.
1149
    case DRIZZLE_TYPE_MICROTIME:
1996.2.1 by Brian Aker
uuid type code.
1150
    case DRIZZLE_TYPE_DATE:
1151
    case DRIZZLE_TYPE_ENUM:
1152
    case DRIZZLE_TYPE_LONG:
1153
    case DRIZZLE_TYPE_LONGLONG:
1154
    case DRIZZLE_TYPE_NULL:
1155
    case DRIZZLE_TYPE_UUID:
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
1156
    case DRIZZLE_TYPE_IPV6:
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
1157
    case DRIZZLE_TYPE_BOOLEAN:
1996.2.1 by Brian Aker
uuid type code.
1158
      break;
1159
    }
1160
1843.6.2 by Brian Aker
Add back in init(). Grr.... this should not be required.
1161
    // This needs to go, we should be setting the "use" on the field so that
1162
    // it does not reference the share/table.
1859.2.11 by Brian Aker
Merge in so that shell requires a share to construct.
1163
    table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1843.6.2 by Brian Aker
Add back in init(). Grr.... this should not be required.
1164
    temp_table.in_use= &session;
1165
1166
    f->init(&temp_table); /* blob default values need table obj */
1167
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1168
    if (! (f->flags & NOT_NULL_FLAG))
1169
    {
1170
      *f->null_ptr|= f->null_bit;
1171
      if (! (null_bit_pos= (null_bit_pos + 1) & 7)) /* @TODO Ugh. */
1172
        null_pos++;
1173
      null_count++;
1174
    }
1175
1176
    if (default_value)
1177
    {
1178
      enum_check_fields old_count_cuted_fields= session.count_cuted_fields;
1637.1.2 by Brian Aker
Put in call for to make sure enum is always accurate.
1179
      session.count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1180
      int res= default_value->save_in_field(f, 1);
1181
      session.count_cuted_fields= old_count_cuted_fields;
1182
      if (res != 0 && res != 3) /* @TODO Huh? */
1183
      {
1184
        my_error(ER_INVALID_DEFAULT, MYF(0), f->field_name);
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
1185
        local_error= ER_INVALID_DEFAULT;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1186
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
1187
        return true;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1188
      }
1189
    }
1996.2.1 by Brian Aker
uuid type code.
1190
    else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1191
    {
1192
      f->set_notnull();
1193
      f->store((int64_t) 1, true);
1194
    }
1195
    else
1196
    {
1197
      f->reset();
1198
    }
1199
1200
    /* hack to undo f->init() */
1660.1.3 by Brian Aker
Encapsulate Table in field
1201
    f->setTable(NULL);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1202
    f->orig_table= NULL;
1203
1999.4.1 by Brian Aker
First pass through, removing the need for us track the position in this
1204
    f->setPosition(fieldnr);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1205
    f->comment= comment;
2046.2.1 by Brian Aker
First pass on micro timestamp.
1206
    if (not default_value &&
1207
        not (f->unireg_check==Field::NEXT_NUMBER) &&
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1208
        (f->flags & NOT_NULL_FLAG) &&
2046.2.1 by Brian Aker
First pass on micro timestamp.
1209
        (not f->is_timestamp()))
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1210
    {
1211
      f->flags|= NO_DEFAULT_VALUE_FLAG;
1212
    }
1213
1214
    if (f->unireg_check == Field::NEXT_NUMBER)
2040.4.1 by Brian Aker
Update to time and field.
1215
      found_next_number_field= &(_fields[fieldnr]);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1216
1217
    if (use_hash) /* supposedly this never fails... but comments lie */
1669.3.1 by Brian Aker
Remove usage of my_hash in table_share.
1218
    {
2040.4.1 by Brian Aker
Update to time and field.
1219
      const char *local_field_name= _fields[fieldnr]->field_name;
1220
      name_hash.insert(make_pair(local_field_name, &(_fields[fieldnr])));
1669.3.1 by Brian Aker
Remove usage of my_hash in table_share.
1221
    }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1222
  }
1223
1574.1.2 by Brian Aker
Remove =this reference.
1224
  keyinfo= key_info;
1225
  for (unsigned int keynr= 0; keynr < keys; keynr++, keyinfo++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1226
  {
1227
    key_part= keyinfo->key_part;
1228
1229
    for (unsigned int partnr= 0;
1230
         partnr < keyinfo->key_parts;
1231
         partnr++, key_part++)
1232
    {
1233
      /* 
1234
       * Fix up key_part->offset by adding data_offset.
1235
       * We really should compute offset as well.
1236
       * But at least this way we are a little better.
1530.1.3 by Brian Aker
Style cleanup for table_share
1237
     */
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1238
      key_part->offset= field_offsets[key_part->fieldnr-1] + data_offset;
1239
    }
1240
  }
1241
1242
  /*
1243
    We need to set the unused bits to 1. If the number of bits is a multiple
1244
    of 8 there are no unused bits.
1245
  */
1246
  if (null_count & 7)
1247
    *(record + null_count / 8)|= ~(((unsigned char) 1 << (null_count & 7)) - 1);
1248
1574.1.2 by Brian Aker
Remove =this reference.
1249
  null_bytes= (null_pos - (unsigned char*) record + (null_bit_pos + 7) / 8);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1250
1574.1.2 by Brian Aker
Remove =this reference.
1251
  last_null_bit_pos= null_bit_pos;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1252
1253
  /* Fix key stuff */
1574.1.2 by Brian Aker
Remove =this reference.
1254
  if (key_parts)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1255
  {
2385.3.20 by Olaf van der Spek
Refactor
1256
    uint32_t local_primary_key= doesKeyNameExist("PRIMARY");
1574.1.2 by Brian Aker
Remove =this reference.
1257
    keyinfo= key_info;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1258
    key_part= keyinfo->key_part;
1259
1574.1.2 by Brian Aker
Remove =this reference.
1260
    for (uint32_t key= 0; key < keys; key++,keyinfo++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1261
    {
1262
      uint32_t usable_parts= 0;
1263
1264
      if (local_primary_key >= MAX_KEY && (keyinfo->flags & HA_NOSAME))
1265
      {
1530.1.3 by Brian Aker
Style cleanup for table_share
1266
        /*
1267
          If the UNIQUE key doesn't have NULL columns and is not a part key
1268
          declare this as a primary key.
1269
        */
1270
        local_primary_key=key;
1271
        for (uint32_t i= 0; i < keyinfo->key_parts; i++)
1272
        {
1273
          uint32_t fieldnr= key_part[i].fieldnr;
2040.4.1 by Brian Aker
Update to time and field.
1274
          if (not fieldnr ||
1275
              _fields[fieldnr-1]->null_ptr ||
1276
              _fields[fieldnr-1]->key_length() != key_part[i].length)
1530.1.3 by Brian Aker
Style cleanup for table_share
1277
          {
1278
            local_primary_key= MAX_KEY; // Can't be used
1279
            break;
1280
          }
1281
        }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1282
      }
1283
1284
      for (uint32_t i= 0 ; i < keyinfo->key_parts ; key_part++,i++)
1285
      {
1530.1.3 by Brian Aker
Style cleanup for table_share
1286
        Field *local_field;
1287
        if (! key_part->fieldnr)
1288
        {
1289
          return ENOMEM;
1290
        }
2040.4.1 by Brian Aker
Update to time and field.
1291
        local_field= key_part->field= _fields[key_part->fieldnr-1];
1530.1.3 by Brian Aker
Style cleanup for table_share
1292
        key_part->type= local_field->key_type();
1293
        if (local_field->null_ptr)
1294
        {
1574.1.2 by Brian Aker
Remove =this reference.
1295
          key_part->null_offset=(uint32_t) ((unsigned char*) local_field->null_ptr - getDefaultValues());
1530.1.3 by Brian Aker
Style cleanup for table_share
1296
          key_part->null_bit= local_field->null_bit;
1297
          key_part->store_length+=HA_KEY_NULL_LENGTH;
1298
          keyinfo->flags|=HA_NULL_PART_KEY;
1299
          keyinfo->extra_length+= HA_KEY_NULL_LENGTH;
1300
          keyinfo->key_length+= HA_KEY_NULL_LENGTH;
1301
        }
1302
        if (local_field->type() == DRIZZLE_TYPE_BLOB ||
1303
            local_field->real_type() == DRIZZLE_TYPE_VARCHAR)
1304
        {
1305
          if (local_field->type() == DRIZZLE_TYPE_BLOB)
1306
            key_part->key_part_flag|= HA_BLOB_PART;
1307
          else
1308
            key_part->key_part_flag|= HA_VAR_LENGTH_PART;
1309
          keyinfo->extra_length+=HA_KEY_BLOB_LENGTH;
1310
          key_part->store_length+=HA_KEY_BLOB_LENGTH;
1311
          keyinfo->key_length+= HA_KEY_BLOB_LENGTH;
1312
        }
1313
        if (i == 0 && key != local_primary_key)
1314
          local_field->flags |= (((keyinfo->flags & HA_NOSAME) &&
1315
                                  (keyinfo->key_parts == 1)) ?
1316
                                 UNIQUE_KEY_FLAG : MULTIPLE_KEY_FLAG);
1317
        if (i == 0)
1318
          local_field->key_start.set(key);
1319
        if (local_field->key_length() == key_part->length &&
1320
            !(local_field->flags & BLOB_FLAG))
1321
        {
1574.1.2 by Brian Aker
Remove =this reference.
1322
          enum ha_key_alg algo= key_info[key].algorithm;
1323
          if (db_type()->index_flags(algo) & HA_KEYREAD_ONLY)
1530.1.3 by Brian Aker
Style cleanup for table_share
1324
          {
1574.1.2 by Brian Aker
Remove =this reference.
1325
            keys_for_keyread.set(key);
1530.1.3 by Brian Aker
Style cleanup for table_share
1326
            local_field->part_of_key.set(key);
1327
            local_field->part_of_key_not_clustered.set(key);
1328
          }
1574.1.2 by Brian Aker
Remove =this reference.
1329
          if (db_type()->index_flags(algo) & HA_READ_ORDER)
1530.1.3 by Brian Aker
Style cleanup for table_share
1330
            local_field->part_of_sortkey.set(key);
1331
        }
1332
        if (!(key_part->key_part_flag & HA_REVERSE_SORT) &&
1333
            usable_parts == i)
1334
          usable_parts++;			// For FILESORT
1335
        local_field->flags|= PART_KEY_FLAG;
1336
        if (key == local_primary_key)
1337
        {
1338
          local_field->flags|= PRI_KEY_FLAG;
1339
          /*
1340
            If this field is part of the primary key and all keys contains
1341
            the primary key, then we can use any key to find this column
1342
          */
1574.1.2 by Brian Aker
Remove =this reference.
1343
          if (storage_engine->check_flag(HTON_BIT_PRIMARY_KEY_IN_READ_INDEX))
1530.1.3 by Brian Aker
Style cleanup for table_share
1344
          {
1574.1.2 by Brian Aker
Remove =this reference.
1345
            local_field->part_of_key= keys_in_use;
1530.1.3 by Brian Aker
Style cleanup for table_share
1346
            if (local_field->part_of_sortkey.test(key))
1574.1.2 by Brian Aker
Remove =this reference.
1347
              local_field->part_of_sortkey= keys_in_use;
1530.1.3 by Brian Aker
Style cleanup for table_share
1348
          }
1349
        }
1350
        if (local_field->key_length() != key_part->length)
1351
        {
1352
          key_part->key_part_flag|= HA_PART_KEY_SEG;
1353
        }
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1354
      }
1355
      keyinfo->usable_key_parts= usable_parts; // Filesort
1356
1574.1.2 by Brian Aker
Remove =this reference.
1357
      set_if_bigger(max_key_length,keyinfo->key_length+
1530.1.3 by Brian Aker
Style cleanup for table_share
1358
                    keyinfo->key_parts);
1574.1.2 by Brian Aker
Remove =this reference.
1359
      total_key_length+= keyinfo->key_length;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1360
1361
      if (keyinfo->flags & HA_NOSAME)
1362
      {
1574.1.2 by Brian Aker
Remove =this reference.
1363
        set_if_bigger(max_unique_length,keyinfo->key_length);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1364
      }
1365
    }
1366
    if (local_primary_key < MAX_KEY &&
1574.1.2 by Brian Aker
Remove =this reference.
1367
        (keys_in_use.test(local_primary_key)))
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1368
    {
1574.1.2 by Brian Aker
Remove =this reference.
1369
      primary_key= local_primary_key;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1370
      /*
1371
        If we are using an integer as the primary key then allow the user to
1372
        refer to it as '_rowid'
1373
      */
1574.1.2 by Brian Aker
Remove =this reference.
1374
      if (key_info[local_primary_key].key_parts == 1)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1375
      {
1574.1.2 by Brian Aker
Remove =this reference.
1376
        Field *local_field= key_info[local_primary_key].key_part[0].field;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1377
        if (local_field && local_field->result_type() == INT_RESULT)
1378
        {
1379
          /* note that fieldnr here (and rowid_field_offset) starts from 1 */
1574.1.2 by Brian Aker
Remove =this reference.
1380
          rowid_field_offset= (key_info[local_primary_key].key_part[0].
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1381
                                      fieldnr);
1382
        }
1383
      }
1384
    }
1385
  }
1386
1574.1.2 by Brian Aker
Remove =this reference.
1387
  if (found_next_number_field)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1388
  {
1574.1.2 by Brian Aker
Remove =this reference.
1389
    Field *reg_field= *found_next_number_field;
1390
    if ((int) (next_number_index= (uint32_t)
1391
               find_ref_key(key_info, keys,
1392
                            getDefaultValues(), reg_field,
1393
                            &next_number_key_offset,
1394
                            &next_number_keypart)) < 0)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1395
    {
1396
      /* Wrong field definition */
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
1397
      local_error= ER_NOT_FORM_FILE;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1398
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
1399
      return true;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1400
    }
1401
    else
1402
    {
1403
      reg_field->flags |= AUTO_INCREMENT_FLAG;
1404
    }
1405
  }
1406
1574.1.2 by Brian Aker
Remove =this reference.
1407
  if (blob_fields)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1408
  {
1409
    /* Store offsets to blob fields to find them fast */
1574.1.8 by Brian Aker
Blob now allocated via vector
1410
    blob_field.resize(blob_fields);
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
1411
    uint32_t *save= &blob_field[0];
1412
    uint32_t k= 0;
2040.4.1 by Brian Aker
Update to time and field.
1413
    for (Fields::iterator iter= _fields.begin(); iter != _fields.end()-1; iter++, k++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1414
    {
1578.2.13 by Brian Aker
Use iterator for Field in share creation.
1415
      if ((*iter)->flags & BLOB_FLAG)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1416
        (*save++)= k;
1417
    }
1418
  }
1419
1802.16.9 by Padraig O'Sullivan
Resolved bitset handling during temporary table creation. All tests pass again.
1420
  all_set.clear();
2040.4.1 by Brian Aker
Update to time and field.
1421
  all_set.resize(_field_size);
1802.16.8 by Padraig O'Sullivan
Removal of all MyBitmap from the code base. Compiles but test failures exist now.
1422
  all_set.set();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1423
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
1424
  return local_error != EE_OK;
1425
}
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1426
1427
/*
1428
  Read table definition from a binary / text based .frm cursor
1429
1430
  SYNOPSIS
1431
  open_table_def()
1432
  session		Thread Cursor
1433
  share		Fill this with table definition
1434
1435
  NOTES
1530.1.3 by Brian Aker
Style cleanup for table_share
1436
  This function is called when the table definition is not cached in
2275.3.6 by Olaf van der Spek
Definition Cache
1437
  definition::Cache::getCache()
1530.1.3 by Brian Aker
Style cleanup for table_share
1438
  The data is returned in 'share', which is alloced by
1439
  alloc_table_share().. The code assumes that share is initialized.
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1440
1441
  RETURN VALUES
1530.1.3 by Brian Aker
Style cleanup for table_share
1442
  0	ok
1443
  1	Error (see open_table_error)
1444
  2    Error (see open_table_error)
1445
  3    Wrong data in .frm cursor
1446
  4    Error (see open_table_error)
1447
  5    Error (see open_table_error: charset unavailable)
1448
  6    Unknown .frm version
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1449
*/
1450
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
1451
int TableShare::open_table_def(Session& session, const identifier::Table &identifier)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1452
{
2140.1.2 by Brian Aker
Merge in decomplication of our error system when reading through the table
1453
  drizzled::error_t local_error= EE_OK;
1454
1455
  message::table::shared_ptr table= plugin::StorageEngine::getTableMessage(session, identifier, local_error);
1456
1457
  if (table and table->IsInitialized())
1458
  {
2140.1.11 by Brian Aker
Refactor so that the return is simpler to work with from parsing.
1459
    if (parse_table_proto(session, *table))
2140.1.2 by Brian Aker
Merge in decomplication of our error system when reading through the table
1460
    {
1461
      local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1462
      my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1463
    }
1464
    else
1465
    {
1466
      setTableCategory(TABLE_CATEGORY_USER);
1467
      local_error= EE_OK;
1468
    }
1469
  }
1470
  else if (table and not table->IsInitialized())
1471
  {
1472
    local_error= ER_CORRUPT_TABLE_DEFINITION_UNKNOWN;
1473
    my_error(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, identifier);
1474
  }
1475
  else
1476
  {
1477
    local_error= ER_TABLE_UNKNOWN;
1478
    my_error(ER_TABLE_UNKNOWN, identifier);
1479
  }
1480
1481
  return static_cast<int>(local_error);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1482
}
1483
1484
1485
/*
1486
  Open a table based on a TableShare
1487
1488
  SYNOPSIS
1530.1.3 by Brian Aker
Style cleanup for table_share
1489
  open_table_from_share()
1490
  session			Thread Cursor
1491
  share		Table definition
1492
  alias       	Alias for table
1493
  db_stat		open flags (for example HA_OPEN_KEYFILE|
1494
  HA_OPEN_RNDFILE..) can be 0 (example in
1495
  ha_example_table)
1496
  ha_open_flags	HA_OPEN_ABORT_IF_LOCKED etc..
1497
  outparam       	result table
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1498
1499
  RETURN VALUES
1530.1.3 by Brian Aker
Style cleanup for table_share
1500
  0	ok
1501
  1	Error (see open_table_error)
1502
  2    Error (see open_table_error)
1503
  3    Wrong data in .frm cursor
1504
  4    Error (see open_table_error)
1505
  5    Error (see open_table_error: charset unavailable)
1506
  7    Table definition has changed in engine
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1507
*/
1626.3.2 by Brian Aker
Cleanup table_share to pass in identifier.
1508
int TableShare::open_table_from_share(Session *session,
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
1509
                                      const identifier::Table &identifier,
1626.3.2 by Brian Aker
Cleanup table_share to pass in identifier.
1510
                                      const char *alias,
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1511
                                      uint32_t db_stat, uint32_t ha_open_flags,
1512
                                      Table &outparam)
1513
{
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1514
  bool error_reported= false;
1864.4.1 by Brian Aker
Move share creation into temporary table (there still exists and issue with
1515
  int ret= open_table_from_share_inner(session, alias, db_stat, outparam);
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1516
1517
  if (not ret)
1864.4.1 by Brian Aker
Move share creation into temporary table (there still exists and issue with
1518
    ret= open_table_cursor_inner(identifier, db_stat, ha_open_flags, outparam, error_reported);
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1519
1520
  if (not ret)
1521
    return ret;
1522
1523
  if (not error_reported)
1524
    open_table_error(ret, errno, 0);
1525
2069.4.1 by Brian Aker
A little on the paranoid side, but not the worst plan ever to check our
1526
  boost::checked_delete(outparam.cursor);
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1527
  outparam.cursor= 0;				// For easier error checking
1528
  outparam.db_stat= 0;
2318.6.60 by Olaf van der Spek
Refactor
1529
  outparam.mem().free_root(MYF(0));       // Safe to call on zeroed root
1864.4.4 by Brian Aker
We now handle the free of the alias inside of table.
1530
  outparam.clearAlias();
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1531
1532
  return ret;
1533
}
1534
2385.2.9 by Olaf van der Spek
Refactor
1535
int TableShare::open_table_from_share_inner(Session *session, const char *alias, uint32_t db_stat, Table &outparam)
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1536
{
2385.2.9 by Olaf van der Spek
Refactor
1537
  int local_error= 1;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1538
  outparam.resetTable(session, this, db_stat);
1539
1864.4.4 by Brian Aker
We now handle the free of the alias inside of table.
1540
  outparam.setAlias(alias);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1541
1542
  /* Allocate Cursor */
1869.1.4 by Brian Aker
TableShare is no longer in the house (i.e. we no longer directly have a copy
1543
  if (not (outparam.cursor= db_type()->getCursor(outparam)))
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1544
    return local_error;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1545
1546
  local_error= 4;
2385.2.9 by Olaf van der Spek
Refactor
1547
  uint32_t records= 0;
1548
  if (db_stat & HA_OPEN_KEYFILE)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1549
    records=1;
1550
1551
  records++;
1552
2385.2.9 by Olaf van der Spek
Refactor
1553
  unsigned char* record= outparam.alloc(rec_buff_length * records);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1554
1555
  if (records == 0)
1556
  {
1557
    /* We are probably in hard repair, and the buffers should not be used */
1574 by Brian Aker
Rollup patch for hiding tableshare.
1558
    outparam.record[0]= outparam.record[1]= getDefaultValues();
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1559
  }
1560
  else
1561
  {
1562
    outparam.record[0]= record;
1563
    if (records > 1)
1564
      outparam.record[1]= record+ rec_buff_length;
1565
    else
1672.3.6 by Brian Aker
First pass in encapsulating row
1566
      outparam.record[1]= outparam.getInsertRecord();   // Safety
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1567
  }
1568
1859.2.14 by Brian Aker
Add support for --with-valgrind
1569
#ifdef HAVE_VALGRIND
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1570
  /*
1571
    We need this because when we read var-length rows, we are not updating
1572
    bytes after end of varchar
1573
  */
1574
  if (records > 1)
1575
  {
1672.3.6 by Brian Aker
First pass in encapsulating row
1576
    memcpy(outparam.getInsertRecord(), getDefaultValues(), rec_buff_length);
1577
    memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1578
    if (records > 2)
1672.3.6 by Brian Aker
First pass in encapsulating row
1579
      memcpy(outparam.getUpdateRecord(), getDefaultValues(), rec_buff_length);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1580
  }
1581
#endif
1582
  if (records > 1)
1583
  {
1672.3.6 by Brian Aker
First pass in encapsulating row
1584
    memcpy(outparam.getUpdateRecord(), getDefaultValues(), null_bytes);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1585
  }
1586
2385.2.9 by Olaf van der Spek
Refactor
1587
  Field** field_ptr = new (outparam.mem()) Field*[_field_size + 1];
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1588
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1589
  outparam.setFields(field_ptr);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1590
2318.6.71 by Olaf van der Spek
Refactor
1591
  record= outparam.getInsertRecord()-1;	/* Fieldstart = 1 */
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1592
1593
  outparam.null_flags= (unsigned char*) record+1;
1594
1595
  /* Setup copy of fields from share, but use the right alias and record */
2040.4.1 by Brian Aker
Update to time and field.
1596
  for (uint32_t i= 0 ; i < _field_size; i++, field_ptr++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1597
  {
2318.6.60 by Olaf van der Spek
Refactor
1598
    if (!((*field_ptr)= _fields[i]->clone(&outparam.mem(), &outparam)))
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1599
      return local_error;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1600
  }
2318.6.71 by Olaf van der Spek
Refactor
1601
  *field_ptr= 0;                              // End marker
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1602
1603
  if (found_next_number_field)
1604
    outparam.found_next_number_field=
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1605
      outparam.getField(positionFields(found_next_number_field));
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1606
  if (timestamp_field)
1999.4.9 by Brian Aker
Created EPOCH
1607
    outparam.timestamp_field= (field::Epoch*) outparam.getField(timestamp_field->position());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1608
1609
  /* Fix key->name and key_part->field */
1610
  if (key_parts)
1611
  {
2385.2.9 by Olaf van der Spek
Refactor
1612
    uint32_t n_length= keys * sizeof(KeyInfo) + key_parts * sizeof(KeyPartInfo);
1613
    KeyInfo* local_key_info= (KeyInfo*) outparam.alloc(n_length);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1614
    outparam.key_info= local_key_info;
2385.2.9 by Olaf van der Spek
Refactor
1615
    KeyPartInfo* key_part= reinterpret_cast<KeyPartInfo*>(local_key_info+keys);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1616
1617
    memcpy(local_key_info, key_info, sizeof(*local_key_info)*keys);
2385.2.9 by Olaf van der Spek
Refactor
1618
    memcpy(key_part, key_info[0].key_part, sizeof(*key_part) * key_parts);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1619
2385.2.9 by Olaf van der Spek
Refactor
1620
    for (KeyInfo* key_info_end= local_key_info + keys; local_key_info < key_info_end; local_key_info++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1621
    {
1622
      local_key_info->table= &outparam;
1623
      local_key_info->key_part= key_part;
1624
2385.2.9 by Olaf van der Spek
Refactor
1625
      for (KeyPartInfo* key_part_end= key_part+ local_key_info->key_parts; key_part < key_part_end; key_part++)
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1626
      {
1578.2.16 by Brian Aker
Merge in change to getTable() to private the field objects.
1627
        Field *local_field= key_part->field= outparam.getField(key_part->fieldnr-1);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1628
2385.2.9 by Olaf van der Spek
Refactor
1629
        if (local_field->key_length() != key_part->length && not (local_field->flags & BLOB_FLAG))
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1630
        {
1631
          /*
1632
            We are using only a prefix of the column as a key:
1633
            Create a new field for the key part that matches the index
1634
          */
2318.6.60 by Olaf van der Spek
Refactor
1635
          local_field= key_part->field= local_field->new_field(&outparam.mem(), &outparam, 0);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1636
          local_field->field_length= key_part->length;
1637
        }
1638
      }
1639
    }
1640
  }
1641
1642
  /* Allocate bitmaps */
1643
2040.4.1 by Brian Aker
Update to time and field.
1644
  outparam.def_read_set.resize(_field_size);
1645
  outparam.def_write_set.resize(_field_size);
1646
  outparam.tmp_set.resize(_field_size);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1647
  outparam.default_column_bitmaps();
1648
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1649
  return 0;
1650
}
1651
2087.4.2 by Brian Aker
Modify TableIdentifier to fit with the rest of the identifiers.
1652
int TableShare::open_table_cursor_inner(const identifier::Table &identifier,
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1653
                                        uint32_t db_stat, uint32_t ha_open_flags,
1654
                                        Table &outparam,
1655
                                        bool &error_reported)
1656
{
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1657
  /* The table struct is now initialized;  Open the table */
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1658
  int local_error= 2;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1659
  if (db_stat)
1660
  {
1578.2.9 by Brian Aker
Simplify ha_open.
1661
    assert(!(db_stat & HA_WAIT_IF_LOCKED));
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1662
    int ha_err;
1626.3.1 by Brian Aker
Adding in TableIdentifier for ha_open; (first pass)
1663
1869.1.7 by Brian Aker
Cleanup of caller to ha_open().
1664
    if ((ha_err= (outparam.cursor->ha_open(identifier,
1665
                                           (db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1666
                                           (db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE : HA_OPEN_IGNORE_IF_LOCKED) | ha_open_flags))))
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1667
    {
1668
      switch (ha_err)
1669
      {
1530.1.3 by Brian Aker
Style cleanup for table_share
1670
      case HA_ERR_NO_SUCH_TABLE:
1671
        /*
1672
          The table did not exists in storage engine, use same error message
1673
          as if the .frm cursor didn't exist
1674
        */
1675
        local_error= 1;
1676
        errno= ENOENT;
1677
        break;
1678
      case EMFILE:
1679
        /*
1680
          Too many files opened, use same error message as if the .frm
1681
          cursor can't open
1682
        */
1683
        local_error= 1;
1684
        errno= EMFILE;
1685
        break;
1686
      default:
1687
        outparam.print_error(ha_err, MYF(0));
1688
        error_reported= true;
1689
        if (ha_err == HA_ERR_TABLE_DEF_CHANGED)
1690
          local_error= 7;
1691
        break;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1692
      }
1861.4.2 by Brian Aker
Small refactor around how we build up the share (this is partwise between
1693
      return local_error;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1694
    }
1695
  }
1696
1697
  return 0;
1698
}
1699
1700
/* error message when opening a form cursor */
1701
void TableShare::open_table_error(int pass_error, int db_errno, int pass_errarg)
1702
{
1703
  char buff[FN_REFLEN];
1704
  myf errortype= ME_ERROR+ME_WAITTANG;
1705
1706
  switch (pass_error) {
1707
  case 7:
1708
  case 1:
1709
    if (db_errno == ENOENT)
1710
    {
2385.3.24 by Olaf van der Spek
Refactor
1711
      identifier::Table identifier(db.data(), table_name.data());
2140.1.3 by Brian Aker
Merge in error message fix for just one type of error for unknown table.
1712
      my_error(ER_TABLE_UNKNOWN, identifier);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1713
    }
1714
    else
1715
    {
2385.3.24 by Olaf van der Spek
Refactor
1716
      snprintf(buff, sizeof(buff), "%s",normalized_path.data());
2385.3.23 by Olaf van der Spek
Refactor
1717
      my_error((db_errno == EMFILE) ? ER_CANT_OPEN_FILE : ER_FILE_NOT_FOUND, errortype, buff, db_errno);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1718
    }
1719
    break;
1720
  case 2:
1530.1.3 by Brian Aker
Style cleanup for table_share
1721
    {
2385.3.23 by Olaf van der Spek
Refactor
1722
      drizzled::error_t err_no= (db_errno == ENOENT) ? ER_FILE_NOT_FOUND : (db_errno == EAGAIN) ? ER_FILE_USED : ER_CANT_OPEN_FILE;
2385.3.24 by Olaf van der Spek
Refactor
1723
      my_error(err_no, errortype, normalized_path.data(), db_errno);
1530.1.3 by Brian Aker
Style cleanup for table_share
1724
      break;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1725
    }
1726
  case 5:
1727
    {
1530.1.3 by Brian Aker
Style cleanup for table_share
1728
      const char *csname= get_charset_name((uint32_t) pass_errarg);
1729
      char tmp[10];
1730
      if (!csname || csname[0] =='?')
1731
      {
1732
        snprintf(tmp, sizeof(tmp), "#%d", pass_errarg);
1733
        csname= tmp;
1734
      }
2385.3.23 by Olaf van der Spek
Refactor
1735
      my_printf_error(ER_UNKNOWN_COLLATION, _("Unknown collation '%s' in table '%-.64s' definition"), MYF(0), csname, table_name.data());
1530.1.3 by Brian Aker
Style cleanup for table_share
1736
      break;
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1737
    }
1738
  case 6:
2385.3.24 by Olaf van der Spek
Refactor
1739
    snprintf(buff, sizeof(buff), "%s", normalized_path.data());
2385.3.23 by Olaf van der Spek
Refactor
1740
    my_printf_error(ER_NOT_FORM_FILE, _("Table '%-.64s' was created with a different version of Drizzle and cannot be read"), MYF(0), buff);
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1741
    break;
1742
  case 8:
1743
    break;
1744
  default:				/* Better wrong error than none */
1745
  case 4:
2385.3.24 by Olaf van der Spek
Refactor
1746
    snprintf(buff, sizeof(buff), "%s", normalized_path.data());
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1747
    my_error(ER_NOT_FORM_FILE, errortype, buff, 0);
1748
    break;
1749
  }
1750
  return;
1751
} /* open_table_error */
1752
2040.4.1 by Brian Aker
Update to time and field.
1753
Field *TableShare::make_field(const message::Table::Field &pfield,
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1754
                              unsigned char *ptr,
1755
                              uint32_t field_length,
1756
                              bool is_nullable,
1757
                              unsigned char *null_pos,
1758
                              unsigned char null_bit,
1759
                              uint8_t decimals,
1760
                              enum_field_types field_type,
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
1761
                              const charset_info_st * field_charset,
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1762
                              Field::utype unireg_check,
1763
                              TYPELIB *interval,
1764
                              const char *field_name)
1765
{
2040.4.1 by Brian Aker
Update to time and field.
1766
  return make_field(pfield,
1767
                    ptr,
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1768
                    field_length,
1769
                    is_nullable,
1770
                    null_pos,
1771
                    null_bit,
1772
                    decimals,
1773
                    field_type,
1774
                    field_charset,
1775
                    unireg_check,
1776
                    interval,
1777
                    field_name,
1778
                    pfield.constraints().is_unsigned());
1779
}
1780
2040.4.1 by Brian Aker
Update to time and field.
1781
Field *TableShare::make_field(const message::Table::Field &,
1782
                              unsigned char *ptr,
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1783
                              uint32_t field_length,
1784
                              bool is_nullable,
1785
                              unsigned char *null_pos,
1786
                              unsigned char null_bit,
1787
                              uint8_t decimals,
1788
                              enum_field_types field_type,
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
1789
                              const charset_info_st * field_charset,
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1790
                              Field::utype unireg_check,
1791
                              TYPELIB *interval,
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1792
                              const char *field_name, 
1793
                              bool is_unsigned)
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1794
{
1795
  if (! is_nullable)
1796
  {
1797
    null_pos=0;
1798
    null_bit=0;
1799
  }
1800
  else
1801
  {
1802
    null_bit= ((unsigned char) 1) << null_bit;
1803
  }
1804
1805
  switch (field_type)
1806
  {
1807
  case DRIZZLE_TYPE_ENUM:
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1808
    return new (&mem_root) Field_enum(ptr,
1999.4.4 by Brian Aker
First pass through on timestamp.
1809
                                      field_length,
1810
                                      null_pos,
1811
                                      null_bit,
1812
                                      field_name,
1813
                                      interval,
1814
                                      field_charset);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1815
  case DRIZZLE_TYPE_VARCHAR:
1835.1.3 by Brian Aker
Fix variable such that we no longer pass share to varstring on creation.
1816
    setVariableWidth();
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1817
    return new (&mem_root) Field_varstring(ptr,field_length,
1892.5.2 by Gustaf Thorslund
Replaced macros with functions/templates. Part of blueprint:
1818
                                      ha_varchar_packlength(field_length),
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1819
                                      null_pos,null_bit,
1820
                                      field_name,
1821
                                      field_charset);
1822
  case DRIZZLE_TYPE_BLOB:
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1823
    return new (&mem_root) Field_blob(ptr,
2137.1.7 by Brian Aker
Formatting
1824
                                      null_pos,
1825
                                      null_bit,
1826
                                      field_name,
1827
                                      this,
1828
                                      field_charset);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1829
  case DRIZZLE_TYPE_DECIMAL:
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1830
    return new (&mem_root) Field_decimal(ptr,
2137.1.7 by Brian Aker
Formatting
1831
                                         field_length,
1832
                                         null_pos,
1833
                                         null_bit,
1834
                                         unireg_check,
1835
                                         field_name,
1836
                                         decimals);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1837
  case DRIZZLE_TYPE_DOUBLE:
1532.1.6 by Brian Aker
Encapsulate the ownership of the table members to the table (so not in
1838
    return new (&mem_root) Field_double(ptr,
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1839
                                   field_length,
1840
                                   null_pos,
1841
                                   null_bit,
1842
                                   unireg_check,
1843
                                   field_name,
1844
                                   decimals,
1845
                                   false,
1846
                                   false /* is_unsigned */);
1996.2.1 by Brian Aker
uuid type code.
1847
  case DRIZZLE_TYPE_UUID:
1848
    return new (&mem_root) field::Uuid(ptr,
1849
                                       field_length,
1850
                                       null_pos,
1851
                                       null_bit,
1852
                                       field_name);
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
1853
  case DRIZZLE_TYPE_IPV6:
1854
    return new (&mem_root) field::IPv6(ptr,
1855
                                       field_length,
1856
                                       null_pos,
1857
                                       null_bit,
1858
                                       field_name);
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
1859
  case DRIZZLE_TYPE_BOOLEAN:
1860
    return new (&mem_root) field::Boolean(ptr,
1861
                                          field_length,
1862
                                          null_pos,
1863
                                          null_bit,
1864
                                          field_name,
1865
                                          is_unsigned);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1866
  case DRIZZLE_TYPE_LONG:
2007 by Brian Aker
Refactor naming for integers.
1867
    return new (&mem_root) field::Int32(ptr,
1868
                                        field_length,
1869
                                        null_pos,
1870
                                        null_bit,
1871
                                        unireg_check,
1872
                                        field_name);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1873
  case DRIZZLE_TYPE_LONGLONG:
2008.2.3 by Brian Aker
Fixing up a, somewhat, hidden unsigned type to solve a few issues around
1874
    {
1875
      if (is_unsigned)
1876
      {
1877
        return new (&mem_root) field::Size(ptr,
1878
                                           field_length,
1879
                                           null_pos,
1880
                                           null_bit,
1881
                                           unireg_check,
1882
                                           field_name);
1883
      }
1884
1885
      return new (&mem_root) field::Int64(ptr,
1886
                                          field_length,
1887
                                          null_pos,
1888
                                          null_bit,
1889
                                          unireg_check,
1890
                                          field_name);
1891
    }
2046.2.1 by Brian Aker
First pass on micro timestamp.
1892
  case DRIZZLE_TYPE_MICROTIME:
1893
    return new (&mem_root) field::Microtime(ptr,
1894
                                            null_pos,
1895
                                            null_bit,
1896
                                            unireg_check,
1897
                                            field_name,
1898
                                            this);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1899
  case DRIZZLE_TYPE_TIMESTAMP:
1999.4.9 by Brian Aker
Created EPOCH
1900
    return new (&mem_root) field::Epoch(ptr,
1901
                                        null_pos,
1902
                                        null_bit,
1903
                                        unireg_check,
1904
                                        field_name,
2046.2.1 by Brian Aker
First pass on micro timestamp.
1905
                                        this);
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
1906
  case DRIZZLE_TYPE_TIME:
2385.2.9 by Olaf van der Spek
Refactor
1907
    return new (&mem_root) field::Time(ptr, field_length, null_pos, null_bit, field_name);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1908
  case DRIZZLE_TYPE_DATE:
2385.2.9 by Olaf van der Spek
Refactor
1909
    return new (&mem_root) Field_date(ptr, null_pos, null_bit, field_name);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1910
  case DRIZZLE_TYPE_DATETIME:
2385.2.9 by Olaf van der Spek
Refactor
1911
    return new (&mem_root) Field_datetime(ptr, null_pos, null_bit, field_name);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1912
  case DRIZZLE_TYPE_NULL:
2385.2.9 by Olaf van der Spek
Refactor
1913
    return new (&mem_root) Field_null(ptr, field_length, field_name);
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1914
  }
2385.2.9 by Olaf van der Spek
Refactor
1915
  assert(false);
1996.2.1 by Brian Aker
uuid type code.
1916
  abort();
1530.1.2 by Brian Aker
Second pass through field name, this also corrects _ name usage.
1917
}
1918
2148.7.11 by Brian Aker
Remove some of the dependencies from session.h so that we make the include
1919
void TableShare::refreshVersion()
1920
{
2263.3.4 by Olaf van der Spek
Prefix global refresh_version
1921
  version= g_refresh_version;
2148.7.11 by Brian Aker
Remove some of the dependencies from session.h so that we make the include
1922
}
1923
1527.1.2 by Brian Aker
Move all TableShare methods into .cc file.
1924
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
1925
} /* namespace drizzled */