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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
14
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
17
17
/* Insert of records */
19
19
#include "config.h"
20
21
#include <drizzled/sql_select.h>
21
22
#include <drizzled/show.h>
22
23
#include <drizzled/error.h>
296
315
if (values->elements != value_count)
298
317
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->abort_on_warning= 0;
324
DRIZZLE_INSERT_DONE(1, 0);
301
328
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->abort_on_warning= 0;
335
DRIZZLE_INSERT_DONE(1, 0);
467
508
session->my_ok((ulong) session->row_count_func,
468
509
info.copied + info.deleted + info.touched, id, buff);
511
session->status_var.inserted_row_count+= session->row_count_func;
470
512
session->abort_on_warning= 0;
471
513
DRIZZLE_INSERT_DONE(0, session->row_count_func);
476
table->cursor->ha_release_auto_increment();
478
free_underlaid_joins(session, &session->lex->select_lex);
479
session->abort_on_warning= 0;
480
DRIZZLE_INSERT_DONE(1, 0);
709
int write_record(Session *session, Table *table,COPY_INFO *info)
743
int write_record(Session *session, Table *table,CopyInfo *info)
713
MyBitmap *save_read_set, *save_write_set;
746
std::vector<unsigned char> key;
747
boost::dynamic_bitset<> *save_read_set, *save_write_set;
714
748
uint64_t prev_insert_id= table->cursor->next_insert_id;
715
749
uint64_t insert_id_for_cur_row= 0;
785
if (!(key=(char*) malloc(table->s->max_unique_length)))
819
key.resize(table->getShare()->max_unique_length);
791
key_copy((unsigned char*) key,table->record[0],table->key_info+key_nr,0);
792
if ((error=(table->cursor->index_read_idx_map(table->record[1],key_nr,
793
(unsigned char*) key, HA_WHOLE_KEY,
821
key_copy(&key[0], table->getInsertRecord(), table->key_info+key_nr, 0);
822
if ((error=(table->cursor->index_read_idx_map(table->getUpdateRecord(),key_nr,
823
&key[0], HA_WHOLE_KEY,
794
824
HA_READ_KEY_EXACT))))
817
847
table->next_number_field->val_int());
819
849
if ((table->cursor->getEngine()->check_flag(HTON_BIT_PARTIAL_COLUMN_READ) &&
820
!bitmap_is_subset(table->write_set, table->read_set)) ||
850
! table->write_set->is_subset_of(*table->read_set)) ||
821
851
table->compare_record())
823
if ((error=table->cursor->ha_update_row(table->record[1],
824
table->record[0])) &&
853
if ((error=table->cursor->updateRecord(table->getUpdateRecord(),
854
table->getInsertRecord())) &&
825
855
error != HA_ERR_RECORD_IS_THE_SAME)
827
857
if (info->ignore &&
1043
1069
List<Item> *update_fields,
1044
1070
List<Item> *update_values,
1045
1071
enum_duplicates duplic,
1046
bool ignore_check_option_errors)
1047
:table_list(table_list_par), table(table_par), fields(fields_par),
1048
autoinc_value_of_last_inserted_row(0),
1049
insert_into_view(table_list_par && 0 != 0)
1072
bool ignore_check_option_errors) :
1073
table_list(table_list_par), table(table_par), fields(fields_par),
1074
autoinc_value_of_last_inserted_row(0),
1075
insert_into_view(table_list_par && 0 != 0)
1051
memset(&info, 0, sizeof(info));
1052
1077
info.handle_duplicates= duplic;
1053
1078
info.ignore= ignore_check_option_errors;
1054
1079
info.update_fields= update_fields;
1251
1276
store_values(values);
1252
1277
session->count_cuted_fields= CHECK_FIELD_IGNORE;
1253
1278
if (session->is_error())
1281
* If we fail mid-way through INSERT..SELECT, we need to remove any
1282
* records that we added to the current Statement message. We can
1283
* use session->row_count to know how many records we have already added.
1285
TransactionServices &ts= TransactionServices::singleton();
1286
ts.removeStatementRecords(session, (session->row_count - 1));
1256
1290
// Release latches in case bulk insert takes a long time
1257
1291
plugin::TransactionalStorageEngine::releaseTemporaryLatches(session);
1259
1293
error= write_record(session, table, &info);
1294
table->auto_increment_field_not_null= false;
1479
1513
create_info->table_existed= 1; // Mark that table existed
1480
1514
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1481
1515
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1482
create_table->table_name);
1516
create_table->getTableName());
1483
1517
return create_table->table;
1486
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1520
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
1491
tmp_table.timestamp_field= 0;
1492
tmp_table.s= &share;
1494
tmp_table.s->db_create_options=0;
1495
tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
1497
if (not table_proto.engine().name().compare("MyISAM"))
1498
tmp_table.s->db_low_byte_first= true;
1499
else if (not table_proto.engine().name().compare("MEMORY"))
1500
tmp_table.s->db_low_byte_first= true;
1502
tmp_table.null_row= false;
1503
tmp_table.maybe_null= false;
1507
CreateField *cr_field;
1508
Field *field, *def_field;
1509
if (item->type() == Item::FUNC_ITEM)
1510
if (item->result_type() != STRING_RESULT)
1511
field= item->tmp_table_field(&tmp_table);
1525
table::Shell tmp_table(share); // Used during 'CreateField()'
1526
tmp_table.timestamp_field= 0;
1528
tmp_table.getMutableShare()->db_create_options= 0;
1529
tmp_table.getMutableShare()->blob_ptr_size= portable_sizeof_char_ptr;
1531
if (not table_proto.engine().name().compare("MyISAM"))
1532
tmp_table.getMutableShare()->db_low_byte_first= true;
1533
else if (not table_proto.engine().name().compare("MEMORY"))
1534
tmp_table.getMutableShare()->db_low_byte_first= true;
1536
tmp_table.null_row= false;
1537
tmp_table.maybe_null= false;
1539
tmp_table.in_use= session;
1543
CreateField *cr_field;
1544
Field *field, *def_field;
1545
if (item->type() == Item::FUNC_ITEM)
1547
if (item->result_type() != STRING_RESULT)
1549
field= item->tmp_table_field(&tmp_table);
1553
field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1513
field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1515
field= create_tmp_field(session, &tmp_table, item, item->type(),
1516
(Item ***) 0, &tmp_field, &def_field, false,
1519
!(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
1520
((Item_field *)item)->field :
1523
if (item->maybe_null)
1524
cr_field->flags &= ~NOT_NULL_FLAG;
1525
alter_info->create_list.push_back(cr_field);
1558
field= create_tmp_field(session, &tmp_table, item, item->type(),
1559
(Item ***) 0, &tmp_field, &def_field, false,
1564
!(cr_field=new CreateField(field,(item->type() == Item::FIELD_ITEM ?
1565
((Item_field *)item)->field :
1571
if (item->maybe_null)
1573
cr_field->flags &= ~NOT_NULL_FLAG;
1576
alter_info->create_list.push_back(cr_field);
1549
1602
or it was created via different mysqld front-end to the
1550
1603
cluster. We don't have much options but throw an error.
1552
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->table_name);
1605
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), create_table->getTableName());
1556
1609
if (not identifier.isTmp())
1558
pthread_mutex_lock(&LOCK_open); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1559
if (session->reopen_name_locked_table(create_table, false))
1611
LOCK_open.lock(); /* CREATE TABLE... has found that the table already exists for insert and is adapting to use it */
1613
if (create_table->table)
1615
table::Concurrent *concurrent_table= static_cast<table::Concurrent *>(create_table->table);
1617
if (concurrent_table->reopen_name_locked_table(create_table, session))
1619
quick_rm_table(*session, identifier);
1623
table= create_table->table;
1561
1628
quick_rm_table(*session, identifier);
1564
table= create_table->table;
1565
pthread_mutex_unlock(&LOCK_open);