Database file not showing on the device

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

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

Database file not showing on the device

Post by Fanfanix » Sun Aug 17, 2014 5:04 am

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.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Database file not showing on the device

Post by Jellicle » Sun Aug 17, 2014 10:55 am

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
14" MacBook Pro
Former LiveCode developer.
Now recovering.

Jellicle
Posts: 453
Joined: Thu Feb 24, 2011 11:07 am

Re: Database file not showing on the device

Post by Jellicle » Mon Aug 18, 2014 8:41 am

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
14" MacBook Pro
Former LiveCode developer.
Now recovering.

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Database file not showing on the device

Post by MaxV » Mon Aug 18, 2014 1:08 pm

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.
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10043
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Database file not showing on the device

Post by FourthWorld » Mon Aug 18, 2014 3:27 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: Database file not showing on the device

Post by Fanfanix » Mon Sep 01, 2014 3:07 pm

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

MaxV
Posts: 1580
Joined: Tue May 28, 2013 2:20 pm
Contact:

Re: Database file not showing on the device

Post by MaxV » Mon Sep 01, 2014 5:05 pm

I would prefer to use:

Code: Select all

put revDataFromQuery(tab,return,connID,tSQL) into tList
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Database file not showing on the device

Post by Simon » Mon Sep 01, 2014 5:12 pm

(specialFolderPath("Documents") & theMobilePath)
for mobile should be;
(specialFolderPath("documents") & theMobilePath)
Case sensitive.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Database file not showing on the device

Post by Klaus » Mon Sep 01, 2014 5:20 pm

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

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Database file not showing on the device

Post by Klaus » Mon Sep 01, 2014 5:22 pm

(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 :D

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Database file not showing on the device

Post by Simon » Mon Sep 01, 2014 5:26 pm

but this is a Livecode script, so that doesn't matter :D
Have I lost the plot again? :(
Isn't the problem on iPad? I'm guessing it works on desktop.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Database file not showing on the device

Post by Klaus » Mon Sep 01, 2014 5:57 pm

This also works on mobile, Simon, no matter HOW you spell "documenTs" :D

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Database file not showing on the device

Post by Simon » Mon Sep 01, 2014 6:28 pm

I am so not keeping up with the times :oops:

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

strongbow
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 146
Joined: Mon Jul 31, 2006 1:39 am
Contact:

Re: Database file not showing on the device

Post by strongbow » Tue Sep 02, 2014 7:57 am

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?

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Database file not showing on the device

Post by Klaus » Tue Sep 02, 2014 5:26 pm

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

...
## 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! :D

Post Reply