820
821
int HailDBCursor::open(const char *name, int, uint32_t)
822
823
const char* haildb_table_name= table_path_to_haildb_name(name);
823
ib_err_t err= ib_cursor_open_table(haildb_table_name, NULL, &cursor);
824
ib_err_t err= ib_table_get_id(haildb_table_name, &table_id);
824
825
bool has_hidden_primary_key= false;
827
828
if (err != DB_SUCCESS)
828
829
return ib_err_t_to_drizzle_error(err);
831
err= ib_cursor_open_table_using_id(table_id, NULL, &cursor);
832
cursor_is_sec_index= false;
834
if (err != DB_SUCCESS)
835
return ib_err_t_to_drizzle_error(err);
830
837
err= ib_index_get_id(haildb_table_name, "HIDDEN_PRIMARY", &idx_id);
832
839
if (err == DB_SUCCESS)
1778
1785
return("BTREE");
1781
static ib_err_t write_row_to_haildb_tuple(Field **fields, ib_tpl_t tuple)
1788
static ib_err_t write_row_to_haildb_tuple(const unsigned char* buf,
1789
Field **fields, ib_tpl_t tuple)
1784
1792
ib_err_t err= DB_ERROR;
1793
ptrdiff_t row_offset= buf - (*fields)->getTable()->getInsertRecord();
1786
1795
for (Field **field= fields; *field; field++, colnr++)
1797
(**field).move_field_offset(row_offset);
1788
1799
if (! (**field).isWriteSet() && (**field).is_null())
1801
(**field).move_field_offset(-row_offset);
1791
1805
if ((**field).is_null())
1793
1807
err= ib_col_set_value(tuple, colnr, NULL, IB_SQL_NULL);
1794
1808
assert(err == DB_SUCCESS);
1809
(**field).move_field_offset(-row_offset);
1878
1895
tuple= ib_clust_read_tuple_create(cursor);
1880
ib_cursor_attach_trx(cursor, transaction);
1897
if (cursor_is_sec_index)
1899
err= ib_cursor_close(cursor);
1900
assert(err == DB_SUCCESS);
1902
err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
1904
if (err != DB_SUCCESS)
1905
return ib_err_t_to_drizzle_error(err);
1907
cursor_is_sec_index= false;
1911
ib_cursor_attach_trx(cursor, transaction);
1882
1914
err= ib_cursor_first(cursor);
1883
1915
if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
1983
2015
tuple= ib_tuple_clear(tuple);
1984
2016
ib_tuple_delete(tuple);
1985
2018
err= ib_cursor_reset(cursor);
1990
int HailDBCursor::doUpdateRecord(const unsigned char *,
2023
int HailDBCursor::doUpdateRecord(const unsigned char *old_data,
2024
unsigned char *new_data)
1993
2026
ib_tpl_t update_tuple;
2028
bool created_tuple= false;
1996
2030
update_tuple= ib_clust_read_tuple_create(cursor);
2034
ib_trx_t transaction= *get_trx(getTable()->in_use);
2036
if (cursor_is_sec_index)
2038
err= ib_cursor_close(cursor);
2039
assert(err == DB_SUCCESS);
2041
err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2043
if (err != DB_SUCCESS)
2044
return ib_err_t_to_drizzle_error(err);
2045
cursor_is_sec_index= false;
2049
ib_cursor_attach_trx(cursor, transaction);
2052
store_key_value_from_haildb(getTable()->key_info + getTable()->getShare()->getPrimaryKey(),
2053
ref, ref_length, old_data);
2055
ib_tpl_t search_tuple= ib_clust_search_tuple_create(cursor);
2057
fill_ib_search_tpl_from_drizzle_key(search_tuple,
2058
getTable()->key_info + 0,
2061
err= ib_cursor_set_lock_mode(cursor, IB_LOCK_X);
2062
assert(err == DB_SUCCESS);
2065
err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2066
assert(err == DB_SUCCESS);
2068
tuple= ib_clust_read_tuple_create(cursor);
2070
err= ib_cursor_read_row(cursor, tuple);
2071
assert(err == DB_SUCCESS);// FIXME
2073
created_tuple= true;
1998
2076
err= ib_tuple_copy(update_tuple, tuple);
1999
2077
assert(err == DB_SUCCESS);
2001
write_row_to_haildb_tuple(getTable()->getFields(), update_tuple);
2079
write_row_to_haildb_tuple(new_data, getTable()->getFields(), update_tuple);
2003
2081
err= ib_cursor_update_row(cursor, tuple, update_tuple);
2005
2083
ib_tuple_delete(update_tuple);
2087
ib_err_t ib_err= ib_cursor_reset(cursor); //fixme check error
2088
assert(ib_err == DB_SUCCESS);
2089
tuple= ib_tuple_clear(tuple);
2090
ib_tuple_delete(tuple);
2007
2094
advance_cursor= true;
2009
if (err == DB_SUCCESS)
2011
else if (err == DB_DUPLICATE_KEY)
2012
return HA_ERR_FOUND_DUPP_KEY;
2096
return ib_err_t_to_drizzle_error(err);
2017
2099
int HailDBCursor::doDeleteRecord(const unsigned char *)
2103
assert(ib_cursor_is_positioned(cursor) == IB_TRUE);
2021
2104
err= ib_cursor_delete_row(cursor);
2022
if (err != DB_SUCCESS)
2025
2106
advance_cursor= true;
2108
return ib_err_t_to_drizzle_error(err);
2029
2111
int HailDBCursor::delete_all_rows(void)
2031
2113
/* I *think* ib_truncate is non-transactional....
2032
2114
so only support TRUNCATE and not DELETE FROM t;
2033
(this is what ha_haildb does)
2115
(this is what ha_innodb does)
2035
2117
if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2036
2118
return HA_ERR_WRONG_COMMAND;
2041
2123
ib_trx_t transaction= ib_trx_begin(IB_TRX_REPEATABLE_READ);
2043
ib_cursor_attach_trx(cursor, transaction);
2125
if (cursor_is_sec_index)
2127
err= ib_cursor_close(cursor);
2128
assert(err == DB_SUCCESS);
2130
err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2132
if (err != DB_SUCCESS)
2133
return ib_err_t_to_drizzle_error(err);
2134
cursor_is_sec_index= false;
2138
ib_cursor_attach_trx(cursor, transaction);
2045
2141
err= ib_schema_lock_exclusive(transaction);
2046
2142
if (err != DB_SUCCESS)
2093
2189
assert(transaction != NULL);
2095
ib_cursor_attach_trx(cursor, transaction);
2191
if (cursor_is_sec_index)
2193
err= ib_cursor_close(cursor);
2194
assert(err == DB_SUCCESS);
2196
err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2197
cursor_is_sec_index= false;
2201
ib_cursor_attach_trx(cursor, transaction);
2204
if (err != DB_SUCCESS)
2205
return ib_err_t_to_drizzle_error(err);
2097
2207
err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2098
2208
assert(err == DB_SUCCESS); // FIXME
2382
2505
if (flag & HA_STATUS_AUTO)
2383
2506
stats.auto_increment_value= 1;
2508
if (flag & HA_STATUS_ERRKEY) {
2509
const char *err_table_name;
2510
const char *err_index_name;
2512
ib_trx_t transaction= *get_trx(getTable()->in_use);
2514
err= ib_get_duplicate_key(transaction, &err_table_name, &err_index_name);
2518
for (unsigned int i = 0; i < getTable()->getShare()->keys; i++)
2520
if (strcmp(err_index_name, getTable()->key_info[i].name) == 0)
2387
2532
int HailDBCursor::doStartIndexScan(uint32_t keynr, bool)
2389
2535
ib_trx_t transaction= *get_trx(getTable()->in_use);
2391
2537
active_index= keynr;
2393
ib_cursor_attach_trx(cursor, transaction);
2395
2539
if (active_index == 0 && ! share->has_hidden_primary_key)
2541
if (cursor_is_sec_index)
2543
err= ib_cursor_close(cursor);
2544
assert(err == DB_SUCCESS);
2546
err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2548
if (err != DB_SUCCESS)
2549
return ib_err_t_to_drizzle_error(err);
2554
ib_cursor_attach_trx(cursor, transaction);
2557
cursor_is_sec_index= false;
2397
2558
tuple= ib_clust_read_tuple_create(cursor);
2402
2562
ib_id_t index_id;
2403
2563
err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2404
2564
getShare()->getKeyInfo(keynr).name,
2406
2566
if (err != DB_SUCCESS)
2567
return ib_err_t_to_drizzle_error(err);
2409
2569
err= ib_cursor_close(cursor);
2410
2570
assert(err == DB_SUCCESS);
2411
2572
err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2413
2574
if (err != DB_SUCCESS)
2575
return ib_err_t_to_drizzle_error(err);
2577
cursor_is_sec_index= true;
2416
2579
tuple= ib_clust_read_tuple_create(cursor);
2417
2580
ib_cursor_set_cluster_access(cursor);
2420
ib_err_t err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2583
err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2421
2584
assert(err == DB_SUCCESS);
2423
2586
advance_cursor= false;