Doesnt insert id -
vassilis - 19.11.2015
What is wrong here?
mysql_log
pawn Код:
[15:47:52] [DEBUG] mysql_format - connection: 1, len: 350, format: "INSERT INTO `houses` (`XEnt`, `YEnt`, `ZEnt`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld` ,`HInterior`, `HPrice`,`HOwner`, `HOwne..."
[15:47:52] [DEBUG] mysql_tquery - connection: 1, query: "INSERT INTO `houses` (`XEnt`, `YEnt`, `ZEnt`, `XExit`, `YExit`, ", callback: "(null)", format: "(null)"
[15:47:52] [DEBUG] cache_insert_id - connection: 1
[15:47:52] [WARNING] cache_insert_id - no active cache
function
PHP код:
function CreateHouse(Float:Xen,Float:Yen,Float:Zen,Float:Xex,Float:Yex,Float:Zex,virtualworld,interiorid,price)
{
static hCount;
new hid = hCount; hCount += 1;
new string[100];
new query[350];
hid += 1;
HouseInfo[hid][XEnt] = Xen;
HouseInfo[hid][YEnt] = Yen;
HouseInfo[hid][ZEnt] = Zen;
HouseInfo[hid][XExit] = Xex;
HouseInfo[hid][YExit] = Yex;
HouseInfo[hid][ZExit] = Zex;
HouseInfo[hid][HVirtualWorld] = virtualworld;
HouseInfo[hid][HInterior] = interiorid;
HouseInfo[hid][HPrice] = price;
HouseInfo[hid][HOwned] = 0;
HouseInfo[hid][HLocked] = 0;
format(string,sizeof(string),""COL_GREEN"HouseName"COL_WHITE": No Owner\n"COL_GREEN"Price"COL_WHITE": %d",price);
Create3DTextLabel(string, COLOR_YELLOW, Xen, Yen, Zen, 40.0, 0, 0);
mysql_format(mysql, query, sizeof(query), "INSERT INTO `houses` (`XEnt`, `YEnt`, `ZEnt`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld` ,`HInterior`, `HPrice`,\
`HOwner`, `HOwned`, `HLocked`, `HName`) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, 'UnOwned', 0, 0, 'For Sale')", Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
mysql_tquery(mysql, query);
HouseInfo[hid][hID] = cache_insert_id();
printf("New house registered. HID: %d", HouseInfo[hid][hID]); //just for debugging.
return 1;
}
Also i have already a column named HOwned it was named H
owned by mistake but i edit it sould i remove this column and make it again?
Re: Doesnt insert id -
gurmani11 - 19.11.2015
PHP код:
new query[500];
strcat(query,"INSERT INTO `houses` (`XEnt`, `YEnt`, `ZEnt`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld` ,`HInterior`, `HPrice`");
format(query,"%s, `HOwner`, `HOwned`, `HLocked`, `HName`) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, 'UnOwned', 0, 0, 'For Sale')",query, Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
mysql_tquery(mysql, query);
Re: Doesnt insert id -
vassilis - 19.11.2015
I don't really think it could work like that

Let me test it
Re: Doesnt insert id -
vassilis - 19.11.2015
EDIT:Error:Argument type missmatch
EDIT(2):double post by mistake
pawn Код:
strcat(query,"INSERT INTO `houses` (`XEnt`, `YEnt`, `ZEnt`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld` ,`HInterior`, `HPrice`");
format(query, "%s, `HOwner`, `HOwned`, `HLocked`, `HName`) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, 'UnOwned', 0, 0, 'For Sale')",Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
mysql_tquery(mysql, query); <<<-The error
HouseInfo[hid][hID] = cache_insert_id();
So i don't really think it works like that
Re: Doesnt insert id -
iGetty - 19.11.2015
pawn Код:
new query[500], Cache:result;
strcat(query,"INSERT INTO `houses` (`XEnt`, `YEnt`, `ZEnt`, `XExit`, `YExit`, `ZExit`, `HVirtualWorld` ,`HInterior`, `HPrice`");
format(query,"%s, `HOwner`, `HOwned`, `HLocked`, `HName`) VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, 'UnOwned', 0, 0, 'For Sale')",query, Xen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
result = mysql_query(mysql, query);
id = cache_insert_id();
cache_delete(result);
Try that ^ - Change "id" to your var.
Re: Doesnt insert id -
vassilis - 19.11.2015
let me test
NO even if i create 10 houses it will still print that it register house id 0
Re: Doesnt insert id -
vassilis - 23.11.2015
any solution?
Re: Doesnt insert id -
PrO.GameR - 23.11.2015
mysql_tquery:
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_tquery
Sends a query which will be executed in another thread and
calls the callback (if there is one) when the execution is finished.
Know what you are using ..
the way to use it is:
PHP код:
mysql_tquery(mysql, query, "OnHouseCreate");
forward OnHouseCreate();
public OnHouseCreate()
{
new id = cache_insert_id();
}
^^ it's there that it returns the cache ID, not right after it, therefore cache_insert_id won't work where you wrote it
Re: Doesnt insert id -
vassilis - 23.11.2015
So you tell me I need to create a callback to register house
Re: Doesnt insert id -
PrO.GameR - 23.11.2015
Yup, Because it doesn't generate a cache unless it's in a callback
It's a relatively cheap cost for a smooth threaded mysql query that won't lag the s... out of your server xD
Here let me give you the code, use this query and add that callback and you are good to go
PHP код:
mysql_tquery(mysql, query, "OnHouseCreate","i",hid);
forward OnHouseCreate(houseid);
public OnHouseCreate(houseid)
{
HouseInfo[houseid][hID] = cache_insert_id();
}