@@ -451,10 +451,15 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
451
451
thd->proc_info =" init" ;
452
452
thd->used_tables =0 ;
453
453
values= its++;
454
+ value_count= values->elements ;
454
455
455
456
if (mysql_prepare_insert (thd, table_list, table, fields, values,
456
457
update_fields, update_values, duplic, &unused_conds,
457
- FALSE ))
458
+ FALSE ,
459
+ (fields.elements || !value_count),
460
+ !ignore && (thd->variables .sql_mode &
461
+ (MODE_STRICT_TRANS_TABLES |
462
+ MODE_STRICT_ALL_TABLES))))
458
463
goto abort ;
459
464
460
465
/* mysql_prepare_insert set table_list->table if it was not set */
@@ -480,7 +485,6 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
480
485
table_list->next_local = 0 ;
481
486
context->resolve_in_table_list_only (table_list);
482
487
483
- value_count= values->elements ;
484
488
while ((values= its++))
485
489
{
486
490
counter++;
@@ -551,17 +555,9 @@ bool mysql_insert(THD *thd,TABLE_LIST *table_list,
551
555
table->file ->start_bulk_insert (values_list.elements );
552
556
553
557
thd->no_trans_update = 0 ;
554
- thd->abort_on_warning = (!ignore &&
555
- (thd->variables .sql_mode &
556
- (MODE_STRICT_TRANS_TABLES |
557
- MODE_STRICT_ALL_TABLES)));
558
-
559
- if ((fields.elements || !value_count) &&
560
- check_that_all_fields_are_given_values (thd, table, table_list))
561
- {
562
- /* thd->net.report_error is now set, which will abort the next loop */
563
- error= 1 ;
564
- }
558
+ thd->abort_on_warning = (!ignore && (thd->variables .sql_mode &
559
+ (MODE_STRICT_TRANS_TABLES |
560
+ MODE_STRICT_ALL_TABLES)));
565
561
566
562
mark_fields_used_by_triggers_for_insert_stmt (thd, table, duplic);
567
563
@@ -934,6 +930,10 @@ static bool mysql_prepare_insert_check_table(THD *thd, TABLE_LIST *table_list,
934
930
be taken from table_list->table)
935
931
where Where clause (for insert ... select)
936
932
select_insert TRUE if INSERT ... SELECT statement
933
+ check_fields TRUE if need to check that all INSERT fields are
934
+ given values.
935
+ abort_on_warning whether to report if some INSERT field is not
936
+ assigned as an error (TRUE) or as a warning (FALSE).
937
937
938
938
TODO (in far future)
939
939
In cases of:
@@ -954,7 +954,8 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
954
954
TABLE *table, List<Item> &fields, List_item *values,
955
955
List<Item> &update_fields, List<Item> &update_values,
956
956
enum_duplicates duplic,
957
- COND **where, bool select_insert)
957
+ COND **where, bool select_insert,
958
+ bool check_fields, bool abort_on_warning)
958
959
{
959
960
SELECT_LEX *select_lex= &thd->lex ->select_lex ;
960
961
Name_resolution_context *context= &select_lex->context ;
@@ -1017,10 +1018,22 @@ bool mysql_prepare_insert(THD *thd, TABLE_LIST *table_list,
1017
1018
table_list->next_local = 0 ;
1018
1019
context->resolve_in_table_list_only (table_list);
1019
1020
1020
- if (!(res= check_insert_fields (thd, context->table_list , fields, *values,
1021
- !insert_into_view, &map) ||
1022
- setup_fields (thd, 0 , *values, 0 , 0 , 0 ))
1023
- && duplic == DUP_UPDATE)
1021
+ res= check_insert_fields (thd, context->table_list , fields, *values,
1022
+ !insert_into_view, &map) ||
1023
+ setup_fields (thd, 0 , *values, 0 , 0 , 0 );
1024
+
1025
+ if (!res && check_fields)
1026
+ {
1027
+ bool saved_abort_on_warning= thd->abort_on_warning ;
1028
+ thd->abort_on_warning = abort_on_warning;
1029
+ res= check_that_all_fields_are_given_values (thd,
1030
+ table ? table :
1031
+ context->table_list ->table ,
1032
+ context->table_list );
1033
+ thd->abort_on_warning = saved_abort_on_warning;
1034
+ }
1035
+
1036
+ if (!res && duplic == DUP_UPDATE)
1024
1037
{
1025
1038
select_lex->no_wrap_view_item = TRUE ;
1026
1039
res= check_update_fields (thd, context->table_list , update_fields, &map);
@@ -2295,7 +2308,7 @@ bool mysql_insert_select_prepare(THD *thd)
2295
2308
lex->query_tables ->table , lex->field_list , 0 ,
2296
2309
lex->update_list , lex->value_list ,
2297
2310
lex->duplicates ,
2298
- &select_lex->where , TRUE ))
2311
+ &select_lex->where , TRUE , FALSE , FALSE ))
2299
2312
DBUG_RETURN (TRUE );
2300
2313
2301
2314
/*
@@ -2357,7 +2370,18 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
2357
2370
!insert_into_view, &map) ||
2358
2371
setup_fields (thd, 0 , values, 0 , 0 , 0 );
2359
2372
2360
- if (info.handle_duplicates == DUP_UPDATE)
2373
+ if (!res && fields->elements )
2374
+ {
2375
+ bool saved_abort_on_warning= thd->abort_on_warning ;
2376
+ thd->abort_on_warning = !info.ignore && (thd->variables .sql_mode &
2377
+ (MODE_STRICT_TRANS_TABLES |
2378
+ MODE_STRICT_ALL_TABLES));
2379
+ res= check_that_all_fields_are_given_values (thd, table_list->table ,
2380
+ table_list);
2381
+ thd->abort_on_warning = saved_abort_on_warning;
2382
+ }
2383
+
2384
+ if (info.handle_duplicates == DUP_UPDATE && !res)
2361
2385
{
2362
2386
Name_resolution_context *context= &lex->select_lex .context ;
2363
2387
Name_resolution_context_state ctx_state;
@@ -2459,9 +2483,7 @@ select_insert::prepare(List<Item> &values, SELECT_LEX_UNIT *u)
2459
2483
(thd->variables .sql_mode &
2460
2484
(MODE_STRICT_TRANS_TABLES |
2461
2485
MODE_STRICT_ALL_TABLES)));
2462
- res= ((fields->elements &&
2463
- check_that_all_fields_are_given_values (thd, table, table_list)) ||
2464
- table_list->prepare_where (thd, 0 , TRUE ) ||
2486
+ res= (table_list->prepare_where (thd, 0 , TRUE ) ||
2465
2487
table_list->prepare_check_option (thd));
2466
2488
2467
2489
if (!res)
0 commit comments