168
168
BlitzData blitz_table;
173
/* Write the table definition to system table. */
174
if ((ecode = dict.open_system_table(from.getPath(), HDBOWRITER)) != 0)
177
drizzled::message::Table proto;
179
int proto_string_len;
181
proto_string = dict.get_system_entry(BLITZ_TABLE_PROTO_KEY.c_str(),
182
BLITZ_TABLE_PROTO_KEY.length(),
185
if (proto_string == NULL) {
189
if (!proto.ParseFromArray(proto_string, proto_string_len)) {
191
return HA_ERR_CRASHED_ON_USAGE;
196
proto.set_name(to.getTableName());
197
proto.set_schema(to.getSchemaName());
198
proto.set_catalog(to.getCatalogName());
200
if (!dict.write_table_definition(proto)) {
201
dict.close_system_table();
202
return HA_ERR_CRASHED_ON_USAGE;
205
dict.close_system_table();
171
207
/* Find out the number of indexes in this table. This information
172
208
is required because BlitzDB creates a file for each indexes.*/
173
209
if (blitz_table.open_data_table(from.getPath().c_str(), HDBOREADER) != 0)
1107
end = key_part->field->pack(pos, row + key_part->offset);
1143
/* Here we normalize VARTEXT1 to VARTEXT2 for simplicity. */
1144
if (key_part->type == HA_KEYTYPE_VARTEXT1) {
1145
/* Extract the length of the string from the row. */
1146
uint16_t data_len = *(uint8_t *)(row + key_part->offset);
1148
/* Copy the length of the string. Use 2 bytes. */
1149
int2store(pos, data_len);
1150
pos += sizeof(data_len);
1152
/* Copy the string data */
1153
memcpy(pos, row + key_part->offset + sizeof(uint8_t), data_len);
1156
end = key_part->field->pack(pos, row + key_part->offset);
1112
1162
return ((char *)pos - pack_to);
1155
1205
for (; key_part != key_part_end; key_part++) {
1156
1206
if (key_part->null_bit) {
1162
if (key_part->type == HA_KEYTYPE_VARTEXT1) {
1163
len = *(uint8_t *)pos;
1164
rv += len + sizeof(uint8_t);
1165
} else if (key_part->type == HA_KEYTYPE_VARTEXT2) {
1213
if (key_part->type == HA_KEYTYPE_VARTEXT1 ||
1214
key_part->type == HA_KEYTYPE_VARTEXT2) {
1166
1215
len = uint2korr(pos);
1167
1216
rv += len + sizeof(uint16_t);
1209
/* This is a temporary workaround for a bug in Drizzle's VARCHAR
1210
where a 1 byte representable length varchar's actual data is
1211
positioned 2 bytes ahead of the beginning of the buffer. The
1212
correct behavior is to be positioned 1 byte ahead. Furthermore,
1213
this is only applicable with varchar keys on READ. */
1258
/* Normalize a VARTEXT1 key to VARTEXT2. */
1214
1259
if (key_part->type == HA_KEYTYPE_VARTEXT1) {
1215
/* Dereference the 1 byte length of the value. */
1216
uint8_t varlen = *(uint8_t *)key_pos;
1217
*keybuf_pos++ = varlen;
1219
/* Read the value by skipping 2 bytes. This is the workaround. */
1220
memcpy(keybuf_pos, key_pos + sizeof(uint16_t), varlen);
1221
offset = (sizeof(uint8_t) + varlen);
1222
keybuf_pos += varlen;
1260
uint16_t str_len = *(uint16_t *)key_pos;
1262
/* Copy the length of the string over to key buffer. */
1263
int2store(keybuf_pos, str_len);
1264
keybuf_pos += sizeof(str_len);
1266
/* Copy the actual value over to the key buffer. */
1267
memcpy(keybuf_pos, key_pos + sizeof(str_len), str_len);
1268
keybuf_pos += str_len;
1270
/* NULL byte + Length of str (2 byte) + Actual String. */
1271
offset = 1 + sizeof(str_len) + str_len;
1224
1273
end = key_part->field->pack(keybuf_pos, key_pos);
1225
1274
offset = end - keybuf_pos;