Saving Data in Standalones

Kay C Lan lan.kc.macmail at gmail.com
Mon Jun 7 01:39:10 EDT 2010


On Mon, Jun 7, 2010 at 5:53 AM, Peter Haworth <pete at mollysrevenge.com>wrote:

>
> I'm not concerned about saving my applications data across runs because I'm
> using an sqlite database for that.  The stuff I need to preserve is more in
> the way of internal settings.  I'd prefer to leave them in custom properties
> if I can because storing them elsewhere will entail a substantial amount of
> work to find all the places in my code where I set and get custom properties
> and replace the logic with something else.
>
> Have you considered using sqlite to do the same? Create a separate table
that contains the internal settings you need to save then on
preOpenCard/preOpenStack  pull this data first, stuff it into your
customProps and then proceed with the normal start-up process of your app.

You could* use setProp handlers to catch every time a custom property is
changed, and issue an UPDATE myPrefTable SET myCustProp = "purple people
eater" to sqlite via an revExecuteSQL command to ensure the db was synced to
the customProps.

It's a pity we can't use wild card characters in setProp calls; imagine how
easy it would be to set up a generic:

setProp (*+), newValue
  --assuming *+ is captured and put into it
  put it into myCustProp
  revExecuteSQL myDBid, "UPDATE myPrefTable SET " & myCustProp  & "= " &
quote & newValue & quote
  pass setProp
end setProp (*+)

Some bright spark here will hopefully point out you can already do that, but
as far as I'm aware you'll have to write a setProp handler for every
customProp you want to save into sqlite.

*Other options are to do a global search for all instances of "set the" and
go through and add the extra revExecuteSQL command inline with your other
statements, or, if you are not worried about keeping the apps state if it
crashes, you could just once save the customProps to your sqlite db on
closeStack.

Just a thought.

HTH



More information about the Use-livecode mailing list