This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
singul4r1ty's profile picture

Interacting with a serialized table in a file

Started by singul4r1ty, 14 April 2013 - 12:32 AM
singul4r1ty #1
Posted 14 April 2013 - 02:32 AM
Hi

I'm making a program for a new server which provides a database storing information about players. I'm just writing the program now, and I'm trying to interact with the stored data, read and change it, and I've encountered a problem.

I'm basically serializing a table and saving it to a file. If I want to modify part of the table, appending or changing, currently I just read the current database to a table, modify that, then re-write the table to the file. However, this database has the potential to be quite big, and if I use that method it could be much more taxing than any other method. What I'm looking for is a way to access and modify elements of the serialized data without opening and rewriting the whole thing each operation.

If there's a better way of storing this data so it can be modified in the way I want, I am happy to look into that, although the server owner wants it to all be done through computercraft, rather than having an SQL database or something running on the server box too.

This is quite an advanced topic, hopefully you understand what I'm asking for!

Many thanks,
singul4r1ty
BlackMenthol #2
Posted 14 April 2013 - 02:58 AM
mh… serialized tables are strings so you need to read them and unserialize them if you want to make some changes easily.

A simply solutioun could be make multiple files instead of only a big one, maybe one file for each players, and then read them and write them one at a time, only when you need it.
LBPHacker #3
Posted 14 April 2013 - 03:11 AM
If there is a maximum length of strings stored in the database, the solution would be quite simple. The only problem is that you can't just move the cursor in a file handle - and that would be the most important part of the whole edit-one-record-but-leave-the-others-as-they-are thingie…
singul4r1ty #4
Posted 14 April 2013 - 09:49 AM
Good idea BlackMenthol, I might try multiple files. Is there a limit on storage space on computers? I can't find any info on it.