~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/field.cc

  • Committer: Brian Aker
  • Date: 2010-12-16 04:01:22 UTC
  • mfrom: (1996.2.1 compare)
  • Revision ID: brian@tangent.org-20101216040122-eodh5shwsij35ybe
Merge in uuid tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
#include "drizzled/field/timestamp.h"
44
44
#include "drizzled/field/datetime.h"
45
45
#include "drizzled/field/varstring.h"
 
46
#include "drizzled/field/uuid.h"
46
47
#include "drizzled/time_functions.h"
47
48
#include "drizzled/internal/m_string.h"
48
49
 
 
50
#include "drizzled/display.h"
 
51
 
49
52
namespace drizzled
50
53
{
51
54
 
54
57
*****************************************************************************/
55
58
 
56
59
static enum_field_types
57
 
field_types_merge_rules [DRIZZLE_TYPE_MAX+1][DRIZZLE_TYPE_MAX+1]=
 
60
field_types_merge_rules [enum_field_types_size][enum_field_types_size]=
58
61
{
59
62
  /* DRIZZLE_TYPE_LONG -> */
60
63
  {
80
83
    DRIZZLE_TYPE_VARCHAR,
81
84
    //DRIZZLE_TYPE_BLOB
82
85
    DRIZZLE_TYPE_BLOB,
 
86
    //DRIZZLE_TYPE_UUID
 
87
    DRIZZLE_TYPE_VARCHAR,
83
88
  },
84
89
  /* DRIZZLE_TYPE_DOUBLE -> */
85
90
  {
105
110
    DRIZZLE_TYPE_VARCHAR,
106
111
    //DRIZZLE_TYPE_BLOB
107
112
    DRIZZLE_TYPE_BLOB,
 
113
    //DRIZZLE_TYPE_UUID
 
114
    DRIZZLE_TYPE_VARCHAR,
108
115
  },
109
116
  /* DRIZZLE_TYPE_NULL -> */
110
117
  {
130
137
    DRIZZLE_TYPE_ENUM,
131
138
    //DRIZZLE_TYPE_BLOB
132
139
    DRIZZLE_TYPE_BLOB,
 
140
    //DRIZZLE_TYPE_UUID
 
141
    DRIZZLE_TYPE_UUID,
133
142
  },
134
143
  /* DRIZZLE_TYPE_TIMESTAMP -> */
135
144
  {
155
164
    DRIZZLE_TYPE_VARCHAR,
156
165
    //DRIZZLE_TYPE_BLOB
157
166
    DRIZZLE_TYPE_BLOB,
 
167
    //DRIZZLE_TYPE_UUID
 
168
    DRIZZLE_TYPE_VARCHAR,
158
169
  },
159
170
  /* DRIZZLE_TYPE_LONGLONG -> */
160
171
  {
179
190
    DRIZZLE_TYPE_VARCHAR,
180
191
    //DRIZZLE_TYPE_BLOB
181
192
    DRIZZLE_TYPE_BLOB,
 
193
    //DRIZZLE_TYPE_UUID
 
194
    DRIZZLE_TYPE_VARCHAR,
182
195
  },
183
196
  /* DRIZZLE_TYPE_DATETIME -> */
184
197
  {
204
217
    DRIZZLE_TYPE_VARCHAR,
205
218
    //DRIZZLE_TYPE_BLOB
206
219
    DRIZZLE_TYPE_BLOB,
 
220
    //DRIZZLE_TYPE_UUID
 
221
    DRIZZLE_TYPE_VARCHAR,
207
222
  },
208
223
  /* DRIZZLE_TYPE_DATE -> */
209
224
  {
229
244
    DRIZZLE_TYPE_VARCHAR,
230
245
    //DRIZZLE_TYPE_BLOB
231
246
    DRIZZLE_TYPE_BLOB,
 
247
    //DRIZZLE_TYPE_UUID
 
248
    DRIZZLE_TYPE_VARCHAR,
232
249
  },
233
250
  /* DRIZZLE_TYPE_VARCHAR -> */
234
251
  {
254
271
    DRIZZLE_TYPE_VARCHAR,
255
272
    //DRIZZLE_TYPE_BLOB
256
273
    DRIZZLE_TYPE_BLOB,
 
274
    //DRIZZLE_TYPE_UUID
 
275
    DRIZZLE_TYPE_VARCHAR,
257
276
  },
258
277
  /* DRIZZLE_TYPE_DECIMAL -> */
259
278
  {
279
298
    DRIZZLE_TYPE_VARCHAR,
280
299
    //DRIZZLE_TYPE_BLOB
281
300
    DRIZZLE_TYPE_BLOB,
 
301
    //DRIZZLE_TYPE_UUID
 
302
    DRIZZLE_TYPE_VARCHAR,
282
303
  },
283
304
  /* DRIZZLE_TYPE_ENUM -> */
284
305
  {
304
325
    DRIZZLE_TYPE_VARCHAR,
305
326
    //DRIZZLE_TYPE_BLOB
306
327
    DRIZZLE_TYPE_BLOB,
307
 
  },
 
328
    //DRIZZLE_TYPE_UUID
 
329
    DRIZZLE_TYPE_VARCHAR,
 
330
   },
308
331
  /* DRIZZLE_TYPE_BLOB -> */
309
332
  {
310
333
    //DRIZZLE_TYPE_LONG
329
352
    DRIZZLE_TYPE_BLOB,
330
353
    //DRIZZLE_TYPE_BLOB
331
354
    DRIZZLE_TYPE_BLOB,
 
355
    //DRIZZLE_TYPE_UUID
 
356
    DRIZZLE_TYPE_VARCHAR,
 
357
  },
 
358
  /* DRIZZLE_TYPE_UUID -> */
 
359
  {
 
360
    //DRIZZLE_TYPE_LONG
 
361
    DRIZZLE_TYPE_VARCHAR,
 
362
    //DRIZZLE_TYPE_DOUBLE
 
363
    DRIZZLE_TYPE_VARCHAR,
 
364
    //DRIZZLE_TYPE_NULL
 
365
    DRIZZLE_TYPE_UUID,
 
366
    //DRIZZLE_TYPE_TIMESTAMP
 
367
    DRIZZLE_TYPE_VARCHAR,
 
368
    //DRIZZLE_TYPE_LONGLONG
 
369
    DRIZZLE_TYPE_VARCHAR,
 
370
    //DRIZZLE_TYPE_DATETIME
 
371
    DRIZZLE_TYPE_VARCHAR,
 
372
    //DRIZZLE_TYPE_DATE
 
373
    DRIZZLE_TYPE_VARCHAR,
 
374
    //DRIZZLE_TYPE_VARCHAR
 
375
    DRIZZLE_TYPE_VARCHAR,
 
376
    //DRIZZLE_TYPE_DECIMAL
 
377
    DRIZZLE_TYPE_VARCHAR,
 
378
    //DRIZZLE_TYPE_VARCHAR,
 
379
    DRIZZLE_TYPE_VARCHAR,
 
380
    //DRIZZLE_TYPE_BLOB
 
381
    DRIZZLE_TYPE_BLOB,
 
382
    //DRIZZLE_TYPE_UUID
 
383
    DRIZZLE_TYPE_UUID,
332
384
  },
333
385
};
334
386
 
335
 
static Item_result field_types_result_type [DRIZZLE_TYPE_MAX+1]=
 
387
static Item_result field_types_result_type [enum_field_types_size]=
336
388
{
337
389
  //DRIZZLE_TYPE_LONG
338
390
  INT_RESULT,
356
408
  STRING_RESULT,
357
409
  //DRIZZLE_TYPE_BLOB
358
410
  STRING_RESULT,
 
411
  //DRIZZLE_TYPE_UUID
 
412
  STRING_RESULT,
359
413
};
360
414
 
361
415
bool test_if_important_data(const CHARSET_INFO * const cs, 
380
434
enum_field_types Field::field_type_merge(enum_field_types a,
381
435
                                         enum_field_types b)
382
436
{
383
 
  assert(a <= DRIZZLE_TYPE_MAX);
384
 
  assert(b <= DRIZZLE_TYPE_MAX);
 
437
  assert(a < enum_field_types_size);
 
438
  assert(b < enum_field_types_size);
385
439
  return field_types_merge_rules[a][b];
386
440
}
387
441
 
388
442
Item_result Field::result_merge_type(enum_field_types field_type)
389
443
{
390
 
  assert(field_type <= DRIZZLE_TYPE_MAX);
 
444
  assert(field_type < enum_field_types_size);
391
445
  return field_types_result_type[field_type];
392
446
}
393
447
 
640
694
  }
641
695
}
642
696
 
643
 
int Field::store(const char *to, 
644
 
                 uint32_t length,
645
 
                 const CHARSET_INFO * const cs,
646
 
                 enum_check_fields check_level)
 
697
int Field::store_and_check(enum_check_fields check_level,
 
698
                           const char *to, 
 
699
                           uint32_t length,
 
700
                           const CHARSET_INFO * const cs)
 
701
 
647
702
{
648
703
  int res;
649
704
  enum_check_fields old_check_level= table->in_use->count_cuted_fields;
778
833
{
779
834
  char buff[40];
780
835
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
781
 
  if (!(res=val_str(&tmp)) ||
782
 
      str_to_datetime_with_warn(res->ptr(), res->length(),
783
 
                                ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
836
  if (!(res=val_str_internal(&tmp)) || str_to_datetime_with_warn(res->ptr(), res->length(),
 
837
                                                                 ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
 
838
  {
784
839
    return 1;
 
840
  }
 
841
 
785
842
  return 0;
786
843
}
787
844
 
789
846
{
790
847
  char buff[40];
791
848
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
792
 
  if (!(res=val_str(&tmp)) ||
793
 
      str_to_time_with_warn(res->ptr(), res->length(), ltime))
 
849
 
 
850
  if (!(res=val_str_internal(&tmp)) || str_to_time_with_warn(res->ptr(), res->length(), ltime))
 
851
  {
794
852
    return 1;
 
853
  }
 
854
 
795
855
  return 0;
796
856
}
797
857
 
888
948
{
889
949
  switch (type) {
890
950
  case DRIZZLE_TYPE_VARCHAR: return (length + (length < 256 ? 1: 2));
 
951
  case DRIZZLE_TYPE_UUID: return field::Uuid::max_string_length();
891
952
  case DRIZZLE_TYPE_DATE:
892
953
  case DRIZZLE_TYPE_ENUM:
893
954
  case DRIZZLE_TYPE_LONG: return 4;
898
959
  case DRIZZLE_TYPE_NULL: return 0;
899
960
  case DRIZZLE_TYPE_BLOB: return 4 + portable_sizeof_char_ptr;
900
961
  case DRIZZLE_TYPE_DECIMAL:
901
 
    abort();
902
 
  default:
903
 
    return 0;
 
962
                          assert(0);
 
963
                          abort();
904
964
  }
 
965
 
 
966
  assert(0);
 
967
  abort();
905
968
}
906
969
 
907
970
uint32_t pack_length_to_packflag(uint32_t type)
1015
1078
    table->clearWriteSet(field_index);
1016
1079
}
1017
1080
 
 
1081
std::ostream& operator<<(std::ostream& output, const Field &field)
 
1082
{
 
1083
  output << "Field:(";
 
1084
  output <<  field.field_name;
 
1085
  output << ", ";
 
1086
  output << drizzled::display::type(field.real_type());
 
1087
  output << ")";
 
1088
 
 
1089
  return output;  // for multiple << operators.
 
1090
}
 
1091
 
1018
1092
} /* namespace drizzled */