12
12
You should have received a copy of the GNU General Public License
13
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
17
/* Insert of records */
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
269
value_count= values->elements;
274
if (prepare_insert(session, table_list, table, fields, values,
271
if (mysql_prepare_insert(session, table_list, table, fields, values,
275
272
update_fields, update_values, duplic, &unused_conds,
277
274
(fields.elements || !value_count ||
278
275
(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
278
/* mysql_prepare_insert set table_list->table if it was not set */
290
279
table= table_list->table;
315
304
if (values->elements != value_count)
317
306
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
309
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
451
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
455
if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
492
456
!session->cuted_fields))
494
458
session->row_count_func= info.copied + info.deleted + info.updated;
495
session->my_ok((ulong) session->rowCount(),
459
session->my_ok((ulong) session->row_count_func,
496
460
info.copied + info.deleted + info.touched, id);
505
469
snprintf(buff, sizeof(buff), ER(ER_INSERT_INFO), (ulong) info.records,
506
470
(ulong) (info.deleted + info.updated), (ulong) session->cuted_fields);
507
471
session->row_count_func= info.copied + info.deleted + info.updated;
508
session->my_ok((ulong) session->rowCount(),
472
session->my_ok((ulong) session->row_count_func,
509
473
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());
475
session->status_var.inserted_row_count+= session->row_count_func;
476
session->abort_on_warning= 0;
477
DRIZZLE_INSERT_DONE(0, session->row_count_func);
482
table->cursor->ha_release_auto_increment();
484
free_underlaid_joins(session, &session->lex->select_lex);
485
session->abort_on_warning= 0;
486
DRIZZLE_INSERT_DONE(1, 0);
659
631
if (!res && check_fields)
661
bool saved_abort_on_warning= session->abortOnWarning();
663
session->setAbortOnWarning(abort_on_warning);
633
bool saved_abort_on_warning= session->abort_on_warning;
634
session->abort_on_warning= abort_on_warning;
664
635
res= check_that_all_fields_are_given_values(session,
666
637
context->table_list->table,
667
638
context->table_list);
668
session->setAbortOnWarning(saved_abort_on_warning);
639
session->abort_on_warning= saved_abort_on_warning;
671
642
if (!res && duplic == DUP_UPDATE)
1106
1077
if (!res && fields->elements)
1108
bool saved_abort_on_warning= session->abortOnWarning();
1109
session->setAbortOnWarning(not info.ignore);
1079
bool saved_abort_on_warning= session->abort_on_warning;
1080
session->abort_on_warning= !info.ignore;
1110
1081
res= check_that_all_fields_are_given_values(session, table_list->table,
1112
session->setAbortOnWarning(saved_abort_on_warning);
1083
session->abort_on_warning= saved_abort_on_warning;
1115
1086
if (info.handle_duplicates == DUP_UPDATE && !res)
1202
1173
table->next_number_field=table->found_next_number_field;
1204
1175
session->cuted_fields=0;
1206
1176
if (info.ignore || info.handle_duplicates != DUP_ERROR)
1207
1177
table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1209
1178
if (info.handle_duplicates == DUP_REPLACE)
1210
1179
table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1212
1180
if (info.handle_duplicates == DUP_UPDATE)
1213
1181
table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1215
session->setAbortOnWarning(not info.ignore);
1182
session->abort_on_warning= !info.ignore;
1216
1183
table->mark_columns_needed_for_insert();
1382
1353
(session->arg_of_last_insert_id_function ?
1383
1354
session->first_successful_insert_id_in_prev_stmt :
1384
1355
(info.copied ? autoinc_value_of_last_inserted_row : 0));
1385
session->my_ok((ulong) session->rowCount(),
1356
session->my_ok((ulong) session->row_count_func,
1386
1357
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());
1358
session->status_var.inserted_row_count+= session->row_count_func;
1359
DRIZZLE_INSERT_SELECT_DONE(0, session->row_count_func);
1504
1478
create_info->table_existed= 1; // Mark that table existed
1505
1479
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1506
1480
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1507
create_table->getTableName());
1481
create_table->table_name);
1508
1482
return create_table->table;
1511
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
1485
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1489
tmp_table.timestamp_field= 0;
1490
tmp_table.setShare(&share);
1492
tmp_table.getMutableShare()->db_create_options= 0;
1493
tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1495
if (not table_proto.engine().name().compare("MyISAM"))
1496
tmp_table.getMutableShare()->db_low_byte_first= true;
1497
else if (not table_proto.engine().name().compare("MEMORY"))
1498
tmp_table.getMutableShare()->db_low_byte_first= true;
1500
tmp_table.null_row= false;
1501
tmp_table.maybe_null= false;
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;
1527
CreateField *cr_field;
1528
Field *field, *def_field;
1529
if (item->type() == Item::FUNC_ITEM)
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);
1505
CreateField *cr_field;
1506
Field *field, *def_field;
1507
if (item->type() == Item::FUNC_ITEM)
1508
if (item->result_type() != STRING_RESULT)
1509
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);
1511
field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1513
field= create_tmp_field(session, &tmp_table, item, item->type(),
1514
(Item ***) 0, &tmp_field, &def_field, false,
1517
!(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
1518
((Item_field *)item)->field :
1521
if (item->maybe_null)
1522
cr_field->flags &= ~NOT_NULL_FLAG;
1523
alter_info->create_list.push_back(cr_field);
1586
1547
or it was created via different mysqld front-end to the
1587
1548
cluster. We don't have much options but throw an error.
1589
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
1550
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1593
1554
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)
1556
LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1557
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;
1559
quick_rm_table(*session, identifier);
1613
(void)plugin::StorageEngine::dropTable(*session, identifier);
1562
table= create_table->table;
1624
1573
it preparable for open. But let us do close_temporary_table() here
1627
session->drop_temporary_table(identifier);
1576
session->drop_temporary_table(create_table);
1631
if (not table) // open failed
1580
if (!table) // open failed
1635
1584
table->reginfo.lock_type=TL_WRITE;
1636
if (not ((*lock)= session->lockTables(&table, 1, DRIZZLE_LOCK_IGNORE_FLUSH)))
1585
if (! ((*lock)= mysql_lock_tables(session, &table, 1,
1586
DRIZZLE_LOCK_IGNORE_FLUSH, ¬_used)))
1640
session->unlockTables(*lock);
1590
mysql_unlock_tables(session, *lock);
1710
1658
session->cuted_fields=0;
1711
1659
if (info.ignore || info.handle_duplicates != DUP_ERROR)
1712
1660
table->cursor->extra(HA_EXTRA_IGNORE_DUP_KEY);
1714
1661
if (info.handle_duplicates == DUP_REPLACE)
1715
1662
table->cursor->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1717
1663
if (info.handle_duplicates == DUP_UPDATE)
1718
1664
table->cursor->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1720
1665
table->cursor->ha_start_bulk_insert((ha_rows) 0);
1721
session->setAbortOnWarning(not info.ignore);
1666
session->abort_on_warning= !info.ignore;
1722
1667
if (check_that_all_fields_are_given_values(session, table, table_list))
1725
1669
table->mark_columns_needed_for_insert();
1726
1670
table->cursor->extra(HA_EXTRA_WRITE_CACHE);