477
ib_trx_t transaction= *get_trx(table->in_use);
477
ib_trx_t transaction= *get_trx(getTable()->in_use);
478
478
ib_cursor_attach_trx(cursor, transaction);
479
479
tuple= ib_clust_read_tuple_create(cursor);
480
480
err= ib_cursor_last(cursor);
487
487
assert (err == DB_SUCCESS);
488
err= ib_tuple_read_u64(tuple, table->getShare()->fields, &nr);
488
err= ib_tuple_read_u64(tuple, getTable()->getShare()->fields, &nr);
491
491
ib_tuple_delete(tuple);
502
502
(void) extra(HA_EXTRA_KEYREAD);
503
table->mark_columns_used_by_index_no_reset(table->getShare()->next_number_index);
504
doStartIndexScan(table->getShare()->next_number_index, 1);
505
if (table->getShare()->next_number_keypart == 0)
503
getTable()->mark_columns_used_by_index_no_reset(getTable()->getShare()->next_number_index);
504
doStartIndexScan(getTable()->getShare()->next_number_index, 1);
505
if (getTable()->getShare()->next_number_keypart == 0)
506
506
{ // Autoincrement at key-start
507
error=index_last(table->getUpdateRecord());
507
error=index_last(getTable()->getUpdateRecord());
511
511
unsigned char key[MAX_KEY_LENGTH];
512
key_copy(key, table->getInsertRecord(),
513
table->key_info + table->getShare()->next_number_index,
514
table->getShare()->next_number_key_offset);
515
error= index_read_map(table->getUpdateRecord(), key,
516
make_prev_keypart_map(table->getShare()->next_number_keypart),
512
key_copy(key, getTable()->getInsertRecord(),
513
getTable()->key_info + getTable()->getShare()->next_number_index,
514
getTable()->getShare()->next_number_key_offset);
515
error= index_read_map(getTable()->getUpdateRecord(), key,
516
make_prev_keypart_map(getTable()->getShare()->next_number_keypart),
517
517
HA_READ_PREFIX_LAST);
523
nr= ((uint64_t) table->found_next_number_field->
524
val_int_offset(table->getShare()->rec_buff_length)+1);
523
nr= ((uint64_t) getTable()->found_next_number_field->
524
val_int_offset(getTable()->getShare()->rec_buff_length)+1);
525
525
doEndIndexScan();
526
526
(void) extra(HA_EXTRA_NO_KEYREAD);
528
if (table->getShare()->getTableProto()->options().auto_increment_value() > nr)
529
nr= table->getShare()->getTableProto()->options().auto_increment_value();
528
if (getTable()->getShare()->getTableProto()->options().auto_increment_value() > nr)
529
nr= getTable()->getShare()->getTableProto()->options().auto_increment_value();
798
798
HailDBCursor::HailDBCursor(drizzled::plugin::StorageEngine &engine_arg,
799
TableShare &table_arg)
800
800
:Cursor(engine_arg, table_arg),
801
801
ib_lock_mode(IB_LOCK_NONE),
802
802
write_can_replace(false),
836
836
lock.init(&share->lock);
839
if (table->getShare()->getPrimaryKey() != MAX_KEY)
840
ref_length= table->key_info[table->getShare()->getPrimaryKey()].key_length;
839
if (getTable()->getShare()->getPrimaryKey() != MAX_KEY)
840
ref_length= getTable()->key_info[getTable()->getShare()->getPrimaryKey()].key_length;
841
841
else if (share->has_hidden_primary_key)
842
842
ref_length= sizeof(uint64_t);
845
unsigned int keynr= get_first_unique_index(*table);
846
ref_length= table->key_info[keynr].key_length;
845
unsigned int keynr= get_first_unique_index(*getTable());
846
ref_length= getTable()->key_info[keynr].key_length;
849
849
in_table_scan= false;
1897
HailDBEngine *storage_engine= static_cast<HailDBEngine*>(engine);
1897
HailDBEngine *storage_engine= static_cast<HailDBEngine*>(getEngine());
1898
1898
err= ib_cursor_reset(cursor);
1899
1899
storage_engine->doCommit(current_session, true);
1900
1900
storage_engine->doStartTransaction(current_session, START_TRANS_NO_OPTIONS);
1901
transaction= *get_trx(table->in_use);
1901
transaction= *get_trx(getTable()->in_use);
1902
1902
assert(err == DB_SUCCESS);
1903
1903
ib_cursor_attach_trx(cursor, transaction);
1904
1904
err= ib_cursor_first(cursor);
1907
1907
assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
1910
if (table->next_number_field)
1910
if (getTable()->next_number_field)
1912
1912
update_auto_increment();
1914
uint64_t temp_auto= table->next_number_field->val_int();
1914
uint64_t temp_auto= getTable()->next_number_field->val_int();
1916
if (temp_auto <= innobase_get_int_col_max_value(table->next_number_field))
1916
if (temp_auto <= innobase_get_int_col_max_value(getTable()->next_number_field))
1938
write_row_to_haildb_tuple(table->getFields(), tuple);
1938
write_row_to_haildb_tuple(getTable()->getFields(), tuple);
1940
1940
if (share->has_hidden_primary_key)
1942
err= ib_tuple_write_u64(tuple, table->getShare()->fields, share->hidden_pkey_auto_increment_value.fetch_and_increment());
1942
err= ib_tuple_write_u64(tuple, getTable()->getShare()->fields, share->hidden_pkey_auto_increment_value.fetch_and_increment());
1945
1945
err= ib_cursor_insert_row(cursor, tuple);
1949
1949
if (write_can_replace)
1951
store_key_value_from_haildb(table->key_info + table->getShare()->getPrimaryKey(),
1951
store_key_value_from_haildb(getTable()->key_info + getTable()->getShare()->getPrimaryKey(),
1952
1952
ref, ref_length, record);
1954
1954
ib_tpl_t search_tuple= ib_clust_search_tuple_create(cursor);
1956
1956
fill_ib_search_tpl_from_drizzle_key(search_tuple,
1957
table->key_info + 0,
1957
getTable()->key_info + 0,
1958
1958
ref, ref_length);
1968
1968
err= ib_cursor_first(cursor);
1969
1969
assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
1971
write_row_to_haildb_tuple(table->getFields(), tuple);
1971
write_row_to_haildb_tuple(getTable()->getFields(), tuple);
1973
1973
err= ib_cursor_insert_row(cursor, tuple);
1974
1974
assert(err==DB_SUCCESS); // probably be nice and process errors
1997
1997
err= ib_tuple_copy(update_tuple, tuple);
1998
1998
assert(err == DB_SUCCESS);
2000
write_row_to_haildb_tuple(table->getFields(), update_tuple);
2000
write_row_to_haildb_tuple(getTable()->getFields(), update_tuple);
2002
2002
err= ib_cursor_update_row(cursor, tuple, update_tuple);
2031
2031
so only support TRUNCATE and not DELETE FROM t;
2032
2032
(this is what ha_haildb does)
2034
if (session_sql_command(table->in_use) != SQLCOM_TRUNCATE)
2034
if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2035
2035
return HA_ERR_WRONG_COMMAND;
2047
2047
ib_err_t rollback_err= ib_trx_rollback(transaction);
2049
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2049
push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2050
2050
ER_CANT_DELETE_FILE,
2051
2051
_("Cannot Lock HailDB Data Dictionary. HailDB Error %d (%s)\n"),
2052
2052
err, ib_strerror(err));
2206
2206
err= ib_cursor_next(cursor);
2208
2208
tuple= ib_tuple_clear(tuple);
2209
ret= read_row_from_haildb(buf, cursor, tuple, table,
2209
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2210
2210
share->has_hidden_primary_key,
2211
2211
&hidden_autoinc_pkey_position);
2243
2243
unsigned int keynr;
2244
if (table->getShare()->getPrimaryKey() != MAX_KEY)
2245
keynr= table->getShare()->getPrimaryKey();
2244
if (getTable()->getShare()->getPrimaryKey() != MAX_KEY)
2245
keynr= getTable()->getShare()->getPrimaryKey();
2247
keynr= get_first_unique_index(*table);
2247
keynr= get_first_unique_index(*getTable());
2249
2249
fill_ib_search_tpl_from_drizzle_key(search_tuple,
2250
table->key_info + keynr,
2250
getTable()->key_info + keynr,
2251
2251
pos, ref_length);
2263
2263
tuple= ib_tuple_clear(tuple);
2266
ret= read_row_from_haildb(buf, cursor, tuple, table,
2266
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2267
2267
share->has_hidden_primary_key,
2268
2268
&hidden_autoinc_pkey_position);
2336
2336
unsigned int keynr;
2337
if (table->getShare()->getPrimaryKey() != MAX_KEY)
2338
keynr= table->getShare()->getPrimaryKey();
2337
if (getTable()->getShare()->getPrimaryKey() != MAX_KEY)
2338
keynr= getTable()->getShare()->getPrimaryKey();
2340
keynr= get_first_unique_index(*table);
2340
keynr= get_first_unique_index(*getTable());
2342
store_key_value_from_haildb(table->key_info + keynr,
2342
store_key_value_from_haildb(getTable()->key_info + keynr,
2343
2343
ref, ref_length, record);
2401
2401
ib_id_t index_id;
2402
err= ib_index_get_id(table_path_to_haildb_name(table_share->getPath()),
2403
table_share->getKeyInfo(keynr).name,
2402
err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2403
getShare()->getKeyInfo(keynr).name,
2405
2405
if (err != DB_SUCCESS)
2547
2547
search_tuple= ib_sec_search_tuple_create(cursor);
2549
2549
fill_ib_search_tpl_from_drizzle_key(search_tuple,
2550
table->key_info + active_index,
2550
getTable()->key_info + active_index,
2551
2551
key_ptr, key_len);
2553
2553
err= ib_cursor_moveto(cursor, search_tuple, search_mode, &res);
2567
2567
tuple= ib_tuple_clear(tuple);
2568
ret= read_row_from_haildb(buf, cursor, tuple, table,
2568
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2569
2569
share->has_hidden_primary_key,
2570
2570
&hidden_autoinc_pkey_position,
2571
2571
(allocate_blobs)? &blobroot : NULL);
2573
getTable()->status= 0;
2575
table->status= STATUS_NOT_FOUND;
2575
getTable()->status= STATUS_NOT_FOUND;
2577
2577
advance_cursor= true;
2594
2594
/* works only with key prefixes */
2595
2595
assert(((keypart_map_arg + 1) & keypart_map_arg) == 0);
2597
KeyPartInfo *key_part_found= table->getShare()->getKeyInfo(key_position).key_part;
2598
KeyPartInfo *end_key_part_found= key_part_found + table->getShare()->getKeyInfo(key_position).key_parts;
2597
KeyPartInfo *key_part_found= getTable()->getShare()->getKeyInfo(key_position).key_part;
2598
KeyPartInfo *end_key_part_found= key_part_found + getTable()->getShare()->getKeyInfo(key_position).key_parts;
2599
2599
uint32_t length= 0;
2601
2601
while (key_part_found < end_key_part_found && keypart_map_arg)
2656
2656
tuple= ib_tuple_clear(tuple);
2657
ret= read_row_from_haildb(buf, cursor, tuple, table,
2657
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2658
2658
share->has_hidden_primary_key,
2659
2659
&hidden_autoinc_pkey_position);
2689
2689
tuple= ib_tuple_clear(tuple);
2690
ret= read_row_from_haildb(buf, cursor, tuple, table,
2690
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2691
2691
share->has_hidden_primary_key,
2692
2692
&hidden_autoinc_pkey_position);
2707
2707
return ib_err_t_to_drizzle_error(err);
2709
2709
tuple= ib_tuple_clear(tuple);
2710
ret= read_row_from_haildb(buf, cursor, tuple, table,
2710
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2711
2711
share->has_hidden_primary_key,
2712
2712
&hidden_autoinc_pkey_position);
2727
2727
return ib_err_t_to_drizzle_error(err);
2729
2729
tuple= ib_tuple_clear(tuple);
2730
ret= read_row_from_haildb(buf, cursor, tuple, table,
2730
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2731
2731
share->has_hidden_primary_key,
2732
2732
&hidden_autoinc_pkey_position);
2733
2733
advance_cursor= true;