[gdal-dev] Ogr2ogr, SQLite and overwriting existing database

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[gdal-dev] Ogr2ogr, SQLite and overwriting existing database

jratike80

Hi,

 

What is the expected behavior if user asks ogr2ogr to create a SQLite database that already exists? The driver page http://www.gdal.org/drv_sqlite.html tells that

“The SQLite driver supports creating new SQLite database files, or adding tables to existing ones. Note that a new database file cannot be created over an existing file.”

 

However, all these commands do overwrite the existing SQlite database

 

ogr2ogr -f sqlite -dsco spatialite=yes foo.sqlite foo.jml

ogr2ogr -f sqlite foo.sqlite foo.jml

ogr2ogr -f gpkg foo.gpkg foo.jml

 

But if I lock the existing database by creating a connection into it I get these messages:

ERROR 1: A file system object called 'foo.gpkg' already exists.

ERROR 1: gpkg driver failed to create foo.gpkg

 

Does “ERROR 1: A file system object called 'foo.gpkg' already exists.” mean that the purpose to prevent overwriting but the check does not work? I have been using quit overwriting as a feature but is it actually a bug?

 

-Jukka Rahkonen-

 

 


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Ogr2ogr, SQLite and overwriting existing database

Even Rouault-2

Hi,

 

> What is the expected behavior if user asks ogr2ogr to create a SQLite

> database that already exists? The driver page

> http://www.gdal.org/drv_sqlite.html tells that "The SQLite driver supports

> creating new SQLite database files, or adding tables to existing ones. Note

> that a new database file cannot be created over an existing file."

 

Outdated statement from 1.X era (just removed it). Now that the SQLite driver is a GDAL driver, it follows the general mechanism of deleting the existing file.

 

>

> But if I lock the existing database by creating a connection into it I get

> these messages: ERROR 1: A file system object called 'foo.gpkg' already

> exists.

> ERROR 1: gpkg driver failed to create foo.gpkg

>

> Does "ERROR 1: A file system object called 'foo.gpkg' already exists." mean

> that the purpose to prevent overwriting but the check does not work? I have

> been using quit overwriting as a feature but is it actually a bug?

 

This is a particularity of the GPKG driver. The file should have normally deleted but due t thhe lock QuietDelete() failed. And the GPKG driver has a specific code to prevent overwriting of an exiting file in its Create() method. In fact it errors out if APPEND_SUBDATASET=YES is not specified, and if it is specified it happens a new raster dataset to the existing file

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Ogr2ogr, SQLite and overwriting existing database

jratike80
In reply to this post by jratike80

Hi Even,

 

Thanks for the clarification. By the way, the behavior with QuietDelete may be different with  SQLite driver but the messages are the same:

 

GDAL: GDALOpen(foo.sqlite, this=0000000001DD6450) succeeds as SQLite.

RASTERLITE: SQLite DB Open

OGR: Unloading VirtualOGR module

GDAL: GDALClose(foo.sqlite, this=0000000001DD6450)

SQLITE: OGR style SQLite DB found !

OGR: Unloading VirtualOGR module

GDAL: QuietDelete(foo.sqlite) invoking Delete()

GDAL: GDALDriver::Create(SQLite,foo.sqlite,0,0,0,Unknown,0000000000000000)

ERROR 1: It seems a file system object called 'foo.sqlite' already exists.

ERROR 1: sqlite driver failed to create foo.sqlite

 

-Jukka-

 

 

Lähettäjä: Even Rouault [mailto:[hidden email]]
Lähetetty: 9. toukokuuta 2018 19:43
Vastaanottaja: [hidden email]
Kopio: Rahkonen Jukka (MML) <[hidden email]>
Aihe: Re: [gdal-dev] Ogr2ogr, SQLite and overwriting existing database

 

Hi,

 

> What is the expected behavior if user asks ogr2ogr to create a SQLite

> database that already exists? The driver page

> http://www.gdal.org/drv_sqlite.html tells that "The SQLite driver supports

> creating new SQLite database files, or adding tables to existing ones. Note

> that a new database file cannot be created over an existing file."

 

Outdated statement from 1.X era (just removed it). Now that the SQLite driver is a GDAL driver, it follows the general mechanism of deleting the existing file.

 

>

> But if I lock the existing database by creating a connection into it I get

> these messages: ERROR 1: A file system object called 'foo.gpkg' already

> exists.

> ERROR 1: gpkg driver failed to create foo.gpkg

>

> Does "ERROR 1: A file system object called 'foo.gpkg' already exists." mean

> that the purpose to prevent overwriting but the check does not work? I have

> been using quit overwriting as a feature but is it actually a bug?

 

This is a particularity of the GPKG driver. The file should have normally deleted but due t thhe lock QuietDelete() failed. And the GPKG driver has a specific code to prevent overwriting of an exiting file in its Create() method. In fact it errors out if APPEND_SUBDATASET=YES is not specified, and if it is specified it happens a new raster dataset to the existing file

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev