108
108
table_list->next_local= 0;
109
109
context->resolve_in_table_list_only(table_list);
110
res= setup_fields(thd, 0, fields, MARK_COLUMNS_WRITE, 0, 0);
110
res= setup_fields(session, 0, fields, MARK_COLUMNS_WRITE, 0, 0);
112
112
/* Restore the current context. */
113
113
ctx_state.restore_state(context, table_list);
180
180
/* Check the fields we are going to modify */
181
if (setup_fields(thd, 0, update_fields, MARK_COLUMNS_WRITE, 0, 0))
181
if (setup_fields(session, 0, update_fields, MARK_COLUMNS_WRITE, 0, 0))
184
184
if (table->timestamp_field)
227
227
end of dispatch_command().
230
bool mysql_insert(Session *thd,TableList *table_list,
230
bool mysql_insert(Session *session,TableList *table_list,
231
231
List<Item> &fields,
232
232
List<List_item> &values_list,
233
233
List<Item> &update_fields,
256
256
Upgrade lock type if the requested lock is incompatible with
257
257
the current connection mode or table operation.
259
upgrade_lock_type(thd, &table_list->lock_type, duplic,
259
upgrade_lock_type(session, &table_list->lock_type, duplic,
260
260
values_list.elements > 1);
265
265
never be able to get a lock on the table. QQQ: why not
266
266
upgrade the lock here instead?
268
if (table_list->lock_type == TL_WRITE_DELAYED && thd->locked_tables &&
269
find_locked_table(thd, table_list->db, table_list->table_name))
268
if (table_list->lock_type == TL_WRITE_DELAYED && session->locked_tables &&
269
find_locked_table(session, table_list->db, table_list->table_name))
271
271
my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
272
272
table_list->table_name);
277
if (open_and_lock_tables(thd, table_list))
277
if (open_and_lock_tables(session, table_list))
280
280
lock_type= table_list->lock_type;
282
thd->set_proc_info("init");
282
session->set_proc_info("init");
283
session->used_tables=0;
285
285
value_count= values->elements;
287
if (mysql_prepare_insert(thd, table_list, table, fields, values,
287
if (mysql_prepare_insert(session, table_list, table, fields, values,
288
288
update_fields, update_values, duplic, &unused_conds,
290
290
(fields.elements || !value_count ||
322
322
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
325
if (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0))
325
if (setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0))
344
344
For single line insert, generate an error if try to set a NOT NULL field
347
thd->count_cuted_fields= ((values_list.elements == 1 &&
347
session->count_cuted_fields= ((values_list.elements == 1 &&
349
349
CHECK_FIELD_ERROR_FOR_NULL :
350
350
CHECK_FIELD_WARN);
351
thd->cuted_fields = 0L;
351
session->cuted_fields = 0L;
352
352
table->next_number_field=table->found_next_number_field;
354
if (thd->slave_thread &&
354
if (session->slave_thread &&
355
355
(info.handle_duplicates == DUP_UPDATE) &&
356
356
(table->next_number_field != NULL) &&
357
357
rpl_master_has_bug(&active_mi->rli, 24432))
361
thd->set_proc_info("update");
361
session->set_proc_info("update");
362
362
if (duplic == DUP_REPLACE)
363
363
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
364
364
if (duplic == DUP_UPDATE)
379
379
if (fields.elements || !value_count)
381
381
restore_record(table,s->default_values); // Get empty record
382
if (fill_record(thd, fields, *values, 0))
382
if (fill_record(session, fields, *values, 0))
384
if (values_list.elements != 1 && ! thd->is_error())
384
if (values_list.elements != 1 && ! session->is_error())
390
TODO: set thd->abort_on_warning if values_list.elements == 1
390
TODO: set session->abort_on_warning if values_list.elements == 1
391
391
and check that all items return warning in case of problem with
409
409
table->record[0][0]= table->s->default_values[0];
411
if (fill_record(thd, table->field, *values, 0))
411
if (fill_record(session, table->field, *values, 0))
413
if (values_list.elements != 1 && ! thd->is_error())
413
if (values_list.elements != 1 && ! session->is_error())
467
467
[Guilhem wrote] Temporary errors may have filled
468
thd->net.last_error/errno. For example if there has
468
session->net.last_error/errno. For example if there has
469
469
been a disk full error when writing the row, and it was
470
MyISAM, then thd->net.last_error/errno will be set to
470
MyISAM, then session->net.last_error/errno will be set to
471
471
"disk full"... and the my_pwrite() will wait until free
472
472
space appears, and so when it finishes then the
473
473
write_row() was entirely successful
475
475
/* todo: consider removing */
476
session->clear_error();
487
487
routines did not result in any error due to the KILLED. In
488
488
such case the flag is ignored for constructing binlog event.
490
assert(thd->killed != Session::KILL_BAD_DATA || error > 0);
491
if (thd->binlog_query(Session::ROW_QUERY_TYPE,
492
thd->query, thd->query_length,
490
assert(session->killed != Session::KILL_BAD_DATA || error > 0);
491
if (session->binlog_query(Session::ROW_QUERY_TYPE,
492
session->query, session->query_length,
493
493
transactional_table, false,
494
(error>0) ? thd->killed : Session::NOT_KILLED) &&
494
(error>0) ? session->killed : Session::NOT_KILLED) &&
495
495
transactional_table)
500
if (thd->transaction.stmt.modified_non_trans_table)
501
thd->transaction.all.modified_non_trans_table= true;
500
if (session->transaction.stmt.modified_non_trans_table)
501
session->transaction.all.modified_non_trans_table= true;
503
503
assert(transactional_table || !changed ||
504
thd->transaction.stmt.modified_non_trans_table);
504
session->transaction.stmt.modified_non_trans_table);
507
thd->set_proc_info("end");
507
session->set_proc_info("end");
509
509
We'll report to the client this id:
510
510
- if the table contains an autoincrement column and we successfully
515
515
inserted, the id of the last "inserted" row (if IGNORE, that value may not
516
516
have been really inserted but ignored).
518
id= (thd->first_successful_insert_id_in_cur_stmt > 0) ?
519
thd->first_successful_insert_id_in_cur_stmt :
520
(thd->arg_of_last_insert_id_function ?
521
thd->first_successful_insert_id_in_prev_stmt :
518
id= (session->first_successful_insert_id_in_cur_stmt > 0) ?
519
session->first_successful_insert_id_in_cur_stmt :
520
(session->arg_of_last_insert_id_function ?
521
session->first_successful_insert_id_in_prev_stmt :
522
522
((table->next_number_field && info.copied) ?
523
523
table->next_number_field->val_int() : 0));
524
524
table->next_number_field=0;
525
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
525
session->count_cuted_fields= CHECK_FIELD_IGNORE;
526
526
table->auto_increment_field_not_null= false;
527
527
if (duplic == DUP_REPLACE)
528
528
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
532
if (values_list.elements == 1 && (!(thd->options & OPTION_WARNINGS) ||
532
if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
533
!session->cuted_fields))
535
thd->row_count_func= info.copied + info.deleted +
536
((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
535
session->row_count_func= info.copied + info.deleted +
536
((session->client_capabilities & CLIENT_FOUND_ROWS) ?
537
537
info.touched : info.updated);
538
my_ok(thd, (ulong) thd->row_count_func, id);
538
my_ok(session, (ulong) session->row_count_func, id);
543
ha_rows updated=((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
543
ha_rows updated=((session->client_capabilities & CLIENT_FOUND_ROWS) ?
544
544
info.touched : info.updated);
546
546
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
547
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
547
(ulong) (info.records - info.copied), (ulong) session->cuted_fields);
549
549
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
550
(ulong) (info.deleted + updated), (ulong) thd->cuted_fields);
551
thd->row_count_func= info.copied + info.deleted + updated;
552
::my_ok(thd, (ulong) thd->row_count_func, id, buff);
550
(ulong) (info.deleted + updated), (ulong) session->cuted_fields);
551
session->row_count_func= info.copied + info.deleted + updated;
552
::my_ok(session, (ulong) session->row_count_func, id, buff);
554
thd->abort_on_warning= 0;
554
session->abort_on_warning= 0;
555
555
DRIZZLE_INSERT_END();
598
if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context,
599
&thd->lex->select_lex.top_join_list,
598
if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
599
&session->lex->select_lex.top_join_list,
601
&thd->lex->select_lex.leaf_tables,
601
&session->lex->select_lex.leaf_tables,
640
bool mysql_prepare_insert(Session *thd, TableList *table_list,
640
bool mysql_prepare_insert(Session *session, TableList *table_list,
641
641
Table *table, List<Item> &fields, List_item *values,
642
642
List<Item> &update_fields, List<Item> &update_values,
643
643
enum_duplicates duplic,
678
678
if (duplic == DUP_UPDATE)
680
680
/* it should be allocated before Item::fix_fields() */
681
if (table_list->set_insert_values(thd->mem_root))
681
if (table_list->set_insert_values(session->mem_root))
685
if (mysql_prepare_insert_check_table(thd, table_list, fields, select_insert))
685
if (mysql_prepare_insert_check_table(session, table_list, fields, select_insert))
702
702
table_list->next_local= 0;
703
703
context->resolve_in_table_list_only(table_list);
705
res= check_insert_fields(thd, context->table_list, fields, *values,
705
res= check_insert_fields(session, context->table_list, fields, *values,
706
706
!insert_into_view, &map) ||
707
setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0);
707
setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0);
709
709
if (!res && check_fields)
711
bool saved_abort_on_warning= thd->abort_on_warning;
712
thd->abort_on_warning= abort_on_warning;
713
res= check_that_all_fields_are_given_values(thd,
711
bool saved_abort_on_warning= session->abort_on_warning;
712
session->abort_on_warning= abort_on_warning;
713
res= check_that_all_fields_are_given_values(session,
715
715
context->table_list->table,
716
716
context->table_list);
717
thd->abort_on_warning= saved_abort_on_warning;
717
session->abort_on_warning= saved_abort_on_warning;
720
720
if (!res && duplic == DUP_UPDATE)
722
res= check_update_fields(thd, context->table_list, update_fields, &map);
722
res= check_update_fields(session, context->table_list, update_fields, &map);
725
725
/* Restore the current context. */
726
726
ctx_state.restore_state(context, table_list);
729
res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0);
729
res= setup_fields(session, 0, update_values, MARK_COLUMNS_READ, 0, 0);
811
811
If we do more than one iteration of this loop, from the second one the
812
812
row will have an explicit value in the autoinc field, which was set at
813
813
the first call of handler::update_auto_increment(). So we must save
814
the autogenerated value to avoid thd->insert_id_for_cur_row to become
814
the autogenerated value to avoid session->insert_id_for_cur_row to become
817
817
if (table->file->insert_id_for_cur_row > 0)
982
982
if (!table->file->has_transactions())
983
thd->transaction.stmt.modified_non_trans_table= true;
983
session->transaction.stmt.modified_non_trans_table= true;
984
984
/* Let us attempt do write_row() once more */
988
thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
988
session->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
990
990
Restore column maps if they where replaced during an duplicate key
1006
1006
after_n_copied_inc:
1007
1007
info->copied++;
1008
thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
1008
session->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
1010
1010
gok_or_after_err:
1012
1012
my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH);
1013
1013
if (!table->file->has_transactions())
1014
thd->transaction.stmt.modified_non_trans_table= true;
1014
session->transaction.stmt.modified_non_trans_table= true;
1018
1018
info->last_errno= error;
1019
1019
/* current_select is NULL if this is a delayed insert */
1020
if (thd->lex->current_select)
1021
thd->lex->current_select->no_error= 0; // Give error
1020
if (session->lex->current_select)
1021
session->lex->current_select->no_error= 0; // Give error
1022
1022
table->file->print_error(error,MYF(0));
1098
1098
if (lex->current_select->select_limit)
1100
1100
lex->set_stmt_unsafe();
1101
thd->set_current_stmt_binlog_row_based_if_mixed();
1101
session->set_current_stmt_binlog_row_based_if_mixed();
1104
1104
SELECT_LEX do not belong to INSERT statement, so we can't add WHERE
1105
1105
clause if table is VIEW
1108
if (mysql_prepare_insert(thd, lex->query_tables,
1108
if (mysql_prepare_insert(session, lex->query_tables,
1109
1109
lex->query_tables->table, lex->field_list, 0,
1110
1110
lex->update_list, lex->value_list,
1111
1111
lex->duplicates,
1159
1159
we are fixing fields from insert list.
1161
1161
lex->current_select= &lex->select_lex;
1162
res= check_insert_fields(thd, table_list, *fields, values,
1162
res= check_insert_fields(session, table_list, *fields, values,
1163
1163
!insert_into_view, &map) ||
1164
setup_fields(thd, 0, values, MARK_COLUMNS_READ, 0, 0);
1164
setup_fields(session, 0, values, MARK_COLUMNS_READ, 0, 0);
1166
1166
if (!res && fields->elements)
1168
bool saved_abort_on_warning= thd->abort_on_warning;
1169
thd->abort_on_warning= !info.ignore;
1170
res= check_that_all_fields_are_given_values(thd, table_list->table,
1168
bool saved_abort_on_warning= session->abort_on_warning;
1169
session->abort_on_warning= !info.ignore;
1170
res= check_that_all_fields_are_given_values(session, table_list->table,
1172
thd->abort_on_warning= saved_abort_on_warning;
1172
session->abort_on_warning= saved_abort_on_warning;
1175
1175
if (info.handle_duplicates == DUP_UPDATE && !res)
1184
1184
table_list->next_local= 0;
1185
1185
context->resolve_in_table_list_only(table_list);
1187
res= res || check_update_fields(thd, context->table_list,
1187
res= res || check_update_fields(session, context->table_list,
1188
1188
*info.update_fields, &map);
1190
1190
When we are not using GROUP BY and there are no ungrouped aggregate functions
1202
1202
table_list->next_name_resolution_table=
1203
1203
ctx_state.get_first_name_resolution_table();
1205
res= res || setup_fields(thd, 0, *info.update_values,
1205
res= res || setup_fields(session, 0, *info.update_values,
1206
1206
MARK_COLUMNS_READ, 0, 0);
1239
1239
Is table which we are changing used somewhere in other parts of
1242
if (unique_table(thd, table_list, table_list->next_global, 0))
1242
if (unique_table(session, table_list, table_list->next_global, 0))
1244
1244
/* Using same table for INSERT and SELECT */
1245
1245
lex->current_select->options|= OPTION_BUFFER_RESULT;
1261
1261
restore_record(table,s->default_values); // Get empty record
1262
1262
table->next_number_field=table->found_next_number_field;
1264
if (thd->slave_thread &&
1264
if (session->slave_thread &&
1265
1265
(info.handle_duplicates == DUP_UPDATE) &&
1266
1266
(table->next_number_field != NULL) &&
1267
1267
rpl_master_has_bug(&active_mi->rli, 24432))
1270
thd->cuted_fields=0;
1270
session->cuted_fields=0;
1271
1271
if (info.ignore || info.handle_duplicates != DUP_ERROR)
1272
1272
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
1273
1273
if (info.handle_duplicates == DUP_REPLACE)
1274
1274
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1275
1275
if (info.handle_duplicates == DUP_UPDATE)
1276
1276
table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1277
thd->abort_on_warning= !info.ignore;
1277
session->abort_on_warning= !info.ignore;
1278
1278
table->mark_columns_needed_for_insert();
1342
thd->count_cuted_fields= CHECK_FIELD_WARN; // Calculate cuted fields
1342
session->count_cuted_fields= CHECK_FIELD_WARN; // Calculate cuted fields
1343
1343
store_values(values);
1344
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
1345
if (thd->is_error())
1344
session->count_cuted_fields= CHECK_FIELD_IGNORE;
1345
if (session->is_error())
1348
error= write_record(thd, table, &info);
1348
error= write_record(session, table, &info);
1384
1384
void select_insert::store_values(List<Item> &values)
1386
1386
if (fields->elements)
1387
fill_record(thd, *fields, values, 1);
1387
fill_record(session, *fields, values, 1);
1389
fill_record(thd, table->field, values, 1);
1389
fill_record(session, table->field, values, 1);
1392
1392
void select_insert::send_error(uint32_t errcode,const char *err)
1417
1417
We must invalidate the table in the query cache before binlog writing
1418
1418
and ha_autocommit_or_rollback.
1420
if (thd->transaction.stmt.modified_non_trans_table)
1421
thd->transaction.all.modified_non_trans_table= true;
1420
if (session->transaction.stmt.modified_non_trans_table)
1421
session->transaction.all.modified_non_trans_table= true;
1423
1423
assert(trans_table || !changed ||
1424
thd->transaction.stmt.modified_non_trans_table);
1424
session->transaction.stmt.modified_non_trans_table);
1427
1427
Write to binlog before commiting transaction. No statement will
1432
1432
if (mysql_bin_log.is_open())
1436
thd->binlog_query(Session::ROW_QUERY_TYPE,
1437
thd->query, thd->query_length,
1435
session->clear_error();
1436
session->binlog_query(Session::ROW_QUERY_TYPE,
1437
session->query, session->query_length,
1438
1438
trans_table, false, killed_status);
1440
1440
table->file->ha_release_auto_increment();
1447
1447
char buff[160];
1448
1448
if (info.ignore)
1449
1449
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
1450
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
1450
(ulong) (info.records - info.copied), (ulong) session->cuted_fields);
1452
1452
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
1453
(ulong) (info.deleted+info.updated), (ulong) thd->cuted_fields);
1454
thd->row_count_func= info.copied + info.deleted +
1455
((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
1453
(ulong) (info.deleted+info.updated), (ulong) session->cuted_fields);
1454
session->row_count_func= info.copied + info.deleted +
1455
((session->client_capabilities & CLIENT_FOUND_ROWS) ?
1456
1456
info.touched : info.updated);
1458
id= (thd->first_successful_insert_id_in_cur_stmt > 0) ?
1459
thd->first_successful_insert_id_in_cur_stmt :
1460
(thd->arg_of_last_insert_id_function ?
1461
thd->first_successful_insert_id_in_prev_stmt :
1458
id= (session->first_successful_insert_id_in_cur_stmt > 0) ?
1459
session->first_successful_insert_id_in_cur_stmt :
1460
(session->arg_of_last_insert_id_function ?
1461
session->first_successful_insert_id_in_prev_stmt :
1462
1462
(info.copied ? autoinc_value_of_last_inserted_row : 0));
1463
::my_ok(thd, (ulong) thd->row_count_func, id, buff);
1463
::my_ok(session, (ulong) session->row_count_func, id, buff);
1496
1496
changed= (info.copied || info.deleted || info.updated);
1497
1497
transactional_table= table->file->has_transactions();
1498
if (thd->transaction.stmt.modified_non_trans_table)
1498
if (session->transaction.stmt.modified_non_trans_table)
1500
1500
if (mysql_bin_log.is_open())
1501
thd->binlog_query(Session::ROW_QUERY_TYPE, thd->query, thd->query_length,
1501
session->binlog_query(Session::ROW_QUERY_TYPE, session->query, session->query_length,
1502
1502
transactional_table, false);
1503
if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
1504
thd->transaction.all.modified_non_trans_table= true;
1503
if (!session->current_stmt_binlog_row_based && !can_rollback_data())
1504
session->transaction.all.modified_non_trans_table= true;
1506
1506
assert(transactional_table || !changed ||
1507
thd->transaction.stmt.modified_non_trans_table);
1507
session->transaction.stmt.modified_non_trans_table);
1508
1508
table->file->ha_release_auto_increment();
1582
1582
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
1584
1584
create_info->table_existed= 1; // Mark that table existed
1585
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1585
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1586
1586
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1587
1587
create_table->table_name);
1588
1588
return(create_table->table);
1595
1595
tmp_table.alias= 0;
1596
1596
tmp_table.timestamp_field= 0;
1597
1597
tmp_table.s= &share;
1598
init_tmp_table_share(thd, &share, "", 0, "", "");
1598
init_tmp_table_share(session, &share, "", 0, "", "");
1600
1600
tmp_table.s->db_create_options=0;
1601
1601
tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
1616
1616
field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1618
field= create_tmp_field(thd, &tmp_table, item, item->type(),
1618
field= create_tmp_field(session, &tmp_table, item, item->type(),
1619
1619
(Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0,
1648
tmp_disable_binlog(thd);
1649
if (!mysql_create_table_no_lock(thd, create_table->db,
1648
tmp_disable_binlog(session);
1649
if (!mysql_create_table_no_lock(session, create_table->db,
1650
1650
create_table->table_name,
1651
1651
create_info, alter_info, 0,
1652
1652
select_field_count, true))
1666
1666
if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1668
1668
pthread_mutex_lock(&LOCK_open);
1669
if (reopen_name_locked_table(thd, create_table, false))
1669
if (reopen_name_locked_table(session, create_table, false))
1671
1671
quick_rm_table(create_info->db_type, create_table->db,
1672
1672
table_case_name(create_info, create_table->table_name),
1687
1687
it preparable for open. But let us do close_temporary_table() here
1690
drop_temporary_table(thd, create_table);
1690
drop_temporary_table(session, create_table);
1694
reenable_binlog(thd);
1694
reenable_binlog(session);
1695
1695
if (!table) // open failed
1699
1699
table->reginfo.lock_type=TL_WRITE;
1700
1700
hooks->prelock(&table, 1); // Call prelock hooks
1701
if (! ((*lock)= mysql_lock_tables(thd, &table, 1,
1701
if (! ((*lock)= mysql_lock_tables(session, &table, 1,
1702
1702
DRIZZLE_LOCK_IGNORE_FLUSH, ¬_used)) ||
1703
1703
hooks->postlock(&table, 1))
1707
mysql_unlock_tables(thd, *lock);
1707
mysql_unlock_tables(session, *lock);
1711
1711
if (!create_info->table_existed)
1712
drop_open_table(thd, table, create_table->db, create_table->table_name);
1712
drop_open_table(session, table, create_table->db, create_table->table_name);
1754
1754
virtual int do_postlock(Table **tables, uint32_t count)
1756
Session *thd= const_cast<Session*>(ptr->get_thd());
1757
if (int error= decide_logging_format(thd, &all_tables))
1756
Session *session= const_cast<Session*>(ptr->get_session());
1757
if (int error= decide_logging_format(session, &all_tables))
1760
1760
Table const *const table = *tables;
1761
if (thd->current_stmt_binlog_row_based &&
1761
if (session->current_stmt_binlog_row_based &&
1762
1762
!table->s->tmp_table &&
1763
1763
!ptr->get_create_info()->table_existed)
1781
1781
row-based replication for the statement. If we are creating a
1782
1782
temporary table, we need to start a statement transaction.
1784
if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 &&
1785
thd->current_stmt_binlog_row_based)
1784
if ((session->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 &&
1785
session->current_stmt_binlog_row_based)
1787
thd->binlog_start_trans_and_stmt();
1787
session->binlog_start_trans_and_stmt();
1790
if (!(table= create_table_from_items(thd, create_info, create_table,
1790
if (!(table= create_table_from_items(session, create_info, create_table,
1791
1791
alter_info, &values,
1792
1792
&extra_lock, hook_ptr)))
1793
1793
return(-1); // abort() deletes table
1830
1830
if (info.handle_duplicates == DUP_UPDATE)
1831
1831
table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1832
1832
table->file->ha_start_bulk_insert((ha_rows) 0);
1833
thd->abort_on_warning= !info.ignore;
1834
if (check_that_all_fields_are_given_values(thd, table, table_list))
1833
session->abort_on_warning= !info.ignore;
1834
if (check_that_all_fields_are_given_values(session, table, table_list))
1836
1836
table->mark_columns_needed_for_insert();
1837
1837
table->file->extra(HA_EXTRA_WRITE_CACHE);
1870
1870
tmp_table_list.table = *tables;
1871
1871
query.length(0); // Have to zero it since constructor doesn't
1873
result= store_create_info(thd, &tmp_table_list, &query, create_info);
1873
result= store_create_info(session, &tmp_table_list, &query, create_info);
1874
1874
assert(result == 0); /* store_create_info() always return 0 */
1876
thd->binlog_query(Session::STMT_QUERY_TYPE,
1876
session->binlog_query(Session::STMT_QUERY_TYPE,
1877
1877
query.ptr(), query.length(),
1878
1878
/* is_trans */ true,
1879
1879
/* suppress_use */ false);
1923
1923
if (!table->s->tmp_table)
1925
ha_autocommit_or_rollback(thd, 0);
1926
end_active_trans(thd);
1925
ha_autocommit_or_rollback(session, 0);
1926
end_active_trans(session);
1929
1929
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1930
1930
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1933
mysql_unlock_tables(thd, *m_plock);
1933
mysql_unlock_tables(session, *m_plock);
1934
1934
*m_plock= NULL;
1958
1958
of the table succeeded or not, since we need to reset the binary
1961
tmp_disable_binlog(thd);
1961
tmp_disable_binlog(session);
1962
1962
select_insert::abort();
1963
thd->transaction.stmt.modified_non_trans_table= false;
1964
reenable_binlog(thd);
1963
session->transaction.stmt.modified_non_trans_table= false;
1964
reenable_binlog(session);
1969
mysql_unlock_tables(thd, *m_plock);
1969
mysql_unlock_tables(session, *m_plock);
1970
1970
*m_plock= NULL;
1976
1976
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1977
1977
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1978
1978
if (!create_info->table_existed)
1979
drop_open_table(thd, table, create_table->db, create_table->table_name);
1979
drop_open_table(session, table, create_table->db, create_table->table_name);
1980
1980
table=0; // Safety