SQLite on iOS database issues

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
observ3
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 34
Joined: Mon Oct 11, 2010 11:05 pm

SQLite on iOS database issues

Post by observ3 » Sun Apr 03, 2011 3:26 am

I'm trying to save data to an SQLite database on one card, then on another card retrieve this information and display it in reverse entry order.
Everything is working great on the desktop, but on iOS I get one of two problems:

1) If I attempt to create the database in the specialfolderpath("documents") directory on first run the app cannot find the database.
2) If I attempt to load a database that has been copied into the app at build I get an error for trying to write to a read only database.

If someone could take a look and suggest a solution... I'm sorry my code has so many commented out portions, but I'm pretty new to this and I've been trying different things all evening.
Really frustrating that this works on desktop perfectly then bugs as soon as it hits the simulator or an iphone.

Thanks.
Attachments
database.livecode.zip
The code that is not working right... sorry for the sloppy comments, I've been working on this all evening trying different approaches.
(4.27 KiB) Downloaded 309 times
Check out my LiveCode program, WriteSpire, on the App Store!

Danny
Posts: 106
Joined: Tue Nov 09, 2010 1:28 am

Re: SQLite on iOS database issues

Post by Danny » Sun Apr 03, 2011 4:54 pm

Hey Observ3

I know first hand how frustrating this can be. You might try this code, it isn't SQLite but it does save a stack effectively and it's simple.
Put this in a button on the first stack...

Code: Select all

on mouseUp
 open stack "Level Select"
      
     if the environment is "mobile" then
      put (specialFolderPath("Documents") & "/Level Select.livecode") into tPathToDatabase
      put (specialFolderPath("engine") & "/Level Select.livecode") into tPathToStartLoc
      
      try
         if not (there is a file tPathToDatabase) then
            put url ("binfile:" & tPathToStartLoc) into temp
            put temp into url ("binfile:" & specialfolderpath("Documents") & "/Level Select.livecode")
            wait 5 milliseconds with messages
         end if
      catch pErr
         put pErr into field 1
      end try
      try
         go stack tPathToDatabase
      catch pErr
         put pErr into field 1
      end try
   end if
end mouseUp
Just get rid of the words "Level Select" and use the name of the second stack. You do need two stacks for this, the first one that pops up won't be saved but it will save the next stack that opens.

Put this into the stack script of the other stack...

Code: Select all

on shutDown
save this stack
end shutDown
I hope this helps. Let me know if you get confused.

Danny

observ3
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 34
Joined: Mon Oct 11, 2010 11:05 pm

Re: SQLite on iOS database issues

Post by observ3 » Mon Apr 04, 2011 3:42 am

Thanks Danny. I don't think that will work for this application, but I will certainly add it to my bag of tricks.
Still hoping someone out there has figured out the black magic of mobile SQL...
Check out my LiveCode program, WriteSpire, on the App Store!

Post Reply