~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_proto_write.cc

default values for DATE columns were being stored in the original string that the user entered in CREATE TABLE while what actually happens is that this string is typecast to DATE (e.g. if it had a time as well the time vanishes silently). This patch fixes what's stored in the table proto. This is visible when you use statement_transform for SHOW CREATE TABLE

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
#include <drizzled/table_proto.h>
38
38
 
 
39
#include "drizzled/function/time/typecast.h"
 
40
 
39
41
using namespace std;
40
42
 
41
43
namespace drizzled {
262
264
          return 1;
263
265
        }
264
266
 
 
267
        if (field_arg->sql_type == DRIZZLE_TYPE_DATE
 
268
            || field_arg->sql_type == DRIZZLE_TYPE_DATETIME
 
269
            || field_arg->sql_type == DRIZZLE_TYPE_TIMESTAMP)
 
270
        {
 
271
          DRIZZLE_TIME ltime;
 
272
 
 
273
          if (field_arg->def->get_date(&ltime, TIME_FUZZY_DATE))
 
274
          {
 
275
            my_error(ER_INVALID_DATETIME_VALUE, MYF(ME_FATALERROR),
 
276
                     default_value->c_str());
 
277
            return 1;
 
278
          }
 
279
 
 
280
          /* We now do the casting down to the appropriate type.
 
281
 
 
282
             Yes, this implicit casting is balls.
 
283
             It was previously done on reading the proto back in,
 
284
             but we really shouldn't store the bogus things in the proto,
 
285
             and instead do the casting behaviour here.
 
286
 
 
287
             the timestamp errors are taken care of elsewhere.
 
288
          */
 
289
 
 
290
          if (field_arg->sql_type == DRIZZLE_TYPE_DATETIME)
 
291
          {
 
292
            Item *typecast= new Item_datetime_typecast(field_arg->def);
 
293
            typecast->quick_fix_field();
 
294
            typecast->val_str(default_value);
 
295
          }
 
296
          else if (field_arg->sql_type == DRIZZLE_TYPE_DATE)
 
297
          {
 
298
            Item *typecast= new Item_date_typecast(field_arg->def);
 
299
            typecast->quick_fix_field();
 
300
            typecast->val_str(default_value);
 
301
          }
 
302
        }
 
303
 
265
304
        if ((field_arg->sql_type==DRIZZLE_TYPE_VARCHAR
266
305
            && field_arg->charset==&my_charset_bin)
267
306
           || (field_arg->sql_type==DRIZZLE_TYPE_BLOB