Doesnt insert id
#1

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 hCounthCount += 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(stringCOLOR_YELLOWXen,  Yen,  Zen40.000);
    
mysql_format(mysqlquerysizeof(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(mysqlquery);
    
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 Howned by mistake but i edit it sould i remove this column and make it again?
Reply
#2

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')",queryXen,Yen,Zen,Xex,Yex,Zex,virtualworld,interiorid,price);
    
mysql_tquery(mysqlquery); 
Reply
#3

I don't really think it could work like that Let me test it
Reply
#4

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
Reply
#5

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.
Reply
#6

let me test
NO even if i create 10 houses it will still print that it register house id 0
Reply
#7

any solution?
Reply
#8

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(mysqlquery"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
Reply
#9

So you tell me I need to create a callback to register house
Reply
#10

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(mysqlquery"OnHouseCreate","i",hid);
forward OnHouseCreate(houseid);
public 
OnHouseCreate(houseid)
{
    
HouseInfo[houseid][hID] = cache_insert_id();

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)