DB Tables are not copied onto mobile device

Creating desktop or client-server database solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Fanfanix
Posts: 17
Joined: Fri Nov 29, 2013 3:31 am

DB Tables are not copied onto mobile device

Post by Fanfanix » Sun Dec 07, 2014 7:38 pm

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.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: DB Tables are not copied onto mobile device

Post by Mark » Mon Dec 08, 2014 9:54 am

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

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: DB Tables are not copied onto mobile device

Post by sturgis » Tue Dec 16, 2014 9:36 pm

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.

Post Reply

Return to “Databases”