databases on iPhone

Getting into LiveCode for iOS? Ask your questions here.

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

databases on iPhone

Post by sylvanr » Sun Dec 05, 2010 5:37 am

I posted this question in the database forum but then realized maybe it should be in the iOS forum?? I just came to realization that standalone applications created with LiveCode are read-only and I found the topic about this at http://forums.runrev.com/phpBB2/viewtop ... =32&t=1124 and this was helpful and I followed the link to http://livecodejournal.com/tutorials/sa ... ution.html and followed instructions for creating a substack and was able to save the database again that way and so now I open the mainstack and then have a button that opens the substack which is not saved in the application so that the end user can modify and add to data in the database. So my final, final question is about how this will work in the iphone OS?? When the master stack opens, and you click on the button to go to the substack, will the substack replace the mainstack on the screen?? How does the iOS handle a mainstack with substack saved outside the application??

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

Re: databases on iPhone

Post by Mark » Sun Dec 05, 2010 1:30 pm

Hi sylvanr,

It might be possible to set a custom property without showing the stack window on screen. Try something like this:

Code: Select all

set the cDataHolder of stack "/path/to/you/stack.rev" to myData
save stack "/path/to/you/stack.rev"
Let me know if this works.

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

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: databases on iPhone

Post by sylvanr » Mon Dec 06, 2010 12:13 pm

I went ahead and purchased LiveCode with the iPhone option to get a better idea of how stacks would actually behave in the simulator. This was my first day with the actual product. When I select "Save as Standalone Application," I get the message:

"There was an error while saving the standalone application device build requires a provisioning profile to be chosen."

Hm. Not sure what I'm supposed to do with that? I just click "OK" and then when I click on "Simulate," the simulator comes up with my stack anyway.

I'm still having problems with saving data in stand alone applications in the trial version I had before purchasing, and now in the iOS simulator. That is the most frustrating aspect of LiveCode for me coming from using Hypercard where saving data to a stack was so easy.

I read Sarah Reichelt's 2005 article "Saving Data in LiveCode standalone" and tried the sub-stack method but couldn't get one stack to open the other stack in the simulator. I get the feeling that the sub-stack method will only work in a desktop environment? n her article, Sarah also discusses a function for a "Saving preferences files" but only addresses the MacOS and Win32.

In this same vein, I followed the article by Mark Major, "Collecting User Preferences: Part 1" at http://runrev.com/newsletter/october/is ... etter3.php and downloaded the stack but the article only addressed MacOs, Win32, >Win2000, and Linux but nothing specific to iOS. I used the code for the MacOs, hoping that would work but didn't do anything in the iOS to save data.

Both these articles seem to address the kind of problem I am having but neither address the iOS.

When I first came across LiveCode, I saw some databases that I think used SQL light? I wonder if those can work in the iOS.

Obviously, from the two articles I mention and other postings I have read, saving data is an important feature for a lot of people but I'm just not sure where to turn to find the method for doing this in the LiveCode iOS.

I do appreciate Mark responding to my problem, saying it might be possible to set a custom property without showing the stack window on screen. I wasn't sure what to do with the code, though? I saved it as a stack script but that didn't seem to work. I also appreciate Klaus responding as well. This was similar to the substack methods that Sarah Reichelt's had talked about in her article. It works fine until I get to the simulator when the first stack will no longer open the second stack.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3317
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: databases on iPhone

Post by bn » Mon Dec 06, 2010 12:56 pm

Hi Sylvanr,
"There was an error while saving the standalone application device build requires a provisioning profile to be chosen."
Hm. Not sure what I'm supposed to do with that? I just click "OK" and then when I click on "Simulate," the simulator comes up with my stack anyway.
You have to register with apple as an iOS developer to get the certificates etc. (welcome to the wonderful world of filling out forms and stuff, but I eventually managed to get there, be shure to follow Apple's directions by the letter, I goofed up on the EXACT address for my credit card, that threw me out of the process.)
The stacks run in the Simulator, no need to save as app, it is only if you want to run the app on the actual device that you need the provisioning profiles and you have to save as a standalone (iOS app). Without the right profile Xcode will not let you install the app on the device. Dont be fooled by the Simulator, it is ok for some things but others you have to do on an actual device. Scrolling for example.
look at this lesson:
http://lessons.runrev.com/spaces/lesson ... -developer
these are iPhone lessons:
http://lessons.runrev.com/spaces/lesson ... 004?page=1

for storing data on the iPhone:
http://lessons.runrev.com/spaces/lesson ... he-iPhone-

regards

Bernd

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

Re: databases on iPhone

Post by Klaus » Mon Dec 06, 2010 1:15 pm

Hi sylvanr,

my name is Klaus and not Mark :)

I wrote the newletter articles, there is a follow-up in the next newsletter, before I received my personal copy of
the iOS plug in, so I did not take this into account.

But there is a paragraph on "File and folder handling" in the PDF that comes with the iOS plug in, which shows exactly
which "specialfolderpath()" you can use in iDevices, and that paragraph is not hidden, but easy to find!

So although my articles do not cover the iDevices per se, everything in the articles applies to these, too, just replace
the appropriate "specialfolderpath()". Now you should know where to look for them 8)


Best

Klaus

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: databases on iPhone

Post by sylvanr » Tue Dec 07, 2010 4:46 am

Thanks for replies. Each time I have gotten stuck so far, someone has been able to keep me moving forward and I do appreciate that. I think that I was so excited to get the program bought and downloaded yesterday with the simulator that I totally missed the pdf that came with the download about file and folder handling that Klaus pointed out.

Today, I also followed the link Bernd sent for storing files at http://lessons.runrev.com/spaces/lesson ... he-iPhone- and was able to integrate the write and read buttons into my database for saving the data in the iOS simulator from two fields with a "write" button and then being able to recover that stored information with a "read" button the next time I opened the database in the simulator. So I do see that it is possible to save some data from two fields on ONE CARD. This presents some new questions:
1. The same two fields appear on each record of a multi-record database. When I change records and use the write and read buttons, they write over the previous records data. I would not want to write write and read buttons for every card with a different path??
2. I also have a button that the end user clicks on to "add card." Is there a way to save the new card when the database is closed and have it still be in the database when the database is reopened? All of that was a given in Hypercard but a mystery in LiveCode. When you added a card to a Hypercard stack, it was added and when you added data to fields, the card and data were all just still there after you closed and reopened the stack. Is anything comparable to that possible in LiveCode? I want the user to be able to add records and delete records and click on buttons on individual records/cards and have the state of those buttons all saved when the user closes the stack/database and have it all be there again on multiple cards/records when they reopen the stack/database.
3. The write and read buttons DO work in the simulator for two fields on ONE card/record of database, but ultimately, I would want the data/records saved without the end user having to click a button to do so- i.e. just saved on closing the database- And the loaded automatically when the user opens the database- so I'm wondering if preopenstack will work for that?
4. Is what I want to do possible in LiveCode without using an sql database with it??? IF I have to go through the learning curve of adding sql, will there be a way to save both the stack and sql database on the iPhone and test in the simulator??

I am very grateful to find out that I can actually save data from fields on one card but what about multiple cards/records. Thank you, thank you, thank you all that have been responsive and have gotten me this far! I do feel like I am making incremental progress toward my goals with your help!

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

Re: databases on iPhone

Post by Klaus » Wed Dec 08, 2010 7:52 pm

Hi sylvane,

here the promised solution for your HyperCard like database without any SQL :)

1. Make your "database" stack a separate (main) stack and give it a stack script like this:

Code: Select all

on closestack
  save this stack
end closestack
2. Save it to your harddisk
3. Create another simple stack that will be your standalone. This can just be a little stack that shows you logo or whatever.
4. Now the stunning trick :D
Import your "database" stack into a custom property of the standalone stack!
...
ask file "where is the database stack"
set the cDatabaseStack of stack "the little standalone stack" to url("binfile:" & it)
...
5. Now the stack (the binary file!) is part of your new standalone stack
6. In the standalone stack check at first (openstack) if the "database" stack has already been saved to the iDevice

Code: Select all

...
if there is NOT a file (specialfolderpath("Whereever you save your data") & "/mydatabase.db") then
## replace of course with a REAL specialfolderpath and a name for the database stack as you like.
## You can omit the suffix or use a fancy one, does not matter!
  put the cDatabaseStack of this stack into url(specialfolderpath("Whereever you save your data") & "/mydatabase.db"))
end if

## Now open that stack that CAN be saved :-)
go stack specialfolderpath("Whereever you save your data") & "/mydatabase.db")
close stack "the little standalone stack"
## or just hide it or whatever
...
7. Create your standalone
8. Done! You now have a HyperCard like stack-based database that can be saved!

OK, try to digest this and ask questions lateron :)


Best

Klaus

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: databases on iPhone

Post by sylvanr » Wed Dec 08, 2010 9:24 pm

Thanks. I am digesting. I will ask questions later.

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

Re: databases on iPhone

Post by Klaus » Wed Dec 08, 2010 10:19 pm

Hi sylvanr,

correction, I totally forgot that you can not have two stacks open at the same time on iDevices so you should do this:
...
# Now open that stack that CAN be saved :-)
go stack specialfolderpath("Whereever you save your data") & "/mydatabase.db") in window of this stack
## THis requires that both stack have identical dimension (height/width)!
...

Best

Klaus

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: databases on iPhone

Post by sylvanr » Sat Dec 11, 2010 10:23 am

Well Klaus, I tried following your instructions but still not getting very far. Maybe I'm just an idiot or something but it still seems obscure to me.

I created one 320 x 460 mainstack which I named "standalone."

I created another 320 x 460 mainstack which I named "database."

I got lost with trying to "import" my "database" stack into my "standalone" stack. I wasn't sure how I was supposed to do that? You said "ask file "where is the database stack" and soI put that in the message box and got a save as dialog and tried saving as url("binfile:" & it) but that didn't seem to get me anywhere? It does seem that I did something a couple of nights ago and did wind up getting something in the Custom Properties box in the Stack Inspector but then I couldn't duplicate it again in another try and so not sure what I am doing wrong there and can't remember what I did the other day in my trial and errors that seemed to work a couple nights ago.

I gave the stack "standalone" the following stack script:

on openstack
if there is not a file (specialFolderPath("Documents") & "database")
then
put stack "database" of this stack into url (specialFolderPath("Documents"))
end if
end openstack

I also put a button on the first and only card of the "standalone" stack and gave it the following script which I hoped would open the "database" stack:

on mouseUp
set the defaultFolder to specialFolderPath("Documents")
go stack specialFolderPath ("Documents") & "standalone" in window of this stack
end mouseUp

I gave the stack "database" the following stack script:

on closestack
  save this stack
end closestack

When I put it all in the simulator, the "standalone" screen pops up with my button but when I click on the button to go to my "database" stack, nothing happens. (I just want to interject here that when I had previously been saving "database" as a substack of "standalone," and had the openstack "database," it had switched to the other stack but then none of the data wa ever saved when I exited out of "database.")

As you can see, I don't really have a clue as to what I am doing. I have tried multiple ways over the last week or so, since I purchased the program, (and even before then when I was playing with the trial version) to get the database stack to save added records and data and still not having any luck with it. I just don't remember Hypercard being this complicated? I don't really consider myself a programmer at all but was able to do quite a bit with Hypercard and I have also used 4th Dimension extensively over the years and never had such problems comprehending what I'm trying to do although there was quite a learning curve for me for both Hypercard and 4D. I just don't know what I'm missing here.

I think it would really help if there were sample stacks as you described that I could actually look at and put in the iOS simulator and see that it actually worked? I guess if I can't get the "database" stack into a custom property of the "standalone" stack, nothing else is going to work so I guess that is really my first question. Am I supposed to be entering "where is the database stack" into the message box? I also tried it in a button. When I get the Save As dialog, what am I entering? It all seems confusing at this point. Hopefully, you can clarify some of this for me. Thanks!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3317
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: databases on iPhone

Post by bn » Sat Dec 11, 2010 2:22 pm

Hi sylvanr,

I tried to do what you want to do. I append the stacks below in zipped form.
It all worked, except that the stack database when it is opened in the window of the stack standalone on the iPhone seems to be in read only mode. Although the keybord popped up ready for text entry. Not shure where this comes from.
I just don't remember Hypercard being this complicated?
I dont remember that you could create standalones for 3 different operating systems and iOS. A lot of the complications stem from the fact that you do things that are a lot more complex than what you did in Hypercard.
Apart from that you actually can use Livecode just as you had Hypercard. But Livecode has a lot more possibilities and you would not want to miss them once you get the hang of it.

Back to the problem of saving to a stack on the iOS. I am baffled but post the stacks anyways. For deployment in the iPhone you only need the stack "standalone". It spits out the "database" stack into the Documents folder within your app. And then opens that folder. I left a button in that you can use to set the customproperty cDatabaseStack of the standalone stack. The button will query you to show him a path to a file and then blindly puts that file into the custom property. You would point it to the database file/stack in case you want to change the database stack. This button is of no use in the app, just during development within Livecode. You might want to look up custom property since Hypercard did not have them. They are amazingly powerful.

This is how far I got. Maybe Klaus or someone else has gotten around this apparent 'read only' state of a stack that is opened on an iOS device.

So close but yet so far... We almost would have solved the problem of simply taking a stack on an iOS device as the data repository. (BTW this is called the splash screen approach, the first stack (standalone) is compiled application which can not be saved between runs, the database is just a document that happens to be a stack that can be modified and saved.)
If it would only work....

Kind regards

Bernd
Attachments
database.livecode.zip
the 'database' file
(1.09 KiB) Downloaded 116 times
standalone.livecode.zip
this is the stack to make an app
(2.05 KiB) Downloaded 119 times

sylvanr
Posts: 80
Joined: Wed Nov 24, 2010 10:38 am

Re: databases on iPhone

Post by sylvanr » Sun Dec 12, 2010 8:35 am

Thanks, Bernd, for the reply and trying to resolve the problem. Although I was sorry to see that you couldn't get the database stack to save data in the simulator either, I was glad to see that the problem may not be entirely mine. I have been working on this every which way I could find to work on it for the last couple of weeks or so and still not able to resolve the problem. Hopefully Klaus will be able to shed some light on this.

I didn't realize you could actually upload stacks as an attachment to this forum. That's great, since I was able to download your stacks and look at them even though they would not save data in the iOS simulator either. Maybe Klaus will upload something that works.

I do know that there was a learning curve with Hypercard and 4D and Filemaker. Of course the iPhone didn't even exist then but I remember longing for a mobile device like that and hoping Apples Newton was going to be that device but it wasn't.

In some ways, the splash screen method is similar to Sarah Reichelt's "sub-stack" method at http://livecodejournal.com/tutorials/sa ... ution.html except that the database stack is saved as a Custom Property rather than a sub-stack. I couldn't get that to work either.

So, I guess I am left to wait and see what Klaus can come up with or clarify. Hopefully he will know how to resolve the problem of saving data. Thanks.

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

Re: databases on iPhone

Post by Klaus » Tue Dec 14, 2010 10:02 pm

Hi all,

since I do not own an iPad or iPhone, I cannot tell if a stack saved in the docs folder will open as "read-only". Please bug report this if necessary!
At least my solution works in desktop apps, so I did not actually check this in the simulator.

@sylvanr
Please see Nr. 4 of my initial posting, it shows what to do to "suck" your stack "database"
into a custom property of your mainstack "standalone", but apparently I had an evil error, so it should read:
...
ANSWER file "where is the database stack"
set the cDatabaseStack of stack "standalone" to url("binfile:" & it)
...


Best

Klaus

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3317
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: databases on iPhone

Post by bn » Tue Dec 14, 2010 10:09 pm

Hi Klaus,

if you try the stack "standalone.livcode.zip" above in the simulator it will show the same behavior. You can not write.

regards

Bernd

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

Re: databases on iPhone

Post by Klaus » Tue Dec 14, 2010 10:12 pm

Hi Klaus ähm Bernd :D

I surely believe you, no need for me to check, so could you please bug report this? Thanks!
bugs@runrev.com


Best

Klaus

Post Reply

Return to “iOS Deployment”