Add two KeyValue files together
Hello everyone!
I've been trying to figure out how to merge two files together using a clean and safe way, without destroying/replacing any keys or duplicating sections. For example:
File #1
File #2
Desired File
Any help with this greatly appreciated! :) |
Re: Add two KeyValue files together
The biggest issue you have is being insane enough to store stats in a kv instead of doing it the appropriate way (that is dbs).
My general advice. |
Re: Add two KeyValue files together
Here are the steps I would go about merging those:
And there you will have them merged. |
Re: Add two KeyValue files together
Quote:
Quote:
And besides, although I'm trying to do this with files holding player statistics, I've never mentioned that in this thread (except for the examples). So it's kinda universal and might help others whatever they'll try to accomplish. |
Re: Add two KeyValue files together
Quote:
|
Re: Add two KeyValue files together
Even if you're using a SQLite database, it's still better than KeyValues.
Having said that, if this is for multiple servers (even on the same machine) you'll probably want a MySQL database. Unless the PostgreSQL driver is working these days... haven't looked at it lately. |
Re: Add two KeyValue files together
All right, so I've taken a little different approach than the one Exolent suggested.
I've created an enum with all the keys of the section including the section name itself and made it into two arrays: Code:
Then cached key values from two files I wanted to merge in them: Code:
CacheFileA()
CacheFileB()
And then created the final file using the two arrays:
CreateFileC()
NOTE: For some reason in the final file the root section is treated like a subsection. Meaning that at some point in the file there will something like: FINAL NOTE: Please don't hate on me for having player stats in a KV file, I'll port them to MySQL once I learn how everything works, I swear.. ;~; |
Re: Add two KeyValue files together
That method is much slower and uses more memory as well. I don't see the reason to do it that way.
Also, you should use an if statement when jumping to keys in case it fails, even if you tell it to create the key when it doesn't exist. Code:
That way you don't "Go Back" when it never moved in the first place. |
Re: Add two KeyValue files together
Quote:
Other than that, I do understand that it uses more memory, but I didn't really mind since I was only to use it once. |
Re: Add two KeyValue files together
Is keyvalues really that much less efficient than databases in terms of data storage?
I figure adding something to RAM is faster than performing I/O, especially if you have no intention to store the data to disk (e.g. stats that are recorded during a round, and then are discarded on round finish). |
All times are GMT -4. The time now is 02:01. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.