Problem with saving/loading
#1

Aigh so I have a problem with saving and loading a business system idk why it compiles correctly and I get 0 errors but it's not working.

here's the code
loading

Код:
stock LoadBusiness()
{
	new DB_Query[228];
	new string[500];
	for(new i; i <= MAX_BUSINESS; i++)
	{
	    mysql_format(Database, DB_Query, sizeof(DB_Query), "SELECT * FROM `BUSINESS` WHERE `ID` = '%d' LIMIT 1", i);
	    if(cache_num_rows() > 0)
		{
		    cache_get_value(i, "NAME", Business[i][Name], 128);
		    cache_get_value_int(i, "TYPE", Business[i][Type]);
		    cache_get_value_int(i, "PRODUCT", Business[i][Product]);
		    cache_get_value_int(i, "FEE", Business[i][Fee]);
		    cache_get_value_int(i, "SAFE", Business[i][Safe]);
		    cache_get_value_int(i, "OWNER", Business[i][Owner]);
		    cache_get_value_int(i, "VW", Business[i][Vw]);
		    cache_get_value_int(i, "INT", Business[i][Int]);
		    cache_get_value_int(i, "OWNER", Business[i][Owner]);
		    cache_get_value_int(i, "PRICE", Business[i][Price]);
		    cache_get_value_name_float(i, "PosX", Business[i][PosX]);
		    cache_get_value_name_float(i, "PosY", Business[i][PosY]);
		    cache_get_value_name_float(i, "PosZ", Business[i][PosZ]);
        	Business[i][Used] = true;
        	if(Business[i][Owner] != -1)
        	{
	        	format(string, sizeof(string),"\t ID : %d\nName : %s\nType : %s\nOwner : %s\nEntrance Fee : $ %d",i,Business[i][Name],GetBusinessType(Business[i][Type]),GetNameFromUniqueID(Business[i][Owner]),Business[i][Fee]);
	        	Business[i][BizText] = Create3DTextLabel(string, COLOR_ADMIN, Business[i][PosX], Business[i][PosX], Business[i][PosX], 10.0, Business[i][Vw], Business[i][Int]);
	        }
	        else
	        {
	            format(string, sizeof(string),"\t ID : %d\nName : NEW BUSINESS\nType : %s\nPrice : %d",i,GetBusinessType(Business[i][Type]),Business[i][Price]);
	            Business[i][BizText] = Create3DTextLabel(string, COLOR_ADMIN, Business[i][PosX], Business[i][PosX], Business[i][PosX], 10.0, Business[i][Vw], Business[i][Int]);
	        }
	        
        }
        else
        {
            Business[i][Used] = false;
        }
    }
    return 1;
}
and saving

Код:
stock SaveBusiness(bizid)
{
	if(Business[bizid][Used])
	{
	    new query[512];
	    format(query, sizeof(query),"UPDATE `BUSINESS` SET `NAME` = %s, `TYPE` = %d, `PRODUCT` = %d, `FEE` = %d, `OWNER` = %d, `SAFE` = %d, `VW` = %d, `INT` = %d, `PRICE` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f WHERE `ID` = %d LIMIT 1",
	    Business[bizid][Name],Business[bizid][Type],Business[bizid][Product],Business[bizid][Fee],Business[bizid][Owner], Business[bizid][Safe],Business[bizid][Vw], Business[bizid][Int], Business[bizid][Price],Business[bizid][PosX],Business[bizid][PosY],Business[bizid][PosZ],bizid);
	    mysql_query(Database, query);
	}
	return 1;
}
Help please.
Reply
#2

Assuming your business name enum is saved as a string you could try replacing:

Код:
cache_get_value(i, "NAME", Business[i][Name], 128);
with
Код:
cache_get_value_name(i, "NAME", Business[i][Name], 128);
If that fails to work go to your logs > plugins folder and put your mysql.log in a pastebin.
Reply
#3

Quote:
Originally Posted by Chyakka
Посмотреть сообщение
Assuming your business name enum is saved as a string you could try replacing:

Код:
cache_get_value(i, "NAME", Business[i][Name], 128);
with
Код:
cache_get_value_name(i, "NAME", Business[i][Name], 128);
If that fails to work go to your logs > plugins folder and put your mysql.log in a pastebin.
it ain't working it's not even being called because when I try to create a new business ig it gets ID 0 like the old one.
and in the mysql.log file there's nothing suspecious.
There's only alot of this "[13:31:45] [ERROR] cache_get_row_count: no active cache" and that's it.
Reply
#4

Quote:
Originally Posted by Nru
Посмотреть сообщение
it ain't working it's not even being called because when I try to create a new business ig it gets ID 0 like the old one.
and in the mysql.log file there's nothing suspecious.
There's only alot of this "[13:31:45] [ERROR] cache_get_row_count: no active cache" and that's it.
Are u using auto increment? Also note that update only works if the row exists. to create a new row use INSERT INTO
Reply
#5

Quote:
Originally Posted by Chyakka
Посмотреть сообщение
Assuming your business name enum is saved as a string you could try replacing:

Код:
cache_get_value(i, "NAME", Business[i][Name], 128);
with
Код:
cache_get_value_name(i, "NAME", Business[i][Name], 128);
If that fails to work go to your logs > plugins folder and put your mysql.log in a pastebin.
Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
Are u using auto increment? Also note that update only works if the row exists. to create a new row use INSERT INTO
I'm not using auto increment ! and yeah I get your points there's the stuff

Код:
CMD:createbusiness(playerid, params[])
{
	if(IsPlayerConnected(playerid))
	{
	    if(pInfo[playerid][Admin] >= 3)
	    {
	        for(new i; i <= MAX_BUSINESS; i++)
	        {
	            if(Business[i][Used] = false)
	            {
	                new Float: x,Float: y,Float: z;
	                new string[500];
	                new DB_Query[500];
	                new name[24] = "BUSINESS";
	                GetPlayerPos(playerid, x,y,z);
		            Business[i][PosX] = x;
	                Business[i][PosY] = y;
	                Business[i][PosZ] = z;
	                Business[i][Fee] = 0;
	                Business[i][Type] = 0;
	                Business[i][Product] = 0;
	                Business[i][Owner] = -1;
	                Business[i][Price] = 30000;
	                Business[i][Vw] = GetPlayerVirtualWorld(playerid);
	                Business[i][Int] = GetPlayerInterior(playerid);
	                Business[i][Used] = true;
	                format(string, sizeof(string),"\t ID : %d\nName : BUSINESS\nType : %s\nPrice : %d",i,GetBusinessType(Business[i][Type]),Business[i][Price]);
	                Business[i][BizText] = Create3DTextLabel(string, COLOR_ADMIN, Business[i][PosX], Business[i][PosY], Business[i][PosZ], 10.0, Business[i][Vw], Business[i][Int]);
	                mysql_format(Database, DB_Query, sizeof(DB_Query), "INSERT INTO `BUSINESS` (`NAME`, `PosX`, `PosY`,`PosZ`, `FEE`, `TYPE`, `ID` , `PRODUCT`, `OWNER`, `VW`, `INT`, `PRICE`	) VALUES ('%s', '%f','%f','%f','0','0','%d','0','-1','%d','%d','30000')",name,Business[i][PosX],Business[i][PosY], Business[i][PosZ],i,Business[i][Vw],Business[i][Int]);
	                mysql_tquery(Database, DB_Query);
					break;
	            }
	        }
	    }
	}
	return 1;
}
Reply
#6

MySQL logs?
Reply
#7

Quote:
Originally Posted by iKarim
Посмотреть сообщение
MySQL logs?
About MySQL logs here you go

Код:
[02:40:18] [WARNING] mysql_connect: no password specified
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:18] [ERROR] cache_get_row_count: no active cache
[02:40:56] [ERROR] error #1062 while executing query "INSERT INTO `BUSINESS` (`NAME`, `PosX`, `PosY`,`PosZ`, `FEE`, `TYPE`, `ID` , `PRODUCT`, `OWNER`, `VW`, `INT`, `PRICE`	) VALUES ('BUSINESS', '1957.813721','1342.186157','15.374607','0','0','0','0','-1','0','0','30000')": Duplicate entry '0' for key 'PRIMARY'
I guess the last error coming cause it's not loading the business
Reply
#8

Try this

PHP код:
stock LoadBusiness()
{
    new 
DB_Query[228];
    new 
string[500];
    for(new 
i<= MAX_BUSINESSi++)
    {
        
mysql_format(DatabaseDB_Querysizeof(DB_Query), "SELECT * FROM `BUSINESS` WHERE `ID` = '%d' LIMIT 1"i);
        
mysql_query(DatabaseDB_Query);
        if(
cache_num_rows() > 0)
        {
            
cache_get_value(0"NAME"Business[i][Name], 128);
            
cache_get_value_int(0"TYPE"Business[i][Type]);
            
cache_get_value_int(0"PRODUCT"Business[i][Product]);
            
cache_get_value_int(0"FEE"Business[i][Fee]);
            
cache_get_value_int(0"SAFE"Business[i][Safe]);
            
cache_get_value_int(0"OWNER"Business[i][Owner]);
            
cache_get_value_int(0"VW"Business[i][Vw]);
            
cache_get_value_int(0"INT"Business[i][Int]);
            
cache_get_value_int(0"OWNER"Business[i][Owner]);
            
cache_get_value_int(0"PRICE"Business[i][Price]);
            
cache_get_value_name_float(0"PosX"Business[i][PosX]);
            
cache_get_value_name_float(0"PosY"Business[i][PosY]);
            
cache_get_value_name_float(0"PosZ"Business[i][PosZ]);
            
Business[i][Used] = true;
            if(
Business[i][Owner] != -1)
            {
                
format(stringsizeof(string),"\t ID : %d\nName : %s\nType : %s\nOwner : %s\nEntrance Fee : $ %d",i,Business[i][Name],GetBusinessType(Business[i][Type]),GetNameFromUniqueID(Business[i][Owner]),Business[i][Fee]);
                
Business[i][BizText] = Create3DTextLabel(stringCOLOR_ADMINBusiness[i][PosX], Business[i][PosX], Business[i][PosX], 10.0Business[i][Vw], Business[i][Int]);
            }
            else
            {
                
format(stringsizeof(string),"\t ID : %d\nName : NEW BUSINESS\nType : %s\nPrice : %d",i,GetBusinessType(Business[i][Type]),Business[i][Price]);
                
Business[i][BizText] = Create3DTextLabel(stringCOLOR_ADMINBusiness[i][PosX], Business[i][PosX], Business[i][PosX], 10.0Business[i][Vw], Business[i][Int]);
            }
        }
        else
        {
            
Business[i][Used] = false;
        }
    }
    return 
1;

Reply
#9

Quote:
Originally Posted by kovac
Посмотреть сообщение
Try this

PHP код:
stock LoadBusiness()
{
    new 
DB_Query[228];
    new 
string[500];
    for(new 
i<= MAX_BUSINESSi++)
    {
        
mysql_format(DatabaseDB_Querysizeof(DB_Query), "SELECT * FROM `BUSINESS` WHERE `ID` = '%d' LIMIT 1"i);
        
mysql_query(DatabaseDB_Query);
        if(
cache_num_rows() > 0)
        {
            
cache_get_value(0"NAME"Business[i][Name], 128);
            
cache_get_value_int(0"TYPE"Business[i][Type]);
            
cache_get_value_int(0"PRODUCT"Business[i][Product]);
            
cache_get_value_int(0"FEE"Business[i][Fee]);
            
cache_get_value_int(0"SAFE"Business[i][Safe]);
            
cache_get_value_int(0"OWNER"Business[i][Owner]);
            
cache_get_value_int(0"VW"Business[i][Vw]);
            
cache_get_value_int(0"INT"Business[i][Int]);
            
cache_get_value_int(0"OWNER"Business[i][Owner]);
            
cache_get_value_int(0"PRICE"Business[i][Price]);
            
cache_get_value_name_float(0"PosX"Business[i][PosX]);
            
cache_get_value_name_float(0"PosY"Business[i][PosY]);
            
cache_get_value_name_float(0"PosZ"Business[i][PosZ]);
            
Business[i][Used] = true;
            if(
Business[i][Owner] != -1)
            {
                
format(stringsizeof(string),"\t ID : %d\nName : %s\nType : %s\nOwner : %s\nEntrance Fee : $ %d",i,Business[i][Name],GetBusinessType(Business[i][Type]),GetNameFromUniqueID(Business[i][Owner]),Business[i][Fee]);
                
Business[i][BizText] = Create3DTextLabel(stringCOLOR_ADMINBusiness[i][PosX], Business[i][PosX], Business[i][PosX], 10.0Business[i][Vw], Business[i][Int]);
            }
            else
            {
                
format(stringsizeof(string),"\t ID : %d\nName : NEW BUSINESS\nType : %s\nPrice : %d",i,GetBusinessType(Business[i][Type]),Business[i][Price]);
                
Business[i][BizText] = Create3DTextLabel(stringCOLOR_ADMINBusiness[i][PosX], Business[i][PosX], Business[i][PosX], 10.0Business[i][Vw], Business[i][Int]);
            }
        }
        else
        {
            
Business[i][Used] = false;
        }
    }
    return 
1;

Ow thank you the loading is now working but the saving I guess it still bugged +REP
Reply
#10

Anyone can help me with the saving process here's the code
Код:
stock SaveBusiness()
{
	for(new i; i <= MAX_BUSINESS; i++)
	{
	    if(Business[i][Used])
	    {
	        new DB_Query[1000];
	        mysql_format(Database, DB_Query, sizeof(DB_Query),"UPDATE `BUSINESS` SET `NAME` = %s, `TYPE` = %d, `PRODUCT` = %d, `FEE` = %d, `OWNER` = %d, `SAFE` = %d, `VW` = %d, `INT` = %d, `PRICE` = %d, `PosX` = %f, `PosY` = %f, `PosZ` = %f WHERE `ID` = %d LIMIT 1",
	        Business[i][Name],Business[i][Type],Business[i][Product],Business[i][Fee],Business[i][Owner], Business[i][Safe],Business[i][Vw], Business[i][Int], Business[i][Price],Business[i][PosX],Business[i][PosY],Business[i][PosZ],i);
	        mysql_tquery(Database, DB_Query);
		}
	}
	return 1;
}
it ain't saving !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)