~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/key.cc

  • Committer: Toru Maesaka
  • Date: 2008-12-17 07:16:37 UTC
  • mto: (685.1.40 devel) (713.1.5 devel)
  • mto: This revision was merged to the branch mainline in revision 713.
  • Revision ID: dev@torum.net-20081217071637-7j9040w7lpms77r2
Removed my_time() and added error checking

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
/* Functions to handle keys and fields in forms */
18
18
 
19
19
#include <drizzled/server_includes.h>
 
20
#include <drizzled/table.h>
 
21
#include <drizzled/field/blob.h>
 
22
 
 
23
#include <string>
 
24
 
 
25
using namespace std;
20
26
 
21
27
/*
22
28
  Search after a key that starts with 'field'
90
96
}
91
97
 
92
98
 
93
 
/**
94
 
  Copy part of a record that forms a key or key prefix to a buffer.
95
 
 
96
 
    The function takes a complete table record (as e.g. retrieved by
97
 
    handler::index_read()), and a description of an index on the same table,
98
 
    and extracts the first key_length bytes of the record which are part of a
99
 
    key into to_key. If length == 0 then copy all bytes from the record that
100
 
    form a key.
101
 
 
102
 
  @param to_key      buffer that will be used as a key
103
 
  @param from_record full record to be copied from
104
 
  @param key_info    descriptor of the index
105
 
  @param key_length  specifies length of all keyparts that will be copied
106
 
*/
107
 
 
108
99
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info,
109
100
              unsigned int key_length)
110
101
{
144
135
}
145
136
 
146
137
 
 
138
void key_copy(basic_string<unsigned char> &to_key,
 
139
              unsigned char *from_record, KEY *key_info,
 
140
              unsigned int key_length)
 
141
{
 
142
  uint32_t length;
 
143
  KEY_PART_INFO *key_part;
 
144
 
 
145
  if (key_length == 0)
 
146
    key_length= key_info->key_length;
 
147
  for (key_part= key_info->key_part; (int) key_length > 0; key_part++)
 
148
  {
 
149
    if (key_part->null_bit)
 
150
    {
 
151
      to_key.push_back(test(from_record[key_part->null_offset] &
 
152
                       key_part->null_bit) ? '1' : '0');
 
153
      key_length--;
 
154
    }
 
155
    if (key_part->key_part_flag & HA_BLOB_PART ||
 
156
        key_part->key_part_flag & HA_VAR_LENGTH_PART)
 
157
    {
 
158
      key_length-= HA_KEY_BLOB_LENGTH;
 
159
      length= cmin((uint16_t)key_length, key_part->length);
 
160
      key_part->field->get_key_image(to_key, length, Field::itRAW);
 
161
      to_key.append(HA_KEY_BLOB_LENGTH, '0');
 
162
    }
 
163
    else
 
164
    {
 
165
      length= cmin((uint16_t)key_length, key_part->length);
 
166
      Field *field= key_part->field;
 
167
      uint32_t bytes= field->get_key_image(to_key, length, Field::itRAW);
 
168
      if (bytes < length)
 
169
        to_key.append(length-bytes, ' ');
 
170
    }
 
171
    key_length-= length;
 
172
  }
 
173
}
 
174
 
 
175
 
147
176
/**
148
177
  Zero the null components of key tuple.
149
178
*/
262
291
  const unsigned char *key_end= key + key_length;;
263
292
 
264
293
  for (key_part=table->key_info[idx].key_part;
265
 
       key < key_end ; 
 
294
       key < key_end ;
266
295
       key_part++, key+= store_length)
267
296
  {
268
297
    uint32_t length;
270
299
 
271
300
    if (key_part->null_bit)
272
301
    {
273
 
      if (*key != test(table->record[0][key_part->null_offset] & 
 
302
      if (*key != test(table->record[0][key_part->null_offset] &
274
303
                       key_part->null_bit))
275
304
        return 1;
276
305
      if (*key)
312
341
/*
313
342
  unpack key-fields from record to some buffer.
314
343
 
315
 
  This is used mainly to get a good error message.  We temporary 
 
344
  This is used mainly to get a good error message.  We temporary
316
345
  change the column bitmap so that all columns are readable.
317
346
 
318
347
  @param
366
395
                                 char_length)) < key_part->length)
367
396
          tmp.length(charpos);
368
397
      }
369
 
      
 
398
 
370
399
      if (key_part->length < field->pack_length())
371
400
        tmp.length(cmin(tmp.length(),(uint32_t)key_part->length));
372
401
      to->append(tmp);