pBlueG / SA-MP-MySQL

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

Help with orm_insert #144

Closed Lathrel closed 7 years ago

Lathrel commented 7 years ago

I'm having a problem trying to insert data into the database.

enum E_VIP_DATA {
    ORM:vip_orm,
    vip_player_reference,
    vip_role[YSI_MAX_STRING],
    vip_level
} new VipData[MAX_PLAYERS][E_VIP_DATA];

ORM:Vip_CreateORM(idx) {
    new ORM:ormid = VipData[idx][vip_orm] = orm_create("vips");

    orm_addvar_int(ormid, VipData[idx][vip_player_reference], "vip_player_reference");
    orm_setkey(ormid, "vip_player_reference");

    orm_addvar_int(ormid, VipData[idx][vip_level], "vip_level");
    orm_addvar_string(ormid, VipData[idx][vip_role], YSI_MAX_STRING, "vip_role");

    return ormid;
}
// Command
VipData[playerid][vip_player_reference] = Player_GetID(playerid); // get ID of player reference
strcpy(VipData[playerid][vip_role], role, YSI_MAX_STRING);
VipData[playerid][vip_level] = level;

new ORM:ormid = ORM:Vip_CreateORM(playerid);
orm_insert_inline(ormid);

When I try to insert, I get this error

[ERROR] error #1364 while executing query "INSERT INTO `vips` (`vip_level`,`vip_role`) VALUES ('0','Bronze')": Field 'vip_player_reference' doesn't have a default value

Why vip_player_reference won't work? I don't want use AUTO_INCREMENT and I need save, insert, delete by vip_player_reference

I Want to do something like this using ORM

INSERT INTO vips (vip_player_reference, vip_level, vip_role) VALUES (%d, %d, '%e')