pBlueG / SA-MP-MySQL

MySQL plugin for San Andreas Multiplayer
BSD 3-Clause "New" or "Revised" License
196 stars 80 forks source link

OnQueryError is not called #193

Closed Romz24 closed 6 years ago

Romz24 commented 6 years ago

Why is it not called? What am I doing wrong?

version: R39-6

maddinat0r commented 6 years ago

Enable full logging, reproduce the problem and upload the log file here.

Zelyutin commented 6 years ago

@maddinat0r Have the same problem. But only with ORM. I'm trying to set owner of house that doesn't exist, but they are linked with Foreign Key in Database.

new query[] = "UPDATE `houses` SET `h_owner_ID` = '4' WHERE `h_ID` = '1'";
mysql_format(DB, query, sizeof(query), query);
mysql_tquery(DB, query);

So, account with ID 4 doesn't exists.

This one is perfectly caught by OnQueryError and I've got this in mode

public OnQueryError(errorid, const error[], const callback[], const query[], MySQL:handle)
{
    printf("ERROR: %d. %s, callback: %s, query: %s", errorid, error, callback, query);
}

and this in my serverlog:

ERROR: 1452. Cannot add or update a child row: a foreign key constraint fails (my_db.houses, CONSTRAINT houses_ibfk_2 FOREIGN KEY (h_owner_ID) REFERENCES accounts (acc_ID) ON UPDATE CASCADE), callback: , query: UPDATE houses SET h_owner_ID = '4' WHERE h_ID = '1' in my server log.

But when I'm trying to do the same but with ORM, no errors occured.

stock test()
{
        houseData[1][owner_ID] = 4;
        printf("%d",orm_save(houseData[1][ORM],"callback"));
        printf("%d",orm_errno(houseData[1][ORM]));
}
f_public callback()
{
    printf("SAVED");
}

I've got no callback call(that is right, as I understand), but there is "1 1" in my console from printf, so orm_save is successful somehow (I think, maybe it's cause this is not "it's problem" and it doesn't care, but it's a bit strange). OnQueryError isn't being triggered this time at all.

In mysql.log the error is perfectly shown:

[16:30:04] [INFO] orm_save: generated query "UPDATE houses SET h_owner_ID='4' WHERE h_ID='1' LIMIT 1" (C:\main.inc:64 -> C:\main.inc:58) [16:30:04] [DEBUG] CHandle::Execute(this=0x6bf4c0, type=1, query=0x707b70) [16:30:04] [DEBUG] CHandle::Execute - return value: true [16:30:04] [DEBUG] orm_save: return value: '1' (C:\main.inc:64 -> C:\main.inc:58) [16:30:04] [DEBUG] AMX callback executed with error '0' [16:30:04] [INFO] Callback successfully executed. [16:30:04] [DEBUG] CConnection::Execute(query=0x707b70, this=0x2b80020, connection=0x6e1be0) [16:30:04] [DEBUG] CQuery::Execute(this=0x707b70, connection=0x6e1be0) [16:30:04] [ERROR] error #1452 while executing query "UPDATE houses SET h_owner_ID='4' WHERE h_ID='1' LIMIT 1": Cannot add or update a child row: a foreign key constraint fails (my_db.houses, CONSTRAINT houses_ibfk_2 FOREIGN KEY (h_owner_ID) REFERENCES accounts (acc_ID) ON UPDATE CASCADE) (C:\main.inc:64 -> C:\main.inc:58) [16:30:04] [DEBUG] CConnection::GetError(this=0x2b80020, connection=0x6e1be0)

So, how can I detect this error in my Mode while using ORM?

maddinat0r commented 6 years ago

The plugin doesn't call any error callback if an ORM-generated query fails. I can't really recall why I didn't add that, but I can implement either a call to OnQueryError or a custom OnOrmQueryError callback. I'll likely do the latter, as it's more clearer on where the query came from, and I can additionally pass the ORM ID. I'll open up a new issue on that and close this one, as that problem isn't directly related to the original question (and the issue creator hasn't answered in over a month).