sqlite on android

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
grimaldiface
Posts: 43
Joined: Tue Apr 08, 2008 9:56 pm
Location: Purdue University

sqlite on android

Post by grimaldiface » Wed Jan 07, 2015 5:01 am

Hi all,

recently finished developing my first iphone app, and now I'm adapting it for android. everything works perfectly in the iphone version. The app uses a sqlite db that is copied over in the copy files to specialFolderPath("engine"). When I try to connect to the db on android, I get an error I was unable to connect to the database. "Database Error: Unable to open the database file".

I verified that the file is properly copying by setting the defaultfolder to specialFolderPath("engine") and putting the files. The database is there I just can't connect to it.
I made sure to check "sqlite" in the standalone settings!

Not sure what else to do. Thoughts?

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

Re: sqlite on android

Post by Mark » Wed Jan 07, 2015 9:40 am

Hi,

What is the exact path to the database? Often, having characters like ()-/: and probably a few others cause such problems on Android. Another possibility is that it wants to be able to make changes to the database but lacks write permission. Copying to the documents folder might help in that case.

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

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: sqlite on android

Post by Klaus » Wed Jan 07, 2015 1:38 pm

Hi grimaldiface,

I may repeat myself, but the SEARCH function here in the forum isn't really THAT bad! 8)
Check this: http://forums.livecode.com/viewtopic.ph ... 16#p114411


Best

Klaus

grimaldiface
Posts: 43
Joined: Tue Apr 08, 2008 9:56 pm
Location: Purdue University

Re: sqlite on android

Post by grimaldiface » Wed Jan 07, 2015 5:36 pm

Mark wrote:Hi,

What is the exact path to the database? Often, having characters like ()-/: and probably a few others cause such problems on Android. Another possibility is that it wants to be able to make changes to the database but lacks write permission. Copying to the documents folder might help in that case.

Kind regards,

Mark
Right now I am using the following code to connect to the db. Only trying to connect at this point, not write changes.

The code I use in my working iPhone version is this...

Code: Select all

 if environment() is "mobile" then
      set the defaultfolder to specialFolderPath("engine")
 else
      set the defaultfolder to the desktop folder
end if 
put revOpenDatabase("sqlite", "strategyDB.sqlite") into tDatabaseID
In another thread, setting the default folder was poo poo'd, so I've also tried:

Code: Select all

if environment() is "mobile" then
      put specialfolderpath("engine") & "/strategyDB.sqlite" into tDBFile
      put revopendatabase("sqlite",tDBFile) into tDatabaseID
end if
Still no luck. Not sure why this works on iOS but not android....

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: sqlite on android

Post by Klaus » Wed Jan 07, 2015 5:39 pm

grimaldiface wrote:Not sure why this works on iOS but not android....
It definitively shouldn't work on iOS either!
Why not take a look at the link I provided? 8)

grimaldiface
Posts: 43
Joined: Tue Apr 08, 2008 9:56 pm
Location: Purdue University

Re: sqlite on android

Post by grimaldiface » Wed Jan 07, 2015 8:32 pm

Klaus wrote:
grimaldiface wrote:Not sure why this works on iOS but not android....
It definitively shouldn't work on iOS either!
Why not take a look at the link I provided? 8)

Klaus--

Thanks. I did read the thread you provided prior to posting this one. You're right, the search isn't THAT bad (but it's still pretty bad!).

I guess I'm not seeing the answer to my problem in that thread--care to help me out? What I don't understand is that you mention I need write privileges for the engine folder? I don't understand why, if I'm not writing anything to the folder, just reading. Maybe I there's something about accessing a database that I don't understand.....

Edit: I'll try copying to documents folder later this evening. But I'm still interested to learn why this isn't working...

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: sqlite on android

Post by Klaus » Thu Jan 08, 2015 12:58 pm

Hi Grimadliface,

see it this way:
The ENGINE folder is TABOO, noone is allowed to write here!

I'm not sure about the actual technical background, but I think opening a database prepares
the db file to be read AND written to and this is prohibited in any case!

Therefore you need to copy it to the users DOCUMENTS folder where we have full access!


Best

Klaus

grimaldiface
Posts: 43
Joined: Tue Apr 08, 2008 9:56 pm
Location: Purdue University

Re: sqlite on android

Post by grimaldiface » Thu Jan 08, 2015 9:51 pm

Klaus wrote:Hi Grimadliface,

see it this way:
The ENGINE folder is TABOO, noone is allowed to write here!

I'm not sure about the actual technical background, but I think opening a database prepares
the db file to be read AND written to and this is prohibited in any case!

Therefore you need to copy it to the users DOCUMENTS folder where we have full access!

Best

Klaus
Sure enough, moving the db to the DOCUMENTS folder solved the problem. There's definitely some difference between iOS and Android here, because I was definitely able to access the db from the ENGINE on iOS. Nevertheless, seems the best course is to just avoid working from the ENGINE altogether. Thanks!

seanmiller
Posts: 50
Joined: Mon Mar 03, 2014 1:17 am

Re: sqlite on android

Post by seanmiller » Wed Dec 02, 2015 4:17 am

Howdy,

Belatedly, I can confirm this is indeed a key difference between iOS and Android. I built an app using SQLite. The database resides in the engine on iOS and works fine. But it didn't work on Android. When I moved the SQLite database to documents, it worked immediately. Thanks for solving this problem!

Sean

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm
Location: McKenna, WA

Re: sqlite on android

Post by quailcreek » Wed Dec 02, 2015 5:36 am

Here's how I handle this.

Code: Select all

 if the environment is not "mobile" then exit preOpenStack
   put specialFolderPath("documents") & “/MyDataBase.sqlite" into tDatabaseFile
   
   if there is not a file tDatabaseFile then
      put url("binfile:" & specialFolderPath("engine") & "/MyDataBase.sqlite") into url("binfile:" & specialFolderPath("documents") & "/MyDataBase.sqlite")
   else
      --      answer "There is a file MyDataBase.sqlite"
   end if
Tom
MacBook Pro OS Mojave 10.14

Post Reply

Return to “iOS Deployment”