×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    77

    database file not accessible after closing

    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()

  2. #2
    Regular Contributor
    Join Date
    Apr 2007
    Location
    Lublin, Poland
    Posts
    81

    Re: database file not accessible after closing

    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

  3. #3
    Registered User
    Join Date
    Sep 2003
    Posts
    77

    Re: database file not accessible after closing

    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()

Similar Threads

  1. Contact Database file how to specify in pkg
    By sohilr in forum Symbian
    Replies: 11
    Last Post: 2007-12-12, 10:56
  2. Help needed with a 3gp file...
    By joedoe_1981 in forum Streaming and Video
    Replies: 0
    Last Post: 2007-07-18, 18:58
  3. How to reformat the file?
    By ryanfunghk in forum Symbian Networking & Messaging (Closed)
    Replies: 0
    Last Post: 2005-03-26, 17:43

Posting Permissions

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