| Reply | « Previous Thread | Next Thread » |
|
I ran into a problem with a closed database file which can't be copied after closing it. Below is a quite extensive code snippet to demonstrate the problem. The original code is much more complex, but this was the smallest example I could reproduce the error with.
A database is created/opened and data written to it. In the function exit_key_handler the database is closed and a backup file should be copied to another directory. Here the problem occurs: The shutil.copyfile command failes with this error message. Code:
File "c:\resource\shutil.py", line 17, in copyfile fsrc = open(src, 'rb') IOError: [Errno 13] Permission denied: 'C:\\Test.dat' Code:
import appuifw import os import shutil import e32 import e32db def new(): integer = 100 string = u"" # dbv_dat = e32db.Db_view() # dbv_dat.prepare(db_dat, u"SELECT * FROM test") db_dat.begin() sql_add = u"INSERT INTO test (test_1,test_2) VALUES (%d,'%s')"%(integer,string) db_dat.execute(sql_add) db_dat.commit() def exit_key_handler(): db_dat.compact() db_dat.close() data_backup_path = u"C:\\Backup" if not os.path.exists(data_backup_path): os.makedirs(data_backup_path) shutil.copyfile(u"C:\\Test.dat",u"C:\\Backup\\Test.dat") app_lock.signal() def run(): global db_dat global app_lock global dbv_dat db_file = u"C:\\Test.dat" db_dat = e32db.Dbms() try: db_dat.open(db_file) except: db_dat.create(db_file) db_dat.open(db_file) db_dat.begin() sql_create = u"CREATE TABLE test (test_1 INTEGER, test_2 VARCHAR)" db_dat.execute(sql_create) db_dat.commit() dbv_dat = e32db.Db_view() dbv_dat.prepare(db_dat, u"SELECT * FROM test") new() appuifw.app.screen = 'normal' app_lock = e32.Ao_lock() appuifw.app.exit_key_handler = exit_key_handler app_lock.wait() run() |
|
Perhaps a view releases the db file only if it's destroyed, which happens (may happen) implicilty at the end of new().
Obvious answer, not necessarily correct. whatever happens happens |
|
Thanks for your hint janekw_! It took me some more playing around, but in the end I got it working with the the following code as 'exit_key_handler'.
The 'del dbv_dat' was the critical missing command. Code:
def exit_key_handler(): global dbv_dat db_dat.compact() db_dat.close() del dbv_dat #this is the 'critical' line data_backup_path = u"C:\\Backup" if not os.path.exists(data_backup_path): os.makedirs(data_backup_path) shutil.copyfile(u"C:\\Test.dat",u"C:\\Backup\\Test.dat") app_lock.signal() |
| Reply | « Previous Thread | Next Thread » |
| Thread Tools | Search this Thread |
|---|---|
| Rate This Thread | |
| Thread | Thread Starter | Forum | Replies | Last Post |
|---|---|---|---|---|
| Theme Studio 3.1 not creating themes | zemm | Themes/Carbide.ui | 11 | 2008-10-18 09:41 |
| Contact Database file how to specify in pkg | sohilr | General Symbian C++ | 11 | 2007-12-12 11:56 |
| Help needed with a 3gp file... | joedoe_1981 | Streaming and Video | 0 | 2007-07-18 19:58 |
| How to reformat the file? | ryanfunghk | Symbian Networking & Messaging | 0 | 2005-03-26 18:43 |
| Help !about .mbm的形成 | wangguoshui | Symbian | 4 | 2004-12-23 04:37 |