~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/key.cc

  • Committer: Brian Aker
  • Date: 2008-12-06 23:57:32 UTC
  • mfrom: (656.1.10 devel)
  • Revision ID: brian@tangent.org-20081206235732-jx228bczpvmxu8ww
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
#include <drizzled/table.h>
21
21
#include <drizzled/field/blob.h>
22
22
 
 
23
#include <string>
 
24
 
 
25
using namespace std;
 
26
 
23
27
/*
24
28
  Search after a key that starts with 'field'
25
29
 
92
96
}
93
97
 
94
98
 
95
 
/**
96
 
  Copy part of a record that forms a key or key prefix to a buffer.
97
 
 
98
 
    The function takes a complete table record (as e.g. retrieved by
99
 
    handler::index_read()), and a description of an index on the same table,
100
 
    and extracts the first key_length bytes of the record which are part of a
101
 
    key into to_key. If length == 0 then copy all bytes from the record that
102
 
    form a key.
103
 
 
104
 
  @param to_key      buffer that will be used as a key
105
 
  @param from_record full record to be copied from
106
 
  @param key_info    descriptor of the index
107
 
  @param key_length  specifies length of all keyparts that will be copied
108
 
*/
109
 
 
110
99
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info,
111
100
              unsigned int key_length)
112
101
{
146
135
}
147
136
 
148
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
 
149
176
/**
150
177
  Zero the null components of key tuple.
151
178
*/
264
291
  const unsigned char *key_end= key + key_length;;
265
292
 
266
293
  for (key_part=table->key_info[idx].key_part;
267
 
       key < key_end ; 
 
294
       key < key_end ;
268
295
       key_part++, key+= store_length)
269
296
  {
270
297
    uint32_t length;
272
299
 
273
300
    if (key_part->null_bit)
274
301
    {
275
 
      if (*key != test(table->record[0][key_part->null_offset] & 
 
302
      if (*key != test(table->record[0][key_part->null_offset] &
276
303
                       key_part->null_bit))
277
304
        return 1;
278
305
      if (*key)
314
341
/*
315
342
  unpack key-fields from record to some buffer.
316
343
 
317
 
  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
318
345
  change the column bitmap so that all columns are readable.
319
346
 
320
347
  @param
368
395
                                 char_length)) < key_part->length)
369
396
          tmp.length(charpos);
370
397
      }
371
 
      
 
398
 
372
399
      if (key_part->length < field->pack_length())
373
400
        tmp.length(cmin(tmp.length(),(uint32_t)key_part->length));
374
401
      to->append(tmp);