Problem with Query
#1

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;
}
Reply
#2

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); 
Reply
#3

It's not MySQL though, it's just SQLite
Reply
#4

I think here is mistake

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

You need replace to '
Reply
#5

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.
Reply
#6

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')
Reply
#7

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;
}
Reply
#8

How do you create truckpoints?
Reply
#9

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);
Reply
#10

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


Forum Jump:


Users browsing this thread: 1 Guest(s)