Problem with saving new house (MYSQL)
#1

Hello guys! I have problem with my houses. When i create house it creates two in base.. http://prntscr.com/jbpzss . I have problem with long line so i create this two functions:
Код:
forward create_property1(kid);
public create_property1(kid)
{
	new query[ 1500 ];
	mysql_format(_dbConnector, query, sizeof(query), "INSERT INTO `propertys` (iSQLID,iOwnerSQLID,iOwned,iOwner,iEnter1,iEnter2,iEnter3,iExit1,iExit2,iExit3,iPrice,iLocked,iInterior,iVW,iVrsta, \
	iSafeStatus,iOruzje1,iOruzje2,iOruzje3,iOruzje4,iMunicija1,iMunicija2,iMunicija3,iMunicija4) VALUES('%d','%d','%d','%e','%f','%f','%f','%f','%f','%f','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d', '%d')",
	II[kid][iSQLID],II[kid][iOwnerSQLID],II[kid][iOwned],II[kid][iOwner],II[kid][iEnter][0],II[kid][iEnter][1],II[kid][iEnter][2],II[kid][iExit][0],II[kid][iExit][1],
	II[kid][iExit][2],II[kid][iPrice],II[kid][iLocked],II[kid][iInterior],II[kid][iVW],II[kid][iVrsta],
	II[kid][iSafeStatus],II[kid][iOruzje][0],II[kid][iOruzje][1],II[kid][iOruzje][2],II[kid][iOruzje][3],II[kid][iMunicija][0],II[kid][iMunicija][1],II[kid][iMunicija][2],II[kid][iMunicija][3]);
    mysql_tquery(_dbConnector, query);
    //mysql_pquery(_dbConnector, query, "OnPropertyCreated", "i", kid);
	return true;
}

forward create_property2(kid);
public create_property2(kid)
{
	new query[ 1500 ];
	mysql_format(_dbConnector, query, sizeof(query), "INSERT INTO `propertys` (iDrugAmmount,iAlarm,iLevel,iAdress,iNeaktivnost,iRentable,iRentPrice,iRentovano,iMats,iMoney) VALUES( '%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')",
	II[kid][iDrugAmmount],II[kid][iAlarm],II[kid][iLevel],II[kid][iAdress],II[kid][iNeaktivnost],
	II[kid][iRentable],II[kid][iRentPrice],II[kid][iRentovano],II[kid][iMats],II[kid][iMoney]);
    mysql_pquery(_dbConnector, query, "OnPropertyCreated", "i", kid);
	return true;
}
And those functions i put in this one
Код:
sql_create_property(kid)
{
    create_property1(kid);
    create_property2(kid);
	return true;
}
Here is the OnPropertyCreated
Код:
forward OnPropertyCreated(id);
public OnPropertyCreated(id)
{
	II[ id ][ iSQLID ] = cache_insert_id();
	return true;
}
How to fix this??
Reply
#2

You execute a query twice in 2 functions and find it strange it adds a double row....
Reply
#3

Do i need to remove one query?
Reply
#4

merge both the queries into a single query
Reply
#5

Quote:
Originally Posted by expressoboy123
Посмотреть сообщение
Do i need to remove one query?
Wait, You use the query twice but want to save data of both querys in 1 row right?
You shouldn't remove a query, but convert them into one.
If the string is very long, you can use strcat to concatenates two strings into one

https://sampwiki.blast.hk/wiki/Strcat
PHP код:
new string[40] = "Hello";
strcat(string" World!");
 
// The string is now 'Hello World!' 
Also, when you execute the first query, you can also use the second query to update the row you added with the first query.

https://dev.mysql.com/doc/refman/8.0/en/update.html
Reply
#6

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
Wait, You use the query twice but want to save data of both querys in 1 row right?
You shouldn't remove a query, but convert them into one.
If the string is very long, you can use strcat to concatenates two strings into one

https://sampwiki.blast.hk/wiki/Strcat
PHP код:
new string[40] = "Hello";
strcat(string" World!");
 
// The string is now 'Hello World!' 
Also, when you execute the first query, you can also use the second query to update the row you added with the first query.

https://dev.mysql.com/doc/refman/8.0/en/update.html
I dont know how to convert them in one...
Reply
#7

Quote:
Originally Posted by expressoboy123
Посмотреть сообщение
I dont know how to convert them in one...
Let me show you an example:

PHP код:
new str[128], string2[1024];
format(str,sizeof(str),"Text 1");
strcat(string2,str);
format(str,sizeof(str),"Text 2");
strcat(string2,str); 
So above you see 2 strings. These strings are defined with 'str'. These strings are converted into string2.
So when you would do this:

PHP код:
SendClientMessage(playerid, -1string2); 
The player will get this message:
Код:
Text 1Text 2
Reply
#8

Now i get it. Thank you! One more question.. Is it better to use strcat or to just update in second function?
Reply
#9

Quote:
Originally Posted by expressoboy123
Посмотреть сообщение
Now i get it. Thank you! One more question.. Is it better to use strcat or to just update in second function?
Your welcome! Its the best to use a single query for this. It won't be necessary to update it in a second query so it would be best to use strcat as this is also more efficient.
Reply
#10

Now i have another problem.. Is this okay? I try to print to check but "radim 7" never print.....
Код:
forward create_property3(kid);
public create_property3(kid) {

	new query[ 1500 ], string[ 1024 ], string2[ 1024 ];
	print("RADIM1");
	format(string2, sizeof(string2), "INSERT INTO `propertys` (iSQLID,iOwnerSQLID,iOwned,iOwner,iEnter1,iEnter2,iEnter3,iExit1,iExit2,iExit3,iPrice,iLocked,iInterior,iVW,iVrsta, \
	iSafeStatus,iOruzje1,iOruzje2,iOruzje3,iOruzje4,iMunicija1,iMunicija2,iMunicija3,iMunicija4) VALUES('%d','%d','%d','%e','%f','%f','%f','%f','%f','%f','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d','%d', '%d')",
	II[kid][iSQLID],II[kid][iOwnerSQLID],II[kid][iOwned],II[kid][iOwner],II[kid][iEnter][0],II[kid][iEnter][1],II[kid][iEnter][2],II[kid][iExit][0],II[kid][iExit][1],
	II[kid][iExit][2],II[kid][iPrice],II[kid][iLocked],II[kid][iInterior],II[kid][iVW],II[kid][iVrsta],
	II[kid][iSafeStatus],II[kid][iOruzje][0],II[kid][iOruzje][1],II[kid][iOruzje][2],II[kid][iOruzje][3],II[kid][iMunicija][0],II[kid][iMunicija][1],II[kid][iMunicija][2],II[kid][iMunicija][3]);
	print("RADIM2");
	strcat(string, string2);
	format(string2, sizeof(string2), "(iDrugAmmount,iAlarm,iLevel,iAdress,iNeaktivnost,iRentable,iRentPrice,iRentovano,iMats,iMoney) VALUES( '%d','%d','%d','%d','%d','%d','%d','%d','%d','%d')",
	II[kid][iDrugAmmount],II[kid][iAlarm],II[kid][iLevel],II[kid][iAdress],II[kid][iNeaktivnost],
	II[kid][iRentable],II[kid][iRentPrice],II[kid][iRentovano],II[kid][iMats],II[kid][iMoney]);
	print("RADIM3");
	strcat(string, string2);
	print("RADIM4");
	strcat(query, string);
	print("RADIM44");
	//mysql_format(_dbConnector, query, sizeof(query), "%s", string);
	print("RADIM5");
	mysql_pquery(_dbConnector, query, "OnPropertyCreated", "i", kid);
	print("RADIM6");
	return true;
}
Код:
forward OnPropertyCreated(id);
public OnPropertyCreated(id)
{
    print("RADIM7");
	II[ id ][ iSQLID ] = cache_insert_id();
	return true;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)