| 4251 | |
| 4252 | |
| 4253 | int |
| 4254 | select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u) |
| 4255 | { |
| 4256 | LEX *lex= thd->lex; |
| 4257 | int res= 0; |
| 4258 | table_map map= 0; |
| 4259 | SELECT_LEX *lex_current_select_save= lex->current_select; |
| 4260 | DBUG_ENTER("select_insert::prepare"); |
| 4261 | |
| 4262 | unit= u; |
| 4263 | |
| 4264 | /* |
| 4265 | Since table in which we are going to insert is added to the first |
| 4266 | select, LEX::current_select should point to the first select while |
| 4267 | we are fixing fields from insert list. |
| 4268 | */ |
| 4269 | lex->current_select= lex->first_select_lex(); |
| 4270 | |
| 4271 | res= (setup_returning_fields(thd, table_list) || |
| 4272 | setup_fields(thd, Ref_ptr_array(), values, MARK_COLUMNS_READ, 0, 0, |
| 4273 | 0) || |
| 4274 | check_insert_fields(thd, table_list, *fields, values, |
| 4275 | !insert_into_view, 1, &map)); |
| 4276 | |
| 4277 | if (!res) |
| 4278 | { |
| 4279 | /* |
| 4280 | Check that all colN=exprN pairs are compatible for assignment, e.g.: |
| 4281 | INSERT INTO t1 (col1, col2) VALUES (expr1, expr2); |
| 4282 | INSERT INTO t1 SET col1=expr1, col2=expr2; |
| 4283 | */ |
| 4284 | res= table_list->table->check_assignability_opt_fields(*fields, values, |
| 4285 | lex->ignore); |
| 4286 | } |
| 4287 | |
| 4288 | if (!res && fields->elements) |
| 4289 | { |
| 4290 | Abort_on_warning_instant_set aws(thd, |
| 4291 | !info.ignore && thd->is_strict_mode()); |
| 4292 | res= check_that_all_fields_are_given_values(thd, table_list->table, |
| 4293 | table_list); |
| 4294 | } |
| 4295 | |
| 4296 | if (info.handle_duplicates == DUP_UPDATE && !res) |
| 4297 | { |
| 4298 | Name_resolution_context *context= &lex->first_select_lex()->context; |
| 4299 | Name_resolution_context_state ctx_state; |
| 4300 | |
| 4301 | /* Save the state of the current name resolution context. */ |
| 4302 | ctx_state.save_state(context, table_list); |
| 4303 | |
| 4304 | /* Perform name resolution only in the first table - 'table_list'. */ |
| 4305 | table_list->next_local= 0; |
| 4306 | context->resolve_in_table_list_only(table_list); |
| 4307 | |
| 4308 | lex->first_select_lex()->no_wrap_view_item= TRUE; |
| 4309 | res= res || |
| 4310 | check_update_fields(thd, context->table_list, |
no test coverage detected