~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table/instance/base.cc

  • Committer: Mark Atwood
  • Date: 2011-10-08 04:50:51 UTC
  • mfrom: (2430.1.1 rf)
  • Revision ID: me@mark.atwood.name-20111008045051-6ha1qiy7k2a9c3jv
Tags: 2011.10.27
mergeĀ lp:~olafvdspek/drizzle/refactor2

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
  abort();
147
147
}
148
148
 
149
 
static Item* default_value_item(enum_field_types field_type, const charset_info_st& charset, bool default_null, 
150
 
  const string& default_value, const string& default_bin_value)
 
149
static Item *default_value_item(enum_field_types field_type,
 
150
                                const charset_info_st *charset,
 
151
                                bool default_null, const string *default_value,
 
152
                                const string *default_bin_value)
151
153
{
 
154
  Item *default_item= NULL;
 
155
  int error= 0;
 
156
 
152
157
  if (default_null)
 
158
  {
153
159
    return new Item_null();
 
160
  }
154
161
 
155
 
  switch (field_type)
 
162
  switch(field_type)
156
163
  {
157
164
  case DRIZZLE_TYPE_LONG:
158
165
  case DRIZZLE_TYPE_LONGLONG:
 
166
    default_item= new Item_int(default_value->c_str(),
 
167
                               (int64_t) internal::my_strtoll10(default_value->c_str(),
 
168
                                                                NULL,
 
169
                                                                &error),
 
170
                               default_value->length());
 
171
 
 
172
    if (error && error != -1) /* was an error and wasn't a negative number */
159
173
    {
160
 
      int error= 0;
161
 
      Item* default_item= new Item_int(default_value.c_str(), (int64_t) internal::my_strtoll10(default_value.c_str(), NULL, &error), default_value.length());
162
 
 
163
 
      if (error && error != -1) /* was an error and wasn't a negative number */
164
 
      {
165
 
        delete default_item;
166
 
        return NULL;
167
 
      }
168
 
      return default_item;
 
174
      delete default_item;
 
175
      return NULL;
169
176
    }
 
177
 
 
178
    break;
170
179
  case DRIZZLE_TYPE_DOUBLE:
171
 
    return new Item_float(default_value.c_str(), default_value.length());
 
180
    default_item= new Item_float(default_value->c_str(),
 
181
                                 default_value->length());
 
182
    break;
172
183
  case DRIZZLE_TYPE_NULL:
173
 
    assert(false);
 
184
    assert(0);
174
185
    abort();
175
186
  case DRIZZLE_TYPE_TIMESTAMP:
176
187
  case DRIZZLE_TYPE_DATETIME:
181
192
  case DRIZZLE_TYPE_IPV6:
182
193
  case DRIZZLE_TYPE_MICROTIME:
183
194
  case DRIZZLE_TYPE_BOOLEAN:
184
 
    // return new Item_string(*default_value, system_charset_info); // crash
185
 
    return new Item_string(default_value.data(), default_value.size(), system_charset_info);
 
195
    default_item= new Item_string(default_value->c_str(),
 
196
                                  default_value->length(),
 
197
                                  system_charset_info);
 
198
    break;
186
199
  case DRIZZLE_TYPE_VARCHAR:
187
200
  case DRIZZLE_TYPE_BLOB: /* Blob is here due to TINYTEXT. Feel the hate. */
188
 
    return &charset== &my_charset_bin
189
 
      ? new Item_string(default_bin_value, &my_charset_bin)
190
 
      : new Item_string(default_value, system_charset_info);
 
201
    if (charset==&my_charset_bin)
 
202
    {
 
203
      default_item= new Item_string(default_bin_value->c_str(),
 
204
                                    default_bin_value->length(),
 
205
                                    &my_charset_bin);
 
206
    }
 
207
    else
 
208
    {
 
209
      default_item= new Item_string(default_value->c_str(),
 
210
                                    default_value->length(),
 
211
                                    system_charset_info);
 
212
    }
 
213
    break;
191
214
  case DRIZZLE_TYPE_DECIMAL:
192
 
    return new Item_decimal(default_value.c_str(), default_value.length(), system_charset_info);
 
215
    default_item= new Item_decimal(default_value->c_str(),
 
216
                                   default_value->length(),
 
217
                                   system_charset_info);
 
218
    break;
193
219
  }
194
 
  return NULL;
 
220
 
 
221
  return default_item;
195
222
}
196
223
 
197
224
 
230
257
  key_info(NULL),
231
258
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
232
259
  all_set(),
 
260
  db(null_lex_string()),
 
261
  table_name(null_lex_string()),
 
262
  path(null_lex_string()),
 
263
  normalized_path(null_lex_string()),
233
264
  block_size(0),
234
265
  version(0),
235
266
  timestamp_offset(0),
289
320
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
290
321
  table_charset(0),
291
322
  all_set(),
 
323
  db(null_lex_string()),
 
324
  table_name(null_lex_string()),
 
325
  path(null_lex_string()),
 
326
  normalized_path(null_lex_string()),
292
327
  block_size(0),
293
328
  version(0),
294
329
  timestamp_offset(0),
355
390
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
356
391
  table_charset(0),
357
392
  all_set(),
 
393
  db(null_lex_string()),
 
394
  table_name(null_lex_string()),
 
395
  path(null_lex_string()),
 
396
  normalized_path(null_lex_string()),
358
397
  block_size(0),
359
398
  version(0),
360
399
  timestamp_offset(0),
424
463
  mem_root(TABLE_ALLOC_BLOCK_SIZE),
425
464
  table_charset(0),
426
465
  all_set(),
 
466
  db(null_lex_string()),
 
467
  table_name(null_lex_string()),
 
468
  path(null_lex_string()),
 
469
  normalized_path(null_lex_string()),
427
470
  block_size(0),
428
471
  version(0),
429
472
  timestamp_offset(0),
699
742
      key_part->key_type= 0;
700
743
    }
701
744
 
702
 
    if (not indx.has_comment())
 
745
    if (! indx.has_comment())
703
746
    {
704
 
      keyinfo->comment.clear();
 
747
      keyinfo->comment.length= 0;
 
748
      keyinfo->comment.str= NULL;
705
749
    }
706
750
    else
707
751
    {
708
752
      keyinfo->flags|= HA_USES_COMMENT;
709
 
      keyinfo->comment.assign(mem().strdup(indx.comment()), indx.comment().length());
 
753
      keyinfo->comment.length= indx.comment().length();
 
754
      keyinfo->comment.str= mem().strdup(indx.comment());
710
755
    }
711
756
 
712
757
    keyinfo->name= mem().strdup(indx.name());
932
977
      unireg_type= Field::TIMESTAMP_UN_FIELD;
933
978
    }
934
979
 
935
 
    str_ref comment;
936
 
    if (pfield.has_comment())
937
 
    {
938
 
      comment.assign(mem().strdup(pfield.comment()), pfield.comment().size());
 
980
    lex_string_t comment;
 
981
    if (!pfield.has_comment())
 
982
    {
 
983
      comment.str= (char*)"";
 
984
      comment.length= 0;
 
985
    }
 
986
    else
 
987
    {
 
988
      comment.str= mem().strdup(pfield.comment());
 
989
      comment.length= pfield.comment().size();
939
990
    }
940
991
 
941
992
    enum_field_types field_type;
944
995
 
945
996
    const charset_info_st *charset= &my_charset_bin;
946
997
 
947
 
    if (field_type == DRIZZLE_TYPE_BLOB || field_type == DRIZZLE_TYPE_VARCHAR)
 
998
    if (field_type == DRIZZLE_TYPE_BLOB ||
 
999
        field_type == DRIZZLE_TYPE_VARCHAR)
948
1000
    {
949
1001
      message::Table::Field::StringFieldOptions field_options= pfield.string_options();
950
1002
 
951
 
      charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
 
1003
      charset= get_charset(field_options.has_collation_id() ?
 
1004
                           field_options.collation_id() : 0);
952
1005
 
953
 
      if (not charset)
 
1006
      if (! charset)
954
1007
        charset= default_charset_info;
955
1008
    }
956
1009
 
958
1011
    {
959
1012
      message::Table::Field::EnumerationValues field_options= pfield.enumeration_values();
960
1013
 
961
 
      charset= get_charset(field_options.has_collation_id() ? field_options.collation_id() : 0);
 
1014
      charset= get_charset(field_options.has_collation_id()?
 
1015
                           field_options.collation_id() : 0);
962
1016
 
963
 
      if (not charset)
 
1017
      if (! charset)
964
1018
        charset= default_charset_info;
965
1019
    }
966
1020
 
967
1021
    uint8_t decimals= 0;
968
 
    if (field_type == DRIZZLE_TYPE_DECIMAL || field_type == DRIZZLE_TYPE_DOUBLE)
 
1022
    if (field_type == DRIZZLE_TYPE_DECIMAL
 
1023
        || field_type == DRIZZLE_TYPE_DOUBLE)
969
1024
    {
970
1025
      message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
971
1026
 
972
 
      if (not pfield.has_numeric_options() || ! fo.has_scale())
 
1027
      if (! pfield.has_numeric_options() || ! fo.has_scale())
973
1028
      {
974
1029
        /*
975
1030
          We don't write the default to table proto so
995
1050
        pfield.options().default_null()  ||
996
1051
        pfield.options().has_default_bin_value())
997
1052
    {
998
 
      default_value= default_value_item(field_type, *charset, pfield.options().default_null(), pfield.options().default_value(), pfield.options().default_bin_value());
 
1053
      default_value= default_value_item(field_type,
 
1054
                                        charset,
 
1055
                                        pfield.options().default_null(),
 
1056
                                        &pfield.options().default_value(),
 
1057
                                        &pfield.options().default_bin_value());
999
1058
      if (default_value == NULL)
1000
1059
      {
1001
1060
        my_error(ER_INVALID_DEFAULT, MYF(0), pfield.name().c_str());