1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
1
/* -*- mode: c++; c-basic-offset: 2; i/dent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
4
* Copyright (C) 2010 Brian Aker
70
70
#include "drizzled/field/decimal.h"
71
71
#include "drizzled/field/real.h"
72
72
#include "drizzled/field/double.h"
73
#include "drizzled/field/long.h"
74
#include "drizzled/field/int64_t.h"
73
#include "drizzled/field/int32.h"
74
#include "drizzled/field/int64.h"
75
#include "drizzled/field/size.h"
75
76
#include "drizzled/field/num.h"
76
77
#include "drizzled/field/timestamp.h"
77
78
#include "drizzled/field/datetime.h"
78
79
#include "drizzled/field/varstring.h"
80
#include "drizzled/field/uuid.h"
80
82
#include "drizzled/definition/cache.h"
264
266
case message::Table::Field::BLOB:
265
267
field_type= DRIZZLE_TYPE_BLOB;
269
case message::Table::Field::UUID:
270
field_type= DRIZZLE_TYPE_UUID;
269
274
abort(); // Programming error
1315
1316
case DRIZZLE_TYPE_LONGLONG:
1316
1317
field_length= MAX_BIGINT_WIDTH;
1319
case DRIZZLE_TYPE_UUID:
1320
field_length= field::Uuid::max_string_length();
1318
1322
case DRIZZLE_TYPE_NULL:
1319
1323
abort(); // Programming error
1322
Field* f= make_field(record + field_offsets[fieldnr] + data_offset,
1324
pfield.constraints().is_nullable(),
1330
MTYP_TYPENR(unireg_type),
1331
((field_type == DRIZZLE_TYPE_ENUM) ?
1332
&intervals[interval_nr++]
1334
getTableProto()->field(fieldnr).name().c_str());
1326
assert(enum_field_types_size == 12);
1328
Field* f= make_field(pfield,
1329
record + field_offsets[fieldnr] + data_offset,
1331
pfield.constraints().is_nullable(),
1337
MTYP_TYPENR(unireg_type),
1338
((field_type == DRIZZLE_TYPE_ENUM) ? &intervals[interval_nr++] : (TYPELIB*) 0),
1339
getTableProto()->field(fieldnr).name().c_str());
1336
1341
field[fieldnr]= f;
1343
// Insert post make_field code here.
1346
case DRIZZLE_TYPE_BLOB:
1347
case DRIZZLE_TYPE_VARCHAR:
1348
case DRIZZLE_TYPE_DOUBLE:
1349
case DRIZZLE_TYPE_DECIMAL:
1350
case DRIZZLE_TYPE_TIMESTAMP:
1351
case DRIZZLE_TYPE_DATETIME:
1352
case DRIZZLE_TYPE_DATE:
1353
case DRIZZLE_TYPE_ENUM:
1354
case DRIZZLE_TYPE_LONG:
1355
case DRIZZLE_TYPE_LONGLONG:
1356
case DRIZZLE_TYPE_NULL:
1357
case DRIZZLE_TYPE_UUID:
1338
1361
// This needs to go, we should be setting the "use" on the field so that
1339
1362
// it does not reference the share/table.
1340
1363
table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1364
1387
return local_error;
1367
else if (f->real_type() == DRIZZLE_TYPE_ENUM &&
1368
(f->flags & NOT_NULL_FLAG))
1390
else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
1370
1392
f->set_notnull();
1371
1393
f->store((int64_t) 1, true);
1392
1414
if (f->unireg_check == Field::NEXT_NUMBER)
1393
1415
found_next_number_field= &(field[fieldnr]);
1395
if (timestamp_field == f)
1396
timestamp_field_offset= fieldnr;
1398
1417
if (use_hash) /* supposedly this never fails... but comments lie */
1400
1419
const char *local_field_name= field[fieldnr]->field_name;
1401
1420
name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1406
1424
keyinfo= key_info;
1831
1847
outparam.found_next_number_field=
1832
1848
outparam.getField(positionFields(found_next_number_field));
1833
1849
if (timestamp_field)
1834
outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field_offset);
1850
outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field->position());
1837
1852
/* Fix key->name and key_part->field */
1998
2013
} /* open_table_error */
2015
Field *TableShare::make_field(message::Table::Field &pfield,
2017
uint32_t field_length,
2019
unsigned char *null_pos,
2020
unsigned char null_bit,
2022
enum_field_types field_type,
2023
const CHARSET_INFO * field_charset,
2024
Field::utype unireg_check,
2026
const char *field_name)
2028
return make_field(ptr,
2039
pfield.constraints().is_unsigned());
2000
2042
Field *TableShare::make_field(unsigned char *ptr,
2001
2043
uint32_t field_length,
2002
2044
bool is_nullable,
2074
2118
false /* is_unsigned */);
2119
case DRIZZLE_TYPE_UUID:
2120
return new (&mem_root) field::Uuid(ptr,
2075
2125
case DRIZZLE_TYPE_LONG:
2076
return new (&mem_root) Field_long(ptr,
2083
false /* is_unsigned */);
2126
return new (&mem_root) field::Int32(ptr,
2084
2132
case DRIZZLE_TYPE_LONGLONG:
2085
return new (&mem_root) Field_int64_t(ptr,
2092
false /* is_unsigned */);
2136
return new (&mem_root) field::Size(ptr,
2144
return new (&mem_root) field::Int64(ptr,
2093
2151
case DRIZZLE_TYPE_TIMESTAMP:
2094
2152
return new (&mem_root) Field_timestamp(ptr,