SA-MP Forums Archive
Big format mysql - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Big format mysql (/showthread.php?tid=295621)



Big format mysql - Ricop522 - 06.11.2011

What I do with this big format ?
pawn Код:
new
        Placa = random(255255), carroID;
   
mysql_query("INSERT INTO veiculos (id, dono, modelo, x, y, z, a, cor1, cor2, mod1, mod2, mod3, mod4, mod5, mod6, mod7, mod8, mod9, mod10, mod11, mod12, trancado, placa, alarme, imobiliser, insurances, factionid, faction, spawnado) VALUES (NULL, '%s', %d, %f, %f, %f, %f, %d, %d, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, %d, %d, %d, %d, %d, %d, %d, %d)", pName(playerid),modeloid, concessionariaSpawn_X, concessionariaSpawn_Y, concessionariaSpawn_Z, concessionariaSpawn_A, COR_PADRAO, COR_PADRAO, 1, Placa, 1, 1, START_INSURANCE, FACTION_CIVIL, 0, 0);
And How I get the ID will be generate?
pawn Код:
mysql_query("SELECT id FROM veiculos WHERE dono = '%s'", pName(playerid));
    mysql_fetch_field_row(carroID, "id");
Is this to get the ID /\ ?

Thanks for reply!

+rep for help


Re: Big format mysql - Ricop522 - 07.11.2011

bump


Re: Big format mysql - Norn - 07.11.2011

pawn Код:
new newly_created_id = mysql_insert_id();
after the query has been executed and before the connection is closed.


Re: Big format mysql - Ricop522 - 07.11.2011

Thanks with the ID problem. +Rep

The big query problem continues..

Thanks .


Re: Big format mysql - Norn - 07.11.2011

Quote:
Originally Posted by Ricop522
Посмотреть сообщение
Thanks with the ID problem. +Rep

The big query problem continues..

Thanks .
Format it into a string first you can't pass variables like that from the function itself afaik.


Re: Big format mysql - Ricop522 - 07.11.2011

Like this ?
pawn Код:
format(ricopStr, sizeof(ricopStr), "INSERT INTO veiculos (id, dono, modelo, x, y, z, a, cor1, cor2, mod1, mod2, mod3, mod4, mod5, mod6, mod7, mod8, mod9, mod10, mod11, mod12, trancado, placa, alarme, imobiliser, insurances, factionid, faction, spawnado) VALUES (NULL, '%s', %d, %f, %f, %f, %f, %d, %d, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, %d, %d, %d, %d, %d, %d, %d, %d)", pName(playerid),modeloid, concessionariaSpawn_X, concessionariaSpawn_Y, concessionariaSpawn_Z, concessionariaSpawn_A, COR_PADRAO, COR_PADRAO, 1, Placa, 1, 1, START_INSURANCE, FACTION_CIVIL, 0, 0);
    mysql_query(ricopStr);



Re: Big format mysql - Norn - 07.11.2011

Quote:
Originally Posted by Ricop522
Посмотреть сообщение
Like this ?
pawn Код:
format(ricopStr, sizeof(ricopStr), "INSERT INTO veiculos (id, dono, modelo, x, y, z, a, cor1, cor2, mod1, mod2, mod3, mod4, mod5, mod6, mod7, mod8, mod9, mod10, mod11, mod12, trancado, placa, alarme, imobiliser, insurances, factionid, faction, spawnado) VALUES (NULL, '%s', %d, %f, %f, %f, %f, %d, %d, NULL, NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL, %d, %d, %d, %d, %d, %d, %d, %d)", pName(playerid),modeloid, concessionariaSpawn_X, concessionariaSpawn_Y, concessionariaSpawn_Z, concessionariaSpawn_A, COR_PADRAO, COR_PADRAO, 1, Placa, 1, 1, START_INSURANCE, FACTION_CIVIL, 0, 0);
    mysql_query(ricopStr);
Yes, you might get "input line too long" from the compiler, if so just put the variables on a new line.


Re: Big format mysql - dowster - 07.11.2011

and for the null values, dont include the column or the null in it at all, mysql doesn't need all the values at one time if you make sure the default setting for that column is null


Re: Big format mysql - Ricop522 - 07.11.2011

Is this correctly?

pawn Код:
new
        Placa = random(255255), carroID, ricopStr[218], ricopStr2[144], ricopStr3[362];
    format(ricopStr, sizeof(ricopStr), "INSERT INTO veiculos (id, dono, modelo, x, y, z, a, cor1, cor2, mod1, mod2, mod3, mod4, mod5, mod6, mod7, mod8, mod9, mod10, mod11, mod12, trancado, placa, alarme, imobiliser, insurances, factionid, faction, spawnado) ");
    format(ricopStr2, sizeof(ricopStr2), "VALUES (NULL, '%s', %d, %f, %f, %f, %f, %d, %d, 0, 0,0,0,0,0,0,0,0,0,0,0, %d, %d, %d, %d, %d, %d, %d, %d)", pName(playerid),modeloid, concessionariaSpawn_X, concessionariaSpawn_Y, concessionariaSpawn_Z, concessionariaSpawn_A, COR_PADRAO, COR_PADRAO, 1, Placa, 1, 1, START_INSURANCE, FACTION_CIVIL, 0, 0);
    format(ricopStr3, 362, "%s%s", ricopStr, ricopStr2);
    mysql_query(ricopStr3);



Re: Big format mysql - dowster - 07.11.2011

I should have added, when you remove the null values, be sure to remove the coresponding column value.

Example, you had a null value for the id column, so remove the id column also, MySQL will just assume that as null if you don't send a value