Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
Developer
p3pp3r
Posts: 157
Registered: ‎12-16-2010
My Carrier: I carry it myself
Accepted Solution

Using copyTo to copy Sqlite database file to user accessible directory

I am trying to copy my Sqlite database file from application private directory to user accessible documents directory. Here is my code:

 

 

// closing db connection
dbConnection.close();
// clearing the db file variable
dbFile = null;

// new handle on the same db file
dbFile = File.applicationStorageDirectory.resolvePath("mydb.db");
// copy to documents directory
dbFile.copyTo(File.documentsDirectory);

 

 

When I try to run the code on the device I get:

 

 

Error: Error #3012: Cannot delete file or directory.
at flash.filesystem::File/copyTo()

 

Error: Error #3012: Cannot delete file or directory. at flash.filesystem::File/copyTo()

 

I have   <action>access_shared</action> in the blackberry-tablet.xml

 

What file or directory it is trying to delete? I am just copying the file.

 

Cannot figure out what is the problem.

----------
If you find this post helpful please "like" it and accept as a solution.
Please use plain text.
Developer
alopix
Posts: 312
Registered: ‎04-10-2011

Re: Using copyTo to copy Sqlite database file to user accessible directory

There's an example on the Adobe AIR help-page:

var original = air.File.documentsDirectory.resolvePath("AIR Test/test.txt");

var newFile = air.File.documentsDirectory.resolvePath("AIR Test/copy.txt");

original.copyTo(newFile, true); // true stands for overwrite!

So you have to specify the new filename too not only the directory.

-----------------------------------------------------------------------------
Check out my apps in the BlackBerry World
Visit my developer blog /dev/alopix
Please use plain text.
Developer
mplacona
Posts: 80
Registered: ‎03-17-2011
My Carrier: -

Re: Using copyTo to copy Sqlite database file to user accessible directory

[ Edited ]

This is how I've done it:

 

http://supportforums.blackberry.com/t5/Tablet-OS-SDK-for-Adobe-AIR/Database-permissions/m-p/1048609#...

 

Sample:

 

 

// Init database
var embededSessionDB:File = File.applicationDirectory.resolvePath("assets/db.sqlite");
var writeSessionDB:File = File.applicationStorageDirectory.resolvePath("assets/db.sqlite");
 			
// If a writable DB doesn't exist, we then copy it into the app folder so it's writteable
if (!writeSessionDB.exists) {
	embededSessionDB.copyTo(writeSessionDB);
}
			
var dbFile:File = writeSessionDB;
	
dbConnection.open(dbFile);

And best of all, no need for "access_shared"

 

Marcos Placona
www.placona.co.uk
My Playbook Apps:
Bonjour | Time Traveller | Magic Ball
Please use plain text.