~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/table.cc

  • Committer: Brian Aker
  • Date: 2010-12-07 09:12:12 UTC
  • mto: This revision was merged to the branch mainline in revision 1985.
  • Revision ID: brian@tangent.org-20101207091212-1m0w20tck6z7632m
This is a fix for bug lp:686197

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c++; c-basic-offset: 2; i/dent-tabs-mode: nil; -*-
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
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/int32.h"
74
 
#include "drizzled/field/int64.h"
 
73
#include "drizzled/field/long.h"
 
74
#include "drizzled/field/int64_t.h"
75
75
#include "drizzled/field/num.h"
76
76
#include "drizzled/field/timestamp.h"
77
77
#include "drizzled/field/datetime.h"
78
78
#include "drizzled/field/varstring.h"
79
 
#include "drizzled/field/uuid.h"
80
79
 
81
80
#include "drizzled/definition/cache.h"
82
81
 
265
264
  case message::Table::Field::BLOB:
266
265
    field_type= DRIZZLE_TYPE_BLOB;
267
266
    break;
268
 
  case message::Table::Field::UUID:
269
 
    field_type= DRIZZLE_TYPE_UUID;
270
 
    break;
271
267
  default:
272
 
    assert(0);
273
 
    abort(); // Programming error
 
268
    field_type= DRIZZLE_TYPE_LONG; /* Set value to kill GCC warning */
 
269
    assert(1);
274
270
  }
275
271
 
276
272
  return field_type;
304
300
                                 default_value->length());
305
301
    break;
306
302
  case DRIZZLE_TYPE_NULL:
307
 
    assert(0);
308
 
    abort();
 
303
    assert(false);
309
304
  case DRIZZLE_TYPE_TIMESTAMP:
310
305
  case DRIZZLE_TYPE_DATETIME:
311
306
  case DRIZZLE_TYPE_DATE:
312
307
  case DRIZZLE_TYPE_ENUM:
313
 
  case DRIZZLE_TYPE_UUID:
314
308
    default_item= new Item_string(default_value->c_str(),
315
309
                                  default_value->length(),
316
310
                                  system_charset_info);
361
355
      size_t num_parts= index.index_part_size();
362
356
      for (size_t y= 0; y < num_parts; ++y)
363
357
      {
364
 
        if (index.index_part(y).fieldnr() == in_field->position())
 
358
        if (index.index_part(y).fieldnr() == in_field->field_index)
365
359
          return true;
366
360
      }
367
361
    }
398
392
  uniques(0),
399
393
  null_fields(0),
400
394
  blob_fields(0),
 
395
  timestamp_field_offset(0),
401
396
  has_variable_width(false),
402
397
  db_create_options(0),
403
398
  db_options_in_use(0),
463
458
  uniques(0),
464
459
  null_fields(0),
465
460
  blob_fields(0),
 
461
  timestamp_field_offset(0),
466
462
  has_variable_width(false),
467
463
  db_create_options(0),
468
464
  db_options_in_use(0),
538
534
  uniques(0),
539
535
  null_fields(0),
540
536
  blob_fields(0),
 
537
  timestamp_field_offset(0),
541
538
  has_variable_width(false),
542
539
  db_create_options(0),
543
540
  db_options_in_use(0),
616
613
  uniques(0),
617
614
  null_fields(0),
618
615
  blob_fields(0),
 
616
  timestamp_field_offset(0),
619
617
  has_variable_width(false),
620
618
  db_create_options(0),
621
619
  db_options_in_use(0),
673
671
  else
674
672
  {
675
673
    assert(0); // We should throw here.
676
 
    abort();
677
674
  }
678
675
}
679
676
 
1135
1132
        unireg_type= Field::TIMESTAMP_DN_FIELD;
1136
1133
      }
1137
1134
      else
1138
 
      {
1139
 
        assert(0); // Invalid update value.
1140
 
        abort();
1141
 
      }
 
1135
        assert(1); // Invalid update value.
1142
1136
    }
1143
1137
    else if (pfield.has_options() &&
1144
1138
             pfield.options().has_update_expression() &&
1231
1225
    }
1232
1226
 
1233
1227
 
 
1228
    db_low_byte_first= true; //Cursor->low_byte_first();
1234
1229
    blob_ptr_size= portable_sizeof_char_ptr;
1235
1230
 
1236
1231
    uint32_t field_length= 0; //Assignment is for compiler complaint.
1315
1310
    case DRIZZLE_TYPE_LONGLONG:
1316
1311
      field_length= MAX_BIGINT_WIDTH;
1317
1312
      break;
1318
 
    case DRIZZLE_TYPE_UUID:
1319
 
      field_length= field::Uuid::max_string_length();
1320
 
      break;
1321
1313
    case DRIZZLE_TYPE_NULL:
1322
1314
      abort(); // Programming error
1323
1315
    }
1324
1316
 
1325
 
    assert(enum_field_types_size == 12);
1326
 
 
1327
1317
    Field* f= make_field(record + field_offsets[fieldnr] + data_offset,
1328
 
                         field_length,
1329
 
                         pfield.constraints().is_nullable(),
1330
 
                         null_pos,
1331
 
                         null_bit_pos,
1332
 
                         decimals,
1333
 
                         field_type,
1334
 
                         charset,
1335
 
                         MTYP_TYPENR(unireg_type),
1336
 
                         ((field_type == DRIZZLE_TYPE_ENUM) ?  &intervals[interval_nr++] : (TYPELIB*) 0),
1337
 
                         getTableProto()->field(fieldnr).name().c_str());
 
1318
                                field_length,
 
1319
                                pfield.constraints().is_nullable(),
 
1320
                                null_pos,
 
1321
                                null_bit_pos,
 
1322
                                decimals,
 
1323
                                field_type,
 
1324
                                charset,
 
1325
                                MTYP_TYPENR(unireg_type),
 
1326
                                ((field_type == DRIZZLE_TYPE_ENUM) ?
 
1327
                                 &intervals[interval_nr++]
 
1328
                                 : (TYPELIB*) 0),
 
1329
                                getTableProto()->field(fieldnr).name().c_str());
1338
1330
 
1339
1331
    field[fieldnr]= f;
1340
1332
 
1341
 
    // Insert post make_field code here.
1342
 
    switch (field_type)
1343
 
    {
1344
 
    case DRIZZLE_TYPE_BLOB:
1345
 
    case DRIZZLE_TYPE_VARCHAR:
1346
 
    case DRIZZLE_TYPE_DOUBLE:
1347
 
    case DRIZZLE_TYPE_DECIMAL:
1348
 
    case DRIZZLE_TYPE_TIMESTAMP:
1349
 
    case DRIZZLE_TYPE_DATETIME:
1350
 
    case DRIZZLE_TYPE_DATE:
1351
 
    case DRIZZLE_TYPE_ENUM:
1352
 
    case DRIZZLE_TYPE_LONG:
1353
 
    case DRIZZLE_TYPE_LONGLONG:
1354
 
    case DRIZZLE_TYPE_NULL:
1355
 
    case DRIZZLE_TYPE_UUID:
1356
 
      break;
1357
 
    }
1358
 
 
1359
1333
    // This needs to go, we should be setting the "use" on the field so that
1360
1334
    // it does not reference the share/table.
1361
1335
    table::Shell temp_table(*this); /* Use this so that BLOB DEFAULT '' works */
1385
1359
        return local_error;
1386
1360
      }
1387
1361
    }
1388
 
    else if (f->real_type() == DRIZZLE_TYPE_ENUM && (f->flags & NOT_NULL_FLAG))
 
1362
    else if (f->real_type() == DRIZZLE_TYPE_ENUM &&
 
1363
             (f->flags & NOT_NULL_FLAG))
1389
1364
    {
1390
1365
      f->set_notnull();
1391
1366
      f->store((int64_t) 1, true);
1399
1374
    f->setTable(NULL);
1400
1375
    f->orig_table= NULL;
1401
1376
 
1402
 
    f->setPosition(fieldnr);
 
1377
    f->field_index= fieldnr;
1403
1378
    f->comment= comment;
1404
1379
    if (! default_value &&
1405
1380
        ! (f->unireg_check==Field::NEXT_NUMBER) &&
1412
1387
    if (f->unireg_check == Field::NEXT_NUMBER)
1413
1388
      found_next_number_field= &(field[fieldnr]);
1414
1389
 
 
1390
    if (timestamp_field == f)
 
1391
      timestamp_field_offset= fieldnr;
 
1392
 
1415
1393
    if (use_hash) /* supposedly this never fails... but comments lie */
1416
1394
    {
1417
1395
      const char *local_field_name= field[fieldnr]->field_name;
1418
1396
      name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1419
1397
    }
 
1398
 
1420
1399
  }
1421
1400
 
1422
1401
  keyinfo= key_info;
1441
1420
    We need to set the unused bits to 1. If the number of bits is a multiple
1442
1421
    of 8 there are no unused bits.
1443
1422
  */
 
1423
 
1444
1424
  if (null_count & 7)
1445
1425
    *(record + null_count / 8)|= ~(((unsigned char) 1 << (null_count & 7)) - 1);
1446
1426
 
1617
1597
    }
1618
1598
  }
1619
1599
 
 
1600
  db_low_byte_first= true; // @todo Question this.
1620
1601
  all_set.clear();
1621
1602
  all_set.resize(fields);
1622
1603
  all_set.set();
1845
1826
    outparam.found_next_number_field=
1846
1827
      outparam.getField(positionFields(found_next_number_field));
1847
1828
  if (timestamp_field)
1848
 
    outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field->position());
 
1829
    outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field_offset);
 
1830
 
1849
1831
 
1850
1832
  /* Fix key->name and key_part->field */
1851
1833
  if (key_parts)
2037
2019
  case DRIZZLE_TYPE_DATE:
2038
2020
  case DRIZZLE_TYPE_DATETIME:
2039
2021
  case DRIZZLE_TYPE_TIMESTAMP:
2040
 
  case DRIZZLE_TYPE_UUID:
2041
2022
    field_charset= &my_charset_bin;
2042
2023
  default: break;
2043
2024
  }
2086
2067
                                   decimals,
2087
2068
                                   false,
2088
2069
                                   false /* is_unsigned */);
2089
 
  case DRIZZLE_TYPE_UUID:
2090
 
    return new (&mem_root) field::Uuid(ptr,
2091
 
                                       field_length,
2092
 
                                       null_pos,
2093
 
                                       null_bit,
2094
 
                                       field_name);
2095
2070
  case DRIZZLE_TYPE_LONG:
2096
 
    return new (&mem_root) field::Int32(ptr,
2097
 
                                        field_length,
2098
 
                                        null_pos,
2099
 
                                        null_bit,
2100
 
                                        unireg_check,
2101
 
                                        field_name);
 
2071
    return new (&mem_root) Field_long(ptr,
 
2072
                                 field_length,
 
2073
                                 null_pos,
 
2074
                                 null_bit,
 
2075
                                 unireg_check,
 
2076
                                 field_name,
 
2077
                                 false,
 
2078
                                 false /* is_unsigned */);
2102
2079
  case DRIZZLE_TYPE_LONGLONG:
2103
 
    return new (&mem_root) field::Int64(ptr,
2104
 
                                        field_length,
2105
 
                                        null_pos,
2106
 
                                        null_bit,
2107
 
                                        unireg_check,
2108
 
                                        field_name);
 
2080
    return new (&mem_root) Field_int64_t(ptr,
 
2081
                                    field_length,
 
2082
                                    null_pos,
 
2083
                                    null_bit,
 
2084
                                    unireg_check,
 
2085
                                    field_name,
 
2086
                                    false,
 
2087
                                    false /* is_unsigned */);
2109
2088
  case DRIZZLE_TYPE_TIMESTAMP:
2110
2089
    return new (&mem_root) Field_timestamp(ptr,
2111
2090
                                      field_length,
2132
2111
                                 field_length,
2133
2112
                                 field_name,
2134
2113
                                 field_charset);
 
2114
  default: // Impossible (Wrong version)
 
2115
    break;
2135
2116
  }
2136
 
  assert(0);
2137
 
  abort();
 
2117
  return 0;
2138
2118
}
2139
2119
 
2140
2120