mysql input line too long and other
#1

Код:
           212: mysql_format(mysql, query, sizeof(query), "INSERT INTO `players` (`ID`, `User`, `Pass`, `IP`, `Admin`,\
			213:`SkinID`, `AccountLocked`, `AccountBanned`, `BanningAdmin`, `BannedReason`, `MoneyHand`, `MoneyBank`,\
			214:`Health`, `Armour`, `LastActivity`, `WeaponSlot1`, `WepSlotAmmo1`, `WeaponSlot2`, `WepSlotAmmo2`, `WeaponSlot3`, `WepSlotAmmo3`, `WeaponSlot4`, `WepSlotAmmo4`, `WeaponSlot5`, `WepSlotAmmo5`) VALUES ('', '%e', '%s', '%s', 0, 299, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 250, 5000, 0, 0, 0, 100.0, 0.0, 0, 0)", GetUserName(playerid), Player[playerid][Pass], IP[playerid]);
           215: mysql_tquery(mysql, query, "CreateUser", "i", playerid);
How to fix this?
Reply
#2

you could set default values in the mysql database...
you basicly can set everything to default except of name password and ip, as you are setting hardcoded values into it anyway....
Reply
#3

try:
pawn Код:
new string[500], query[500];
format(string, sizeof(string), "INSERT INTO `players` (`ID`, `User`, `Pass`, `IP`, `Admin`, `MoneyHand`, `MoneyBank`, `Health`, `Armour`, ");
strcat(string, "`LastActivity`, `WeaponSlot1`, `WeaponAmmo1`, `WeaponSlot2`, `WeaponAmmo2`, `WeaponSlot3`, `WeaponAmmo3`, `WeaponSlot4`, `WeaponAmmo4`, `WeaponSlot5`, `WeaponAmmo5`) ");
strcat(string, "VALUES (``, `%e`, `%s`, `%s`, 0, 299, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 250, 5000, 0, 0, 0, 100.0, 0.0,0, 0)");
mysql_format(mysql, query, sizeof(query), string, GetUserName(playerid), Player[playerid][Pass], IP[playerid]);
mysql_tquery(mysql, query, "CreateUser", "i", playerid);
Reply
#4

That gets messy just use strlib by slice.

https://github.com/oscar-broman/strlib

Query example.

pawn Код:
strimplode(" ",
        q,
        sizeof(q),
        "CREATE TABLE IF NOT EXISTS `PlayerClassData`",
        "(PlayerName TEXT,",
        "p_Class INTEGER,",
        "p_LastSwitch INTEGER,",
        "p_ClassLevel TEXT,",
        "p_ClassTime TEXT,",
        "p_ClassCurrLevel TEXT);"
    );
Reply
#5

Just going to copy my reply from 5 minutes ago in another thread;

Quote:
Originally Posted by Vince
Посмотреть сообщение
1) Use default values. This will significantly shorten your query because you don't have to insert zeros.
2) Inventory information should actually be moved to a separate table. If there can be an indefinite amount of something it should be in a separate table. Now you can argue that you only want to store three weapons, but if in the future you decide you want to store more you have to edit your database and your queries, whereas with proper normalization you wouldn't have to change anything.
Time for another tutorial on normalization, I guess.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)