saving stacks to db

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

saving stacks to db

Post by sturgis » Tue Sep 11, 2012 12:06 am

Does anyone know of a way to save a stack in memory to a database without saving to drive first? Or ftp the stack live without saving first? Or even stuffing a stack into a property?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: saving stacks to db

Post by sturgis » Tue Sep 11, 2012 12:25 am

Figured out a method that seems to work well enough.

If anyone is interested heres a description of the method

copy the stack to the clipboard

copy stack "stackname"

At this point simply stuff the clipboarddata wherever you want it saved. A property, or database, or send it to a web server for handling or whatever.

To get it back, retrieve the data, stuff it back into the clipboarddata and "paste"

set the clipboarddata["objects"] to <what ever ccontains the saved data>
paste

Voila', up pops the stack. Interestingly enough, since paste is smart, it checks to see if the stack already exists and if it does, changes it to "copy of stack..." as if you hadn't gone through all the steps. If the stack isn't in memory already, the name remains as it was.

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

Re: saving stacks to db

Post by FourthWorld » Tue Sep 11, 2012 12:45 am

Good work, Sturgis. It would never have occurred to me that the copy command will work on a stack. Very handy....
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

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

Re: saving stacks to db

Post by Klaus » Tue Sep 11, 2012 10:31 am

Cool, didn't know this, thanks for the info!

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: saving stacks to db

Post by sturgis » Tue Sep 11, 2012 1:03 pm

Opens up some interesting possibilities. LIke a versioning system, or what I am trying to work up, a plugin so that a class working on write locked systems (public lab, systems are overwritten every night with a fresh clean image) so that stacks can be saved to a central db tagged by user. Accessible from any station etc.
No builds without a real save of course so something will have to be figured out for that.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: saving stacks to db

Post by sturgis » Tue Sep 18, 2012 5:32 pm

If anyone is interested, this works great for stacks with no substacks.

To copy a stack and all its substacks to an array, loop through the substacks and shove them into the array first, set their mainstack to themselves, when the substacks are done, the mainstack is now a single stack. Save it to the array tagged as main some way. THen loop through the subs again and set their mainstack back to normal.

Seems pretty fast, works well. I have a test stack so far that will backup any named stack and its substacks to an array that is stuffed into a property. Database backup with date stamps next hopefully.

Post Reply