~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

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
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"
34
35
#include "drizzled/field/enum.h"
35
36
#include "drizzled/field/null.h"
36
37
#include "drizzled/field/date.h"
37
38
#include "drizzled/field/decimal.h"
38
39
#include "drizzled/field/real.h"
39
40
#include "drizzled/field/double.h"
40
 
#include "drizzled/field/long.h"
41
 
#include "drizzled/field/int64_t.h"
 
41
#include "drizzled/field/int32.h"
 
42
#include "drizzled/field/int64.h"
42
43
#include "drizzled/field/num.h"
43
 
#include "drizzled/field/timestamp.h"
 
44
#include "drizzled/field/epoch.h"
44
45
#include "drizzled/field/datetime.h"
45
46
#include "drizzled/field/varstring.h"
 
47
#include "drizzled/field/uuid.h"
46
48
#include "drizzled/temporal.h"
47
49
#include "drizzled/item/string.h"
48
50
 
 
51
#include "drizzled/display.h"
 
52
 
49
53
#include <algorithm>
50
54
 
51
55
using namespace std;
70
74
 
71
75
  /* Fix if the original table had 4 byte pointer blobs */
72
76
  if (flags & BLOB_FLAG)
73
 
    pack_length= (pack_length - old_field->getTable()->getShare()->blob_ptr_size + portable_sizeof_char_ptr);
 
77
  {
 
78
    pack_length= (pack_length - old_field->getTable()->getShare()->sizeBlobPtr() + portable_sizeof_char_ptr);
 
79
  }
74
80
 
75
81
  switch (sql_type) 
76
82
  {
98
104
  if (!(flags & (NO_DEFAULT_VALUE_FLAG)) &&
99
105
      !(flags & AUTO_INCREMENT_FLAG) &&
100
106
      old_field->ptr && orig_field &&
101
 
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
 
107
      (not old_field->is_timestamp() ||                /* set def only if */
102
108
       old_field->getTable()->timestamp_field != old_field ||  /* timestamp field */
103
109
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
104
110
  {
111
117
    {
112
118
      char buff[MAX_FIELD_WIDTH], *pos;
113
119
      String tmp(buff, sizeof(buff), charset), *res;
114
 
      res= orig_field->val_str(&tmp);
 
120
      res= orig_field->val_str_internal(&tmp);
115
121
      pos= (char*) memory::sql_strmake(res->ptr(), res->length());
116
122
      def= new Item_string(pos, res->length(), charset);
117
123
    }
139
145
      break;
140
146
    case DRIZZLE_TYPE_DECIMAL:
141
147
      key_length= pack_length=
142
 
        my_decimal_get_binary_size(my_decimal_length_to_precision(length,
 
148
        class_decimal_get_binary_size(class_decimal_length_to_precision(length,
143
149
                  decimals,
144
150
                  flags &
145
151
                  UNSIGNED_FLAG),
223
229
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
224
230
  */
225
231
  if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
226
 
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
 
232
      (fld_type_modifier & NOT_NULL_FLAG) && (fld_type != DRIZZLE_TYPE_TIMESTAMP and fld_type != DRIZZLE_TYPE_MICROTIME))
 
233
  {
227
234
    flags|= NO_DEFAULT_VALUE_FLAG;
 
235
  }
228
236
 
229
237
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
230
238
    fld_length= 0;
245
253
    case DRIZZLE_TYPE_NULL:
246
254
      break;
247
255
    case DRIZZLE_TYPE_DECIMAL:
248
 
      my_decimal_trim(&length, &decimals);
 
256
      class_decimal_trim(&length, &decimals);
249
257
      if (length > DECIMAL_MAX_PRECISION)
250
258
      {
251
259
        my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
257
265
        my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
258
266
        return(true);
259
267
      }
260
 
      length= my_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
261
 
      pack_length= my_decimal_get_binary_size(length, decimals);
 
268
      length= class_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
 
269
      pack_length= class_decimal_get_binary_size(length, decimals);
262
270
      break;
263
271
    case DRIZZLE_TYPE_VARCHAR:
264
272
      /*
296
304
        return(true);
297
305
      }
298
306
      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);
299
314
    case DRIZZLE_TYPE_TIMESTAMP:
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;
 
315
      length= MicroTimestamp::MAX_STRING_LENGTH;
 
316
 
312
317
      if (fld_default_value)
313
318
      {
314
319
        /* Grammar allows only NOW() value for ON UPDATE clause */
324
329
          def= 0;
325
330
        }
326
331
        else
 
332
        {
327
333
          unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
328
 
                                              Field::NONE);
 
334
                         Field::NONE);
 
335
        }
329
336
      }
330
337
      else
331
338
      {
350
357
    case DRIZZLE_TYPE_DATE:
351
358
      length= Date::MAX_STRING_LENGTH;
352
359
      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;
353
366
    case DRIZZLE_TYPE_DATETIME:
354
367
      length= DateTime::MAX_STRING_LENGTH;
355
368
      break;
 
369
    case DRIZZLE_TYPE_TIME:
 
370
      length= DateTime::MAX_STRING_LENGTH;
 
371
      break;
356
372
    case DRIZZLE_TYPE_ENUM:
357
373
      {
358
374
        /* Should be safe. */
390
406
  return false; /* success */
391
407
}
392
408
 
 
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
 
393
445
} /* namespace drizzled */