231
231
return (ib_trx_t*) session->getEngineData(embedded_innodb_engine);
234
/* This is a superset of the map from innobase plugin.
235
Unlike innobase plugin we don't act on errors here, we just
237
static int ib_err_t_to_drizzle_error(ib_err_t err)
249
return ER_QUERY_INTERRUPTED; // FIXME: is this correct?
251
case DB_OUT_OF_MEMORY:
252
return HA_ERR_OUT_OF_MEM;
254
case DB_DUPLICATE_KEY:
255
return HA_ERR_FOUND_DUPP_KEY;
257
case DB_FOREIGN_DUPLICATE_KEY:
258
return HA_ERR_FOREIGN_DUPLICATE_KEY;
260
case DB_MISSING_HISTORY:
261
return HA_ERR_TABLE_DEF_CHANGED;
263
case DB_RECORD_NOT_FOUND:
264
return HA_ERR_NO_ACTIVE_RECORD;
267
return HA_ERR_LOCK_DEADLOCK;
269
case DB_LOCK_WAIT_TIMEOUT:
270
return HA_ERR_LOCK_WAIT_TIMEOUT;
272
case DB_NO_REFERENCED_ROW:
273
return HA_ERR_NO_REFERENCED_ROW;
275
case DB_ROW_IS_REFERENCED:
276
return HA_ERR_ROW_IS_REFERENCED;
278
case DB_CANNOT_ADD_CONSTRAINT:
279
return HA_ERR_CANNOT_ADD_FOREIGN;
281
case DB_CANNOT_DROP_CONSTRAINT:
282
return HA_ERR_ROW_IS_REFERENCED; /* misleading. should have new err code */
284
case DB_COL_APPEARS_TWICE_IN_INDEX:
286
return HA_ERR_CRASHED;
288
case DB_MUST_GET_MORE_FILE_SPACE:
289
case DB_OUT_OF_FILE_SPACE:
290
return HA_ERR_RECORD_FILE_FULL;
292
case DB_TABLE_IS_BEING_USED:
293
return HA_ERR_WRONG_COMMAND;
295
case DB_TABLE_NOT_FOUND:
296
return HA_ERR_NO_SUCH_TABLE;
298
case DB_TOO_BIG_RECORD:
299
return HA_ERR_TO_BIG_ROW;
301
case DB_NO_SAVEPOINT:
302
return HA_ERR_NO_SAVEPOINT;
304
case DB_LOCK_TABLE_FULL:
305
return HA_ERR_LOCK_TABLE_FULL;
307
case DB_PRIMARY_KEY_IS_NULL:
308
return ER_PRIMARY_CANT_HAVE_NULL;
310
case DB_TOO_MANY_CONCURRENT_TRXS:
311
return HA_ERR_RECORD_FILE_FULL; /* need better error code */
313
case DB_END_OF_INDEX:
314
return HA_ERR_END_OF_FILE;
317
return HA_ERR_UNSUPPORTED;
234
321
static ib_trx_level_t tx_isolation_to_ib_trx_level(enum_tx_isolation level)
296
383
err= ib_savepoint_rollback(*transaction, savepoint.getName().c_str(),
297
384
savepoint.getName().length());
298
if (err != DB_SUCCESS)
386
return ib_err_t_to_drizzle_error(err);
304
389
int EmbeddedInnoDBEngine::doReleaseSavepoint(Session* session,
605
690
*nb_reserved_values= 1;
693
static const char* table_path_to_innodb_name(const char* name)
695
size_t l= strlen(name);
698
while(slashes>0 && l > 0)
608
710
static void TableIdentifier_to_innodb_name(const TableIdentifier &identifier, std::string *str)
610
str->reserve(identifier.getSchemaName().length() + identifier.getTableName().length() + 1);
611
// str->append(identifier.getPath().c_str()+2);
612
str->assign(identifier.getSchemaName());
614
str->append(identifier.getTableName());
712
str->assign(table_path_to_innodb_name(identifier.getPath().c_str()));
617
715
EmbeddedInnoDBCursor::EmbeddedInnoDBCursor(drizzled::plugin::StorageEngine &engine_arg,
618
716
TableShare &table_arg)
619
717
:Cursor(engine_arg, table_arg),
718
ib_lock_mode(IB_LOCK_NONE),
620
719
write_can_replace(false),
723
static unsigned int get_first_unique_index(drizzled::Table &table)
725
for (uint32_t k= 0; k < table.getShare()->keys; k++)
727
if (table.key_info[k].flags & HA_NOSAME)
624
736
int EmbeddedInnoDBCursor::open(const char *name, int, uint32_t)
626
ib_err_t err= ib_cursor_open_table(name+2, NULL, &cursor);
738
const char* innodb_table_name= table_path_to_innodb_name(name);
739
ib_err_t err= ib_cursor_open_table(innodb_table_name, NULL, &cursor);
627
740
bool has_hidden_primary_key= false;
628
assert (err == DB_SUCCESS);
631
err= ib_index_get_id(name+2, "HIDDEN_PRIMARY", &idx_id);
743
if (err != DB_SUCCESS)
744
return ib_err_t_to_drizzle_error(err);
746
err= ib_index_get_id(innodb_table_name, "HIDDEN_PRIMARY", &idx_id);
632
748
if (err == DB_SUCCESS)
633
749
has_hidden_primary_key= true;
962
if (table_message.type() == message::Table::TEMPORARY)
964
ib_bool_t create_db_err= ib_database_create(GLOBAL_TEMPORARY_EXT);
965
if (create_db_err != IB_TRUE)
838
969
TableIdentifier_to_innodb_name(identifier, &innodb_table_name);
840
971
ib_tbl_fmt_t innodb_table_format= IB_TBL_COMPACT;
859
990
ER_CANT_CREATE_TABLE,
860
991
_("Cannot create table %s. InnoDB Error %d (%s)\n"),
861
992
innodb_table_name.c_str(), innodb_err, ib_strerror(innodb_err));
862
return HA_ERR_GENERIC;
993
return ib_err_t_to_drizzle_error(innodb_err);
865
996
for (int colnr= 0; colnr < table_message.field_size() ; colnr++)
880
1011
" InnoDB Error %d (%s)\n"),
881
1012
field.name().c_str(), innodb_table_name.c_str(),
882
1013
innodb_err, ib_strerror(innodb_err));
883
return HA_ERR_GENERIC;
1014
return ib_err_t_to_drizzle_error(innodb_err);
885
1016
if (field_err != 0)
886
1017
return field_err;
995
1126
return HA_ERR_GENERIC;
998
innodb_err= store_table_message(innodb_schema_transaction,
999
innodb_table_name.c_str(),
1129
if (table_message.type() == message::Table::TEMPORARY)
1131
session.storeTableMessage(identifier, table_message);
1132
innodb_err= DB_SUCCESS;
1135
innodb_err= store_table_message(innodb_schema_transaction,
1136
innodb_table_name.c_str(),
1002
1139
if (innodb_err == DB_SUCCESS)
1003
1140
innodb_err= ib_trx_commit(innodb_schema_transaction);
1014
1151
_("Cannot create table %s. InnoDB Error %d (%s)\n"),
1015
1152
innodb_table_name.c_str(),
1016
1153
innodb_err, ib_strerror(innodb_err));
1017
return HA_ERR_GENERIC;
1154
return ib_err_t_to_drizzle_error(innodb_err);
1081
1218
return HA_ERR_GENERIC;
1084
if (delete_table_message_from_innodb(innodb_schema_transaction, innodb_table_name.c_str()) != DB_SUCCESS)
1086
ib_schema_unlock(innodb_schema_transaction);
1087
ib_err_t rollback_err= ib_trx_rollback(innodb_schema_transaction);
1088
assert(rollback_err == DB_SUCCESS);
1089
return HA_ERR_GENERIC;
1221
if (identifier.getType() == message::Table::TEMPORARY)
1223
session.removeTableMessage(identifier);
1224
delete_table_message_from_innodb(innodb_schema_transaction,
1225
innodb_table_name.c_str());
1229
if (delete_table_message_from_innodb(innodb_schema_transaction, innodb_table_name.c_str()) != DB_SUCCESS)
1231
ib_schema_unlock(innodb_schema_transaction);
1232
ib_err_t rollback_err= ib_trx_rollback(innodb_schema_transaction);
1233
assert(rollback_err == DB_SUCCESS);
1234
return HA_ERR_GENERIC;
1092
1238
innodb_err= ib_table_drop(innodb_schema_transaction, innodb_table_name.c_str());
1229
1375
string from_innodb_table_name;
1230
1376
string to_innodb_table_name;
1378
if (to.getType() == message::Table::TEMPORARY
1379
&& from.getType() == message::Table::TEMPORARY)
1381
session.renameTableMessage(from, to);
1232
1385
TableIdentifier_to_innodb_name(from, &from_innodb_table_name);
1233
1386
TableIdentifier_to_innodb_name(to, &to_innodb_table_name);
1265
1418
assert(rollback_err == DB_SUCCESS);
1266
1419
rollback_err= ib_trx_rollback(innodb_schema_transaction);
1267
1420
assert(rollback_err == DB_SUCCESS);
1421
return ib_err_t_to_drizzle_error(err);
1271
1424
void EmbeddedInnoDBEngine::getTableNamesInSchemaFromInnoDB(
1480
int EmbeddedInnoDBEngine::doGetTableDefinition(Session&,
1633
int EmbeddedInnoDBEngine::doGetTableDefinition(Session &session,
1481
1634
const TableIdentifier &identifier,
1482
1635
drizzled::message::Table &table)
1484
1637
ib_crsr_t innodb_cursor= NULL;
1485
1638
string innodb_table_name;
1640
/* Check temporary tables!? */
1641
if (session.getTableMessage(identifier, table))
1487
1644
TableIdentifier_to_innodb_name(identifier, &innodb_table_name);
1489
1646
if (ib_cursor_open_table(innodb_table_name.c_str(), NULL, &innodb_cursor) != DB_SUCCESS)
1847
2005
ib_cursor_attach_trx(cursor, transaction);
2007
err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2008
assert(err == DB_SUCCESS); // FIXME
1849
2010
tuple= ib_clust_read_tuple_create(cursor);
1851
ib_err_t err= ib_cursor_first(cursor);
2012
err= ib_cursor_first(cursor);
1852
2013
if (err != DB_SUCCESS && err != DB_END_OF_INDEX)
2015
previous_error= ib_err_t_to_drizzle_error(err);
2016
err= ib_cursor_reset(cursor);
2017
return previous_error;
1855
2020
advance_cursor= false;
2065
2241
void EmbeddedInnoDBCursor::position(const unsigned char *record)
2067
if (table->getShare()->getPrimaryKey() != MAX_KEY)
2068
store_key_value_from_innodb(table->key_info + table->getShare()->getPrimaryKey(),
2243
if (share->has_hidden_primary_key)
2244
*((uint64_t*) ref)= hidden_autoinc_pkey_position;
2248
if (table->getShare()->getPrimaryKey() != MAX_KEY)
2249
keynr= table->getShare()->getPrimaryKey();
2251
keynr= get_first_unique_index(*table);
2253
store_key_value_from_innodb(table->key_info + keynr,
2069
2254
ref, ref_length, record);
2071
*((uint64_t*) ref)= hidden_autoinc_pkey_position;
2104
2289
ib_id_t index_id;
2105
err= ib_index_get_id(table_share->getPath()+2,
2290
err= ib_index_get_id(table_path_to_innodb_name(table_share->getPath()),
2106
2291
table_share->getKeyInfo(keynr).name,
2108
2293
if (err != DB_SUCCESS)
2111
2296
err= ib_cursor_close(cursor);
2297
assert(err == DB_SUCCESS);
2112
2298
err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2114
2300
if (err != DB_SUCCESS)
2258
2447
return HA_ERR_KEY_NOT_FOUND;
2261
assert(err==DB_SUCCESS);
2450
if (err != DB_SUCCESS)
2452
return ib_err_t_to_drizzle_error(err);
2263
2455
tuple= ib_tuple_clear(tuple);
2264
2456
ret= read_row_from_innodb(buf, cursor, tuple, table,
2373
2565
if (advance_cursor)
2374
2567
err= ib_cursor_prev(cursor);
2376
if (active_index == 0)
2378
tuple= ib_tuple_clear(tuple);
2379
ret= read_row_from_innodb(buf, cursor, tuple, table,
2380
share->has_hidden_primary_key,
2381
&hidden_autoinc_pkey_position);
2568
if (err != DB_SUCCESS)
2570
if (err == DB_END_OF_INDEX)
2571
return HA_ERR_END_OF_FILE;
2577
tuple= ib_tuple_clear(tuple);
2578
ret= read_row_from_innodb(buf, cursor, tuple, table,
2579
share->has_hidden_primary_key,
2580
&hidden_autoinc_pkey_position);
2384
2582
advance_cursor= true;
2395
2593
err= ib_cursor_first(cursor);
2396
2594
if (err != DB_SUCCESS)
2398
if (err == DB_END_OF_INDEX)
2399
return HA_ERR_END_OF_FILE;
2595
return ib_err_t_to_drizzle_error(err);
2404
2597
tuple= ib_tuple_clear(tuple);
2405
2598
ret= read_row_from_innodb(buf, cursor, tuple, table,
2420
2613
err= ib_cursor_last(cursor);
2421
2614
if (err != DB_SUCCESS)
2423
if (err == DB_END_OF_INDEX)
2424
return HA_ERR_END_OF_FILE;
2615
return ib_err_t_to_drizzle_error(err);
2429
if (active_index == 0)
2431
tuple= ib_tuple_clear(tuple);
2432
ret= read_row_from_innodb(buf, cursor, tuple, table,
2433
share->has_hidden_primary_key,
2434
&hidden_autoinc_pkey_position);
2435
advance_cursor= true;
2617
tuple= ib_tuple_clear(tuple);
2618
ret= read_row_from_innodb(buf, cursor, tuple, table,
2619
share->has_hidden_primary_key,
2620
&hidden_autoinc_pkey_position);
2621
advance_cursor= true;