SA-MP Forums Archive
MYSQL Duplicating Issue - 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: MYSQL Duplicating Issue (/showthread.php?tid=486255)



MYSQL Duplicating Issue - UnknownGamer - 07.01.2014

Hi Everyone,

I'm having one issue now, with a MYSQL Issue. Can you solve this, or at-least help me understand whats wrong.

pawn Код:
/* @FUTURE */
        mysql_format(dbhandle, query, sizeof query, "INSERT INTO vehicles VALUES (%d, %d, %.2f, %.2f, %.2f, %.2f, %d, %d, %d, '%e', %d, %d, %d, %d, '%e') \
        ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id), model = VALUES(model), "
,
        CarInfo[idx][cdbID], CarInfo[idx][cModel], CarInfo[idx][cLocationx],    CarInfo[idx][cLocationy],
        CarInfo[idx][cLocationz], CarInfo[idx][cAngle], CarInfo[idx][cColorOne], CarInfo[idx][cColorTwo],
        0, CarInfo[idx][cOwner], CarInfo[idx][cLock], CarInfo[idx][cPaintjob], CarInfo[idx][cVirWorld], CarInfo[idx][cCode], CarInfo[idx][cPlate]);
       
        strcat(query, "locX = VALUES(locX), \
        locY = VALUES(locY), locZ = VALUES(locZ), angle = VALUES(angle), \
        color1 = VALUES(color1), color2 = VALUES(color2), ownerId = VALUES(ownerId), \
        owner = VALUES(owner),\
        locked = VALUES(locked), paintjob = VALUES(paintjob), \
        virtualworld = VALUES(virtualworld), code = VALUES(code), plate = VALUES(plate)"
);     
       
        mysql_tquery_inline(dbhandle, query, using CarHandler, "");
/imageshack/img69/6205/x2lq.png That's the issue.


Re: MYSQL Duplicating Issue - sammp - 07.01.2014

What version are you using?


Re: MYSQL Duplicating Issue - UnknownGamer - 07.01.2014

R34


Re: MYSQL Duplicating Issue - ikey07 - 07.01.2014

My suggestion is set default values for each field in the database, and in the script, use INSERT INTO only for values which are different than default.


But your whole query looks abit akward, use this kind of query:



mysql_query("INSERT INTO `table` (`stat1`,`stat2`,`stat3`,`stat4`) VALUES ('%s','%d','%d','%f');",stat1,stat2,stat3,stat4);


Re: MYSQL Duplicating Issue - UnknownGamer - 08.01.2014

Still not fixed, this is a pain now. Cars constantly messing up.

pawn Код:
[22:21:17] [DEBUG] mysql_tquery - scheduling query "INSERT INTO vehicles VALUES (0, 0, 0.00, 0.00, 0.00, 0.00, 0, 0, 0, '', 0, 0, 0, 0, '') ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id), model = VALUES(model), locX = VALUES(locX), locY = VALUES(locY), locZ = VALUES(locZ), angle = VALUES(angle), color1 = VALUES(color1), color2 = VALUES(color2), ownerId = VALUES(ownerId), owner = VALUES(owner),locked = VALUES(locked), paintjob = VALUES(paintjob), virtualworld = VALUES(virtualworld), code = VALUES(code), plate = VALUES(plate)"..
[22:21:17] [DEBUG] mysql_format - connection: 1, len: 548, format: "INSERT INTO vehicles VALUES (%d, %d, %.2f, %.2f, %.2f, %.2f, %d, %d, %d, '%e', %d, %d, %d, %d, '%e') ON DUPLICATE KEY UPDATE    id ..."
[22:21:17] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO vehicles VALUES (0, 0, 0.00, 0.00, 0.00, 0.00, 0, 0,", callback: "FJ37DH3JG_MYSQL_INTERNAL", format: "d"
[22:21:17] [DEBUG] CMySQLQuery::CMySQLQuery() - constructor called
[22:21:17] [DEBUG] CMySQLQuery::Create - inline function detected
[22:21:17] [DEBUG] mysql_tquery - scheduling query "INSERT INTO vehicles VALUES (0, 0, 0.00, 0.00, 0.00, 0.00, 0, 0, 0, '', 0, 0, 0, 0, '') ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id), model = VALUES(model), locX = VALUES(locX), locY = VALUES(locY), locZ = VALUES(locZ), angle = VALUES(angle), color1 = VALUES(color1), color2 = VALUES(color2), ownerId = VALUES(ownerId), owner = VALUES(owner),locked = VALUES(locked), paintjob = VALUES(paintjob), virtualworld = VALUES(virtualworld), code = VALUES(code), plate = VALUES(plate)"..
[22:21:17] [DEBUG] CMySQLQuery::Execute[()] - starting query execution
[22:21:17] [DEBUG] CMySQLQuery::Execute[()] - query was successful
That's from the MYSQL log.

pawn Код:
else if(update == 4)
    {      
        new
            query[548];
           
        inline CarHandler() {
            CarInfo[idx][cdbID] = cache_insert_id(dbhandle);
           
            mysql_tquery(dbhandle, "START TRANSACTION", "", "");
           
            for(new i = 0; i != MAX_CAR_COMPONENTS; ++i) {
                mysql_format(dbhandle, query, sizeof query, "INSERT INTO vehicle_components SET slotId = %d, vehicleId = %d, value = %d ON DUPLICATE KEY UPDATE value = VALUES(value)", i, CarInfo[idx][cdbID], CarInfo[idx][cComponent][i]);
                mysql_tquery(dbhandle, query, "", "");
            }
           
            mysql_tquery(dbhandle, "COMMIT", "", "");
            printf("[SCRIPT] MySQL Vehicle Updated (carid: %d, dbid: %d)", idx, CarInfo[idx][cdbID]);

            if(erase) fixmemset(CarInfo[idx], 0, cInfo);
        }

        /* @FUTURE */
        mysql_format(dbhandle, query, sizeof query, "INSERT INTO vehicles VALUES (%d, %d, %.2f, %.2f, %.2f, %.2f, %d, %d, %d, '%e', %d, %d, %d, %d, '%e') \
        ON DUPLICATE KEY UPDATE id = LAST_INSERT_ID(id), model = VALUES(model), "
,
        CarInfo[idx][cdbID], CarInfo[idx][cModel], CarInfo[idx][cLocationx],    CarInfo[idx][cLocationy],
        CarInfo[idx][cLocationz], CarInfo[idx][cAngle], CarInfo[idx][cColorOne], CarInfo[idx][cColorTwo],
        0, CarInfo[idx][cOwner], CarInfo[idx][cLock], CarInfo[idx][cPaintjob], CarInfo[idx][cVirWorld], CarInfo[idx][cCode], CarInfo[idx][cPlate]);
       
        strcat(query, "locX = VALUES(locX), \
        locY = VALUES(locY), locZ = VALUES(locZ), angle = VALUES(angle), \
        color1 = VALUES(color1), color2 = VALUES(color2), ownerId = VALUES(ownerId), \
        owner = VALUES(owner),\
        locked = VALUES(locked), paintjob = VALUES(paintjob), \
        virtualworld = VALUES(virtualworld), code = VALUES(code), plate = VALUES(plate)"
);     
       
        mysql_tquery_inline(dbhandle, query, using CarHandler, "");
That's the code... What is the issue, I don't see nothing wrong?


Re: MYSQL Duplicating Issue - sammp - 08.01.2014

Well it looks like to me whatever is being stored into the CarInfo enums evidently isn't saving.. Or has this worked in the past? If you're using the R34 version I advise you use the ORM system, it's a ton easier than that.

Try and assign some data to something in CarInfo, then try the query.