~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.cc

  • Committer: lbieber
  • Date: 2010-10-01 13:06:31 UTC
  • mfrom: (1802.2.2 drizzle-bug-651948)
  • mto: This revision was merged to the branch mainline in revision 1805.
  • Revision ID: lbieber@orisndriz08-20101001130631-xubscnhmj7r5dn6g
Merge Andrew - Fix bug 651948 - Index lengths not retrieved using drizzledump

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
 
#include "drizzled/item/string.h"
50
 
 
51
 
#include "drizzled/display.h"
52
47
 
53
48
#include <algorithm>
54
49
 
74
69
 
75
70
  /* Fix if the original table had 4 byte pointer blobs */
76
71
  if (flags & BLOB_FLAG)
77
 
  {
78
 
    pack_length= (pack_length - old_field->getTable()->getShare()->sizeBlobPtr() + portable_sizeof_char_ptr);
79
 
  }
 
72
    pack_length= (pack_length - old_field->getTable()->getShare()->blob_ptr_size + portable_sizeof_char_ptr);
80
73
 
81
74
  switch (sql_type) 
82
75
  {
104
97
  if (!(flags & (NO_DEFAULT_VALUE_FLAG)) &&
105
98
      !(flags & AUTO_INCREMENT_FLAG) &&
106
99
      old_field->ptr && orig_field &&
107
 
      (not old_field->is_timestamp() ||                /* set def only if */
 
100
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
108
101
       old_field->getTable()->timestamp_field != old_field ||  /* timestamp field */
109
102
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
110
103
  {
117
110
    {
118
111
      char buff[MAX_FIELD_WIDTH], *pos;
119
112
      String tmp(buff, sizeof(buff), charset), *res;
120
 
      res= orig_field->val_str_internal(&tmp);
 
113
      res= orig_field->val_str(&tmp);
121
114
      pos= (char*) memory::sql_strmake(res->ptr(), res->length());
122
115
      def= new Item_string(pos, res->length(), charset);
123
116
    }
145
138
      break;
146
139
    case DRIZZLE_TYPE_DECIMAL:
147
140
      key_length= pack_length=
148
 
        class_decimal_get_binary_size(class_decimal_length_to_precision(length,
 
141
        my_decimal_get_binary_size(my_decimal_length_to_precision(length,
149
142
                  decimals,
150
143
                  flags &
151
144
                  UNSIGNED_FLAG),
229
222
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
230
223
  */
231
224
  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
 
  {
 
225
      (fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
234
226
    flags|= NO_DEFAULT_VALUE_FLAG;
235
 
  }
236
227
 
237
228
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
238
229
    fld_length= 0;
253
244
    case DRIZZLE_TYPE_NULL:
254
245
      break;
255
246
    case DRIZZLE_TYPE_DECIMAL:
256
 
      class_decimal_trim(&length, &decimals);
 
247
      my_decimal_trim(&length, &decimals);
257
248
      if (length > DECIMAL_MAX_PRECISION)
258
249
      {
259
250
        my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
265
256
        my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
266
257
        return(true);
267
258
      }
268
 
      length= class_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
269
 
      pack_length= class_decimal_get_binary_size(length, decimals);
 
259
      length= my_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
 
260
      pack_length= my_decimal_get_binary_size(length, decimals);
270
261
      break;
271
262
    case DRIZZLE_TYPE_VARCHAR:
272
263
      /*
304
295
        return(true);
305
296
      }
306
297
      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
298
    case DRIZZLE_TYPE_TIMESTAMP:
315
 
      length= MicroTimestamp::MAX_STRING_LENGTH;
316
 
 
 
299
      if (!fld_length)
 
300
      {
 
301
        length= DateTime::MAX_STRING_LENGTH;
 
302
      }
 
303
 
 
304
      /* This assert() should be correct due to absence of length
 
305
         specifiers for timestamp. Previous manipulation also wasn't
 
306
         ever called (from examining lcov)
 
307
      */
 
308
      assert(length == (uint32_t)DateTime::MAX_STRING_LENGTH);
 
309
 
 
310
      flags|= UNSIGNED_FLAG;
317
311
      if (fld_default_value)
318
312
      {
319
313
        /* Grammar allows only NOW() value for ON UPDATE clause */
329
323
          def= 0;
330
324
        }
331
325
        else
332
 
        {
333
326
          unireg_check= (fld_on_update_value ? Field::TIMESTAMP_UN_FIELD:
334
 
                         Field::NONE);
335
 
        }
 
327
                                              Field::NONE);
336
328
      }
337
329
      else
338
330
      {
357
349
    case DRIZZLE_TYPE_DATE:
358
350
      length= Date::MAX_STRING_LENGTH;
359
351
      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
352
    case DRIZZLE_TYPE_DATETIME:
367
353
      length= DateTime::MAX_STRING_LENGTH;
368
354
      break;
369
 
    case DRIZZLE_TYPE_TIME:
370
 
      length= DateTime::MAX_STRING_LENGTH;
371
 
      break;
372
355
    case DRIZZLE_TYPE_ENUM:
373
356
      {
374
357
        /* Should be safe. */
406
389
  return false; /* success */
407
390
}
408
391
 
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
392
} /* namespace drizzled */