Opened 8 years ago
Closed 8 years ago
#6509 closed enhancement (fixed)
VFK: allow reading DB as valid datasource
Reported by: | martinl | Owned by: | warmerdam |
---|---|---|---|
Priority: | normal | Milestone: | 2.2.0 |
Component: | OGR_SF | Version: | svn-trunk |
Severity: | normal | Keywords: | VFK |
Cc: |
Description
Based on input data the VFK driver creates an internal SQLite database from which data are read. The patch bellow allows to open DB created by VFK driver as a valid datasource (background: user wants to read several VFK files into one DB). The problem is that VFK driver must be registered before SQLite driver otherwise SQLite driver will be used as valid driver for such data.
Index: ogr/ogrsf_frmts/generic/ogrregisterall.cpp =================================================================== --- ogr/ogrsf_frmts/generic/ogrregisterall.cpp (revision 34211) +++ ogr/ogrsf_frmts/generic/ogrregisterall.cpp (working copy) @@ -104,6 +104,10 @@ #ifdef GMT_ENABLED RegisterOGRGMT(); #endif +#ifdef VFK_ENABLED + /* Register before SQLite, that could recognize .db file too */ + RegisterOGRVFK(); +#endif #ifdef SQLITE_ENABLED RegisterOGRGeoPackage(); RegisterOGRSQLite(); @@ -182,9 +186,6 @@ #ifdef GTM_ENABLED RegisterOGRGTM(); #endif -#ifdef VFK_ENABLED - RegisterOGRVFK(); -#endif #ifdef PGDUMP_ENABLED RegisterOGRPGDump(); #endif
Any idea how this issue could be solved without such significant change? See full attachment:vfk-open-db.diff
Attachments (2)
Change History (7)
by , 8 years ago
Attachment: | vfk-open-db.diff added |
---|
follow-up: 2 comment:1 by , 8 years ago
The issue with your patch is that the identify() method has
/* Valid datasource is also SQLite DB previously created by VFK driver */ if ( poOpenInfo->nHeaderBytes >= 15 && STARTS_WITH((const char*)poOpenInfo->pabyHeader, "SQLite format 3") ) return TRUE;
so any SQLite3 DB will match with that criterion. It should at least return GDAL_IDENTIFY_UNKNOWN which means "I have some reasons to think I can read this file but I'm not sure without more checks".
An inconvenience with registering VFK before SQLite is that "regular" sqlite (or spatialite) dbs will be opened twice. As VFK is likely a less common use case that sqlite/spatialite (world usage considered), another solution might be in the SQLite driver to do the test "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%s', VFK_DB_TABLE); and exit silently if it succeeds so that the VFK driver can later be probed.
follow-up: 3 comment:2 by , 8 years ago
Replying to rouault:
so any SQLite3 DB will match with that criterion. It should at least return GDAL_IDENTIFY_UNKNOWN which means "I have some reasons to think I can read this file but I'm not sure without more checks".
OK, I will change the return value. Anyway it's exactly this case, see
+ if (m_bIsDbSource) { + /* check if it's really VFK DB source */ + sqlite3_stmt *hStmt; + + osCommand.Printf("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%s'", + VFK_DB_TABLE); + hStmt = PrepareStatement(osCommand.c_str()); + if (ExecuteSQL(hStmt) == OGRERR_NONE && + sqlite3_column_int(hStmt, 0) != 1) { + sqlite3_close(m_poDB); + m_poDB = NULL; + } + sqlite3_finalize(hStmt); + }
An inconvenience with registering VFK before SQLite is that "regular" sqlite (or spatialite) dbs will be opened twice. As VFK is likely a less common use case that sqlite/spatialite (world usage considered), another solution might be in the SQLite driver to do the test "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='%s', VFK_DB_TABLE); and exit silently if it succeeds so that the VFK driver can later be probed.
This would be probably better solution. I will prepare new version of the patch.
comment:3 by , 8 years ago
Replying to martinl:
This would be probably better solution. I will prepare new version of the patch.
by , 8 years ago
Attachment: | vfk-open-db-1.diff added |
---|
Open VFK DB as valid datasource