Skip to content

Commit

Permalink
ExecuteSQL(): add a warning if the dialect name isn't recognized (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Nov 27, 2023
1 parent a09033a commit d75fea1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
30 changes: 30 additions & 0 deletions gcore/gdaldataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6478,6 +6478,36 @@ GDALDataset::ExecuteSQL(const char *pszStatement, OGRGeometry *poSpatialFilter,
#endif
}

if (pszDialect != nullptr && !EQUAL(pszDialect, "") &&
!EQUAL(pszDialect, "OGRSQL"))
{
std::string osDialectList = "'OGRSQL'";
#ifdef SQLITE_ENABLED
osDialectList += ", 'SQLITE'";
#endif
const char *pszDialects =
GetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS);
if (pszDialects)
{
const CPLStringList aosTokens(
CSLTokenizeString2(pszDialects, " ", 0));
for (int i = 0; i < aosTokens.size(); ++i)
{
if (!EQUAL(aosTokens[i], "OGRSQL") &&
!EQUAL(aosTokens[i], "SQLITE"))
{
osDialectList += ", '";
osDialectList += aosTokens[i];
osDialectList += "'";
}
}
}
CPLError(CE_Warning, CPLE_NotSupported,
"Dialect '%s' is unsupported. Only supported dialects are %s. "
"Defaulting to OGRSQL",
pszDialect, osDialectList.c_str());
}

/* -------------------------------------------------------------------- */
/* Handle CREATE INDEX statements specially. */
/* -------------------------------------------------------------------- */
Expand Down
7 changes: 4 additions & 3 deletions ogr/ogrsf_frmts/gpkg/ogrgeopackagedatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7310,11 +7310,12 @@ OGRLayer *GDALGeoPackageDataset::ExecuteSQL(const char *pszSQLCommand,
return nullptr;
}

if (pszDialect != nullptr && EQUAL(pszDialect, "OGRSQL"))
return GDALDataset::ExecuteSQL(osSQLCommand, poSpatialFilter,
pszDialect);
else if (pszDialect != nullptr && EQUAL(pszDialect, "INDIRECT_SQLITE"))
return GDALDataset::ExecuteSQL(osSQLCommand, poSpatialFilter, "SQLITE");
else if (pszDialect != nullptr && !EQUAL(pszDialect, "NATIVE") &&
!EQUAL(pszDialect, "SQLITE"))
return GDALDataset::ExecuteSQL(osSQLCommand, poSpatialFilter,
pszDialect);

#if SQLITE_VERSION_NUMBER < 3007017
// Emulate PRAGMA application_id
Expand Down
10 changes: 6 additions & 4 deletions ogr/ogrsf_frmts/sqlite/ogrsqlitedatasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3206,12 +3206,14 @@ OGRLayer *OGRSQLiteDataSource::ExecuteSQL(const char *pszSQLCommand,
}
}

if (pszDialect != nullptr && EQUAL(pszDialect, "OGRSQL"))
return GDALDataset::ExecuteSQL(pszSQLCommand, poSpatialFilter,
pszDialect);
else if (pszDialect != nullptr && EQUAL(pszDialect, "INDIRECT_SQLITE"))
if (pszDialect != nullptr && EQUAL(pszDialect, "INDIRECT_SQLITE"))
return GDALDataset::ExecuteSQL(pszSQLCommand, poSpatialFilter,
"SQLITE");
else if (pszDialect != nullptr && !EQUAL(pszDialect, "NATIVE") &&
!EQUAL(pszDialect, "SQLITE"))

return GDALDataset::ExecuteSQL(pszSQLCommand, poSpatialFilter,
pszDialect);

/* -------------------------------------------------------------------- */
/* Special case DELLAYER: command. */
Expand Down

0 comments on commit d75fea1

Please sign in to comment.