diff options
author | unknown <evgen@moonbone.local> | 2006-04-24 17:52:15 +0400 |
---|---|---|
committer | unknown <evgen@moonbone.local> | 2006-04-24 17:52:15 +0400 |
commit | ccee4036c2a542dd2eb6dfae8f8e0a4d1190dc15 (patch) | |
tree | ceaf1389974db4bb5e61c87360323618e16642aa /sql | |
parent | 2a138695bf6eecb3c8f6b4e3fcb9a1a224b53c2d (diff) | |
parent | 4b7c4cd27f68b9aac1970b9f21c50d4eee35df7d (diff) | |
download | mariadb-git-ccee4036c2a542dd2eb6dfae8f8e0a4d1190dc15.tar.gz |
Manually merged
sql/item.cc:
Auto merged
sql/sql_select.cc:
Auto merged
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item.cc | 18 | ||||
-rw-r--r-- | sql/share/errmsg.txt | 2 | ||||
-rw-r--r-- | sql/sql_select.cc | 4 |
3 files changed, 22 insertions, 2 deletions
diff --git a/sql/item.cc b/sql/item.cc index 8cf6fde1dbd..507e99eb989 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -3137,7 +3137,8 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) both clauses contain different fields with the same names, a warning is issued that name of 'ref' is ambiguous. We extend ANSI SQL in that when no GROUP BY column is found, then a HAVING name is resolved as a possibly - derived SELECT column. + derived SELECT column. This extension is allowed only if the + MODE_ONLY_FULL_GROUP_BY sql mode isn't enabled. NOTES The resolution procedure is: @@ -3147,7 +3148,9 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) in the GROUP BY clause of Q. - If found different columns with the same name in GROUP BY and SELECT - issue a warning and return the GROUP BY column, - - otherwise return the found SELECT column. + - otherwise + - if the MODE_ONLY_FULL_GROUP_BY mode is enabled return error + - else return the found SELECT column. RETURN @@ -3192,6 +3195,17 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select) } } + if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY && + select_ref != not_found_item && !group_by_ref) + { + /* + Report the error if fields was found only in the SELECT item list and + the strict mode is enabled. + */ + my_error(ER_NON_GROUPING_FIELD_USED, MYF(0), + ref->name, "HAVING"); + return NULL; + } if (select_ref != not_found_item || group_by_ref) { if (select_ref != not_found_item && !ambiguous_fields) diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt index 9519e77903d..f174ba559d8 100644 --- a/sql/share/errmsg.txt +++ b/sql/share/errmsg.txt @@ -5615,3 +5615,5 @@ ER_MAX_PREPARED_STMT_COUNT_REACHED 42000 eng "Can't create more than max_prepared_stmt_count statements (current value: %lu)" ER_VIEW_RECURSIVE eng "`%-.64s`.`%-.64s` contain view recursion" +ER_NON_GROUPING_FIELD_USED 42000 + eng "non-grouping field '%-.64s' is used in %-.64s clause" diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 47c5281b258..3a616c28755 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -12613,6 +12613,10 @@ setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, if (item->type() != Item::SUM_FUNC_ITEM && !item->marker && !item->const_item()) { + /* + TODO: change ER_WRONG_FIELD_WITH_GROUP to more detailed + ER_NON_GROUPING_FIELD_USED + */ my_error(ER_WRONG_FIELD_WITH_GROUP, MYF(0), item->full_name()); return 1; } |