~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/definition/table.cc

  • Committer: Brian Aker
  • Date: 2010-12-20 19:20:57 UTC
  • mto: This revision was merged to the branch mainline in revision 2016.
  • Revision ID: brian@tangent.org-20101220192057-1ch4b9uo008d8rje
Merge in additional fixes for sign, plus alter table, plus TIME on
processlist.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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:
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/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"
79
81
 
80
82
#include "drizzled/definition/cache.h"
81
83
 
264
266
  case message::Table::Field::BLOB:
265
267
    field_type= DRIZZLE_TYPE_BLOB;
266
268
    break;
 
269
  case message::Table::Field::UUID:
 
270
    field_type= DRIZZLE_TYPE_UUID;
 
271
    break;
267
272
  default:
268
273
    assert(0);
269
274
    abort(); // Programming error
306
311
  case DRIZZLE_TYPE_DATETIME:
307
312
  case DRIZZLE_TYPE_DATE:
308
313
  case DRIZZLE_TYPE_ENUM:
 
314
  case DRIZZLE_TYPE_UUID:
309
315
    default_item= new Item_string(default_value->c_str(),
310
316
                                  default_value->length(),
311
317
                                  system_charset_info);
356
362
      size_t num_parts= index.index_part_size();
357
363
      for (size_t y= 0; y < num_parts; ++y)
358
364
      {
359
 
        if (index.index_part(y).fieldnr() == in_field->field_index)
 
365
        if (index.index_part(y).fieldnr() == in_field->position())
360
366
          return true;
361
367
      }
362
368
    }
393
399
  uniques(0),
394
400
  null_fields(0),
395
401
  blob_fields(0),
396
 
  timestamp_field_offset(0),
397
402
  has_variable_width(false),
398
403
  db_create_options(0),
399
404
  db_options_in_use(0),
459
464
  uniques(0),
460
465
  null_fields(0),
461
466
  blob_fields(0),
462
 
  timestamp_field_offset(0),
463
467
  has_variable_width(false),
464
468
  db_create_options(0),
465
469
  db_options_in_use(0),
535
539
  uniques(0),
536
540
  null_fields(0),
537
541
  blob_fields(0),
538
 
  timestamp_field_offset(0),
539
542
  has_variable_width(false),
540
543
  db_create_options(0),
541
544
  db_options_in_use(0),
614
617
  uniques(0),
615
618
  null_fields(0),
616
619
  blob_fields(0),
617
 
  timestamp_field_offset(0),
618
620
  has_variable_width(false),
619
621
  db_create_options(0),
620
622
  db_options_in_use(0),
1230
1232
    }
1231
1233
 
1232
1234
 
1233
 
    db_low_byte_first= true; //Cursor->low_byte_first();
1234
1235
    blob_ptr_size= portable_sizeof_char_ptr;
1235
1236
 
1236
1237
    uint32_t field_length= 0; //Assignment is for compiler complaint.
1315
1316
    case DRIZZLE_TYPE_LONGLONG:
1316
1317
      field_length= MAX_BIGINT_WIDTH;
1317
1318
      break;
 
1319
    case DRIZZLE_TYPE_UUID:
 
1320
      field_length= field::Uuid::max_string_length();
 
1321
      break;
1318
1322
    case DRIZZLE_TYPE_NULL:
1319
1323
      abort(); // Programming error
1320
1324
    }
1321
1325
 
1322
 
    Field* f= make_field(record + field_offsets[fieldnr] + data_offset,
1323
 
                                field_length,
1324
 
                                pfield.constraints().is_nullable(),
1325
 
                                null_pos,
1326
 
                                null_bit_pos,
1327
 
                                decimals,
1328
 
                                field_type,
1329
 
                                charset,
1330
 
                                MTYP_TYPENR(unireg_type),
1331
 
                                ((field_type == DRIZZLE_TYPE_ENUM) ?
1332
 
                                 &intervals[interval_nr++]
1333
 
                                 : (TYPELIB*) 0),
1334
 
                                getTableProto()->field(fieldnr).name().c_str());
 
1326
    assert(enum_field_types_size == 12);
 
1327
 
 
1328
    Field* f= make_field(pfield,
 
1329
                         record + field_offsets[fieldnr] + data_offset,
 
1330
                         field_length,
 
1331
                         pfield.constraints().is_nullable(),
 
1332
                         null_pos,
 
1333
                         null_bit_pos,
 
1334
                         decimals,
 
1335
                         field_type,
 
1336
                         charset,
 
1337
                         MTYP_TYPENR(unireg_type),
 
1338
                         ((field_type == DRIZZLE_TYPE_ENUM) ?  &intervals[interval_nr++] : (TYPELIB*) 0),
 
1339
                         getTableProto()->field(fieldnr).name().c_str());
1335
1340
 
1336
1341
    field[fieldnr]= f;
1337
1342
 
 
1343
    // Insert post make_field code here.
 
1344
    switch (field_type)
 
1345
    {
 
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:
 
1358
      break;
 
1359
    }
 
1360
 
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;
1365
1388
      }
1366
1389
    }
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))
1369
1391
    {
1370
1392
      f->set_notnull();
1371
1393
      f->store((int64_t) 1, true);
1379
1401
    f->setTable(NULL);
1380
1402
    f->orig_table= NULL;
1381
1403
 
1382
 
    f->field_index= fieldnr;
 
1404
    f->setPosition(fieldnr);
1383
1405
    f->comment= comment;
1384
1406
    if (! default_value &&
1385
1407
        ! (f->unireg_check==Field::NEXT_NUMBER) &&
1392
1414
    if (f->unireg_check == Field::NEXT_NUMBER)
1393
1415
      found_next_number_field= &(field[fieldnr]);
1394
1416
 
1395
 
    if (timestamp_field == f)
1396
 
      timestamp_field_offset= fieldnr;
1397
 
 
1398
1417
    if (use_hash) /* supposedly this never fails... but comments lie */
1399
1418
    {
1400
1419
      const char *local_field_name= field[fieldnr]->field_name;
1401
1420
      name_hash.insert(make_pair(local_field_name, &(field[fieldnr])));
1402
1421
    }
1403
 
 
1404
1422
  }
1405
1423
 
1406
1424
  keyinfo= key_info;
1425
1443
    We need to set the unused bits to 1. If the number of bits is a multiple
1426
1444
    of 8 there are no unused bits.
1427
1445
  */
1428
 
 
1429
1446
  if (null_count & 7)
1430
1447
    *(record + null_count / 8)|= ~(((unsigned char) 1 << (null_count & 7)) - 1);
1431
1448
 
1602
1619
    }
1603
1620
  }
1604
1621
 
1605
 
  db_low_byte_first= true; // @todo Question this.
1606
1622
  all_set.clear();
1607
1623
  all_set.resize(fields);
1608
1624
  all_set.set();
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);
1835
 
 
 
1850
    outparam.timestamp_field= (Field_timestamp*) outparam.getField(timestamp_field->position());
1836
1851
 
1837
1852
  /* Fix key->name and key_part->field */
1838
1853
  if (key_parts)
1997
2012
  return;
1998
2013
} /* open_table_error */
1999
2014
 
 
2015
Field *TableShare::make_field(message::Table::Field &pfield,
 
2016
                              unsigned char *ptr,
 
2017
                              uint32_t field_length,
 
2018
                              bool is_nullable,
 
2019
                              unsigned char *null_pos,
 
2020
                              unsigned char null_bit,
 
2021
                              uint8_t decimals,
 
2022
                              enum_field_types field_type,
 
2023
                              const CHARSET_INFO * field_charset,
 
2024
                              Field::utype unireg_check,
 
2025
                              TYPELIB *interval,
 
2026
                              const char *field_name)
 
2027
{
 
2028
  return make_field(ptr,
 
2029
                    field_length,
 
2030
                    is_nullable,
 
2031
                    null_pos,
 
2032
                    null_bit,
 
2033
                    decimals,
 
2034
                    field_type,
 
2035
                    field_charset,
 
2036
                    unireg_check,
 
2037
                    interval,
 
2038
                    field_name,
 
2039
                    pfield.constraints().is_unsigned());
 
2040
}
 
2041
 
2000
2042
Field *TableShare::make_field(unsigned char *ptr,
2001
2043
                              uint32_t field_length,
2002
2044
                              bool is_nullable,
2007
2049
                              const CHARSET_INFO * field_charset,
2008
2050
                              Field::utype unireg_check,
2009
2051
                              TYPELIB *interval,
2010
 
                              const char *field_name)
 
2052
                              const char *field_name, 
 
2053
                              bool is_unsigned)
2011
2054
{
2012
2055
  if (! is_nullable)
2013
2056
  {
2024
2067
  case DRIZZLE_TYPE_DATE:
2025
2068
  case DRIZZLE_TYPE_DATETIME:
2026
2069
  case DRIZZLE_TYPE_TIMESTAMP:
 
2070
  case DRIZZLE_TYPE_UUID:
2027
2071
    field_charset= &my_charset_bin;
2028
2072
  default: break;
2029
2073
  }
2072
2116
                                   decimals,
2073
2117
                                   false,
2074
2118
                                   false /* is_unsigned */);
 
2119
  case DRIZZLE_TYPE_UUID:
 
2120
    return new (&mem_root) field::Uuid(ptr,
 
2121
                                       field_length,
 
2122
                                       null_pos,
 
2123
                                       null_bit,
 
2124
                                       field_name);
2075
2125
  case DRIZZLE_TYPE_LONG:
2076
 
    return new (&mem_root) Field_long(ptr,
2077
 
                                 field_length,
2078
 
                                 null_pos,
2079
 
                                 null_bit,
2080
 
                                 unireg_check,
2081
 
                                 field_name,
2082
 
                                 false,
2083
 
                                 false /* is_unsigned */);
 
2126
    return new (&mem_root) field::Int32(ptr,
 
2127
                                        field_length,
 
2128
                                        null_pos,
 
2129
                                        null_bit,
 
2130
                                        unireg_check,
 
2131
                                        field_name);
2084
2132
  case DRIZZLE_TYPE_LONGLONG:
2085
 
    return new (&mem_root) Field_int64_t(ptr,
2086
 
                                    field_length,
2087
 
                                    null_pos,
2088
 
                                    null_bit,
2089
 
                                    unireg_check,
2090
 
                                    field_name,
2091
 
                                    false,
2092
 
                                    false /* is_unsigned */);
 
2133
    {
 
2134
      if (is_unsigned)
 
2135
      {
 
2136
        return new (&mem_root) field::Size(ptr,
 
2137
                                           field_length,
 
2138
                                           null_pos,
 
2139
                                           null_bit,
 
2140
                                           unireg_check,
 
2141
                                           field_name);
 
2142
      }
 
2143
 
 
2144
      return new (&mem_root) field::Int64(ptr,
 
2145
                                          field_length,
 
2146
                                          null_pos,
 
2147
                                          null_bit,
 
2148
                                          unireg_check,
 
2149
                                          field_name);
 
2150
    }
2093
2151
  case DRIZZLE_TYPE_TIMESTAMP:
2094
2152
    return new (&mem_root) Field_timestamp(ptr,
2095
2153
                                      field_length,
2116
2174
                                 field_length,
2117
2175
                                 field_name,
2118
2176
                                 field_charset);
2119
 
  default: // Impossible (Wrong version)
2120
 
    break;
2121
2177
  }
2122
 
  return 0;
 
2178
  assert(0);
 
2179
  abort();
2123
2180
}
2124
2181
 
2125
2182