SA-MP Forums Archive
Problem with Query - 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: Problem with Query (/showthread.php?tid=607552)



Problem with Query - XStormiest - 21.05.2016

I've got a problem with a query, it won't create new lines, I don't know why...

pawn Код:
stock CreateTruckPoint(delivID, delivType ,delivName[], delivObj[], cashreward = 0, Float:posx = -1.0, Float:posy = -1.0, Float:posz = -1.0)
{
    new query[128];
    format(query, sizeof(query), "INSERT INTO `TruckPoints` (`DeliveryID`, `DeliveryType`, `DeliveryObjective`, `DeliveryName`, `CashReward`, `FinalPositionX`, `FinalPositionY`, `FinalPositionZ`) VALUES('%d', '%s', '%s', '%d', '%f`, '%f', '%f')", delivID, delivType, delivObj, delivName, cashreward, posx, posy, posz);
    db_query(truckpoints, query);
    return 1;
}



Re: Problem with Query - luke49 - 21.05.2016

after public OnGameModeInit()
PHP код:
db mysql_connect(M_HostM_UserM_DataM_Pass); 
replace your code in:
PHP код:
new query[128];
mysql_format(dbquerysizeof(query), "INSERT INTO `TruckPoints` (`DeliveryID`, `DeliveryType`, `DeliveryObjective`, `DeliveryName`, `CashReward`, `FinalPositionX`, `FinalPositionY`, `FinalPositionZ`) VALUES('%d', '%s', '%s', '%d', '%f`, '%f', '%f')"delivIDdelivTypedelivObjdelivNamecashrewardposxposyposz);
mysql_pquery(dbquery""""playerid); 



Re: Problem with Query - XStormiest - 21.05.2016

It's not MySQL though, it's just SQLite


Re: Problem with Query - ScIrUsna - 21.05.2016

I think here is mistake

VALUES('%d', '%s', '%s', '%d', '%f`, '%f', '%f')

You need replace to '


Re: Problem with Query - Sjn - 21.05.2016

Have you checked your database? If it's giving a warning there. If I am not wrong, there should be at least one unique row. Otherwise it won't create another one. I'd say, DeliveryID should be a primary key.

You should enable logging whenever you're working with it, you can figure the errors out yourself.


Re: Problem with Query - Sawalha - 21.05.2016

you have a count mistake, so that the whole query messed up;

you have inserted into 8 fields, meanwhile the values count are 7

Код:
`DeliveryID`, `DeliveryType`, `DeliveryObjective`, `DeliveryName`, `CashReward`, `FinalPositionX`, `FinalPositionY`, `FinalPositionZ`
Код:
VALUES('%d', '%s', '%s', '%d', '%f`, '%f', '%f')
the correct one according to your function parameters' types is:

Код:
VALUES('%d', '%d', '%s', '%s', '%d', '%f`, '%f', '%f')



Re: Problem with Query - XStormiest - 21.05.2016

So it seems like I have forgotten to add a value but still, the line isn't adding, and how can I make an Primary key in SQLite (I know Im quite noob into databases, I used file based till now)

Here is the function
pawn Код:
stock CreateTruckPoint(delivID, delivType ,delivName[], delivObj[], cashreward = 0, Float:posx = -1.0, Float:posy = -1.0, Float:posz = -1.0)
{
    new query[128];
    format(query, sizeof(query), "INSERT INTO `TruckPoints` (`DeliveryID`, `DeliveryType`, `DeliveryObjective`, `DeliveryName`, `CashReward`, `FinalPositionX`, `FinalPositionY`, `FinalPositionZ`) VALUES('%d', '%d', '%s', '%s', '%d', '%f', '%f', '%f')", delivID, delivType, delivObj, delivName, cashreward, posx, posy, posz);
    db_query(truckpoints, query);
    return 1;
}



Re: Problem with Query - luke49 - 21.05.2016

How do you create truckpoints?


Re: Problem with Query - XStormiest - 21.05.2016

Under my "OnFilterScriptInit"

pawn Код:
CreateJobInfoGet();
    CreateJobCars(515);
    LoadTruckPoints();
    //Creating database
    truckpoints = db_open(DATABASE_NAME);
    db_query(truckpoints, "CREATE TABLE IF NOT EXISTS `TruckPoints` (`DeliveryID`,`DeliveryType`, `DeliveryObjective`, `DeliveryName` , `CashReward`, `FinalPositionX`, `FinalPositionY`, `FinalPositionZ`)");
    CreateTruckPoint(0, 1, "Deliver the Coca-Cola", "Coca-Cola Light", 1000, 0.0, 0.0, 0.0);



Re: Problem with Query - Sawalha - 21.05.2016

you didn't identify their data types in that query..