You Are Here:

Community: Developer Discussion Boards

#1 Old database file not accessible after closing - 2008-01-28, 21:25

Join Date: Sep 2003
Posts: 50
dehlerm
Offline
Regular Contributor
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'
When the two code lines commented out in function new() are activated and the equivalent lines are commented out in function run, everything works like expected. Anyone knows why?

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()
Reply With Quote

#2 Old Re: database file not accessible after closing - 2008-02-04, 14:28

Join Date: Apr 2007
Posts: 81
Location: Lublin, Poland
janekw_'s Avatar
janekw_
Offline
Regular Contributor
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
Reply With Quote

#3 Old Re: database file not accessible after closing - 2008-02-26, 12:20

Join Date: Sep 2003
Posts: 50
dehlerm
Offline
Regular Contributor
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 With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
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

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia