Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's a bug? orm_delete #80

Closed
HxTheDash opened this issue Feb 23, 2016 · 6 comments
Closed

It's a bug? orm_delete #80

HxTheDash opened this issue Feb 23, 2016 · 6 comments
Assignees
Labels

Comments

@HxTheDash
Copy link

Hello, I'm having a problem using the orm_delete.
If I have an existing ORM, and I use orm_delete, it works perfectly, but if I create a new ORM then and try to delete with orm_delete, does not affect the database, the log ORM is destroyed, but the values are not out the database.

[00:21:00] [DEBUG] orm_delete - orm_id: 5, clearvars: true
[00:21:00] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[00:21:00] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 44.996 milliseconds
[00:21:00] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
[00:21:08] [DEBUG] orm_create - table: "db_test", connectionHandle: 1
[00:21:08] [DEBUG] COrm::Create - creating new orm object..
[00:21:08] [DEBUG] COrm::Create - orm object created (id: 7)
[00:21:08] [DEBUG] orm_addvar_int - orm_id: 7, var: 04CE29E8, varname: "id"
[00:21:08] [DEBUG] orm_setkey - orm_id: 7, varname: "id"
[00:21:08] [DEBUG] orm_addvar_int - orm_id: 7, var: 04CE29EC, varname: "testid"
[00:21:08] [DEBUG] orm_addvar_int - orm_id: 7, var: 04CE29F0, varname: "testid2"
[00:21:08] [DEBUG] orm_insert - orm_id: 7, callback: "(null)", format: "(null)"
[00:21:08] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[00:21:08] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 38.669 milliseconds
[00:21:08] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving
[00:21:16] [DEBUG] orm_delete - orm_id: 7, clearvars: true
[00:21:16] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[00:21:16] [DEBUG] CMySQLQuery::Execute[] - query was successfully executed within 0.453 milliseconds
[00:21:16] [DEBUG] CMySQLQuery::Execute[] - no callback specified, skipping result saving

@maddinat0r
Copy link
Collaborator

Can you always reproduce that bug? If yes, can you provide some PAWN code to reproduce this?

@HxTheDash
Copy link
Author

Yes, I really need help with this, See an exemple @maddinat0r

Try:
/createhouse /deletehouse
again
/createhouse /deletehouse

#define MAX_HOUSE 5

enum hhouse {
    ORM:h_ORM,
    h_ID,
    h_Price
}
new House[MAX_HOUSE][hhouse];


ORM:CreateORM(h) {
    new ORM:ormid = House[h][h_ORM] = orm_create("houses", dbhandle);

    orm_addvar_int(ormid, House[h][h_ID], "id");
    orm_setkey(ormid, "id");

    orm_addvar_int(ormid, House[h][h_Price], "price");
    return ormid;
}

public OnGameModeInit() {
    mysql_tquery(dbhandle, "SELECT * FROM `houses`", "LoadHouses", "");
}

forward LoadHouses();
public LoadHouses() {

    for(new i = 0; i < cache_num_rows(); i++) {
        new ORM:ormid = CreateORM(i);
        orm_apply_cache(ormid, i);
    }
}

CMD:createhouse(playerid, params[]) {
    #pragma unused params

    new house = 0;

    new ORM:ormid = CreateORM(house);
    House[house][h_Price] = 100;
    orm_insert(ormid);

    printf("house %d created", house);
    return 1;
}

CMD:deletehouse(playerid, params[]) {
    #pragma unused params

    new house = 0;
    House[house][h_Price] = 0;
    orm_delete(House[house][h_ORM]);

    printf("house %d destroyed", house);
    return 1;
}

@maddinat0r maddinat0r self-assigned this Mar 16, 2016
@maddinat0r maddinat0r added the bug label Mar 16, 2016
@maddinat0r
Copy link
Collaborator

Reproduced it, definitely a bug.

@maddinat0r
Copy link
Collaborator

Script I used to reproduce this (for historical purposes):

new Mysql; 
new ORM:Orm;

new IntVar = 123456;
new Float:FloatVar;


public OnGameModeInit()
{
    mysql_log(LOG_ALL);
    Mysql = mysql_connect(mysql_host, mysql_user, mysql_database, mysql_password);
    if (mysql_errno() != 0)
        return printf("no connection");

    SetTimerEx("CreateInsert", 0, false, "d", 1);

    return 1;
}

forward CreateInsert(number);
public CreateInsert(number)
{
    if (number > 10)
        return 1;
    Orm = orm_create("test2", Mysql);

    orm_addvar_int(Orm, IntVar, "number");
    orm_setkey(Orm, "number");

    orm_addvar_float(Orm, FloatVar, "float");

    FloatVar = random(999) + (random(10000) / 10000.0);

    orm_insert(Orm);

    SetTimerEx("Delete", 500, false, "d", number);
    return 1;
}

forward Delete(number);
public Delete(number)
{
    FloatVar = 0.0;
    orm_delete(Orm);
    SetTimerEx("CreateInsert", 500, false, "d", number + 1);
    return 1;
}

public OnGameModeExit()
{
    orm_destroy(Orm);
    mysql_close(Mysql);
    return 1;
}

main() {}

@ghost
Copy link

ghost commented Mar 16, 2016

Hi,

This new code that I implemented works perfectly, but see the log.

LOG:
[15:04:05] [ERROR] COrm::ApplyActiveResult - invalid row specified

Test this new code @maddinat0r

#define MAX_HOUSE 5

enum hhouse {
    ORM:h_ORM,
    h_ID,
    h_Price
}
new House[MAX_HOUSE][hhouse];


ORM:CreateORM(h) {
    new ORM:ormid = House[h][h_ORM] = orm_create("houses", dbhandle);

    orm_addvar_int(ormid, House[h][h_ID], "id");
    orm_setkey(ormid, "id");

    orm_addvar_int(ormid, House[h][h_Price], "price");
    return ormid;
}

forward LoadHouses();
public LoadHouses() {

    for(new i = 0; i < cache_num_rows(); i++) {
        new ORM:ormid = CreateORM(i);
        orm_apply_cache(ormid, i);
    }
}

CMD:createhouse(playerid, params[]) {
    #pragma unused params

    CreateHouse();
    return 1;
}

CMD:deletehouse(playerid, params[]) {

    new houseid = strval(params); // /deletehouse [ houseid ]

    House[houseid][h_Price] = 0;
    orm_delete(House[houseid][h_ORM]);

    printf("house %d destroyed", houseid);
    return 1;
}

CreateHouse() {
    mysql_tquery(dbhandle, "INSERT INTO `houses` (price) VALUES (100)", "q_CreateHouse", "");
}

forward q_CreateHouse();
public q_CreateHouse() {
    new houseid = GetHouseFreeSlot();

    House[houseid][h_ID] = cache_insert_id();
    new ORM:ormid = CreateORM(houseid);

    orm_apply_cache(ormid, houseid); // THIS IS IMPORTANT

    printf("house %d created", houseid);
}

GetHouseFreeSlot() {
    for(new i; i < MAX_HOUSE; i++) {
        if(House[i][h_ID] == 0) return i;
    }
    return -1;
}

@maddinat0r
Copy link
Collaborator

You're trying to apply a INSERT-type result to an ORM object, of course this doesn't work. An INSERT query doesn't return any rows and fields to be applied on anything. The way @HxTheDash did it is way better (and produces no errors).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants