Data Persistence

Richard Gaskin ambassador at fourthworld.com
Fri Jul 27 20:12:07 CEST 2018


John McKenzie wrote:

 > An SQLite database seems like extreme overkill but I will give it
 > a try if it is needed to get the app to work.

SQLite is very feature-rich, but if you don't need the relationality 
provided by a full-featured RDBMS it can be like swatting flies with a 
grenade launcher.

Persistence can be provided by any format that can be written to disk. 
You may be surprised by how many programs use simple flat text files. 
And in LC, arrays are easy and efficient to work with, and can be 
serialized to disk with arrayEncode (resulting in files I affectionately 
call "LSON", a LiveCode-optimized alternative to the 
JavaScript-optimized JSON).

Indeed, many who use an RDBMS write code to return the result of queries 
in the form of an LC array.  If you don't need the relationality, and if 
your data is of a size that fits comfortably in RAM, using an array 
directly is about as simple as it can be.

If your data does not fit comfortably in RAM, you may find that breaking 
it into multiple LSON files can work quite nicely.


 > Does this require me to pre-install any sort of database software?

Selecting the SQLite driver in the Standalone Build should be all that's 
needed.


 >  Brian, I gathered from your post that the only way to work with a
 > text file as data storage on Android is to save every time a field
 > is changed? How would I do this in such a way that it knows to save
 > when "1421" is typed as a time of day as opposed to the app trying
 > to save it after "1" is typed, then again when "2" is typed, etc.
 > Or perhaps there is no way and I have to re-save every time a
 > character it typed.

Finding appropriate auto-save triggers is the third hard thing in 
computing (the first two being cache invalidation and naming things <g>).

Saving on every keystroke may be overkill. Saving on closeField may 
suffice when the contents of each field do not contain much data.  If 
you have a long field in which a user may spend significant time, you 
may consider a periodic timer for saving as a middle path between 
closeField and textChanged.

-- 
  Richard Gaskin
  Fourth World Systems
  Software Design and Development for the Desktop, Mobile, and the Web
  ____________________________________________________________________
  Ambassador at FourthWorld.com                http://www.FourthWorld.com



More information about the use-livecode mailing list