Page 1 of 2
Database file not showing on the device
Posted: Sun Aug 17, 2014 5:04 am
by Fanfanix
The database connection is lost when I am testing the app on my iPad.
My app is a quiz with questions and answer. The question does not come up at all on the iPad.
What am I doing wrong? Where in the standalone setup do I have to mention there is a database file SqlLite ?
Thanks for any help.
Re: Database file not showing on the device
Posted: Sun Aug 17, 2014 10:55 am
by Jellicle
The database needs to be copied to the app's documents directory. Include it in the binary and copy it to the device on first launch.
Gerry
Re: Database file not showing on the device
Posted: Mon Aug 18, 2014 8:41 am
by Jellicle
To elaborate, when you build the app binary have the database file in the Copy Files pane of the Standalone Application Settings for the app. That'll copy it to the binary. Then, in your openstack script, have something like this:
Code: Select all
on openstack
if the environment = "mobile" then
if there is not a file (specialFolderPath("Documents") & "/database.sqlite") then
put (specialFolderPath("engine") & "/database.sqlite") into spath
put url ("binfile:" & spath) into dpath
put dpath into url ("binfile:"& (specialFolderPath("Documents") & "/database.sqlite"))
end if
end if
-- open the database here
end openstack
Obviously you need to replace the file name "database.sqlite" with whatever the actual name of your database is.
Gerry
Re: Database file not showing on the device
Posted: Mon Aug 18, 2014 1:08 pm
by MaxV
In
File -> Standalone Application Settings... there is a
Copy Files section that permit you to specify what files or folder to copy relative to your application.
However for security reasons, I don't think that you can copy external app files on iOS. I suggest you to incorporate your sqlite file as a custom properties like explained in this page:
http://livecode.wikia.com/wiki/Loading, ... inary_file
then you may write the file in the device and use it.
I suppose that iOS, like Android, reserve a virtual folder to applications; this way they can't hurt the device.
Re: Database file not showing on the device
Posted: Mon Aug 18, 2014 3:27 pm
by FourthWorld
Moderation note: a duplicate of this thread in "Complete Beginners" was merged with this topic.
Going forward, please make only one thread per topic so those who might be able to help can know where to do so, and others who would find the topic useful can find the answers in one place. Thanks.
Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 3:07 pm
by Fanfanix
Gerry,
Thanks for the codes to access the database on mobile. In fact, I was able to connect to the database but when it gets to read the table, I receive this error : revdberr, Database Error: No such table Histoire" The table "Histoire" does exist and it has records in it.
Here are the codes to open the database:
# Open the database
put "/users/frantzcharles/Documents/All About LiveCode/Cric-Crac/CricCracDB.sqlite" into thePath
put "/CricCracDB.sqlite" into theMobilePath
if the environment = "mobile" then
if there is not a file (specialFolderPath("Documents") & theMobilePath) then
put (specialFolderPath("engine") & theMobilePath) into sPath
put url ("binfile:" & sPath) into dPath
put dPath into url ("binfile:" & (specialFolderPath("Documents") & theMobilePath))
end if
put (specialFolderPath("Documents") & "/CricCracDB.sqlite") into tDBPath
put revOpenDatabase("sqlite", tDBPath ,,,,,,) into tConID
else
## this is not mobile
put revOpenDatabase("sqlite", thePath ,,,,,,) into tConID
end if
Here are the codes to access the table
put "Select Hist_Question from Histoire where Hist_Id = " & tNextQ into tSQL
put revdb_querylist(,,g_ConID, tSQL) into tList
Do I need to do something with the table before I can read from it?
Thanks for your help.
Fanix
Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 5:05 pm
by MaxV
I would prefer to use:
Code: Select all
put revDataFromQuery(tab,return,connID,tSQL) into tList
Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 5:12 pm
by Simon
(specialFolderPath("Documents") & theMobilePath)
for mobile should be;
(specialFolderPath("documents") & theMobilePath)
Case sensitive.
Simon
Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 5:20 pm
by Klaus
I would prefer to use:
Code: Select all
put revDataFromQuery(tab,return,connID,tSQL) into tList
The default delimiters for DB access are TAB and CR, so if you leave these 2 params
it will still work as exspected with TAB and CR

Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 5:22 pm
by Klaus
(specialFolderPath("Documents") & theMobilePath)
for mobile should be;
(specialFolderPath("documents") & theMobilePath)
Case sensitive.
Yes, iOS and Android have case sensitive file systems,
but this is a Livecode script, so that doesn't matter

Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 5:26 pm
by Simon
but this is a Livecode script, so that doesn't matter

Have I lost the plot again?
Isn't the problem on iPad? I'm guessing it works on desktop.
Simon
Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 5:57 pm
by Klaus
This also works on mobile, Simon, no matter HOW you spell "documenTs"

Re: Database file not showing on the device
Posted: Mon Sep 01, 2014 6:28 pm
by Simon
I am so not keeping up with the times
Anyway;
Hi Fanfanix,
In fact, I was able to connect to the database but when it gets to read the table, I receive this error : revdberr, Database Error: No such table Histoire"
When I read the line from the dictionary that said something like "if there is not a database by that name liveCode will create one..." I thought that was really cool! Well I don't think it's cool anymore. sure you can connect to a database, but a new one, and you'll never be told until you get the "revdberr".
Simon
Re: Database file not showing on the device
Posted: Tue Sep 02, 2014 7:57 am
by strongbow
Your problem may be the line:
put url ("binfile:" & sPath) into dPath
You don't have a variable sPath, but you do have one called thePath that you set up at the start of your script. Perhaps try fixing that?
Re: Database file not showing on the device
Posted: Tue Sep 02, 2014 5:26 pm
by Klaus
strongbow wrote:Your problem may be the line:
put url ("binfile:" & sPath) into dPath
You don't have a variable sPath, but you do have one called thePath that you set up at the start of your script. Perhaps try fixing that?
No
...
## thePath is obviously only used on the DESKTOP
put "/users/frantzcharles/Documents/All About LiveCode/Cric-Crac/CricCracDB.sqlite" into thePath
put "/CricCracDB.sqlite" into theMobilePath
if the environment = "mobile" then
if there is not a file (specialFolderPath("Documents") & theMobilePath) then
put (specialFolderPath("engine") & theMobilePath) into sPath
## These two lines are also correct!
put url ("binfile:" & sPath) into dPath
put dPath into url ("binfile:" & (specialFolderPath("Documents") & theMobilePath))
end if
put (specialFolderPath("Documents") & "/CricCracDB.sqlite") into tDBPath
put revOpenDatabase("sqlite", tDBPath ,,,,,,) into tConID
else
## this is not mobile
put revOpenDatabase("sqlite", thePath ,,,,,,) into tConID
end if
...
But everything else looks OK!?
No idea why that does not work...
I am sure it is one of these obvious "OMG! slap on the forehead" things!
