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

-dialect OGRSQL: COUNT does not validate the column name #9972

Closed
jidanni opened this issue May 21, 2024 · 1 comment · Fixed by #9986
Closed

-dialect OGRSQL: COUNT does not validate the column name #9972

jidanni opened this issue May 21, 2024 · 1 comment · Fixed by #9986
Assignees

Comments

@jidanni
Copy link
Contributor

jidanni commented May 21, 2024

With -dialect SQLite problems are caught right away,

$ ogrinfo -dialect SQLite -q -sql 'SELECT count(zzz) FROM vermilion_co_il' some.kmz
ERROR 1: In ExecuteSQL(): sqlite3_prepare_v2(SELECT count(zzz) FROM vermilion_co_il):
  no such column: zzz

But with -dialect OGRSQL, count() masks the problem,

$ ogrinfo -dialect OGRSQL -q -sql 'SELECT count(zzz) FROM vermilion_co_il' some.kmz
Layer name: vermilion_co_il
OGRFeature(vermilion_co_il):0
  COUNT_zzz (Integer) = 1

Only after we strip off the count() is the problem finally caught,

$ ogrinfo -dialect OGRSQL -q -sql 'SELECT zzz FROM vermilion_co_il' some.kmz
ERROR 1: Unrecognized field name zzz.

GDAL 3.8.5

@jratike80
Copy link
Collaborator

jratike80 commented May 21, 2024

Count(foo) seems to do the same as count(*) and returns the total number or records. The same happens with count(distinct foo).

Maybe I would describe the problem somehow like "COUNT does not validate the column name".

@rouault rouault changed the title -dialect OGRSQL: count() masks errors -dialect OGRSQL: COUNT does not validate the column name May 21, 2024
@rouault rouault self-assigned this May 22, 2024
rouault added a commit to rouault/gdal that referenced this issue May 22, 2024
and error out if it doesn't exist, otherwise it evaluates as COUNT(*)

Fixes OSGeo#9972
rouault added a commit that referenced this issue May 28, 2024
and error out if it doesn't exist, otherwise it evaluates as COUNT(*)

Fixes #9972
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants