25
25
#include <drizzled/server_includes.h>
26
26
#include <drizzled/sql_select.h>
27
27
#include <drizzled/sql_show.h>
29
#include <drizzled/drizzled_error_messages.h>
28
#include <drizzled/rpl_mi.h>
29
#include <drizzled/error.h>
30
#include <drizzled/slave.h>
31
#include <drizzled/sql_parse.h>
32
#include <drizzled/probes.h>
31
34
/* Define to force use of my_malloc() if the allocated memory block is big */
108
111
table_list->next_local= 0;
109
112
context->resolve_in_table_list_only(table_list);
110
res= setup_fields(thd, 0, fields, MARK_COLUMNS_WRITE, 0, 0);
113
res= setup_fields(session, 0, fields, MARK_COLUMNS_WRITE, 0, 0);
112
115
/* Restore the current context. */
113
116
ctx_state.restore_state(context, table_list);
177
183
/* Check the fields we are going to modify */
178
if (setup_fields(thd, 0, update_fields, MARK_COLUMNS_WRITE, 0, 0))
184
if (setup_fields(session, 0, update_fields, MARK_COLUMNS_WRITE, 0, 0))
181
187
if (table->timestamp_field)
224
230
end of dispatch_command().
227
bool mysql_insert(THD *thd,TableList *table_list,
233
bool mysql_insert(Session *session,TableList *table_list,
228
234
List<Item> &fields,
229
235
List<List_item> &values_list,
230
236
List<Item> &update_fields,
253
259
Upgrade lock type if the requested lock is incompatible with
254
260
the current connection mode or table operation.
256
upgrade_lock_type(thd, &table_list->lock_type, duplic,
262
upgrade_lock_type(session, &table_list->lock_type, duplic,
257
263
values_list.elements > 1);
262
268
never be able to get a lock on the table. QQQ: why not
263
269
upgrade the lock here instead?
265
if (table_list->lock_type == TL_WRITE_DELAYED && thd->locked_tables &&
266
find_locked_table(thd, table_list->db, table_list->table_name))
271
if (table_list->lock_type == TL_WRITE_DELAYED && session->locked_tables &&
272
find_locked_table(session, table_list->db, table_list->table_name))
268
274
my_error(ER_DELAYED_INSERT_TABLE_LOCKED, MYF(0),
269
275
table_list->table_name);
274
if (open_and_lock_tables(thd, table_list))
280
if (open_and_lock_tables(session, table_list))
277
283
lock_type= table_list->lock_type;
279
thd_proc_info(thd, "init");
285
session->set_proc_info("init");
286
session->used_tables=0;
282
288
value_count= values->elements;
284
if (mysql_prepare_insert(thd, table_list, table, fields, values,
290
if (mysql_prepare_insert(session, table_list, table, fields, values,
285
291
update_fields, update_values, duplic, &unused_conds,
287
293
(fields.elements || !value_count ||
319
325
my_error(ER_WRONG_VALUE_COUNT_ON_ROW, MYF(0), counter);
322
if (setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0))
328
if (setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0))
341
347
For single line insert, generate an error if try to set a NOT NULL field
344
thd->count_cuted_fields= ((values_list.elements == 1 &&
350
session->count_cuted_fields= ((values_list.elements == 1 &&
346
352
CHECK_FIELD_ERROR_FOR_NULL :
347
353
CHECK_FIELD_WARN);
348
thd->cuted_fields = 0L;
354
session->cuted_fields = 0L;
349
355
table->next_number_field=table->found_next_number_field;
351
if (thd->slave_thread &&
357
if (session->slave_thread &&
352
358
(info.handle_duplicates == DUP_UPDATE) &&
353
359
(table->next_number_field != NULL) &&
354
360
rpl_master_has_bug(&active_mi->rli, 24432))
358
thd_proc_info(thd, "update");
364
session->set_proc_info("update");
359
365
if (duplic == DUP_REPLACE)
360
366
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
361
367
if (duplic == DUP_UPDATE)
376
382
if (fields.elements || !value_count)
378
384
restore_record(table,s->default_values); // Get empty record
379
if (fill_record(thd, fields, *values, 0))
385
if (fill_record(session, fields, *values, 0))
381
if (values_list.elements != 1 && ! thd->is_error())
387
if (values_list.elements != 1 && ! session->is_error())
387
TODO: set thd->abort_on_warning if values_list.elements == 1
393
TODO: set session->abort_on_warning if values_list.elements == 1
388
394
and check that all items return warning in case of problem with
406
412
table->record[0][0]= table->s->default_values[0];
408
if (fill_record(thd, table->field, *values, 0))
414
if (fill_record(session, table->field, *values, 0))
410
if (values_list.elements != 1 && ! thd->is_error())
416
if (values_list.elements != 1 && ! session->is_error())
464
470
[Guilhem wrote] Temporary errors may have filled
465
thd->net.last_error/errno. For example if there has
471
session->net.last_error/errno. For example if there has
466
472
been a disk full error when writing the row, and it was
467
MyISAM, then thd->net.last_error/errno will be set to
473
MyISAM, then session->net.last_error/errno will be set to
468
474
"disk full"... and the my_pwrite() will wait until free
469
475
space appears, and so when it finishes then the
470
476
write_row() was entirely successful
472
478
/* todo: consider removing */
479
session->clear_error();
484
490
routines did not result in any error due to the KILLED. In
485
491
such case the flag is ignored for constructing binlog event.
487
assert(thd->killed != THD::KILL_BAD_DATA || error > 0);
488
if (thd->binlog_query(THD::ROW_QUERY_TYPE,
489
thd->query, thd->query_length,
493
assert(session->killed != Session::KILL_BAD_DATA || error > 0);
494
if (session->binlog_query(Session::ROW_QUERY_TYPE,
495
session->query, session->query_length,
490
496
transactional_table, false,
491
(error>0) ? thd->killed : THD::NOT_KILLED) &&
497
(error>0) ? session->killed : Session::NOT_KILLED) &&
492
498
transactional_table)
497
if (thd->transaction.stmt.modified_non_trans_table)
498
thd->transaction.all.modified_non_trans_table= true;
503
if (session->transaction.stmt.modified_non_trans_table)
504
session->transaction.all.modified_non_trans_table= true;
500
506
assert(transactional_table || !changed ||
501
thd->transaction.stmt.modified_non_trans_table);
507
session->transaction.stmt.modified_non_trans_table);
504
thd_proc_info(thd, "end");
510
session->set_proc_info("end");
506
512
We'll report to the client this id:
507
513
- if the table contains an autoincrement column and we successfully
512
518
inserted, the id of the last "inserted" row (if IGNORE, that value may not
513
519
have been really inserted but ignored).
515
id= (thd->first_successful_insert_id_in_cur_stmt > 0) ?
516
thd->first_successful_insert_id_in_cur_stmt :
517
(thd->arg_of_last_insert_id_function ?
518
thd->first_successful_insert_id_in_prev_stmt :
521
id= (session->first_successful_insert_id_in_cur_stmt > 0) ?
522
session->first_successful_insert_id_in_cur_stmt :
523
(session->arg_of_last_insert_id_function ?
524
session->first_successful_insert_id_in_prev_stmt :
519
525
((table->next_number_field && info.copied) ?
520
526
table->next_number_field->val_int() : 0));
521
527
table->next_number_field=0;
522
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
528
session->count_cuted_fields= CHECK_FIELD_IGNORE;
523
529
table->auto_increment_field_not_null= false;
524
530
if (duplic == DUP_REPLACE)
525
531
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
529
if (values_list.elements == 1 && (!(thd->options & OPTION_WARNINGS) ||
535
if (values_list.elements == 1 && (!(session->options & OPTION_WARNINGS) ||
536
!session->cuted_fields))
532
thd->row_count_func= info.copied + info.deleted +
533
((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
538
session->row_count_func= info.copied + info.deleted +
539
((session->client_capabilities & CLIENT_FOUND_ROWS) ?
534
540
info.touched : info.updated);
535
my_ok(thd, (ulong) thd->row_count_func, id);
541
my_ok(session, (ulong) session->row_count_func, id);
540
ha_rows updated=((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
546
ha_rows updated=((session->client_capabilities & CLIENT_FOUND_ROWS) ?
541
547
info.touched : info.updated);
543
549
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
544
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
550
(ulong) (info.records - info.copied), (ulong) session->cuted_fields);
546
552
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
547
(ulong) (info.deleted + updated), (ulong) thd->cuted_fields);
548
thd->row_count_func= info.copied + info.deleted + updated;
549
::my_ok(thd, (ulong) thd->row_count_func, id, buff);
553
(ulong) (info.deleted + updated), (ulong) session->cuted_fields);
554
session->row_count_func= info.copied + info.deleted + updated;
555
::my_ok(session, (ulong) session->row_count_func, id, buff);
551
thd->abort_on_warning= 0;
557
session->abort_on_warning= 0;
552
558
DRIZZLE_INSERT_END();
595
if (setup_tables_and_check_access(thd, &thd->lex->select_lex.context,
596
&thd->lex->select_lex.top_join_list,
601
if (setup_tables_and_check_access(session, &session->lex->select_lex.context,
602
&session->lex->select_lex.top_join_list,
598
&thd->lex->select_lex.leaf_tables,
604
&session->lex->select_lex.leaf_tables,
637
bool mysql_prepare_insert(THD *thd, TableList *table_list,
643
bool mysql_prepare_insert(Session *session, TableList *table_list,
638
644
Table *table, List<Item> &fields, List_item *values,
639
645
List<Item> &update_fields, List<Item> &update_values,
640
646
enum_duplicates duplic,
675
681
if (duplic == DUP_UPDATE)
677
683
/* it should be allocated before Item::fix_fields() */
678
if (table_list->set_insert_values(thd->mem_root))
684
if (table_list->set_insert_values(session->mem_root))
682
if (mysql_prepare_insert_check_table(thd, table_list, fields, select_insert))
688
if (mysql_prepare_insert_check_table(session, table_list, fields, select_insert))
699
705
table_list->next_local= 0;
700
706
context->resolve_in_table_list_only(table_list);
702
res= check_insert_fields(thd, context->table_list, fields, *values,
708
res= check_insert_fields(session, context->table_list, fields, *values,
703
709
!insert_into_view, &map) ||
704
setup_fields(thd, 0, *values, MARK_COLUMNS_READ, 0, 0);
710
setup_fields(session, 0, *values, MARK_COLUMNS_READ, 0, 0);
706
712
if (!res && check_fields)
708
bool saved_abort_on_warning= thd->abort_on_warning;
709
thd->abort_on_warning= abort_on_warning;
710
res= check_that_all_fields_are_given_values(thd,
714
bool saved_abort_on_warning= session->abort_on_warning;
715
session->abort_on_warning= abort_on_warning;
716
res= check_that_all_fields_are_given_values(session,
712
718
context->table_list->table,
713
719
context->table_list);
714
thd->abort_on_warning= saved_abort_on_warning;
720
session->abort_on_warning= saved_abort_on_warning;
717
723
if (!res && duplic == DUP_UPDATE)
719
res= check_update_fields(thd, context->table_list, update_fields, &map);
725
res= check_update_fields(session, context->table_list, update_fields, &map);
722
728
/* Restore the current context. */
723
729
ctx_state.restore_state(context, table_list);
726
res= setup_fields(thd, 0, update_values, MARK_COLUMNS_READ, 0, 0);
732
res= setup_fields(session, 0, update_values, MARK_COLUMNS_READ, 0, 0);
808
814
If we do more than one iteration of this loop, from the second one the
809
815
row will have an explicit value in the autoinc field, which was set at
810
816
the first call of handler::update_auto_increment(). So we must save
811
the autogenerated value to avoid thd->insert_id_for_cur_row to become
817
the autogenerated value to avoid session->insert_id_for_cur_row to become
814
820
if (table->file->insert_id_for_cur_row > 0)
979
985
if (!table->file->has_transactions())
980
thd->transaction.stmt.modified_non_trans_table= true;
986
session->transaction.stmt.modified_non_trans_table= true;
981
987
/* Let us attempt do write_row() once more */
985
thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
991
session->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
987
993
Restore column maps if they where replaced during an duplicate key
1003
1009
after_n_copied_inc:
1004
1010
info->copied++;
1005
thd->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
1011
session->record_first_successful_insert_id_in_cur_stmt(table->file->insert_id_for_cur_row);
1007
1013
gok_or_after_err:
1009
1015
my_safe_afree(key,table->s->max_unique_length,MAX_KEY_LENGTH);
1010
1016
if (!table->file->has_transactions())
1011
thd->transaction.stmt.modified_non_trans_table= true;
1017
session->transaction.stmt.modified_non_trans_table= true;
1015
1021
info->last_errno= error;
1016
1022
/* current_select is NULL if this is a delayed insert */
1017
if (thd->lex->current_select)
1018
thd->lex->current_select->no_error= 0; // Give error
1023
if (session->lex->current_select)
1024
session->lex->current_select->no_error= 0; // Give error
1019
1025
table->file->print_error(error,MYF(0));
1095
1101
if (lex->current_select->select_limit)
1097
1103
lex->set_stmt_unsafe();
1098
thd->set_current_stmt_binlog_row_based_if_mixed();
1104
session->set_current_stmt_binlog_row_based_if_mixed();
1101
1107
SELECT_LEX do not belong to INSERT statement, so we can't add WHERE
1102
1108
clause if table is VIEW
1105
if (mysql_prepare_insert(thd, lex->query_tables,
1111
if (mysql_prepare_insert(session, lex->query_tables,
1106
1112
lex->query_tables->table, lex->field_list, 0,
1107
1113
lex->update_list, lex->value_list,
1108
1114
lex->duplicates,
1156
1162
we are fixing fields from insert list.
1158
1164
lex->current_select= &lex->select_lex;
1159
res= check_insert_fields(thd, table_list, *fields, values,
1165
res= check_insert_fields(session, table_list, *fields, values,
1160
1166
!insert_into_view, &map) ||
1161
setup_fields(thd, 0, values, MARK_COLUMNS_READ, 0, 0);
1167
setup_fields(session, 0, values, MARK_COLUMNS_READ, 0, 0);
1163
1169
if (!res && fields->elements)
1165
bool saved_abort_on_warning= thd->abort_on_warning;
1166
thd->abort_on_warning= !info.ignore;
1167
res= check_that_all_fields_are_given_values(thd, table_list->table,
1171
bool saved_abort_on_warning= session->abort_on_warning;
1172
session->abort_on_warning= !info.ignore;
1173
res= check_that_all_fields_are_given_values(session, table_list->table,
1169
thd->abort_on_warning= saved_abort_on_warning;
1175
session->abort_on_warning= saved_abort_on_warning;
1172
1178
if (info.handle_duplicates == DUP_UPDATE && !res)
1181
1187
table_list->next_local= 0;
1182
1188
context->resolve_in_table_list_only(table_list);
1184
res= res || check_update_fields(thd, context->table_list,
1190
res= res || check_update_fields(session, context->table_list,
1185
1191
*info.update_fields, &map);
1187
1193
When we are not using GROUP BY and there are no ungrouped aggregate functions
1199
1205
table_list->next_name_resolution_table=
1200
1206
ctx_state.get_first_name_resolution_table();
1202
res= res || setup_fields(thd, 0, *info.update_values,
1208
res= res || setup_fields(session, 0, *info.update_values,
1203
1209
MARK_COLUMNS_READ, 0, 0);
1236
1242
Is table which we are changing used somewhere in other parts of
1239
if (unique_table(thd, table_list, table_list->next_global, 0))
1245
if (unique_table(session, table_list, table_list->next_global, 0))
1241
1247
/* Using same table for INSERT and SELECT */
1242
1248
lex->current_select->options|= OPTION_BUFFER_RESULT;
1258
1264
restore_record(table,s->default_values); // Get empty record
1259
1265
table->next_number_field=table->found_next_number_field;
1261
if (thd->slave_thread &&
1267
if (session->slave_thread &&
1262
1268
(info.handle_duplicates == DUP_UPDATE) &&
1263
1269
(table->next_number_field != NULL) &&
1264
1270
rpl_master_has_bug(&active_mi->rli, 24432))
1267
thd->cuted_fields=0;
1273
session->cuted_fields=0;
1268
1274
if (info.ignore || info.handle_duplicates != DUP_ERROR)
1269
1275
table->file->extra(HA_EXTRA_IGNORE_DUP_KEY);
1270
1276
if (info.handle_duplicates == DUP_REPLACE)
1271
1277
table->file->extra(HA_EXTRA_WRITE_CAN_REPLACE);
1272
1278
if (info.handle_duplicates == DUP_UPDATE)
1273
1279
table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1274
thd->abort_on_warning= !info.ignore;
1280
session->abort_on_warning= !info.ignore;
1275
1281
table->mark_columns_needed_for_insert();
1339
thd->count_cuted_fields= CHECK_FIELD_WARN; // Calculate cuted fields
1345
session->count_cuted_fields= CHECK_FIELD_WARN; // Calculate cuted fields
1340
1346
store_values(values);
1341
thd->count_cuted_fields= CHECK_FIELD_IGNORE;
1342
if (thd->is_error())
1347
session->count_cuted_fields= CHECK_FIELD_IGNORE;
1348
if (session->is_error())
1345
error= write_record(thd, table, &info);
1351
error= write_record(session, table, &info);
1381
1387
void select_insert::store_values(List<Item> &values)
1383
1389
if (fields->elements)
1384
fill_record(thd, *fields, values, 1);
1390
fill_record(session, *fields, values, 1);
1386
fill_record(thd, table->field, values, 1);
1392
fill_record(session, table->field, values, 1);
1389
1395
void select_insert::send_error(uint32_t errcode,const char *err)
1414
1420
We must invalidate the table in the query cache before binlog writing
1415
1421
and ha_autocommit_or_rollback.
1417
if (thd->transaction.stmt.modified_non_trans_table)
1418
thd->transaction.all.modified_non_trans_table= true;
1423
if (session->transaction.stmt.modified_non_trans_table)
1424
session->transaction.all.modified_non_trans_table= true;
1420
1426
assert(trans_table || !changed ||
1421
thd->transaction.stmt.modified_non_trans_table);
1427
session->transaction.stmt.modified_non_trans_table);
1424
1430
Write to binlog before commiting transaction. No statement will
1429
1435
if (mysql_bin_log.is_open())
1433
thd->binlog_query(THD::ROW_QUERY_TYPE,
1434
thd->query, thd->query_length,
1438
session->clear_error();
1439
session->binlog_query(Session::ROW_QUERY_TYPE,
1440
session->query, session->query_length,
1435
1441
trans_table, false, killed_status);
1437
1443
table->file->ha_release_auto_increment();
1444
1450
char buff[160];
1445
1451
if (info.ignore)
1446
1452
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
1447
(ulong) (info.records - info.copied), (ulong) thd->cuted_fields);
1453
(ulong) (info.records - info.copied), (ulong) session->cuted_fields);
1449
1455
sprintf(buff, ER(ER_INSERT_INFO), (ulong) info.records,
1450
(ulong) (info.deleted+info.updated), (ulong) thd->cuted_fields);
1451
thd->row_count_func= info.copied + info.deleted +
1452
((thd->client_capabilities & CLIENT_FOUND_ROWS) ?
1456
(ulong) (info.deleted+info.updated), (ulong) session->cuted_fields);
1457
session->row_count_func= info.copied + info.deleted +
1458
((session->client_capabilities & CLIENT_FOUND_ROWS) ?
1453
1459
info.touched : info.updated);
1455
id= (thd->first_successful_insert_id_in_cur_stmt > 0) ?
1456
thd->first_successful_insert_id_in_cur_stmt :
1457
(thd->arg_of_last_insert_id_function ?
1458
thd->first_successful_insert_id_in_prev_stmt :
1461
id= (session->first_successful_insert_id_in_cur_stmt > 0) ?
1462
session->first_successful_insert_id_in_cur_stmt :
1463
(session->arg_of_last_insert_id_function ?
1464
session->first_successful_insert_id_in_prev_stmt :
1459
1465
(info.copied ? autoinc_value_of_last_inserted_row : 0));
1460
::my_ok(thd, (ulong) thd->row_count_func, id, buff);
1466
::my_ok(session, (ulong) session->row_count_func, id, buff);
1493
1499
changed= (info.copied || info.deleted || info.updated);
1494
1500
transactional_table= table->file->has_transactions();
1495
if (thd->transaction.stmt.modified_non_trans_table)
1501
if (session->transaction.stmt.modified_non_trans_table)
1497
1503
if (mysql_bin_log.is_open())
1498
thd->binlog_query(THD::ROW_QUERY_TYPE, thd->query, thd->query_length,
1504
session->binlog_query(Session::ROW_QUERY_TYPE, session->query, session->query_length,
1499
1505
transactional_table, false);
1500
if (!thd->current_stmt_binlog_row_based && !can_rollback_data())
1501
thd->transaction.all.modified_non_trans_table= true;
1506
if (!session->current_stmt_binlog_row_based && !can_rollback_data())
1507
session->transaction.all.modified_non_trans_table= true;
1503
1509
assert(transactional_table || !changed ||
1504
thd->transaction.stmt.modified_non_trans_table);
1510
session->transaction.stmt.modified_non_trans_table);
1505
1511
table->file->ha_release_auto_increment();
1579
1585
if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
1581
1587
create_info->table_existed= 1; // Mark that table existed
1582
push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1588
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
1583
1589
ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
1584
1590
create_table->table_name);
1585
1591
return(create_table->table);
1592
1598
tmp_table.alias= 0;
1593
1599
tmp_table.timestamp_field= 0;
1594
1600
tmp_table.s= &share;
1595
init_tmp_table_share(thd, &share, "", 0, "", "");
1601
init_tmp_table_share(session, &share, "", 0, "", "");
1597
1603
tmp_table.s->db_create_options=0;
1598
1604
tmp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
1613
1619
field= item->tmp_table_field_from_field_type(&tmp_table, 0);
1615
field= create_tmp_field(thd, &tmp_table, item, item->type(),
1621
field= create_tmp_field(session, &tmp_table, item, item->type(),
1616
1622
(Item ***) 0, &tmp_field, &def_field, 0, 0, 0, 0,
1645
tmp_disable_binlog(thd);
1646
if (!mysql_create_table_no_lock(thd, create_table->db,
1651
tmp_disable_binlog(session);
1652
if (!mysql_create_table_no_lock(session, create_table->db,
1647
1653
create_table->table_name,
1648
1654
create_info, alter_info, 0,
1649
select_field_count))
1655
select_field_count, true))
1651
1657
if (create_info->table_existed &&
1652
1658
!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1663
1669
if (!(create_info->options & HA_LEX_CREATE_TMP_TABLE))
1665
1671
pthread_mutex_lock(&LOCK_open);
1666
if (reopen_name_locked_table(thd, create_table, false))
1672
if (reopen_name_locked_table(session, create_table, false))
1668
1674
quick_rm_table(create_info->db_type, create_table->db,
1669
1675
table_case_name(create_info, create_table->table_name),
1684
1690
it preparable for open. But let us do close_temporary_table() here
1687
drop_temporary_table(thd, create_table);
1693
drop_temporary_table(session, create_table);
1691
reenable_binlog(thd);
1697
reenable_binlog(session);
1692
1698
if (!table) // open failed
1696
1702
table->reginfo.lock_type=TL_WRITE;
1697
1703
hooks->prelock(&table, 1); // Call prelock hooks
1698
if (! ((*lock)= mysql_lock_tables(thd, &table, 1,
1704
if (! ((*lock)= mysql_lock_tables(session, &table, 1,
1699
1705
DRIZZLE_LOCK_IGNORE_FLUSH, ¬_used)) ||
1700
1706
hooks->postlock(&table, 1))
1704
mysql_unlock_tables(thd, *lock);
1710
mysql_unlock_tables(session, *lock);
1708
1714
if (!create_info->table_existed)
1709
drop_open_table(thd, table, create_table->db, create_table->table_name);
1715
drop_open_table(session, table, create_table->db, create_table->table_name);
1751
1757
virtual int do_postlock(Table **tables, uint32_t count)
1753
THD *thd= const_cast<THD*>(ptr->get_thd());
1754
if (int error= decide_logging_format(thd, &all_tables))
1759
Session *session= const_cast<Session*>(ptr->get_session());
1760
if (int error= decide_logging_format(session, &all_tables))
1757
1763
Table const *const table = *tables;
1758
if (thd->current_stmt_binlog_row_based &&
1764
if (session->current_stmt_binlog_row_based &&
1759
1765
!table->s->tmp_table &&
1760
1766
!ptr->get_create_info()->table_existed)
1778
1784
row-based replication for the statement. If we are creating a
1779
1785
temporary table, we need to start a statement transaction.
1781
if ((thd->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 &&
1782
thd->current_stmt_binlog_row_based)
1787
if ((session->lex->create_info.options & HA_LEX_CREATE_TMP_TABLE) == 0 &&
1788
session->current_stmt_binlog_row_based)
1784
thd->binlog_start_trans_and_stmt();
1790
session->binlog_start_trans_and_stmt();
1787
if (!(table= create_table_from_items(thd, create_info, create_table,
1793
if (!(table= create_table_from_items(session, create_info, create_table,
1788
1794
alter_info, &values,
1789
1795
&extra_lock, hook_ptr)))
1790
1796
return(-1); // abort() deletes table
1827
1833
if (info.handle_duplicates == DUP_UPDATE)
1828
1834
table->file->extra(HA_EXTRA_INSERT_WITH_UPDATE);
1829
1835
table->file->ha_start_bulk_insert((ha_rows) 0);
1830
thd->abort_on_warning= !info.ignore;
1831
if (check_that_all_fields_are_given_values(thd, table, table_list))
1836
session->abort_on_warning= !info.ignore;
1837
if (check_that_all_fields_are_given_values(session, table, table_list))
1833
1839
table->mark_columns_needed_for_insert();
1834
1840
table->file->extra(HA_EXTRA_WRITE_CACHE);
1867
1873
tmp_table_list.table = *tables;
1868
1874
query.length(0); // Have to zero it since constructor doesn't
1870
result= store_create_info(thd, &tmp_table_list, &query, create_info);
1876
result= store_create_info(session, &tmp_table_list, &query, create_info);
1871
1877
assert(result == 0); /* store_create_info() always return 0 */
1873
thd->binlog_query(THD::STMT_QUERY_TYPE,
1879
session->binlog_query(Session::STMT_QUERY_TYPE,
1874
1880
query.ptr(), query.length(),
1875
1881
/* is_trans */ true,
1876
1882
/* suppress_use */ false);
1920
1926
if (!table->s->tmp_table)
1922
ha_autocommit_or_rollback(thd, 0);
1923
end_active_trans(thd);
1928
ha_autocommit_or_rollback(session, 0);
1929
end_active_trans(session);
1926
1932
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1927
1933
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1930
mysql_unlock_tables(thd, *m_plock);
1936
mysql_unlock_tables(session, *m_plock);
1931
1937
*m_plock= NULL;
1955
1961
of the table succeeded or not, since we need to reset the binary
1958
tmp_disable_binlog(thd);
1964
tmp_disable_binlog(session);
1959
1965
select_insert::abort();
1960
thd->transaction.stmt.modified_non_trans_table= false;
1961
reenable_binlog(thd);
1966
session->transaction.stmt.modified_non_trans_table= false;
1967
reenable_binlog(session);
1966
mysql_unlock_tables(thd, *m_plock);
1972
mysql_unlock_tables(session, *m_plock);
1967
1973
*m_plock= NULL;
1973
1979
table->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
1974
1980
table->file->extra(HA_EXTRA_WRITE_CANNOT_REPLACE);
1975
1981
if (!create_info->table_existed)
1976
drop_open_table(thd, table, create_table->db, create_table->table_name);
1982
drop_open_table(session, table, create_table->db, create_table->table_name);
1977
1983
table=0; // Safety