DB Tables are not copied onto mobile device
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
DB Tables are not copied onto mobile device
I created a sqlite database "Employee" with 2 tables. I populated from a desktop app both tables with appropriate data. On the desktop app, I am able to access both tables and display the data. I want to use the same database in a mobile app. What are the codes to copy the database Employee with the 2 tables in a mobile app? Currently, in the mobile device, I can only see the database name but NO tables at all. I want to copy the database along with the 2 tables populated with data. Any help, I would highly appreciate it. Thanks.
Re: DB Tables are not copied onto mobile device
Hi,
How can you "see" the database name? Do you mean that you can see the file using "if there is a file..."?
How do you currently copy the file over to your standalone? Normally, you'd do this in the standalone application settings.
Do you need write access to the database? If so, you should copy the file to the documents folder by script.
Kind regards,
Mark
How can you "see" the database name? Do you mean that you can see the file using "if there is a file..."?
How do you currently copy the file over to your standalone? Normally, you'd do this in the standalone application settings.
Do you need write access to the database? If so, you should copy the file to the documents folder by script.
Kind regards,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
Re: DB Tables are not copied onto mobile device
As Mark said, you should include the database file as part of the standalone settings. (file, standalone settings, choose "copy files" at the top, then add the database file.)
Once that is done, when you build your standalone the database file will be included in the apk bundle (on android) and be contained in the specialfolderpath("engine") folder. Since the engine folder isn't writeable, you'll need to copy the database file over to a writable location.
put specialfolderpath("engine") & "/databasefilename.sqlite" into tSourcePath -- put the path to the original in a variable
put specialfolderpath("documents") & "/databasefilename.sqlite" into tTargetPath -- put the path you want to copy it to into a variable
put url merge("binfile:[[tSourcePath]]") into url merge("binfile:[[tTargetPath]]") -- put the contents of the original file into a file in the target location
You'll also not want to do this every time of course. You'll want to use "if there is a file tTargetPath" to see if its already there.
When you open your database, if you're pointing to a location without a database file, you'll end up with an empty database with no tables, which is what it sounds like is happening. Since i'm not sure how mobile deals with files in documents when you re-install an app, it might be possible that there is already an empty file there now, so that might be something that needs to be dealt with.
Once that is done, when you build your standalone the database file will be included in the apk bundle (on android) and be contained in the specialfolderpath("engine") folder. Since the engine folder isn't writeable, you'll need to copy the database file over to a writable location.
put specialfolderpath("engine") & "/databasefilename.sqlite" into tSourcePath -- put the path to the original in a variable
put specialfolderpath("documents") & "/databasefilename.sqlite" into tTargetPath -- put the path you want to copy it to into a variable
put url merge("binfile:[[tSourcePath]]") into url merge("binfile:[[tTargetPath]]") -- put the contents of the original file into a file in the target location
You'll also not want to do this every time of course. You'll want to use "if there is a file tTargetPath" to see if its already there.
When you open your database, if you're pointing to a location without a database file, you'll end up with an empty database with no tables, which is what it sounds like is happening. Since i'm not sure how mobile deals with files in documents when you re-install an app, it might be possible that there is already an empty file there now, so that might be something that needs to be dealt with.