~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/key.cc

  • Committer: Monty Taylor
  • Date: 2008-11-13 22:41:09 UTC
  • mto: (589.1.3 devel) (584.1.7 devel)
  • mto: This revision was merged to the branch mainline in revision 585.
  • Revision ID: monty@inaugust.com-20081113224109-4rkzdtn5f2ppzf9q
Check gnu ld status rather than gcc status (you never know)

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;
26
20
 
27
21
/*
28
22
  Search after a key that starts with 'field'
96
90
}
97
91
 
98
92
 
 
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
 
99
108
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info,
100
109
              unsigned int key_length)
101
110
{
135
144
}
136
145
 
137
146
 
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
 
 
176
147
/**
177
148
  Zero the null components of key tuple.
178
149
*/
291
262
  const unsigned char *key_end= key + key_length;;
292
263
 
293
264
  for (key_part=table->key_info[idx].key_part;
294
 
       key < key_end ;
 
265
       key < key_end ; 
295
266
       key_part++, key+= store_length)
296
267
  {
297
268
    uint32_t length;
299
270
 
300
271
    if (key_part->null_bit)
301
272
    {
302
 
      if (*key != test(table->record[0][key_part->null_offset] &
 
273
      if (*key != test(table->record[0][key_part->null_offset] & 
303
274
                       key_part->null_bit))
304
275
        return 1;
305
276
      if (*key)
341
312
/*
342
313
  unpack key-fields from record to some buffer.
343
314
 
344
 
  This is used mainly to get a good error message.  We temporary
 
315
  This is used mainly to get a good error message.  We temporary 
345
316
  change the column bitmap so that all columns are readable.
346
317
 
347
318
  @param
395
366
                                 char_length)) < key_part->length)
396
367
          tmp.length(charpos);
397
368
      }
398
 
 
 
369
      
399
370
      if (key_part->length < field->pack_length())
400
371
        tmp.length(cmin(tmp.length(),(uint32_t)key_part->length));
401
372
      to->append(tmp);