Best way to save an array into SQL, and a question about cellmin
#1

What's the best way to save an array into SQL, like player weapons and ammo.

Also I've asked a question in the 'Little coding questions - For general minor queries 5' but didn't get any help, hope somebody replies here.

Quote:
Originally Posted by xVIP3Rx
Посмотреть сообщение
I've ran into this fix by Slice but I have trouble understanding what is "cellmin" and why is he packing the packed string (cellmin_value) when pack is true.

pawn Код:
// valstr fix by Slice
stock FIX_valstr(dest[], value, bool:pack = false)
{
    // format can't handle cellmin properly
    static const cellmin_value[] = !"-2147483648";
 
    if (value == cellmin)
        pack && strpack(dest, cellmin_value, 12) || strunpack(dest, cellmin_value, 12);
    else
        format(dest, 12, "%d", value), pack && strpack(dest, dest, 12);
}
#define valstr FIX_valstr
Reply
#2

I'd recommend simply placing them an integer value with columns like

pawn Код:
Player_Weapon_Slot_%d
so you can use a loop to load the data by the slotID of the gun, etc.
Reply
#3

That would make ALOT of columns, for example if I have an "Array[30]", it would make a 30 columns, and for every array that would be more than 100 columns just for few arrays.
Reply
#4

Well: I Mean SQL isn't good for arrays, and all that: maybe use an .ini for things like that? If it's for player weapons, maybe something like:

Player_Weapons_%s.ini

%s being the players name. You probably get where I am going; .ini files are better for array, and non-"indexed" or "columned" data storage.
Reply
#5

Quote:
Originally Posted by Abagail
Посмотреть сообщение
I'd recommend simply placing them an integer value with columns like

pawn Код:
Player_Weapon_Slot_%d
so you can use a loop to load the data by the slotID of the gun, etc.
This is the absolute WORST thing you could do.

You might want to read: https://sampforum.blast.hk/showthread.php?tid=505081
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
I've read the other one with connecting two databases together and actually did it, but with more arrays it became huge and hard to manage;

Quote:
Originally Posted by Vince
Посмотреть сообщение
Does not conform to the standards of normalization. Multiple values per column is fundamentally wrong.
Alright, Thanks.
Reply
#7

Does not conform to the standards of normalization. Multiple values per column is fundamentally wrong.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
This is the absolute WORST thing you could do.

You might want to read: https://sampforum.blast.hk/showthread.php?tid=505081
I dont really store arrays, that much, - but can you explain why it is such a bad way of storing array data? I'm assuming it'd slow down the MySQL server / queries, or something alike?
Reply
#9

Because in real world applications you don't use "SELECT *". This is something considered to be only used by database administrators and developers while testing or developing but it should not ever be included in any finished products (we use this in SA-MP because core functionality is extremely limited and there's hardly any string functions). Suppose I need to save an array with a thousand values. Am I going to make a thousand columns? Of course not.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)