[gdal-dev] Delete a sqlite database

Ludovic Granjon ludovic.granjon at u-bourgogne.fr
Wed Nov 24 05:14:05 EST 2010


Hi all
Finally I solved my problem with an over way :
I don't call a datasource.executeSQL for my join.
Now I did my join with python and than I can manage my sqlite connection 
and than I'm able to close it correctly.
So it works for me now

Thanks

Ludovic

Le 22/11/2010 15:42, Jason Roberts a écrit :
> Hi Ludovic and Frank,
>
> As I understand from discussions with Evan Rouault, Destroy() is an obsolete
> method in the Python bindings that should not be used. See
> http://trac.osgeo.org/gdal/wiki/PythonGotchas#CertainobjectscontainaDestroym
> ethodbutyoushouldneveruseit.
>
> If that understanding is not correct, please let me know.
>
> Rather than calling Destroy(), it might be better to set all of the
> variables to None (i.e. joinlayer, layer, and datasource) to hopefully cause
> Python to destruct these instances. But I see from Ludovic's latest email
> that he tried it and it did not work. So it is time for a new idea...
>
> In any case, please let me know if there is a scenario in which Destroy() is
> supposed to be called from the Python bindings, contrary to Evan's advice.
>
> Thanks,
> Jason
>
> -----Original Message-----
> From: gdal-dev-bounces at lists.osgeo.org
> [mailto:gdal-dev-bounces at lists.osgeo.org] On Behalf Of Frank Warmerdam
> Sent: Monday, November 22, 2010 9:24 AM
> To: Ludovic Granjon
> Cc: gdal-dev at lists.osgeo.org
> Subject: Re: [gdal-dev] Delete a sqlite database
>
> Ludovic Granjon wrote:
>> Hi all
>> I try in a python script to delete a sqlite database that I use in an
>> OGR ExecuteSQL.
>> Let me give you an example :
>> If I do :
>>
>>   >>>  from osgeo import *
>>   >>>  import os
>>   >>>  datasource = ogr.Open("decoupe.shp")
>>   >>>  layer = datasource.GetLayer()
>>   >>>  joinLayer=datasource.ExecuteSQL("SELECT decoupe.FID as ligne_id,
>> c.lFid as ligne_id2, c.count as count FROM decoupe LEFT JOIN
>> 'project.sqlite'.comptage c ON decoupe.FID=c.lFid")
>>   >>>  datasource.Destroy()
>>
>> It seems that there still a connection to my sqlite database and I can't
>> delete it.
>>
>> When I try on MS Windows (There's no error on linux) :
>>   >>>  os.remove('project.sqlite')
>>
>> I have :
>> Traceback (most recent call last):
>> File "<pyshell#5>", line 1, in<module>
>> os.remove('project.sqlite')
>> WindowsError: [Error 13] Le processus ne peut pas accéder au fichier car
>> ce fichier est utilisé par un autre processus: 'project.sqlite'
>>
>>
>> Do you know a way to do that ?
> Ludovic,
>
> I think newish versions of the Python bindings attempt to keep the
> datasource
> alive as long as their are references to layers from it.  I would suggest
> setting layer and joinLayer variables to None before calling destroy on the
> datasource or even just setting the datasource to None.  I'm not positive
> that
> this is the issue - perhaps you could let us know if it works.
>
> Best regards,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ludovic_granjon.vcf
Type: text/x-vcard
Size: 149 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/gdal-dev/attachments/20101124/1833f0d7/ludovic_granjon.vcf


More information about the gdal-dev mailing list