1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
4
* Copyright (C) 2008-2009 Sun Microsystems
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
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>
52
#include <drizzled/display.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/long.h"
41
#include "drizzled/field/int64_t.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/temporal.h"
47
#include "drizzled/item/string.h"
54
49
#include <algorithm>
105
98
if (!(flags & (NO_DEFAULT_VALUE_FLAG)) &&
106
99
!(flags & AUTO_INCREMENT_FLAG) &&
107
100
old_field->ptr && orig_field &&
108
(not old_field->is_timestamp() || /* set def only if */
101
(sql_type != DRIZZLE_TYPE_TIMESTAMP || /* set def only if */
109
102
old_field->getTable()->timestamp_field != old_field || /* timestamp field */
110
103
unireg_check == Field::TIMESTAMP_UN_FIELD)) /* has default val */
119
112
char buff[MAX_FIELD_WIDTH], *pos;
120
113
String tmp(buff, sizeof(buff), charset), *res;
121
res= orig_field->val_str_internal(&tmp);
114
res= orig_field->val_str(&tmp);
122
115
pos= (char*) memory::sql_strmake(res->ptr(), res->length());
123
116
def= new Item_string(pos, res->length(), charset);
230
223
it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
232
225
if (!fld_default_value && !(fld_type_modifier & AUTO_INCREMENT_FLAG) &&
233
(fld_type_modifier & NOT_NULL_FLAG) && (fld_type != DRIZZLE_TYPE_TIMESTAMP and fld_type != DRIZZLE_TYPE_MICROTIME))
226
(fld_type_modifier & NOT_NULL_FLAG) && fld_type != DRIZZLE_TYPE_TIMESTAMP)
235
227
flags|= NO_DEFAULT_VALUE_FLAG;
238
229
if (fld_length && !(length= (uint32_t) atoi(fld_length)))
254
245
case DRIZZLE_TYPE_NULL:
256
247
case DRIZZLE_TYPE_DECIMAL:
257
class_decimal_trim(&length, &decimals);
248
my_decimal_trim(&length, &decimals);
258
249
if (length > DECIMAL_MAX_PRECISION)
260
251
my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
266
257
my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
269
length= class_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
270
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);
272
263
case DRIZZLE_TYPE_VARCHAR:
308
case DRIZZLE_TYPE_MICROTIME:
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)
315
299
case DRIZZLE_TYPE_TIMESTAMP:
316
length= MicroTimestamp::MAX_STRING_LENGTH;
302
length= DateTime::MAX_STRING_LENGTH;
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)
309
assert(length == (uint32_t)DateTime::MAX_STRING_LENGTH);
311
flags|= UNSIGNED_FLAG;
318
312
if (fld_default_value)
320
314
/* Grammar allows only NOW() value for ON UPDATE clause */
358
350
case DRIZZLE_TYPE_DATE:
359
351
length= Date::MAX_STRING_LENGTH;
361
case DRIZZLE_TYPE_UUID:
362
length= field::Uuid::max_string_length();
364
case DRIZZLE_TYPE_BOOLEAN:
365
length= field::Boolean::max_string_length();
367
353
case DRIZZLE_TYPE_DATETIME:
368
354
length= DateTime::MAX_STRING_LENGTH;
370
case DRIZZLE_TYPE_TIME:
371
length= DateTime::MAX_STRING_LENGTH;
373
356
case DRIZZLE_TYPE_ENUM:
375
358
/* Should be safe. */
378
List<String>::iterator it(fld_interval_list->begin());
361
List_iterator<String> it(*fld_interval_list);
380
363
while ((tmp= it++))
381
364
interval_list.push_back(tmp);
407
390
return false; /* success */
410
std::ostream& operator<<(std::ostream& output, const CreateField &field)
412
output << "CreateField:(";
413
output << field.field_name;
415
output << drizzled::display::type(field.type());
418
if (field.flags & NOT_NULL_FLAG)
419
output << " NOT_NULL";
421
if (field.flags & PRI_KEY_FLAG)
422
output << ", PRIMARY KEY";
424
if (field.flags & UNIQUE_KEY_FLAG)
425
output << ", UNIQUE KEY";
427
if (field.flags & MULTIPLE_KEY_FLAG)
428
output << ", MULTIPLE KEY";
430
if (field.flags & BLOB_FLAG)
433
if (field.flags & UNSIGNED_FLAG)
434
output << ", UNSIGNED";
436
if (field.flags & BINARY_FLAG)
437
output << ", BINARY";
440
output << *field.field;
443
return output; // for multiple << operators.
446
393
} /* namespace drizzled */