MCPcopy Create free account
hub / github.com/MariaDB/server / mysql_prepare_insert

Function mysql_prepare_insert

sql/sql_insert.cc:1800–1957  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1798*/
1799
1800int mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
1801 List<Item> &fields, List_item *values,
1802 List<Item> &update_fields, List<Item> &update_values,
1803 enum_duplicates duplic, bool ignore,
1804 COND **where,
1805 bool select_insert, bool * const cache_insert_values)
1806{
1807 SELECT_LEX *select_lex= thd->lex->first_select_lex();
1808 Name_resolution_context *context= &select_lex->context;
1809 Name_resolution_context_state ctx_state;
1810 bool insert_into_view= (table_list->view != 0);
1811 bool res= 0;
1812 table_map map= 0;
1813 TABLE *table;
1814 DBUG_ENTER("mysql_prepare_insert");
1815 DBUG_PRINT("enter", ("table_list: %p view: %d",
1816 table_list, (int) insert_into_view));
1817 /* INSERT should have a SELECT or VALUES clause */
1818 DBUG_ASSERT (!select_insert || !values);
1819
1820 if (mysql_handle_derived(thd->lex, DT_INIT))
1821 DBUG_RETURN(1);
1822 if (table_list->handle_derived(thd->lex, DT_MERGE_FOR_INSERT))
1823 DBUG_RETURN(1);
1824 if (thd->lex->handle_list_of_derived(table_list, DT_PREPARE))
1825 DBUG_RETURN(1);
1826
1827 if (duplic == DUP_UPDATE)
1828 {
1829 /* it should be allocated before Item::fix_fields() */
1830 if (table_list->set_insert_values(thd->mem_root))
1831 DBUG_RETURN(1);
1832 }
1833
1834 table= table_list->table;
1835
1836 if (table->file->check_if_updates_are_ignored("INSERT"))
1837 DBUG_RETURN(-1);
1838
1839 if (mysql_prepare_insert_check_table(thd, table_list, fields, select_insert))
1840 DBUG_RETURN(1);
1841
1842 /* Prepare the fields in the statement. */
1843 if (values)
1844 {
1845 /* if we have INSERT ... VALUES () we cannot have a GROUP BY clause */
1846 DBUG_ASSERT (!select_lex->group_list.elements);
1847
1848 /* Save the state of the current name resolution context. */
1849 ctx_state.save_state(context, table_list);
1850
1851 /*
1852 Perform name resolution only in the first table - 'table_list',
1853 which is the table that is inserted into.
1854 */
1855 table_list->next_local= 0;
1856 context->resolve_in_table_list_only(table_list);
1857

Callers 3

mysql_insertFunction · 0.85
mysql_test_insert_commonFunction · 0.85

Calls 15

mysql_handle_derivedFunction · 0.85
setup_returning_fieldsFunction · 0.85
setup_fieldsFunction · 0.85
check_insert_fieldsFunction · 0.85
check_update_fieldsFunction · 0.85
unique_tableFunction · 0.85
first_select_lexMethod · 0.80

Tested by

no test coverage detected