25
25
#include <drizzled/probes.h>
26
26
#include <drizzled/sql_base.h>
27
27
#include <drizzled/sql_load.h>
28
#include <drizzled/field/epoch.h>
28
#include <drizzled/field/timestamp.h>
29
29
#include <drizzled/lock.h>
30
30
#include "drizzled/sql_table.h"
31
31
#include "drizzled/pthread_globals.h"
32
32
#include "drizzled/transaction_services.h"
33
33
#include "drizzled/plugin/transactional_storage_engine.h"
35
#include "drizzled/table/shell.h"
272
270
value_count= values->elements;
274
if (prepare_insert(session, table_list, table, fields, values,
272
if (mysql_prepare_insert(session, table_list, table, fields, values,
275
273
update_fields, update_values, duplic, &unused_conds,
277
275
(fields.elements || !value_count ||
278
276
(0) != 0), !ignore))
281
table->cursor->ha_release_auto_increment();
283
free_underlaid_joins(session, &session->lex->select_lex);
284
session->setAbortOnWarning(false);
285
DRIZZLE_INSERT_DONE(1, 0);
289
279
/* mysql_prepare_insert set table_list->table if it was not set */
290
280
table= table_list->table;
315
305
if (values->elements != value_count)
317
307
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
320
table->cursor->ha_release_auto_increment();
322
free_underlaid_joins(session, &session->lex->select_lex);
323
session->setAbortOnWarning(false);
324
DRIZZLE_INSERT_DONE(1, 0);
328
310
if (setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0))
331
table->cursor->ha_release_auto_increment();
333
free_underlaid_joins(session, &session->lex->select_lex);
334
session->setAbortOnWarning(false);
335
DRIZZLE_INSERT_DONE(1, 0);
478
452
table->cursor->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
483
table->cursor->ha_release_auto_increment();
485
free_underlaid_joins(session, &session->lex->select_lex);
486
session->setAbortOnWarning(false);
487
DRIZZLE_INSERT_DONE(1, 0);
491
456
if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
492
457
!session->cuted_fields))
494
459
session->row_count_func= info.copied + info.deleted + info.updated;
495
session->my_ok((ulong) session->rowCount(),
460
session->my_ok((ulong) session->row_count_func,
496
461
info.copied + info.deleted + info.touched, id);
505
470
snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
506
471
(ulong) (info.deleted + info.updated), (ulong) session->cuted_fields);
507
472
session->row_count_func= info.copied + info.deleted + info.updated;
508
session->my_ok((ulong) session->rowCount(),
473
session->my_ok((ulong) session->row_count_func,
509
474
info.copied + info.deleted + info.touched, id, buff);
511
session->status_var.inserted_row_count+= session->rowCount();
512
session->setAbortOnWarning(false);
513
DRIZZLE_INSERT_DONE(0, session->rowCount());
476
session->status_var.inserted_row_count+= session->row_count_func;
477
session->abort_on_warning= 0;
478
DRIZZLE_INSERT_DONE(0, session->row_count_func);
483
table->cursor->ha_release_auto_increment();
485
free_underlaid_joins(session, &session->lex->select_lex);
486
session->abort_on_warning= 0;
487
DRIZZLE_INSERT_DONE(1, 0);
659
632
if (!res && check_fields)
661
bool saved_abort_on_warning= session->abortOnWarning();
663
session->setAbortOnWarning(abort_on_warning);
634
bool saved_abort_on_warning= session->abort_on_warning;
635
session->abort_on_warning= abort_on_warning;
664
636
res= check_that_all_fields_are_given_values(session,
666
638
context->table_list->table,
667
639
context->table_list);
668
session->setAbortOnWarning(saved_abort_on_warning);
640
session->abort_on_warning= saved_abort_on_warning;
671
643
if (!res && duplic == DUP_UPDATE)
1106
1078
if (!res && fields->elements)
1108
bool saved_abort_on_warning= session->abortOnWarning();
1109
session->setAbortOnWarning(not info.ignore);
1080
bool saved_abort_on_warning= session->abort_on_warning;
1081
session->abort_on_warning= !info.ignore;
1110
1082
res= check_that_all_fields_are_given_values(session, table_list->table,
1112
session->setAbortOnWarning(saved_abort_on_warning);
1084
session->abort_on_warning= saved_abort_on_warning;
1115
1087
if (info.handle_duplicates == DUP_UPDATE && !res)
1202
1174
table->next_number_field=table->found_next_number_field;
1204
1176
session->cuted_fields=0;
1206
1177
if (info.ignore || info.handle_duplicates != DUP_ERROR)
1207
1178
table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1209
1179
if (info.handle_duplicates == DUP_REPLACE)
1210
1180
table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1212
1181
if (info.handle_duplicates == DUP_UPDATE)
1213
1182
table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1215
session->setAbortOnWarning(not info.ignore);
1183
session->abort_on_warning= !info.ignore;
1216
1184
table->mark_columns_needed_for_insert();
1382
1354
(session->arg_of_last_insert_id_function ?
1383
1355
session->first_successful_insert_id_in_prev_stmt :
1384
1356
(info.copied ? autoinc_value_of_last_inserted_row : 0));
1385
session->my_ok((ulong) session->rowCount(),
1357
session->my_ok((ulong) session->row_count_func,
1386
1358
info.copied + info.deleted + info.touched, id, buff);
1387
session->status_var.inserted_row_count+= session->rowCount();
1388
DRIZZLE_INSERT_SELECT_DONE(0, session->rowCount());
1359
session->status_var.inserted_row_count+= session->row_count_func;
1360
DRIZZLE_INSERT_SELECT_DONE(0, session->row_count_func);
1504
1479
create_info->table_existed= 1; // Mark that table existed
1505
1480
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1506
1481
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1507
create_table->getTableName());
1482
create_table->table_name);
1508
1483
return create_table->table;
1511
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
1486
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1490
tmp_table.timestamp_field= 0;
1491
tmp_table.setShare(&share);
1493
tmp_table.getMutableShare()->db_create_options= 0;
1494
tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1496
if (not table_proto.engine().name().compare("MyISAM"))
1497
tmp_table.getMutableShare()->db_low_byte_first= true;
1498
else if (not table_proto.engine().name().compare("MEMORY"))
1499
tmp_table.getMutableShare()->db_low_byte_first= true;
1501
tmp_table.null_row= false;
1502
tmp_table.maybe_null= false;
1504
tmp_table.in_use= session;
1516
table::Shell tmp_table(share); // Used during 'CreateField()'
1518
if (not table_proto.engine().name().compare("MyISAM"))
1519
tmp_table.getMutableShare()->db_low_byte_first= true;
1520
else if (not table_proto.engine().name().compare("MEMORY"))
1521
tmp_table.getMutableShare()->db_low_byte_first= true;
1523
tmp_table.in_use= session;
1508
CreateField *cr_field;
1509
Field *field, *def_field;
1510
if (item->type() == Item::FUNC_ITEM)
1527
CreateField *cr_field;
1528
Field *field, *def_field;
1529
if (item->type() == Item::FUNC_ITEM)
1512
if (item->result_type() != STRING_RESULT)
1531
if (item->result_type() != STRING_RESULT)
1533
field= item->tmp_table_field(&tmp_table);
1537
field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1514
field= item->tmp_table_field(&tmp_table);
1542
field= create_tmp_field(session, &tmp_table, item, item->type(),
1543
(Item ***) 0, &tmp_field, &def_field, false,
1548
!(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
1549
((Item_field *)item)->field :
1555
if (item->maybe_null)
1557
cr_field->flags &= ~NOT_NULL_FLAG;
1560
alter_info->create_list.push_back(cr_field);
1518
field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1523
field= create_tmp_field(session, &tmp_table, item, item->type(),
1524
(Item ***) 0, &tmp_field, &def_field, false,
1529
!(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
1530
((Item_field *)item)->field :
1536
if (item->maybe_null)
1538
cr_field->flags &= ~NOT_NULL_FLAG;
1541
alter_info->create_list.push_back(cr_field);
1586
1565
or it was created via different mysqld front-end to the
1587
1566
cluster. We don't have much options but throw an error.
1589
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
1568
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1593
1572
if (not identifier.isTmp())
1595
/* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1596
boost::mutex::scoped_lock scopedLock(table::Cache::singleton().mutex());
1598
if (create_table->table)
1574
LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1575
if (session->reopen_name_locked_table(create_table, false))
1600
table::Concurrent *concurrent_table= static_cast<table::Concurrent *>(create_table->table);
1602
if (concurrent_table->reopen_name_locked_table(create_table, session))
1604
(void)plugin::StorageEngine::dropTable(*session, identifier);
1608
table= create_table->table;
1577
quick_rm_table(*session, identifier);
1613
(void)plugin::StorageEngine::dropTable(*session, identifier);
1580
table= create_table->table;
1624
1591
it preparable for open. But let us do close_temporary_table() here
1627
session->drop_temporary_table(identifier);
1594
session->drop_temporary_table(create_table);
1631
if (not table) // open failed
1598
if (!table) // open failed
1635
1602
table->reginfo.lock_type=TL_WRITE;
1636
if (not ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH)))
1603
if (! ((*lock)= mysql_lock_tables(session, &table, 1,
1604
DRIZZLE_LOCK_IGNORE_FLUSH, ¬_used)))
1640
session->unlockTables(*lock);
1608
mysql_unlock_tables(session, *lock);
1710
1676
session->cuted_fields=0;
1711
1677
if (info.ignore || info.handle_duplicates != DUP_ERROR)
1712
1678
table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1714
1679
if (info.handle_duplicates == DUP_REPLACE)
1715
1680
table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1717
1681
if (info.handle_duplicates == DUP_UPDATE)
1718
1682
table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1720
1683
table->cursor->ha_start_bulk_insert((ha_rows) 0);
1721
session->setAbortOnWarning(not info.ignore);
1684
session->abort_on_warning= !info.ignore;
1722
1685
if (check_that_all_fields_are_given_values(session, table, table_list))
1725
1687
table->mark_columns_needed_for_insert();
1726
1688
table->cursor->extra(HA_EXTRA_WRITE_CACHE);