~drizzle-trunk/drizzle/development

1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
/**
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
21
 * @file Implementation of CreateField class
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
22
 */
23
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
24
#include <config.h>
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
25
#include <errno.h>
1241.9.1 by Monty Taylor
Removed global.h. Fixed all the headers.
26
#include <float.h>
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
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>
2154.2.18 by Brian Aker
Merge in all changes for include files.
50
#include <drizzled/table.h>
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
51
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
52
#include <drizzled/display.h>
2008.2.4 by Brian Aker
Merge in additional fixes for sign, plus alter table, plus TIME on
53
1067.4.1 by Nathan Williams
First few changes at converting cmin to std::min.
54
#include <algorithm>
55
56
using namespace std;
57
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
58
namespace drizzled
59
{
1067.4.1 by Nathan Williams
First few changes at converting cmin to std::min.
60
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
61
/** Create a field suitable for create of table. */
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
62
CreateField::CreateField(Field *old_field, Field *orig_field)
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
63
{
64
  field= old_field;
65
  field_name= change= old_field->field_name;
66
  length= old_field->field_length;
67
  flags= old_field->flags;
68
  unireg_check= old_field->unireg_check;
69
  pack_length= old_field->pack_length();
70
  key_length= old_field->key_length();
71
  sql_type= old_field->real_type();
72
  charset= old_field->charset(); // May be NULL ptr
73
  comment= old_field->comment;
74
  decimals= old_field->decimals();
75
76
  /* Fix if the original table had 4 byte pointer blobs */
77
  if (flags & BLOB_FLAG)
2134.1.4 by Brian Aker
Simple encapsulation for table.
78
  {
79
    pack_length= (pack_length - old_field->getTable()->getShare()->sizeBlobPtr() + portable_sizeof_char_ptr);
80
  }
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
81
82
  switch (sql_type) 
83
  {
84
    case DRIZZLE_TYPE_BLOB:
85
      sql_type= DRIZZLE_TYPE_BLOB;
86
      length/= charset->mbmaxlen;
87
      key_length/= charset->mbmaxlen;
88
      break;
89
    case DRIZZLE_TYPE_ENUM:
90
    case DRIZZLE_TYPE_VARCHAR:
91
      /* This is corrected in create_length_to_internal_length */
92
      length= (length+charset->mbmaxlen-1) / charset->mbmaxlen;
93
      break;
94
    default:
95
      break;
96
  }
97
1315.2.15 by Stewart Smith
remove the now unused SET_FLAG define. We don't have the SET field type, and this flag was never set.
98
  if (flags & ENUM_FLAG)
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
99
    interval= ((Field_enum*) old_field)->typelib;
100
  else
101
    interval= 0;
102
  def= 0;
103
  char_length= length;
104
1638.10.114 by Stewart Smith
when creating a CreateField from a Field, a auto_incremen column should not have a default value of 0 as that's not magic.
105
  if (!(flags & (NO_DEFAULT_VALUE_FLAG)) &&
106
      !(flags & AUTO_INCREMENT_FLAG) &&
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
107
      old_field->ptr && orig_field &&
2046.2.1 by Brian Aker
First pass on micro timestamp.
108
      (not old_field->is_timestamp() ||                /* set def only if */
1660.1.3 by Brian Aker
Encapsulate Table in field
109
       old_field->getTable()->timestamp_field != old_field ||  /* timestamp field */
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
110
       unireg_check == Field::TIMESTAMP_UN_FIELD))        /* has default val */
111
  {
112
    ptrdiff_t diff;
113
114
    /* Get the value from default_values */
1672.3.6 by Brian Aker
First pass in encapsulating row
115
    diff= (ptrdiff_t) (orig_field->getTable()->getDefaultValues() - orig_field->getTable()->getInsertRecord());
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
116
    orig_field->move_field_offset(diff);	// Points now at default_values
117
    if (! orig_field->is_real_null())
118
    {
119
      char buff[MAX_FIELD_WIDTH], *pos;
120
      String tmp(buff, sizeof(buff), charset), *res;
1996.2.1 by Brian Aker
uuid type code.
121
      res= orig_field->val_str_internal(&tmp);
1253.1.6 by Monty Taylor
Moved mem_root functions into drizzled::memory:: namespace.
122
      pos= (char*) memory::sql_strmake(res->ptr(), res->length());
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
123
      def= new Item_string(pos, res->length(), charset);
124
    }
1672.3.6 by Brian Aker
First pass in encapsulating row
125
    orig_field->move_field_offset(-diff);	// Back to getInsertRecord()
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
126
  }
127
}
128
129
/**
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
130
  Convert CreateField::length from number of characters to number of bytes.
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
131
*/
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
132
void CreateField::create_length_to_internal_length(void)
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
133
{
134
  switch (sql_type) 
135
  {
136
    case DRIZZLE_TYPE_BLOB:
137
    case DRIZZLE_TYPE_VARCHAR:
138
      length*= charset->mbmaxlen;
139
      key_length= length;
140
      pack_length= calc_pack_length(sql_type, length);
141
      break;
142
    case DRIZZLE_TYPE_ENUM:
143
      /* Pack_length already calculated in ::init() */
144
      length*= charset->mbmaxlen;
145
      key_length= pack_length;
146
      break;
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
147
    case DRIZZLE_TYPE_DECIMAL:
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
148
      key_length= pack_length=
2030.1.2 by Brian Aker
First pass in refactoring of the name of my_decimal.
149
        class_decimal_get_binary_size(class_decimal_length_to_precision(length,
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
150
                  decimals,
151
                  flags &
152
                  UNSIGNED_FLAG),
153
          decimals);
154
      break;
155
    default:
156
      key_length= pack_length= calc_pack_length(sql_type, length);
157
      break;
158
  }
159
}
160
161
/**
162
  Init for a tmp table field. To be extended if need be.
163
*/
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
164
void CreateField::init_for_tmp_table(enum_field_types sql_type_arg,
1119.9.10 by Jay Pipes
Removes FIELDFLAG_MAYBE_NULL and f_maybe_null() macro.
165
                                     uint32_t length_arg,
166
                                     uint32_t decimals_arg,
1119.9.18 by Stewart Smith
Fix maybe_null for CreateField created for temp table in item/sum.cc (Item_sum_distinct)
167
                                     bool maybe_null)
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
168
{
169
  field_name= "";
170
  sql_type= sql_type_arg;
171
  char_length= length= length_arg;;
172
  unireg_check= Field::NONE;
173
  interval= 0;
174
  charset= &my_charset_bin;
1119.9.16 by Stewart Smith
don't store decimal/double scale in pack_flag, instead use the numeric option scale field in the table proto. This removes f_decimals() macro and the bits in the pack_flag for scale.
175
  decimals= decimals_arg & FIELDFLAG_MAX_DEC;
1119.9.18 by Stewart Smith
Fix maybe_null for CreateField created for temp table in item/sum.cc (Item_sum_distinct)
176
177
  if (! maybe_null)
178
    flags= NOT_NULL_FLAG;
179
  else
180
    flags= 0;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
181
}
182
1052.2.7 by Nathan Williams
Merged trunk and resolved conflicts.
183
bool CreateField::init(Session *,
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
184
                        char *fld_name,
185
                        enum_field_types fld_type,
186
                        char *fld_length,
187
                        char *fld_decimals,
188
                        uint32_t fld_type_modifier,
189
                        LEX_STRING *fld_comment,
190
                        char *fld_change,
191
                        List<String> *fld_interval_list,
2254 by Brian Aker
Shift CHARSET_INFO to charset_info_st
192
                        const charset_info_st * const fld_charset,
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
193
                        uint32_t,
194
                        enum column_format_type column_format_in)
195
{
196
  uint32_t sign_len= 0;
197
  uint32_t allowed_type_modifier= 0;
198
  uint32_t max_field_charlength= MAX_FIELD_CHARLENGTH;
199
200
  field= 0;
201
  field_name= fld_name;
202
  flags= fld_type_modifier;
203
  flags|= (((uint32_t)column_format_in & COLUMN_FORMAT_MASK) << COLUMN_FORMAT_FLAGS);
204
  unireg_check= (fld_type_modifier & AUTO_INCREMENT_FLAG ?
205
                 Field::NEXT_NUMBER : Field::NONE);
206
  decimals= fld_decimals ? (uint32_t)atoi(fld_decimals) : 0;
207
  if (decimals >= NOT_FIXED_DEC)
208
  {
209
    my_error(ER_TOO_BIG_SCALE, MYF(0), decimals, fld_name,
210
             NOT_FIXED_DEC-1);
211
    return(true);
212
  }
213
214
  sql_type= fld_type;
215
  length= 0;
216
  change= fld_change;
217
  interval= 0;
218
  pack_length= key_length= 0;
219
  charset= fld_charset;
2179.2.1 by Olaf van der Spek
Rename List::empty to clear (std::list uses clear)
220
  interval_list.clear();
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
221
222
  comment= *fld_comment;
223
224
  if (fld_length && !(length= (uint32_t) atoi(fld_length)))
971.6.11 by Eric Day
Removed purecov messages.
225
    fld_length= 0;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
226
  sign_len= fld_type_modifier & UNSIGNED_FLAG ? 0 : 1;
227
228
  switch (fld_type) 
229
  {
230
    case DRIZZLE_TYPE_LONG:
231
      if (!fld_length)
232
        length= MAX_INT_WIDTH+sign_len;
233
      allowed_type_modifier= AUTO_INCREMENT_FLAG;
234
      break;
235
    case DRIZZLE_TYPE_LONGLONG:
236
      if (!fld_length)
237
        length= MAX_BIGINT_WIDTH;
238
      allowed_type_modifier= AUTO_INCREMENT_FLAG;
239
      break;
240
    case DRIZZLE_TYPE_NULL:
241
      break;
1211.1.1 by Brian Aker
Updating with my change to to DECIMAL from NEWDECIMAL and Stewart's update
242
    case DRIZZLE_TYPE_DECIMAL:
2030.1.2 by Brian Aker
First pass in refactoring of the name of my_decimal.
243
      class_decimal_trim(&length, &decimals);
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
244
      if (length > DECIMAL_MAX_PRECISION)
245
      {
246
        my_error(ER_TOO_BIG_PRECISION, MYF(0), length, fld_name,
247
                DECIMAL_MAX_PRECISION);
248
        return(true);
249
      }
250
      if (length < decimals)
251
      {
252
        my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
253
        return(true);
254
      }
2030.1.2 by Brian Aker
First pass in refactoring of the name of my_decimal.
255
      length= class_decimal_precision_to_length(length, decimals, fld_type_modifier & UNSIGNED_FLAG);
256
      pack_length= class_decimal_get_binary_size(length, decimals);
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
257
      break;
258
    case DRIZZLE_TYPE_VARCHAR:
259
      /*
260
        Long VARCHAR's are automaticly converted to blobs in mysql_prepare_table
261
        if they don't have a default value
262
      */
263
      max_field_charlength= MAX_FIELD_VARCHARLENGTH;
264
      break;
265
    case DRIZZLE_TYPE_BLOB:
266
      flags|= BLOB_FLAG;
267
      break;
268
    case DRIZZLE_TYPE_DOUBLE:
269
      allowed_type_modifier= AUTO_INCREMENT_FLAG;
270
      if (!fld_length && !fld_decimals)
271
      {
272
        length= DBL_DIG+7;
273
        decimals= NOT_FIXED_DEC;
274
      }
275
      if (length < decimals &&
276
          decimals != NOT_FIXED_DEC)
277
      {
278
        my_error(ER_M_BIGGER_THAN_D, MYF(0), fld_name);
279
        return(true);
280
      }
281
      break;
2046.2.1 by Brian Aker
First pass on micro timestamp.
282
    case DRIZZLE_TYPE_MICROTIME:
2057.2.3 by Brian Aker
Move the syntax for creation to what the standard has.
283
      /* 
284
        This assert() should be correct due to absence of length
285
        specifiers for timestamp. Previous manipulation also wasn't
286
        ever called (from examining lcov)
287
      */
288
      assert(fld_type);
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
289
    case DRIZZLE_TYPE_TIMESTAMP:
2057.2.3 by Brian Aker
Move the syntax for creation to what the standard has.
290
      length= MicroTimestamp::MAX_STRING_LENGTH;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
291
      break;
292
    case DRIZZLE_TYPE_DATE:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
293
      length= Date::MAX_STRING_LENGTH;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
294
      break;
1996.2.1 by Brian Aker
uuid type code.
295
    case DRIZZLE_TYPE_UUID:
296
      length= field::Uuid::max_string_length();
297
      break;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
298
    case DRIZZLE_TYPE_BOOLEAN:
299
      length= field::Boolean::max_string_length();
2023.2.1 by Brian Aker
Merge in BOOL type.
300
      break;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
301
    case DRIZZLE_TYPE_DATETIME:
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
302
      length= DateTime::MAX_STRING_LENGTH;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
303
      break;
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
304
    case DRIZZLE_TYPE_TIME:
305
      length= DateTime::MAX_STRING_LENGTH;
306
      break;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
307
    case DRIZZLE_TYPE_ENUM:
308
      {
309
        /* Should be safe. */
1782.4.4 by Brian Aker
Fix enum at being an intefer (which is what PG did, and it saves on
310
        pack_length= 4;
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
311
2183.2.10 by Olaf van der Spek
Use List::begin()
312
        List<String>::iterator it(fld_interval_list->begin());
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
313
        String *tmp;
314
        while ((tmp= it++))
1101.1.24 by Monty Taylor
Reverted my change to interval_list
315
          interval_list.push_back(tmp);
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
316
        length= 1;
317
        break;
318
    }
319
  }
320
  /* Remember the value of length */
321
  char_length= length;
322
323
  if (!(flags & BLOB_FLAG) &&
324
      ((length > max_field_charlength &&
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
325
        fld_type != DRIZZLE_TYPE_ENUM  &&
326
        (fld_type != DRIZZLE_TYPE_VARCHAR)) ||
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
327
       (!length && fld_type != DRIZZLE_TYPE_VARCHAR)))
328
  {
329
    my_error((fld_type == DRIZZLE_TYPE_VARCHAR) ?  ER_TOO_BIG_FIELDLENGTH : ER_TOO_BIG_DISPLAYWIDTH,
330
              MYF(0),
2221.12.4 by Stewart Smith
fix ER_TOO_BIG_FIELDLENGTH error message to always be number of characters, not sometimes number of bytes
331
             fld_name, max_field_charlength / (charset? charset->mbmaxlen : 1));
1055.2.10 by Jay Pipes
Moves Create_field implementation out into its own implementation file.
332
    return true;
333
  }
334
  fld_type_modifier&= AUTO_INCREMENT_FLAG;
335
  if ((~allowed_type_modifier) & fld_type_modifier)
336
  {
337
    my_error(ER_WRONG_FIELD_SPEC, MYF(0), fld_name);
338
    return true;
339
  }
340
341
  return false; /* success */
342
}
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
343
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
344
bool CreateField::setDefaultValue(Item *default_value_item,
345
                                  Item *on_update_item)
346
{
347
  def= default_value_item;
348
349
  /*
350
    Set NO_DEFAULT_VALUE_FLAG if this field doesn't have a default value and
351
    it is NOT NULL, not an AUTO_INCREMENT field and not a TIMESTAMP.
352
  */
353
  if (! default_value_item
354
      && ! (flags & AUTO_INCREMENT_FLAG)
355
      && (flags & NOT_NULL_FLAG)
356
      && (sql_type != DRIZZLE_TYPE_TIMESTAMP
357
          and sql_type != DRIZZLE_TYPE_MICROTIME))
358
  {
359
    flags|= NO_DEFAULT_VALUE_FLAG;
360
  }
2221.12.7 by Stewart Smith
in ALTER TABLE SET DEFAULT code path, use the new CreateField::setDefaultValue method - this means we have the same logic for setting default values for a CreateField as in CREATE TABLE
361
  else
362
  {
363
    flags&= ~NO_DEFAULT_VALUE_FLAG;
364
  }
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
365
366
  if (sql_type == DRIZZLE_TYPE_BLOB && default_value_item)
367
  {
368
    /* Allow empty as default value. */
369
    String str,*res;
370
    res= default_value_item->val_str(&str);
371
    if (res->length())
372
    {
373
      my_error(ER_BLOB_CANT_HAVE_DEFAULT, MYF(0), field_name);
374
      return(true);
375
    }
376
  }
377
378
  if (sql_type == DRIZZLE_TYPE_TIMESTAMP
379
      || sql_type == DRIZZLE_TYPE_MICROTIME)
380
  {
2221.12.8 by Stewart Smith
fix logic for ON UPDATE for TEMPSTAMP columns in CreateField::setDefaultValue in ALTER TABLE SET DEFAULT code path (as we're modifying existing CreateField, not just creating one
381
    bool on_update_now= on_update_item
382
      || (unireg_check == Field::TIMESTAMP_DNUN_FIELD
383
          || unireg_check == Field::TIMESTAMP_UN_FIELD);
384
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
385
    if (default_value_item)
386
    {
387
      /* Grammar allows only NOW() value for ON UPDATE clause */
388
      if (default_value_item->type() == Item::FUNC_ITEM &&
389
          ((Item_func*)default_value_item)->functype() == Item_func::NOW_FUNC)
390
      {
2221.12.8 by Stewart Smith
fix logic for ON UPDATE for TEMPSTAMP columns in CreateField::setDefaultValue in ALTER TABLE SET DEFAULT code path (as we're modifying existing CreateField, not just creating one
391
        unireg_check= (on_update_now ? Field::TIMESTAMP_DNUN_FIELD:
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
392
                       Field::TIMESTAMP_DN_FIELD);
393
        /*
394
          We don't need default value any longer moreover it is dangerous.
395
          Everything handled by unireg_check further.
396
        */
397
        def= 0;
398
      }
399
      else
400
      {
2221.12.8 by Stewart Smith
fix logic for ON UPDATE for TEMPSTAMP columns in CreateField::setDefaultValue in ALTER TABLE SET DEFAULT code path (as we're modifying existing CreateField, not just creating one
401
        unireg_check= (on_update_now ? Field::TIMESTAMP_UN_FIELD:
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
402
                       Field::NONE);
403
      }
404
    }
405
    else
406
    {
407
      /*
408
        If we have default TIMESTAMP NOT NULL column without explicit DEFAULT
409
        or ON UPDATE values then for the sake of compatiblity we should treat
410
        this column as having DEFAULT NOW() ON UPDATE NOW() (when we don't
411
        have another TIMESTAMP column with auto-set option before this one)
412
        or DEFAULT 0 (in other cases).
413
        So here we are setting TIMESTAMP_OLD_FIELD only temporary, and will
414
        replace this value by TIMESTAMP_DNUN_FIELD or NONE later when
415
        information about all TIMESTAMP fields in table will be availiable.
416
417
        If we have TIMESTAMP NULL column without explicit DEFAULT value
418
        we treat it as having DEFAULT NULL attribute.
419
      */
2221.12.8 by Stewart Smith
fix logic for ON UPDATE for TEMPSTAMP columns in CreateField::setDefaultValue in ALTER TABLE SET DEFAULT code path (as we're modifying existing CreateField, not just creating one
420
      unireg_check= (on_update_now ? Field::TIMESTAMP_UN_FIELD :
2221.12.5 by Stewart Smith
factor out setting default value out from CreatField::init and into new CreateField::setDefaultValue. This also means we fix up a error message to be correct in type_blob.
421
                     (flags & NOT_NULL_FLAG ? Field::TIMESTAMP_OLD_FIELD :
422
                      Field::NONE));
423
    }
424
  }
425
426
  return false;
427
}
428
2008.2.4 by Brian Aker
Merge in additional fixes for sign, plus alter table, plus TIME on
429
std::ostream& operator<<(std::ostream& output, const CreateField &field)
430
{
431
  output << "CreateField:(";
432
  output <<  field.field_name;
433
  output << ", ";
2246.4.6 by Olaf van der Spek
Remove some unnecessary drizzled::
434
  output << display::type(field.type());
2008.2.4 by Brian Aker
Merge in additional fixes for sign, plus alter table, plus TIME on
435
  output << ", { ";
436
437
  if (field.flags & NOT_NULL_FLAG)
438
    output << " NOT_NULL";
439
440
  if (field.flags & PRI_KEY_FLAG)
441
    output << ", PRIMARY KEY";
442
443
  if (field.flags & UNIQUE_KEY_FLAG)
444
    output << ", UNIQUE KEY";
445
446
  if (field.flags & MULTIPLE_KEY_FLAG)
447
    output << ", MULTIPLE KEY";
448
449
  if (field.flags & BLOB_FLAG)
450
    output << ", BLOB";
451
452
  if (field.flags & UNSIGNED_FLAG)
453
    output << ", UNSIGNED";
454
455
  if (field.flags & BINARY_FLAG)
456
    output << ", BINARY";
457
  output << "}, ";
458
  if (field.field)
459
    output << *field.field;
460
  output << ")";
461
462
  return output;  // for multiple << operators.
463
}
464
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
465
} /* namespace drizzled */