~linuxjedi/drizzle/drizzle-bug-647360

« back to all changes in this revision

Viewing changes to drizzled/field/enum.cc

  • Committer: lbieber
  • Date: 2010-09-23 15:49:15 UTC
  • mfrom: (1788.1.3 build)
  • Revision ID: lbieber@orisndriz08-20100923154915-mshh9pwln0igdwrn
Merge Brian - Rollup patch of enum + style on varchar. This modifies enum to always being the same value.
Merge Stewart - Fix embedded_innodb plugin now that TIMESTAMP is 8 bytes. 
Merge Shrews - fix bug 643630 -  Transaction_reader not handling CHAR values that include quotes properly

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
** If one uses this string in a number context one gets the type number.
39
39
****************************************************************************/
40
40
 
41
 
enum ha_base_keytype Field_enum::key_type() const
42
 
{
43
 
  switch (packlength)
44
 
  {
45
 
  case 1:
46
 
    return HA_KEYTYPE_BINARY;
47
 
  case 2:
48
 
    return HA_KEYTYPE_ULONG_INT;
49
 
  default:
50
 
    assert(packlength <= 2);
51
 
    return HA_KEYTYPE_ULONG_INT;
52
 
  }
53
 
}
54
 
 
55
41
void Field_enum::store_type(uint64_t value)
56
42
{
57
43
  value--; /* we store as starting from 0, although SQL starts from 1 */
58
44
 
59
 
  switch (packlength) {
60
 
  case 1: ptr[0]= (unsigned char) value;  break;
61
 
  case 2:
62
45
#ifdef WORDS_BIGENDIAN
63
46
  if (getTable()->s->db_low_byte_first)
64
47
  {
65
 
    int2store(ptr,(unsigned short) value);
 
48
    int4store(ptr, (unsigned short) value);
66
49
  }
67
50
  else
68
51
#endif
69
 
    shortstore(ptr,(unsigned short) value);
70
 
  break;
71
 
  default:
72
 
    assert(packlength <= 2);
73
 
  }
 
52
    longstore(ptr, (unsigned short) value);
74
53
}
75
54
 
76
55
/**
152
131
{
153
132
  ASSERT_COLUMN_MARKED_FOR_READ;
154
133
 
155
 
  switch (packlength) {
156
 
  case 1:
157
 
    return ((int64_t) ptr[0]) + 1; /* SQL is from 1, we store from 0 */
158
 
  case 2:
159
 
  {
160
 
    uint16_t tmp;
 
134
  uint16_t tmp;
161
135
#ifdef WORDS_BIGENDIAN
162
 
    if (getTable()->s->db_low_byte_first)
163
 
      tmp=sint2korr(ptr);
164
 
    else
 
136
  if (getTable()->s->db_low_byte_first)
 
137
    tmp= sint4korr(ptr);
 
138
  else
165
139
#endif
166
 
      shortget(tmp,ptr);
167
 
    return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
168
 
  }
169
 
  default:
170
 
    assert(packlength <= 2);
171
 
  }
172
 
  return 0;                                     // impossible
 
140
    longget(tmp,ptr);
 
141
  return ((int64_t) tmp) + 1; /* SQL is from 1, we store from 0 */
173
142
}
174
143
 
175
144
String *Field_enum::val_str(String *, String *val_ptr)
194
163
{
195
164
  unsigned char *old= ptr;
196
165
  ptr= (unsigned char*) a_ptr;
197
 
  uint64_t a=Field_enum::val_int();
 
166
  uint64_t a= Field_enum::val_int();
198
167
  ptr= (unsigned char*) b_ptr;
199
 
  uint64_t b=Field_enum::val_int();
 
168
  uint64_t b= Field_enum::val_int();
200
169
  ptr= old;
201
170
  return (a < b) ? -1 : (a > b) ? 1 : 0;
202
171
}
204
173
void Field_enum::sort_string(unsigned char *to,uint32_t )
205
174
{
206
175
  uint64_t value=Field_enum::val_int()-1; /* SQL is 1 based, stored as 0 based*/
207
 
  to+=packlength-1;
208
 
  for (uint32_t i=0 ; i < packlength ; i++)
 
176
  to+=pack_length() -1;
 
177
  for (uint32_t i=0 ; i < pack_length() ; i++)
209
178
  {
210
179
    *to-- = (unsigned char) (value & 255);
211
180
    value>>=8;