I can't delete SQLite db file

1,245 views
Skip to first unread message

RusPython

unread,
May 15, 2009, 1:35:35 PM5/15/09
to sqlalchemy
Hi guys,

I have next code:

import os
from sqlalchemy import *
from sqlalchemy.orm import *

metadata = MetaData()
engine = create_engine('sqlite:///temp.db', convert_unicode=True)
metadata.bind = engine

branches = Table('branches', metadata,
Column('id', Integer, primary_key=True),
Column('name', String(100)),
Column('email', String(100)),
Column('pos', Integer),
)

class Branch(object): pass

mapBranch = mapper(Branch, branches)

metadata.create_all()
session = create_session()

# Here I fill database

session.close()

# Here I want arch dbfile and then delete it
os.remove('.\temp.db')

# And I get error :(

Traceback (most recent call last):
File "G:\project\python\tgk\trunk\src\mail\viewer.py", line 37, in
onClick
converter.convert(branch)
File "G:\project\python\tgk\trunk\src\db\converter.py", line 44, in
convert
os.remove(paths.temp)
WindowsError: [Error 32] The process cannot access the file: 'G:\
\project
\\python\\tgk\\trunk\\src\\temp.db'

How I can close connection with db file?

Thanks,
Viktor

Mike Conley

unread,
May 15, 2009, 2:18:52 PM5/15/09
to sqlal...@googlegroups.com
I found that you need to call  
eng.dispose()
to disconnect from the database before deleting the file.

Not sure about what is happening under the covers at that point, but it seems to work.

--
Mike Conley

Виктор Иконников

unread,
May 15, 2009, 2:58:57 PM5/15/09
to sqlal...@googlegroups.com
...*work[s]

2009/5/16 Виктор Иконников <viktor.i...@gmail.com>
Hi Mike,

Thank you very much. It's work.

2009/5/16 Mike Conley <mcon...@gmail.com>

Виктор Иконников

unread,
May 15, 2009, 2:53:33 PM5/15/09
to sqlal...@googlegroups.com
Hi Mike,

Thank you very much. It's work.

2009/5/16 Mike Conley <mcon...@gmail.com>
I found that you need to call  
Reply all
Reply to author
Forward
0 new messages