~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.cc

  • Committer: Brian Aker
  • Date: 2010-11-11 18:59:06 UTC
  • mto: This revision was merged to the branch mainline in revision 1927.
  • Revision ID: brian@tangent.org-20101111185906-at4lyjpv9aewg3fz
Encapsulate temporary tables.

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, Inc.
 
4
 *  Copyright (C) 2008-2009 Sun Microsystems
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
31
31
#include "drizzled/field/str.h"
32
32
#include "drizzled/field/num.h"
33
33
#include "drizzled/field/blob.h"
34
 
#include "drizzled/field/boolean.h"
35
34
#include "drizzled/field/enum.h"
36
35
#include "drizzled/field/null.h"
37
36
#include "drizzled/field/date.h"
38
37
#include "drizzled/field/decimal.h"
39
38
#include "drizzled/field/real.h"
40
39
#include "drizzled/field/double.h"
41
 
#include "drizzled/field/int32.h"
42
 
#include "drizzled/field/int64.h"
 
40
#include "drizzled/field/long.h"
 
41
#include "drizzled/field/int64_t.h"
43
42
#include "drizzled/field/num.h"
44
 
#include "drizzled/field/epoch.h"
 
43
#include "drizzled/field/timestamp.h"
45
44
#include "drizzled/field/datetime.h"
46
45
#include "drizzled/field/varstring.h"
47
 
#include "drizzled/field/uuid.h"
48
46
#include "drizzled/temporal.h"
49
47
#include "drizzled/item/string.h"
50
48
 
51
 
#include "drizzled/display.h"
52
 
 
53
49
#include <algorithm>
54
50
 
55
51
using namespace std;
74
70
 
75
71
  /* Fix if the original table had 4 byte pointer blobs */
76
72
  if (flags & BLOB_FLAG)
77
 
  {
78
 
    pack_length= (pack_length - old_field->getTable()->getShare()->sizeBlobPtr() + portable_sizeof_char_ptr);
79
 
  }
 
73
    pack_length= (pack_length - old_field->getTable()->getShare()->blob_ptr_size + portable_sizeof_char_ptr);
80
74
 
81
75
  switch (sql_type) 
82
76
  {
104
98
  if (!(flags & (NO_DEFAULT_VALUE_FLAG)) &&
105
99
      !(flags & AUTO_INCREMENT_FLAG) &&
106
100
      old_field->ptr && orig_field &&
107
 
      (not old_field->is_timestamp() ||                /* set def only if */
 
101
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
108
102
       old_field->getTable()->timestamp_field != old_field ||  /* timestamp field */
109
103
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
110
104
  {
117
111
    {
118
112
      char buff[MAX_FIELD_WIDTH], *pos;
119
113
      String tmp(buff, sizeof(buff), charset), *res;
120
 
      res= orig_field->val_str_internal(&tmp);
 
114
      res= orig_field->val_str(&tmp);
121
115
      pos= (char*) memory::sql_strmake(res->ptr(), res->length());
122
116
      def= new Item_string(pos, res->length(), charset);
123
117
    }
145
139
      break;
146
140
    case DRIZZLE_TYPE_DECIMAL:
147
141
      key_length= pack_length=
148
 
        class_decimal_get_binary_size(class_decimal_length_to_precision(length,
 
142
        my_decimal_get_binary_size(my_decimal_length_to_precision(length,
149
143
                  decimals,
150
144
                  flags &
151
145
                  UNSIGNED_FLAG),
229
223
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
230
224
  */
231
225
  if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
232
 
      (fld_type_modifier & NOT_NULL_FLAG) && (fld_type != DRIZZLE_TYPE_TIMESTAMP and fld_type != DRIZZLE_TYPE_MICROTIME))
233
 
  {
 
226
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
234
227
    flags|= NO_DEFAULT_VALUE_FLAG;
235
 
  }
236
228
 
237
229
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
238
230
    fld_length= 0;
253
245
    case DRIZZLE_TYPE_NULL:
254
246
      break;
255
247
    case DRIZZLE_TYPE_DECIMAL:
256
 
      class_decimal_trim(&length, &decimals);
 
248
      my_decimal_trim(&length, &decimals);
257
249
      if (length > DECIMAL_MAX_PRECISION)
258
250
      {
259
251
        my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
265
257
        my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
266
258
        return(true);
267
259
      }
268
 
      length= class_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
269
 
      pack_length= class_decimal_get_binary_size(length, decimals);
 
260
      length= my_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
 
261
      pack_length= my_decimal_get_binary_size(length, decimals);
270
262
      break;
271
263
    case DRIZZLE_TYPE_VARCHAR:
272
264
      /*
304
296
        return(true);
305
297
      }
306
298
      break;
307
 
    case DRIZZLE_TYPE_MICROTIME:
308
 
      /* 
309
 
        This assert() should be correct due to absence of length
310
 
        specifiers for timestamp. Previous manipulation also wasn't
311
 
        ever called (from examining lcov)
312
 
      */
313
 
      assert(fld_type);
314
299
    case DRIZZLE_TYPE_TIMESTAMP:
315
 
      length= MicroTimestamp::MAX_STRING_LENGTH;
316
 
 
 
300
      if (!fld_length)
 
301
      {
 
302
        length= DateTime::MAX_STRING_LENGTH;
 
303
      }
 
304
 
 
305
      /* This assert() should be correct due to absence of length
 
306
         specifiers for timestamp. Previous manipulation also wasn't
 
307
         ever called (from examining lcov)
 
308
      */
 
309
      assert(length == (uint32_t)DateTime::MAX_STRING_LENGTH);
 
310
 
 
311
      flags|= UNSIGNED_FLAG;
317
312
      if (fld_default_value)
318
313
      {
319
314
        /* Grammar allows only NOW() value for ON UPDATE clause */
329
324
          def= 0;
330
325
        }
331
326
        else
332
 
        {
333
327
          unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
334
 
                         Field::NONE);
335
 
        }
 
328
                                              Field::NONE);
336
329
      }
337
330
      else
338
331
      {
357
350
    case DRIZZLE_TYPE_DATE:
358
351
      length= Date::MAX_STRING_LENGTH;
359
352
      break;
360
 
    case DRIZZLE_TYPE_UUID:
361
 
      length= field::Uuid::max_string_length();
362
 
      break;
363
 
    case DRIZZLE_TYPE_BOOLEAN:
364
 
      length= field::Boolean::max_string_length();
365
 
      break;
366
353
    case DRIZZLE_TYPE_DATETIME:
367
354
      length= DateTime::MAX_STRING_LENGTH;
368
355
      break;
369
 
    case DRIZZLE_TYPE_TIME:
370
 
      length= DateTime::MAX_STRING_LENGTH;
371
 
      break;
372
356
    case DRIZZLE_TYPE_ENUM:
373
357
      {
374
358
        /* Should be safe. */
406
390
  return false; /* success */
407
391
}
408
392
 
409
 
std::ostream& operator<<(std::ostream& output, const CreateField &field)
410
 
{
411
 
  output << "CreateField:(";
412
 
  output <<  field.field_name;
413
 
  output << ", ";
414
 
  output << drizzled::display::type(field.type());
415
 
  output << ", { ";
416
 
 
417
 
  if (field.flags & NOT_NULL_FLAG)
418
 
    output << " NOT_NULL";
419
 
 
420
 
  if (field.flags & PRI_KEY_FLAG)
421
 
    output << ", PRIMARY KEY";
422
 
 
423
 
  if (field.flags & UNIQUE_KEY_FLAG)
424
 
    output << ", UNIQUE KEY";
425
 
 
426
 
  if (field.flags & MULTIPLE_KEY_FLAG)
427
 
    output << ", MULTIPLE KEY";
428
 
 
429
 
  if (field.flags & BLOB_FLAG)
430
 
    output << ", BLOB";
431
 
 
432
 
  if (field.flags & UNSIGNED_FLAG)
433
 
    output << ", UNSIGNED";
434
 
 
435
 
  if (field.flags & BINARY_FLAG)
436
 
    output << ", BINARY";
437
 
  output << "}, ";
438
 
  if (field.field)
439
 
    output << *field.field;
440
 
  output << ")";
441
 
 
442
 
  return output;  // for multiple << operators.
443
 
}
444
 
 
445
393
} /* namespace drizzled */