How to save data from standalone?

Andre Garzia soapdog at mac.com
Mon Feb 6 17:20:41 EST 2006


Marielle et al,

sorry for arriving late on the thread. I don't know how it started,  
my connection been a little flacky due to some horrible thunderstorms.

As for saving data, I'd say that first you need to decide if you're  
going the way of databases or the way of file system.

If you're going to use the file system as the storage, I use the  
documents folder on Windows machines and the application support  
folder  on MacOS X (the code for application support folder is "asup"  
use it with special folder path function, prefix it with a tilde so  
that you write into the users one and not the system wide one). If  
you're afraid of multiple instances of the stack writting to the same  
file, then you could use a lock file to tag if the file is available  
for writting or not. For example before writting to a file, you  
create an empty lock file, after writting the file you delete the  
lock file, any stack writting should check for the presence of that  
file before commiting anything to the hard drive. This is a simple  
process and it works, but it has some potential bugs, for example a  
stray lock file left from a process that force quitted, so you should  
make your lock files expire with time. So if a stack finds a lock  
file, it checks the modification date is more than 5 minutes old, you  
could delete it...  If your only fear is that one user could write to  
other users file, then you could prefix the file with the username,  
this way the would write to different files.

As I read on this quick email, it appears that you have some massive  
amount of data to store, I'd use some database engine for that, it's  
easier to query then the file system and you can make better data  
relationships than simply storing files. Some database engines  
support transactions, using them you can avoid the problem of one  
user fiddling with the other users data. You could use an embedable  
database engine such as altSQLite or Valentina.


Cheers
andre



On Feb 6, 2006, at 7:54 PM, Marielle Lange wrote:

> But with multiple users, the data of one user gets overwritten by  
> the data of another one, no? Sarah's trick of storing the data  
> within the package content or some directory presents the same  
> problem if I understand correctly, doesn't it? Overwriting the data  
> of one user with the ones of another will be a real problem. I am  
> not storing preferences, I am storing actual data.
>
> I tried to talk some experienced (non revolution) programmer about  
> the file in the package solution. I was told to keep away from that.
>
> Using pathToUsersDocumentsFolder would therefore be a better  
> approach, but I don't really want to create a file within this  
> folder as the file is in a completely adhoc format that would  
> puzzle anybody who come across it.
>
> Eric's solution is the best one, but I have a long list of data to  
> save. I did consider it. The problem is that it's is not really  
> appropriate to store that amount of data in a preferences file.  
> They are not preferences, they are data.
>
> Has anybody ever tried the     User/Library/Application  
> Support       way? Is there any problem associated with this  
> solution? What's the equivalent on a PC? I am not after a quick fix  
> but after a "clean" way to do this (compliant with developer's  
> recommendations). I can find this info for a mac, but I know little  
> about PCs.
>
> Thanks for your help,
> Marielle




More information about the use-livecode mailing list