INSERT statement implementation SYNOPSIS mysql_insert() result NULL if the insert is not outputing results via 'RETURNING' clause. @note Like implementations of other DDL/DML in MySQL, this function relies on the caller to close the thread tables. This is done in the end of dispatch_command(). */
| 740 | end of dispatch_command(). |
| 741 | */ |
| 742 | bool mysql_insert(THD *thd, TABLE_LIST *table_list, |
| 743 | List<Item> &fields, List<List_item> &values_list, |
| 744 | List<Item> &update_fields, List<Item> &update_values, |
| 745 | enum_duplicates duplic, bool ignore, select_result *result) |
| 746 | { |
| 747 | bool retval= true; |
| 748 | int error, res; |
| 749 | bool transactional_table, joins_freed= FALSE; |
| 750 | bool changed; |
| 751 | const bool was_insert_delayed= (table_list->lock_type == TL_WRITE_DELAYED); |
| 752 | bool using_bulk_insert= 0; |
| 753 | uint value_count; |
| 754 | /* counter of iteration in bulk PS operation*/ |
| 755 | ulonglong iteration= 0; |
| 756 | ulonglong last_affected_rows= 0; |
| 757 | ulonglong id; |
| 758 | COPY_INFO info; |
| 759 | TABLE *table= 0; |
| 760 | List_iterator_fast<List_item> its(values_list); |
| 761 | List_item *values; |
| 762 | Name_resolution_context *context; |
| 763 | Name_resolution_context_state ctx_state; |
| 764 | SELECT_LEX *returning= thd->lex->has_returning() ? thd->lex->returning() : 0; |
| 765 | unsigned char *readbuff= NULL; |
| 766 | Running_stmt_guard guard(thd, active_dml_stmt::INSERTING_STMT); |
| 767 | |
| 768 | List<List_item> insert_values_cache; |
| 769 | bool cache_insert_values= FALSE; |
| 770 | |
| 771 | #ifndef EMBEDDED_LIBRARY |
| 772 | char *query= thd->query(); |
| 773 | /* |
| 774 | log_on is about delayed inserts only. |
| 775 | By default, both logs are enabled (this won't cause problems if the server |
| 776 | runs without --log-bin). |
| 777 | */ |
| 778 | bool log_on= (thd->variables.option_bits & OPTION_BIN_LOG); |
| 779 | #endif |
| 780 | thr_lock_type lock_type; |
| 781 | Item *unused_conds= 0; |
| 782 | DBUG_ENTER("mysql_insert"); |
| 783 | |
| 784 | bzero((char*) &info,sizeof(info)); |
| 785 | create_explain_query(thd->lex, thd->mem_root); |
| 786 | /* |
| 787 | Upgrade lock type if the requested lock is incompatible with |
| 788 | the current connection mode or table operation. |
| 789 | */ |
| 790 | upgrade_lock_type(thd, &table_list->lock_type, duplic); |
| 791 | |
| 792 | /* |
| 793 | We can't write-delayed into a table locked with LOCK TABLES: |
| 794 | this will lead to a deadlock, since the delayed thread will |
| 795 | never be able to get a lock on the table. |
| 796 | */ |
| 797 | if (table_list->lock_type == TL_WRITE_DELAYED && thd->locked_tables_mode && |
| 798 | find_locked_table(thd->open_tables, table_list->db.str, |
| 799 | table_list->table_name.str)) |
no test coverage detected