~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.cc

  • Committer: Brian Aker
  • Date: 2011-02-21 17:37:00 UTC
  • mto: (2192.1.1 drizzle-staging)
  • mto: This revision was merged to the branch mainline in revision 2193.
  • Revision ID: brian@tangent.org-20110221173700-6wdfbxm60zq9q9se
Merge in change from REPLICATION to REPLICATE as keyword.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008-2009 Sun Microsystems
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
 * @file Implementation of CreateField class
22
22
 */
23
23
 
24
 
#include "config.h"
 
24
#include <config.h>
25
25
#include <errno.h>
26
26
#include <float.h>
27
 
#include "drizzled/sql_select.h"
28
 
#include "drizzled/error.h"
29
 
#include "drizzled/field.h"
30
 
#include "drizzled/create_field.h"
31
 
#include "drizzled/field/str.h"
32
 
#include "drizzled/field/num.h"
33
 
#include "drizzled/field/blob.h"
34
 
#include "drizzled/field/enum.h"
35
 
#include "drizzled/field/null.h"
36
 
#include "drizzled/field/date.h"
37
 
#include "drizzled/field/decimal.h"
38
 
#include "drizzled/field/real.h"
39
 
#include "drizzled/field/double.h"
40
 
#include "drizzled/field/int32.h"
41
 
#include "drizzled/field/int64.h"
42
 
#include "drizzled/field/num.h"
43
 
#include "drizzled/field/timestamp.h"
44
 
#include "drizzled/field/datetime.h"
45
 
#include "drizzled/field/varstring.h"
46
 
#include "drizzled/field/uuid.h"
47
 
#include "drizzled/temporal.h"
48
 
#include "drizzled/item/string.h"
 
27
#include <drizzled/sql_select.h>
 
28
#include <drizzled/error.h>
 
29
#include <drizzled/field.h>
 
30
#include <drizzled/create_field.h>
 
31
#include <drizzled/field/str.h>
 
32
#include <drizzled/field/num.h>
 
33
#include <drizzled/field/blob.h>
 
34
#include <drizzled/field/boolean.h>
 
35
#include <drizzled/field/enum.h>
 
36
#include <drizzled/field/null.h>
 
37
#include <drizzled/field/date.h>
 
38
#include <drizzled/field/decimal.h>
 
39
#include <drizzled/field/real.h>
 
40
#include <drizzled/field/double.h>
 
41
#include <drizzled/field/int32.h>
 
42
#include <drizzled/field/int64.h>
 
43
#include <drizzled/field/num.h>
 
44
#include <drizzled/field/epoch.h>
 
45
#include <drizzled/field/datetime.h>
 
46
#include <drizzled/field/varstring.h>
 
47
#include <drizzled/field/uuid.h>
 
48
#include <drizzled/temporal.h>
 
49
#include <drizzled/item/string.h>
 
50
#include <drizzled/table.h>
 
51
 
 
52
#include <drizzled/display.h>
49
53
 
50
54
#include <algorithm>
51
55
 
71
75
 
72
76
  /* Fix if the original table had 4 byte pointer blobs */
73
77
  if (flags & BLOB_FLAG)
74
 
    pack_length= (pack_length - old_field->getTable()->getShare()->blob_ptr_size + portable_sizeof_char_ptr);
 
78
  {
 
79
    pack_length= (pack_length - old_field->getTable()->getShare()->sizeBlobPtr() + portable_sizeof_char_ptr);
 
80
  }
75
81
 
76
82
  switch (sql_type) 
77
83
  {
99
105
  if (!(flags & (NO_DEFAULT_VALUE_FLAG)) &&
100
106
      !(flags & AUTO_INCREMENT_FLAG) &&
101
107
      old_field->ptr && orig_field &&
102
 
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
 
108
      (not old_field->is_timestamp() ||                /* set def only if */
103
109
       old_field->getTable()->timestamp_field != old_field ||  /* timestamp field */
104
110
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
105
111
  {
140
146
      break;
141
147
    case DRIZZLE_TYPE_DECIMAL:
142
148
      key_length= pack_length=
143
 
        my_decimal_get_binary_size(my_decimal_length_to_precision(length,
 
149
        class_decimal_get_binary_size(class_decimal_length_to_precision(length,
144
150
                  decimals,
145
151
                  flags &
146
152
                  UNSIGNED_FLAG),
215
221
  interval= 0;
216
222
  pack_length= key_length= 0;
217
223
  charset= fld_charset;
218
 
  interval_list.empty();
 
224
  interval_list.clear();
219
225
 
220
226
  comment= *fld_comment;
221
227
 
224
230
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
225
231
  */
226
232
  if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
227
 
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
 
233
      (fld_type_modifier & NOT_NULL_FLAG) && (fld_type != DRIZZLE_TYPE_TIMESTAMP and fld_type != DRIZZLE_TYPE_MICROTIME))
 
234
  {
228
235
    flags|= NO_DEFAULT_VALUE_FLAG;
 
236
  }
229
237
 
230
238
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
231
239
    fld_length= 0;
246
254
    case DRIZZLE_TYPE_NULL:
247
255
      break;
248
256
    case DRIZZLE_TYPE_DECIMAL:
249
 
      my_decimal_trim(&length, &decimals);
 
257
      class_decimal_trim(&length, &decimals);
250
258
      if (length > DECIMAL_MAX_PRECISION)
251
259
      {
252
260
        my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
258
266
        my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
259
267
        return(true);
260
268
      }
261
 
      length= my_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
262
 
      pack_length= my_decimal_get_binary_size(length, decimals);
 
269
      length= class_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
 
270
      pack_length= class_decimal_get_binary_size(length, decimals);
263
271
      break;
264
272
    case DRIZZLE_TYPE_VARCHAR:
265
273
      /*
297
305
        return(true);
298
306
      }
299
307
      break;
 
308
    case DRIZZLE_TYPE_MICROTIME:
 
309
      /* 
 
310
        This assert() should be correct due to absence of length
 
311
        specifiers for timestamp. Previous manipulation also wasn't
 
312
        ever called (from examining lcov)
 
313
      */
 
314
      assert(fld_type);
300
315
    case DRIZZLE_TYPE_TIMESTAMP:
301
 
      if (!fld_length)
302
 
      {
303
 
        length= DateTime::MAX_STRING_LENGTH;
304
 
      }
305
 
 
306
 
      /* This assert() should be correct due to absence of length
307
 
         specifiers for timestamp. Previous manipulation also wasn't
308
 
         ever called (from examining lcov)
309
 
      */
310
 
      assert(length == (uint32_t)DateTime::MAX_STRING_LENGTH);
311
 
 
312
 
      flags|= UNSIGNED_FLAG;
 
316
      length= MicroTimestamp::MAX_STRING_LENGTH;
 
317
 
313
318
      if (fld_default_value)
314
319
      {
315
320
        /* Grammar allows only NOW() value for ON UPDATE clause */
325
330
          def= 0;
326
331
        }
327
332
        else
 
333
        {
328
334
          unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
329
 
                                              Field::NONE);
 
335
                         Field::NONE);
 
336
        }
330
337
      }
331
338
      else
332
339
      {
354
361
    case DRIZZLE_TYPE_UUID:
355
362
      length= field::Uuid::max_string_length();
356
363
      break;
 
364
    case DRIZZLE_TYPE_BOOLEAN:
 
365
      length= field::Boolean::max_string_length();
 
366
      break;
357
367
    case DRIZZLE_TYPE_DATETIME:
358
368
      length= DateTime::MAX_STRING_LENGTH;
359
369
      break;
 
370
    case DRIZZLE_TYPE_TIME:
 
371
      length= DateTime::MAX_STRING_LENGTH;
 
372
      break;
360
373
    case DRIZZLE_TYPE_ENUM:
361
374
      {
362
375
        /* Should be safe. */
363
376
        pack_length= 4;
364
377
 
365
 
        List_iterator<String> it(*fld_interval_list);
 
378
        List<String>::iterator it(*fld_interval_list);
366
379
        String *tmp;
367
380
        while ((tmp= it++))
368
381
          interval_list.push_back(tmp);
394
407
  return false; /* success */
395
408
}
396
409
 
 
410
std::ostream& operator<<(std::ostream& output, const CreateField &field)
 
411
{
 
412
  output << "CreateField:(";
 
413
  output <<  field.field_name;
 
414
  output << ", ";
 
415
  output << drizzled::display::type(field.type());
 
416
  output << ", { ";
 
417
 
 
418
  if (field.flags & NOT_NULL_FLAG)
 
419
    output << " NOT_NULL";
 
420
 
 
421
  if (field.flags & PRI_KEY_FLAG)
 
422
    output << ", PRIMARY KEY";
 
423
 
 
424
  if (field.flags & UNIQUE_KEY_FLAG)
 
425
    output << ", UNIQUE KEY";
 
426
 
 
427
  if (field.flags & MULTIPLE_KEY_FLAG)
 
428
    output << ", MULTIPLE KEY";
 
429
 
 
430
  if (field.flags & BLOB_FLAG)
 
431
    output << ", BLOB";
 
432
 
 
433
  if (field.flags & UNSIGNED_FLAG)
 
434
    output << ", UNSIGNED";
 
435
 
 
436
  if (field.flags & BINARY_FLAG)
 
437
    output << ", BINARY";
 
438
  output << "}, ";
 
439
  if (field.field)
 
440
    output << *field.field;
 
441
  output << ")";
 
442
 
 
443
  return output;  // for multiple << operators.
 
444
}
 
445
 
397
446
} /* namespace drizzled */