21.11.2013, 19:16
(
Последний раз редактировалось Emmet_; 24.11.2013 в 17:44.
)
INI to SQLite converter
Introduction
After having a discussion with [uL]Pottus here, I've decided to release this small but useful library which has the capability to convert INI files to a SQLite row.
How it works
There is only one function:
Let's break that down:
For example, if you've just converted your account system to SQLite and you want to convert a player's existing file upon connecting:
That code will create all of the columns in the database by default (fetches them from the file) and add them into the database. Pretty simple, right?
Notes
I made this at around 2:00 AM last night and just finished it up today. Of course, I was tired last night so if there any bugs, you know what to do!
- This include will take up a significant amount of memory and CPU usage upon converting, so use it at your own risk!
- SQLite places a limit on how many columns you can add in one table creation, so use create_columns with caution!
- There might be bugs; if so, report them!
MySQL version
There is no MySQL version at the moment. However, creating one wouldn't be too hard. I don't have time to create one and test it right now, so you have to modify the code and do it yourself until I have enough time to create a MySQL version.
Download
Pastebin
Solidfiles
Introduction
After having a discussion with [uL]Pottus here, I've decided to release this small but useful library which has the capability to convert INI files to a SQLite row.
How it works
There is only one function:
pawn Код:
Convert(file[], db[], table[], custom_field[] = "", custom_value[] = "", bool:create_columns = false);
- file[] - The name of the file you wish to convert.
- db[] - The database you would like to store the row into.
- table[] - The table you would like to store the row into.
- custom_field[] - Adds a custom field upon conversion (example: "Username").
- custom_value[] - Assigns a value to the custom value (example: playername).
- create_columns - Automatically create the columns in the database.
For example, if you've just converted your account system to SQLite and you want to convert a player's existing file upon connecting:
pawn Код:
public OnPlayerConnect(playerid)
{
new
path[32],
playerName[24];
GetPlayerName(playerid, playerName, sizeof(playerName));
format(szPath, sizeof(szPath), "%s.ini", playerName);
if (fexist(path))
{
Convert(path, "Accounts.db", "Accounts", "Username", playerName, true);
fremove(path);
}
return 1;
}
Notes
I made this at around 2:00 AM last night and just finished it up today. Of course, I was tired last night so if there any bugs, you know what to do!
- This include will take up a significant amount of memory and CPU usage upon converting, so use it at your own risk!
- SQLite places a limit on how many columns you can add in one table creation, so use create_columns with caution!
- There might be bugs; if so, report them!
MySQL version
There is no MySQL version at the moment. However, creating one wouldn't be too hard. I don't have time to create one and test it right now, so you have to modify the code and do it yourself until I have enough time to create a MySQL version.
Download
Pastebin
Solidfiles