~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/key.cc

  • Committer: Monty Taylor
  • Date: 2008-12-06 07:22:02 UTC
  • mto: (656.1.7 devel) (660.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 665.
  • Revision ID: monty@inaugust.com-20081206072202-2g25o9doqr1l8euu
OOOh doggie. Got rid of my_alloca.

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
*/