~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/create_field.cc

Added the testsuite location finding code to support in-plugin-dir test suites.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * @file Implementation of CreateField class
22
22
 */
23
23
 
24
 
#include "config.h"
 
24
#include "drizzled/server_includes.h"
25
25
#include <errno.h>
26
 
#include <float.h>
27
26
#include "drizzled/sql_select.h"
28
27
#include "drizzled/error.h"
29
28
#include "drizzled/field.h"
37
36
#include "drizzled/field/decimal.h"
38
37
#include "drizzled/field/real.h"
39
38
#include "drizzled/field/double.h"
40
 
#include "drizzled/field/int32.h"
41
 
#include "drizzled/field/int64.h"
 
39
#include "drizzled/field/long.h"
 
40
#include "drizzled/field/int64_t.h"
42
41
#include "drizzled/field/num.h"
43
42
#include "drizzled/field/timestamp.h"
44
43
#include "drizzled/field/datetime.h"
45
44
#include "drizzled/field/varstring.h"
46
 
#include "drizzled/field/uuid.h"
47
45
#include "drizzled/temporal.h"
48
 
#include "drizzled/item/string.h"
49
46
 
50
47
#include <algorithm>
51
48
 
52
49
using namespace std;
53
50
 
54
 
namespace drizzled
55
 
{
56
51
 
57
52
/** Create a field suitable for create of table. */
58
53
CreateField::CreateField(Field *old_field, Field *orig_field)
71
66
 
72
67
  /* Fix if the original table had 4 byte pointer blobs */
73
68
  if (flags & BLOB_FLAG)
74
 
    pack_length= (pack_length - old_field->getTable()->getShare()->blob_ptr_size + portable_sizeof_char_ptr);
 
69
    pack_length= (pack_length - old_field->table->s->blob_ptr_size + portable_sizeof_char_ptr);
75
70
 
76
71
  switch (sql_type) 
77
72
  {
89
84
      break;
90
85
  }
91
86
 
92
 
  if (flags & ENUM_FLAG)
 
87
  if (flags & (ENUM_FLAG | SET_FLAG))
93
88
    interval= ((Field_enum*) old_field)->typelib;
94
89
  else
95
90
    interval= 0;
96
91
  def= 0;
97
92
  char_length= length;
98
93
 
99
 
  if (!(flags & (NO_DEFAULT_VALUE_FLAG)) &&
100
 
      !(flags & AUTO_INCREMENT_FLAG) &&
 
94
  if (!(flags & (NO_DEFAULT_VALUE_FLAG )) &&
101
95
      old_field->ptr && orig_field &&
102
96
      (sql_type != DRIZZLE_TYPE_TIMESTAMP ||                /* set def only if */
103
 
       old_field->getTable()->timestamp_field != old_field ||  /* timestamp field */
 
97
       old_field->table->timestamp_field != old_field ||  /* timestamp field */
104
98
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
105
99
  {
106
100
    ptrdiff_t diff;
107
101
 
108
102
    /* Get the value from default_values */
109
 
    diff= (ptrdiff_t) (orig_field->getTable()->getDefaultValues() - orig_field->getTable()->getInsertRecord());
 
103
    diff= (ptrdiff_t) (orig_field->table->s->default_values - orig_field->table->record[0]);
110
104
    orig_field->move_field_offset(diff);        // Points now at default_values
111
105
    if (! orig_field->is_real_null())
112
106
    {
113
107
      char buff[MAX_FIELD_WIDTH], *pos;
114
108
      String tmp(buff, sizeof(buff), charset), *res;
115
 
      res= orig_field->val_str_internal(&tmp);
116
 
      pos= (char*) memory::sql_strmake(res->ptr(), res->length());
 
109
      res= orig_field->val_str(&tmp);
 
110
      pos= (char*) sql_strmake(res->ptr(), res->length());
117
111
      def= new Item_string(pos, res->length(), charset);
118
112
    }
119
 
    orig_field->move_field_offset(-diff);       // Back to getInsertRecord()
 
113
    orig_field->move_field_offset(-diff);       // Back to record[0]
120
114
  }
121
115
}
122
116
 
138
132
      length*= charset->mbmaxlen;
139
133
      key_length= pack_length;
140
134
      break;
141
 
    case DRIZZLE_TYPE_DECIMAL:
 
135
    case DRIZZLE_TYPE_NEWDECIMAL:
142
136
      key_length= pack_length=
143
137
        my_decimal_get_binary_size(my_decimal_length_to_precision(length,
144
138
                  decimals,
167
161
  interval= 0;
168
162
  charset= &my_charset_bin;
169
163
  decimals= decimals_arg & FIELDFLAG_MAX_DEC;
 
164
  pack_flag= 0;
170
165
 
171
166
  if (! maybe_null)
172
167
    flags= NOT_NULL_FLAG;
245
240
      break;
246
241
    case DRIZZLE_TYPE_NULL:
247
242
      break;
248
 
    case DRIZZLE_TYPE_DECIMAL:
 
243
    case DRIZZLE_TYPE_NEWDECIMAL:
249
244
      my_decimal_trim(&length, &decimals);
250
245
      if (length > DECIMAL_MAX_PRECISION)
251
246
      {
300
295
    case DRIZZLE_TYPE_TIMESTAMP:
301
296
      if (!fld_length)
302
297
      {
303
 
        length= DateTime::MAX_STRING_LENGTH;
 
298
        length= drizzled::DateTime::MAX_STRING_LENGTH;
304
299
      }
305
300
 
306
301
      /* This assert() should be correct due to absence of length
307
302
         specifiers for timestamp. Previous manipulation also wasn't
308
303
         ever called (from examining lcov)
309
304
      */
310
 
      assert(length == (uint32_t)DateTime::MAX_STRING_LENGTH);
 
305
      assert(length == (uint32_t)drizzled::DateTime::MAX_STRING_LENGTH);
311
306
 
312
307
      flags|= UNSIGNED_FLAG;
313
308
      if (fld_default_value)
349
344
      }
350
345
      break;
351
346
    case DRIZZLE_TYPE_DATE:
352
 
      length= Date::MAX_STRING_LENGTH;
353
 
      break;
354
 
    case DRIZZLE_TYPE_UUID:
355
 
      length= field::Uuid::max_string_length();
 
347
      length= drizzled::Date::MAX_STRING_LENGTH;
356
348
      break;
357
349
    case DRIZZLE_TYPE_DATETIME:
358
 
      length= DateTime::MAX_STRING_LENGTH;
 
350
      length= drizzled::DateTime::MAX_STRING_LENGTH;
359
351
      break;
360
352
    case DRIZZLE_TYPE_ENUM:
361
353
      {
362
354
        /* Should be safe. */
363
 
        pack_length= 4;
 
355
        pack_length= get_enum_pack_length(fld_interval_list->elements);
364
356
 
365
357
        List_iterator<String> it(*fld_interval_list);
366
358
        String *tmp;
393
385
 
394
386
  return false; /* success */
395
387
}
396
 
 
397
 
} /* namespace drizzled */