Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OGRSQL: validate column name in COUNT(field_name) #9986

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion autotest/ogr/ogr_sql_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,10 @@ def test_ogr_sql_28():
"SELECT COUNT(*) FROM",
"SELECT COUNT(*) AS foo FROM",
"SELECT COUNT(* FROM my_layer",
"SELECT COUNT(i_dont_exist) FROM my_layer",
"SELECT COUNT(FOO intfield) FROM my_layer",
"SELECT COUNT(DISTINCT intfield FROM my_layer",
"SELECT COUNT(DISTINCT i_dont_exist) FROM my_layer",
"SELECT COUNT(DISTINCT *) FROM my_layer",
"SELECT FOO(DISTINCT intfield) FROM my_layer",
"SELECT FOO(DISTINCT intfield) as foo FROM my_layer",
Expand Down Expand Up @@ -1084,7 +1086,7 @@ def test_ogr_sql_36():
# Test select count([distinct] column) with null values (#4354)


def test_ogr_sql_37():
def test_ogr_sql_count_and_null():

ds = ogr.GetDriverByName("Memory").CreateDataSource("ogr_sql_37")
lyr = ds.CreateLayer("layer")
Expand Down
2 changes: 1 addition & 1 deletion ogr/ogrsf_frmts/generic/ogr_gensql.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ int OGRGenSQLResultsLayer::PrepareSummary()

/* -------------------------------------------------------------------- */
/* We treat COUNT(*) as a special case, and fill with */
/* GetFeatureCount(). */
/* GetFeatureCount(). */
/* -------------------------------------------------------------------- */

if (psSelectInfo->result_columns() == 1 &&
Expand Down
3 changes: 2 additions & 1 deletion ogr/swq_select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,8 @@ CPLErr swq_select::parse(swq_field_list *field_list,
// Record field type.
def->field_type = this_type;

if (def->field_index == -1 && def->col_func != SWQCF_COUNT)
if (def->field_index == -1 && !(def->col_func == SWQCF_COUNT &&
strcmp(def->field_name, "*") == 0))
{
CPLError(
CE_Failure, CPLE_AppDefined, "Unrecognized field name %s.",
Expand Down
Loading