[gdal-dev] Shape datafile locked

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

[gdal-dev] Shape datafile locked

Stephan Braeuer
I am using GDAL with c# and run into a problem deleting datasource files
after running ExecuteSQL.
The key here is that a datasource is opened implicitly via the JOIN
statement. An implicitly opened shapefile (here node3109.shp) remains locked
after the datasource has been closed.

Opening the file upfront does not help either. Here is the c# code snippet:

  using (DataSource datasource = OSGeo.OGR.Ogr.Open(pipeFile, 0))
  {
     string statement =
         "SELECT p.id, n.grnd_lvl FROM pipe3109 p " +
         "LEFT JOIN 'node3109.shp'.node3109 n ON n.node_id = p.ds_node_id";
     using (Layer layer = datasource.ExecuteSQL(statement, null,
string.Empty))
     {
     }
  }
  File.Delete(pipeFile);   //ok
  File.Delete(nodeFile);  //throws



Anyone knowing a solution to avoid the lock?

Thanks
Stephan







--
Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html
_______________________________________________
gdal-dev mailing list
[hidden email]
https://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Shape datafile locked

Even Rouault-2

On mardi 13 mars 2018 10:01:48 CET Stephan Braeuer wrote:

> I am using GDAL with c# and run into a problem deleting datasource files

> after running ExecuteSQL.

> The key here is that a datasource is opened implicitly via the JOIN

> statement. An implicitly opened shapefile (here node3109.shp) remains locked

> after the datasource has been closed.

>

> Opening the file upfront does not help either. Here is the c# code snippet:

>

> using (DataSource datasource = OSGeo.OGR.Ogr.Open(pipeFile, 0))

> {

> string statement =

> "SELECT p.id, n.grnd_lvl FROM pipe3109 p " +

> "LEFT JOIN 'node3109.shp'.node3109 n ON n.node_id = p.ds_node_id";

> using (Layer layer = datasource.ExecuteSQL(statement, null,

> string.Empty))

> {

 

You probably need an explicit

datasource.ReleaseResultSet(layer)

here. As I don't think layers resulting from ExecuteSQL() are garbage collected by the C# bindings (they are not by other binding languages)

 

> }

> }

> File.Delete(pipeFile); //ok

> File.Delete(nodeFile); //throws

>

>

>

> Anyone knowing a solution to avoid the lock?

>

> Thanks

> Stephan

>

>

>

>

>

>

>

> --

> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html

> _______________________________________________

> gdal-dev mailing list

> [hidden email]

> https://lists.osgeo.org/mailman/listinfo/gdal-dev

 

 

--

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: Shape datafile locked

Stephan Braeuer

Calling datasource.ReleaseResultSet(layer) did the trick.

Thanks!

 

From: Even Rouault [mailto:[hidden email]]
Sent: Tuesday, March 13, 2018 6:12 PM
To: [hidden email]
Cc: Stephan Braeuer <[hidden email]>
Subject: Re: [gdal-dev] Shape datafile locked

 

On mardi 13 mars 2018 10:01:48 CET Stephan Braeuer wrote:

> I am using GDAL with c# and run into a problem deleting datasource files

> after running ExecuteSQL.

> The key here is that a datasource is opened implicitly via the JOIN

> statement. An implicitly opened shapefile (here node3109.shp) remains locked

> after the datasource has been closed.

>

> Opening the file upfront does not help either. Here is the c# code snippet:

>

> using (DataSource datasource = OSGeo.OGR.Ogr.Open(pipeFile, 0))

> {

> string statement =

> "SELECT p.id, n.grnd_lvl FROM pipe3109 p " +

> "LEFT JOIN 'node3109.shp'.node3109 n ON n.node_id = p.ds_node_id";

> using (Layer layer = datasource.ExecuteSQL(statement, null,

> string.Empty))

> {

 

You probably need an explicit

datasource.ReleaseResultSet(layer)

here. As I don't think layers resulting from ExecuteSQL() are garbage collected by the C# bindings (they are not by other binding languages)

 

> }

> }

> File.Delete(pipeFile); //ok

> File.Delete(nodeFile); //throws

>

>

>

> Anyone knowing a solution to avoid the lock?

>

> Thanks

> Stephan

>

>

>

>

>

>

>

> --

> Sent from: http://osgeo-org.1560.x6.nabble.com/GDAL-Dev-f3742093.html

> _______________________________________________

> gdal-dev mailing list

> [hidden email]

> https://lists.osgeo.org/mailman/listinfo/gdal-dev

 

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


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