[gdal-dev] Delete a sqlite database
Ludovic Granjon
ludovic.granjon at u-bourgogne.fr
Mon Nov 22 09:40:20 EST 2010
Le 22/11/2010 15:24, Frank Warmerdam a écrit :
> 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,
Thanks Franck for your answer
I try :
>>> layer = None
>>> joinLayer = None
>>> datasource.Destroy()
and :
>>> layer = None
>>> joinLayer = None
>>> datasource = None
But I have the same error.
Best regards
Ludovic
-------------- 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/20101122/79b21f9c/ludovic_granjon.vcf
More information about the gdal-dev
mailing list