A_MYSQL Issue
#1

pawn Код:
new string2[500];
        format(string2, sizeof(string2),"UPDATE `ownedcars` SET Model = '%d', Location_X = '%f', Location_Y = '%f'
        , Location_Z = '%f', Angle = '%f', Color_1 = '%d', Color_2 = '%d', Owner = '%s', PlateSet = '%d', Plate = '%s'
        , Owned = '%d', Locked = '%d', Paintjob = '%d', Virtualworld = '%d', Component0 = '%d', Component1 = '%d'
        , Component2 = '%d', Component3 = '%d', Component4 = '%d', Component5 = '%d', Component6 = '%d', Component7 = '%d'
        , Component8 = '%d', Component9 = '%d', Component10 = '%d', Component11 = '%d', Component12 = '%d', Component13 = '%d'
        , SecurityCode = '%d'"
, CarInfo[idx][cModel], CarInfo[idx][cLocationx], CarInfo[idx][cLocationy], CarInfo[idx][cLocationz],
        CarInfo[idx][cAngle], CarInfo[idx][cColorOne], CarInfo[idx][cColorTwo], CarInfo[idx][cOwner], CarInfo[idx][cPlateSet],
        CarInfo[idx][cPlate], CarInfo[idx][cOwned], CarInfo[idx][cLock], CarInfo[idx][cPaintjob], CarInfo[idx][cVirWorld],
        CarInfo[idx][cComponent0], CarInfo[idx][cComponent1], CarInfo[idx][cComponent2], CarInfo[idx][cComponent3], CarInfo[idx][cComponent4],
        CarInfo[idx][cComponent5], CarInfo[idx][cComponent6], CarInfo[idx][cComponent7], CarInfo[idx][cComponent8], CarInfo[idx][cComponent9],
        CarInfo[idx][cComponent10], CarInfo[idx][cComponent11], CarInfo[idx][cComponent12], CarInfo[idx][cComponent13], CarInfo[idx][cCode]);
        mysql_query(string2);
Okay so after reading about saving SQL querys to a database, what did I do wrong there, looks fine to me?

pawn Код:
error 037: invalid string (possibly non-terminated string)
error 017: undefined symbol "UPDATE"
Reply
#2

Quote:
Originally Posted by UnknownGamer
Посмотреть сообщение
pawn Код:
new string2[500];
        format(string2, sizeof(string2),"UPDATE `ownedcars` SET Model = '%d', Location_X = '%f', Location_Y = '%f'
        , Location_Z = '%f', Angle = '%f', Color_1 = '%d', Color_2 = '%d', Owner = '%s', PlateSet = '%d', Plate = '%s'
        , Owned = '%d', Locked = '%d', Paintjob = '%d', Virtualworld = '%d', Component0 = '%d', Component1 = '%d'
        , Component2 = '%d', Component3 = '%d', Component4 = '%d', Component5 = '%d', Component6 = '%d', Component7 = '%d'
        , Component8 = '%d', Component9 = '%d', Component10 = '%d', Component11 = '%d', Component12 = '%d', Component13 = '%d'
        , SecurityCode = '%d'"
, CarInfo[idx][cModel], CarInfo[idx][cLocationx], CarInfo[idx][cLocationy], CarInfo[idx][cLocationz],
        CarInfo[idx][cAngle], CarInfo[idx][cColorOne], CarInfo[idx][cColorTwo], CarInfo[idx][cOwner], CarInfo[idx][cPlateSet],
        CarInfo[idx][cPlate], CarInfo[idx][cOwned], CarInfo[idx][cLock], CarInfo[idx][cPaintjob], CarInfo[idx][cVirWorld],
        CarInfo[idx][cComponent0], CarInfo[idx][cComponent1], CarInfo[idx][cComponent2], CarInfo[idx][cComponent3], CarInfo[idx][cComponent4],
        CarInfo[idx][cComponent5], CarInfo[idx][cComponent6], CarInfo[idx][cComponent7], CarInfo[idx][cComponent8], CarInfo[idx][cComponent9],
        CarInfo[idx][cComponent10], CarInfo[idx][cComponent11], CarInfo[idx][cComponent12], CarInfo[idx][cComponent13], CarInfo[idx][cCode]);
        mysql_query(string2);
Okay so after reading about saving SQL querys to a database, what did I do wrong there, looks fine to me?

pawn Код:
error 037: invalid string (possibly non-terminated string)
error 017: undefined symbol "UPDATE"
You break the string value in format (New line in a string).

You can fix it by adding a backslash '\' after your line.
So your code will be:
pawn Код:
new string2[500];
        format(string2, sizeof(string2),"UPDATE `ownedcars` SET Model = '%d', Location_X = '%f', Location_Y = '%f' \
        , Location_Z = '%f', Angle = '%f', Color_1 = '%d', Color_2 = '%d', Owner = '%s', PlateSet = '%d', Plate = '%s' \
        , Owned = '%d', Locked = '%d', Paintjob = '%d', Virtualworld = '%d', Component0 = '%d', Component1 = '%d' \
        , Component2 = '%d', Component3 = '%d', Component4 = '%d', Component5 = '%d', Component6 = '%d', Component7 = '%d' \
        , Component8 = '%d', Component9 = '%d', Component10 = '%d', Component11 = '%d', Component12 = '%d', Component13 = '%d' \
        , SecurityCode = '%d'"
, CarInfo[idx][cModel], CarInfo[idx][cLocationx], CarInfo[idx][cLocationy], CarInfo[idx][cLocationz],
        CarInfo[idx][cAngle], CarInfo[idx][cColorOne], CarInfo[idx][cColorTwo], CarInfo[idx][cOwner], CarInfo[idx][cPlateSet],
        CarInfo[idx][cPlate], CarInfo[idx][cOwned], CarInfo[idx][cLock], CarInfo[idx][cPaintjob], CarInfo[idx][cVirWorld],
        CarInfo[idx][cComponent0], CarInfo[idx][cComponent1], CarInfo[idx][cComponent2], CarInfo[idx][cComponent3], CarInfo[idx][cComponent4],
        CarInfo[idx][cComponent5], CarInfo[idx][cComponent6], CarInfo[idx][cComponent7], CarInfo[idx][cComponent8], CarInfo[idx][cComponent9],
        CarInfo[idx][cComponent10], CarInfo[idx][cComponent11], CarInfo[idx][cComponent12], CarInfo[idx][cComponent13], CarInfo[idx][cCode]);
        mysql_query(string2);
Reply
#3

Quote:
Originally Posted by BlackBank3
Посмотреть сообщение
You break the string value in format (New line in a string).

You can fix it by adding a backslash '\' after your line.
So your code will be:
pawn Код:
new string2[500];
        format(string2, sizeof(string2),"UPDATE `ownedcars` SET Model = '%d', Location_X = '%f', Location_Y = '%f' \
        , Location_Z = '%f', Angle = '%f', Color_1 = '%d', Color_2 = '%d', Owner = '%s', PlateSet = '%d', Plate = '%s' \
        , Owned = '%d', Locked = '%d', Paintjob = '%d', Virtualworld = '%d', Component0 = '%d', Component1 = '%d' \
        , Component2 = '%d', Component3 = '%d', Component4 = '%d', Component5 = '%d', Component6 = '%d', Component7 = '%d' \
        , Component8 = '%d', Component9 = '%d', Component10 = '%d', Component11 = '%d', Component12 = '%d', Component13 = '%d' \
        , SecurityCode = '%d'"
, CarInfo[idx][cModel], CarInfo[idx][cLocationx], CarInfo[idx][cLocationy], CarInfo[idx][cLocationz],
        CarInfo[idx][cAngle], CarInfo[idx][cColorOne], CarInfo[idx][cColorTwo], CarInfo[idx][cOwner], CarInfo[idx][cPlateSet],
        CarInfo[idx][cPlate], CarInfo[idx][cOwned], CarInfo[idx][cLock], CarInfo[idx][cPaintjob], CarInfo[idx][cVirWorld],
        CarInfo[idx][cComponent0], CarInfo[idx][cComponent1], CarInfo[idx][cComponent2], CarInfo[idx][cComponent3], CarInfo[idx][cComponent4],
        CarInfo[idx][cComponent5], CarInfo[idx][cComponent6], CarInfo[idx][cComponent7], CarInfo[idx][cComponent8], CarInfo[idx][cComponent9],
        CarInfo[idx][cComponent10], CarInfo[idx][cComponent11], CarInfo[idx][cComponent12], CarInfo[idx][cComponent13], CarInfo[idx][cCode]);
        mysql_query(string2);
Still getting the same error
Reply
#4

Either try the first line, before the format on one line, then the format on the bottom, or strcat.
Reply
#5

Quote:
Originally Posted by Isolated
Посмотреть сообщение
Either try the first line, before the format on one line, then the format on the bottom, or strcat.
Okay so I got them to save now and everything else. Just the loading seems to be failing, and I truely have no idea whats wrong, Still a noob, and getting used to SQL, I'd really love any help

pawn Код:
public LoadCar()
{
    new row[4000], carid;
    for(new idx = 1; idx < sizeof(CarInfo) ; idx++)
    {
        mysql_query("SELECT * FROM ownedcars");
        mysql_store_result();
        while(mysql_retrieve_row())
        {
            mysql_fetch_row(row);
            carid ++;
            sscanf(row, "p<|>e<ddffffiis[60]ddds[60]dddddddddddddddd>", CarInfo[carid]);
        }
        mysql_free_result();
    }
    printf("[MYSQL-DATABASE]: Loaded %d Owned Vehicles.", carid);
    return 1;
}
It says there's 0 loaded cars, there's 2 rows of cars in the database.

Any idea why that doesn't load them with the sscanf?
Reply
#6

pawn Код:
row[4000] ?! 500 should be ok or maybe less

public LoadCar()
{
    new row[500], carid = 1;
    mysql_query("SELECT * FROM ownedcars");
    mysql_store_result();
    while(mysql_next_row() && carid < sizeof(CarInfo))
    {
        mysql_fetch_row(row);
        sscanf(row, "p<|>e<ddffffiis[60]ddds[60]dddddddddddddddd>", CarInfo[carid]);
        carid++;
    }
    mysql_free_result();
    return printf("[MYSQL-DATABASE]: Loaded %d Owned Vehicles.", carid);
}
Reply
#7

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
row[4000] ?! 500 should be ok or maybe less

public LoadCar()
{
    new row[500], carid = 1;
    mysql_query("SELECT * FROM ownedcars");
    mysql_store_result();
    while(mysql_next_row() && carid < sizeof(CarInfo))
    {
        mysql_fetch_row(row);
        sscanf(row, "p<|>e<ddffffiis[60]ddds[60]dddddddddddddddd>", CarInfo[carid]);
        carid++;
    }
    mysql_free_result();
    return printf("[MYSQL-DATABASE]: Loaded %d Owned Vehicles.", carid);
}
It said I loaded 1 car, theres 2 in the DB

Just tested, cars didn't create. LoadCar(); - Is called on OnGameModeInit.
Reply
#8

Show new CarInfo[What here ?][some enum];
Reply
#9

Quote:
Originally Posted by Jefff
Посмотреть сообщение
Show new CarInfo[What here ?][some enum];
pawn Код:
enum cInfo
{
    cModel,
    Float:cLocationx,
    Float:cLocationy,
    Float:cLocationz,
    Float:cAngle,
    cColorOne,
    cColorTwo,
    cOwner[MAX_PLAYER_NAME],
    cPlate[24],
    cPlateSet,
    cOwned,
    cLock,
    cPaintjob,
    cVirWorld,
    cComponent0,
    cComponent1,
    cComponent2,
    cComponent3,
    cComponent4,
    cComponent5,
    cComponent6,
    cComponent7,
    cComponent8,
    cComponent9,
    cComponent10,
    cComponent11,
    cComponent12,
    cComponent13,
    cCode
};
new CarInfo[600][cInfo];
Reply
#10

Try now and show log

pawn Код:
public LoadCar()
{
    new row[500], carid = 1;
    mysql_query("SELECT * FROM ownedcars");
    mysql_store_result();
    print("1");
    while(mysql_next_row() && carid < sizeof(CarInfo))
    {
        printf("carid: %d",carid);
        mysql_fetch_row(row);
        sscanf(row, "p<|>e<iffffiis[" #MAX_PLAYER_NAME "]s[" #MAX_PLAYER_NAME "]iiiiiiiiiiiiiiiiiiii>", CarInfo[carid]);
        carid++;
    }
    print("2");
    mysql_free_result();
    return printf("[MYSQL-DATABASE]: Loaded %d Owned Vehicles.", carid);
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)