[MYSQL](Hardcoding). Its not saving any rows.
#1

Here are my codes below.

My problem is , I set MOTD in server. But when i restart the server it looses the MOTD. In short, It doesnt save my MOTD into "misc" table.

pawn Код:
stock g_mysql_SaveMOTD()
{
    new query[1024];

    format(query, sizeof(query), "UPDATE `misc` SET ");

    format(query, sizeof(query), "%s `gMOTD` = '%s',", query, g_mysql_ReturnEscaped(GlobalMOTD, MainPipeline));
    format(query, sizeof(query), "%s `aMOTD` = '%s',", query, g_mysql_ReturnEscaped(AdminMOTD, MainPipeline));
    format(query, sizeof(query), "%s `vMOTD` = '%s',", query, g_mysql_ReturnEscaped(VIPMOTD, MainPipeline));
    format(query, sizeof(query), "%s `cMOTD` = '%s',", query, g_mysql_ReturnEscaped(CAMOTD, MainPipeline));
    format(query, sizeof(query), "%s `pMOTD` = '%s',", query, g_mysql_ReturnEscaped(pMOTD, MainPipeline));
    format(query, sizeof(query), "%s `ShopTechPay` = '%.2f',", query, ShopTechPay);
    format(query, sizeof(query), "%s `GiftCode` = '%s',", query, g_mysql_ReturnEscaped(GiftCode, MainPipeline));
    format(query, sizeof(query), "%s `GiftCodeBypass` = '%d',", query, GiftCodeBypass);
    format(query, sizeof(query), "%s `TotalCitizens` = '%d',", query, TotalCitizens);
    format(query, sizeof(query), "%s `TRCitizens` = '%d',", query, TRCitizens);
    format(query, sizeof(query), "%s `ShopClosed` = '%d',", query, ShopClosed);
    format(query, sizeof(query), "%s `RimMod` = '%d',", query, RimMod);
    format(query, sizeof(query), "%s `CarVoucher` = '%d',", query, CarVoucher);
    format(query, sizeof(query), "%s `PVIPVoucher` = '%d',", query, PVIPVoucher);
    format(query, sizeof(query), "%s `GarageVW` = '%d',", query, GarageVW);
    format(query, sizeof(query), "%s `PumpkinStock` = '%d',", query, PumpkinStock);
    format(query, sizeof(query), "%s `HalloweenShop` = '%d'", query, HalloweenShop);

    mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}
Heres the loading mysql function.
pawn Код:
stock g_mysql_LoadMOTD()
{
    mysql_function_query(MainPipeline, "SELECT `gMOTD`,`aMOTD`,`vMOTD`,`cMOTD`,`pMOTD`,`ShopTechPay`,`GiftCode`,`GiftCodeBypass`,`TotalCitizens`,`TRCitizens`,`SecurityCode`,`ShopClosed`,`RimMod`,`CarVoucher`,`PVIPVoucher`, `GarageVW`, `PumpkinStock`, `HalloweenShop` FROM `misc`", true, "OnQueryFinish", "iii", LOADMOTDDATA_THREAD, INVALID_PLAYER_ID, -1);
}
I dont know if the problem is in Loading function or Saving function. Im confuse.
Reply
#2

If this will not fix or wont found the problem / solution then My problem will be : How can i save and load a string or variable into an .ini file. Like in this concept below.

i did /motd test
then it will save the motd into .ini
then the motd inside the ini will be
MOTD test
after the server start it will load the motd into .ini
Reply
#3

Format does not append to the query variable, it just overwrites whatever is in query. In your case, query will be 'Halloweenshop'=' '.

Do new query[1024], querypart[128];

Use querypart in your format functions. After every format, do strcat to join querypart into query. See: https://sampwiki.blast.hk/wiki/Strcat

Printf query at the end so you can check if the query is built correctly.
Reply
#4

Quote:
Originally Posted by Sithis
Посмотреть сообщение
Format does not append to the query variable, it just overwrites whatever is in query. In your case, query will be 'Halloweenshop'=' '.

Do new query[1024], querypart[128];

Use querypart in your format functions. After every format, do strcat to join querypart into query. See: https://sampwiki.blast.hk/wiki/Strcat

Printf query at the end so you can check if the query is built correctly.
Sorry, Im just newbie in MySQL scripting. And its so hardcore.

Can you say what codes need to change ? Post it here please.
Reply
#5

I even gave you a link to the wiki on how to use the strcat function. What is unclear?
Reply
#6

Quote:
Originally Posted by Sithis
Посмотреть сообщение
I even gave you a link to the wiki on how to use the strcat function. What is unclear?
Anyone? Im confuse.

Or just teach me step by step how to store variable or string into an .ini file then load it ?
Reply
#7

Код:
stock g_mysql_SaveMOTD()
{
	new query[1024], querypart[128];

	querypart(query, sizeof(query), "UPDATE `misc` SET ");

	querypart(query, sizeof(query), "%s `gMOTD` = '%s',", query, g_mysql_ReturnEscaped(GlobalMOTD, MainPipeline));
	querypart(query, sizeof(query), "%s `aMOTD` = '%s',", query, g_mysql_ReturnEscaped(AdminMOTD, MainPipeline));
	querypart(query, sizeof(query), "%s `vMOTD` = '%s',", query, g_mysql_ReturnEscaped(VIPMOTD, MainPipeline));
	querypart(query, sizeof(query), "%s `cMOTD` = '%s',", query, g_mysql_ReturnEscaped(CAMOTD, MainPipeline));
	querypart(query, sizeof(query), "%s `pMOTD` = '%s',", query, g_mysql_ReturnEscaped(pMOTD, MainPipeline));
	querypart(query, sizeof(query), "%s `ShopTechPay` = '%.2f',", query, ShopTechPay);
	querypart(query, sizeof(query), "%s `GiftCode` = '%s',", query, g_mysql_ReturnEscaped(GiftCode, MainPipeline));
	querypart(query, sizeof(query), "%s `GiftCodeBypass` = '%d',", query, GiftCodeBypass);
	querypart(query, sizeof(query), "%s `TotalCitizens` = '%d',", query, TotalCitizens);
	querypart(query, sizeof(query), "%s `TRCitizens` = '%d',", query, TRCitizens);
	querypart(query, sizeof(query), "%s `ShopClosed` = '%d',", query, ShopClosed);
	querypart(query, sizeof(query), "%s `RimMod` = '%d',", query, RimMod);
	querypart(query, sizeof(query), "%s `CarVoucher` = '%d',", query, CarVoucher);
	querypart(query, sizeof(query), "%s `PVIPVoucher` = '%d',", query, PVIPVoucher);
	querypart(query, sizeof(query), "%s `GarageVW` = '%d',", query, GarageVW);
	querypart(query, sizeof(query), "%s `PumpkinStock` = '%d',", query, PumpkinStock);
	querypart(query, sizeof(query), "%s `HalloweenShop` = '%d'", query, HalloweenShop);

	mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}
Reply
#8

Can you print the final formatted query please and let us know what the result is?

pawn Код:
stock g_mysql_SaveMOTD()
{
    new query[1024];

    format(query, sizeof(query), "UPDATE `misc` SET ");

    format(query, sizeof(query), "%s `gMOTD` = '%s',", query, g_mysql_ReturnEscaped(GlobalMOTD, MainPipeline));
    format(query, sizeof(query), "%s `aMOTD` = '%s',", query, g_mysql_ReturnEscaped(AdminMOTD, MainPipeline));
    format(query, sizeof(query), "%s `vMOTD` = '%s',", query, g_mysql_ReturnEscaped(VIPMOTD, MainPipeline));
    format(query, sizeof(query), "%s `cMOTD` = '%s',", query, g_mysql_ReturnEscaped(CAMOTD, MainPipeline));
    format(query, sizeof(query), "%s `pMOTD` = '%s',", query, g_mysql_ReturnEscaped(pMOTD, MainPipeline));
    format(query, sizeof(query), "%s `ShopTechPay` = '%.2f',", query, ShopTechPay);
    format(query, sizeof(query), "%s `GiftCode` = '%s',", query, g_mysql_ReturnEscaped(GiftCode, MainPipeline));
    format(query, sizeof(query), "%s `GiftCodeBypass` = '%d',", query, GiftCodeBypass);
    format(query, sizeof(query), "%s `TotalCitizens` = '%d',", query, TotalCitizens);
    format(query, sizeof(query), "%s `TRCitizens` = '%d',", query, TRCitizens);
    format(query, sizeof(query), "%s `ShopClosed` = '%d',", query, ShopClosed);
    format(query, sizeof(query), "%s `RimMod` = '%d',", query, RimMod);
    format(query, sizeof(query), "%s `CarVoucher` = '%d',", query, CarVoucher);
    format(query, sizeof(query), "%s `PVIPVoucher` = '%d',", query, PVIPVoucher);
    format(query, sizeof(query), "%s `GarageVW` = '%d',", query, GarageVW);
    format(query, sizeof(query), "%s `PumpkinStock` = '%d',", query, PumpkinStock);
    format(query, sizeof(query), "%s `HalloweenShop` = '%d'", query, HalloweenShop);
     
        printf("Query: [%s]", query); //copy and paste the result inside the square brackets.
    mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}
Reply
#9

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
Can you print the final formatted query please and let us know what the result is?

pawn Код:
stock g_mysql_SaveMOTD()
{
    new query[1024];

    format(query, sizeof(query), "UPDATE `misc` SET ");

    format(query, sizeof(query), "%s `gMOTD` = '%s',", query, g_mysql_ReturnEscaped(GlobalMOTD, MainPipeline));
    format(query, sizeof(query), "%s `aMOTD` = '%s',", query, g_mysql_ReturnEscaped(AdminMOTD, MainPipeline));
    format(query, sizeof(query), "%s `vMOTD` = '%s',", query, g_mysql_ReturnEscaped(VIPMOTD, MainPipeline));
    format(query, sizeof(query), "%s `cMOTD` = '%s',", query, g_mysql_ReturnEscaped(CAMOTD, MainPipeline));
    format(query, sizeof(query), "%s `pMOTD` = '%s',", query, g_mysql_ReturnEscaped(pMOTD, MainPipeline));
    format(query, sizeof(query), "%s `ShopTechPay` = '%.2f',", query, ShopTechPay);
    format(query, sizeof(query), "%s `GiftCode` = '%s',", query, g_mysql_ReturnEscaped(GiftCode, MainPipeline));
    format(query, sizeof(query), "%s `GiftCodeBypass` = '%d',", query, GiftCodeBypass);
    format(query, sizeof(query), "%s `TotalCitizens` = '%d',", query, TotalCitizens);
    format(query, sizeof(query), "%s `TRCitizens` = '%d',", query, TRCitizens);
    format(query, sizeof(query), "%s `ShopClosed` = '%d',", query, ShopClosed);
    format(query, sizeof(query), "%s `RimMod` = '%d',", query, RimMod);
    format(query, sizeof(query), "%s `CarVoucher` = '%d',", query, CarVoucher);
    format(query, sizeof(query), "%s `PVIPVoucher` = '%d',", query, PVIPVoucher);
    format(query, sizeof(query), "%s `GarageVW` = '%d',", query, GarageVW);
    format(query, sizeof(query), "%s `PumpkinStock` = '%d',", query, PumpkinStock);
    format(query, sizeof(query), "%s `HalloweenShop` = '%d'", query, HalloweenShop);
     
        printf("Query: [%s]", query); //copy and paste the result inside the square brackets.
    mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
}
Here is it, As you can its updating but the misc table inside phmyadmin is still empty.

Код:
[10:09:24] [zcmd] [Ivann Setland]: /motd Test
[10:09:24] Query: [UPDATE `misc` SET  `gMOTD` = 'Test', `aMOTD` = '', `vMOTD` = '', `cMOTD` = '', `pMOTD` = '', `ShopTechPay` = '0.00', `GiftCode` = '', `GiftCodeBypass` = '0', `TotalCitizens` = '0', `TRCitizens` = '0', `ShopClosed` = '0', `RimMod` = '0', `CarVoucher` = '0', `PVIPVoucher` = '0', `GarageVW` = '0', `PumpkinStock` = '0', `HalloweenShop` = '0']
[10:09:27] [zcmd] [Ivann Setland]: /amotd test
[10:09:27] Query: [UPDATE `misc` SET  `gMOTD` = 'Test', `aMOTD` = 'test', `vMOTD` = '', `cMOTD` = '', `pMOTD` = '', `ShopTechPay` = '0.00', `GiftCode` = '', `GiftCodeBypass` = '0', `TotalCitizens` = '0', `TRCitizens` = '0', `ShopClosed` = '0', `RimMod` = '0', `CarVoucher` = '0', `PVIPVoucher` = '0', `GarageVW` = '0', `PumpkinStock` = '0', `HalloweenShop` = '0']
[10:09:31] [zcmd] [Ivann Setland]: /cmotd test
[10:09:31] Query: [UPDATE `misc` SET  `gMOTD` = 'Test', `aMOTD` = 'test', `vMOTD` = '', `cMOTD` = 'test', `pMOTD` = '', `ShopTechPay` = '0.00', `GiftCode` = '', `GiftCodeBypass` = '0', `TotalCitizens` = '0', `TRCitizens` = '0', `ShopClosed` = '0', `RimMod` = '0', `CarVoucher` = '0', `PVIPVoucher` = '0', `GarageVW` = '0', `PumpkinStock` = '0', `HalloweenShop` = '0']
[10:09:35] [zcmd] [Ivann Setland]: /vipmotd test
[10:09:35] Query: [UPDATE `misc` SET  `gMOTD` = 'Test', `aMOTD` = 'test', `vMOTD` = 'test', `cMOTD` = 'test', `pMOTD` = '', `ShopTechPay` = '0.00', `GiftCode` = '', `GiftCodeBypass` = '0', `TotalCitizens` = '0', `TRCitizens` = '0', `ShopClosed` = '0', `RimMod` = '0', `CarVoucher` = '0', `PVIPVoucher` = '0', `GarageVW` = '0', `PumpkinStock` = '0', `HalloweenShop` = '0']
Reply
#10

Have you tried just updating one field and have you made sure all of the fields actually exist in the table? I can't see an issue with the query being sent so my next thought would be one/more of the fields don't exist.

Maybe just try this and see what happens?
pawn Код:
format(query, sizeof(query), "UPDATE `misc` SET");

    format(query, sizeof(query), "%s `gMOTD` = '%s',", query, g_mysql_ReturnEscaped(GlobalMOTD, MainPipeline));
mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
Even if you have checked the fields several times, just make sure all fields exist and match the case aswell.
Reply
#11

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
Have you tried just updating one field and have you made sure all of the fields actually exist in the table? I can't see an issue with the query being sent so my next thought would be one/more of the fields don't exist.

Maybe just try this and see what happens?
pawn Код:
format(query, sizeof(query), "UPDATE `misc` SET");

    format(query, sizeof(query), "%s `gMOTD` = '%s',", query, g_mysql_ReturnEscaped(GlobalMOTD, MainPipeline));
mysql_function_query(MainPipeline, query, false, "OnQueryFinish", "i", SENDDATA_THREAD);
Even if you have checked the fields several times, just make sure all fields exist and match the case aswell.
This is exactly what i mean, The fields / misc table was empty first then when it g_mysql_SaveMOTD. It doesnt save to the misc table. Is it because its empty?

NOTE : Before saving the MOTD the misc table is empty. Is there any query that can make those fields?
Reply
#12

Kind of getting confused a bit

Which of the following is it?
1) The table does not exist in the first place.
2) The table exists but the fields gMOTD, etc., are just empty (their value is default (empty string, 0, 0.0, etc)).

You can create the table if it doesn't exist if you want to.

(Just ignore this reply if you are going to stick with the file based system instead.
pawn Код:
mysql_connect(/*your credentials*/); //connecting to the database.
mysql_query("CREATE TABLE IF NOT EXISTS misc(gMOTD VARCHAR(60), aMOTD VARCHAR(60), cMOTD VARCHAR(60), ..rest of fields)");
Reply
#13

Quote:
Originally Posted by EiresJason
Посмотреть сообщение
Kind of getting confused a bit

Which of the following is it?
1) The table does not exist in the first place.
2) The table exists but the fields gMOTD, etc., are just empty (their value is default (empty string, 0, 0.0, etc)).

You can create the table if it doesn't exist if you want to.

(Just ignore this reply if you are going to stick with the file based system instead.
pawn Код:
mysql_connect(/*your credentials*/); //connecting to the database.
mysql_query("CREATE TABLE IF NOT EXISTS misc(gMOTD VARCHAR(60), aMOTD VARCHAR(60), cMOTD VARCHAR(60), ..rest of fields)");
1) Yes table misc is empty. It doesnt have any fields.
2) No , gMOTD....aMOTD is missing, Its not inside the misc, So the problem, Fields gMOTD... aMOTD is missing or not saving. In short, Table misc is empty or does not have any fields.

This is what i mean, CREATE TABLE IF NOT EXIST. THANKS FOR THESE QUERIES. I will try it too.

P.S:
gMOTD down to HaloweenShop is missing or not exist inside the misc table. In short its not saving too.

gMOTD down to HaloweenShop
Reply
#14

Ok cool.

You shouldn't try to access a field in a table that doesn't exist. It will mess up the query (unsure if it does anything else than failing the query).

If the misc table has no fields (which I didn't think was possible, I thought a table HAD to have atleast one field), then you should either fill in the data or use the above query to fill it in for you.

Only do a few at first though and then slowly add in the others like ShopTechPay, etc.
Reply
#15

Confirmed, I just tried to create an empty table and it wouldn't let me (Navicat).

Also, if there isn't any record in your table (even if all your fields are present and have the proper data like int or float or varchar), update won't do anything and your update query will fail as well.

You can't update a line that doesn't exist.
You'll have to add all the proper columns (fields) to your table first, then add at least one row of data into your table.

After that, your update query should work.
But since your query doesn't have a WHERE clause, having more than one row in your table will update ALL rows at once because the WHERE clause is used to state which row to update.
No WHERE clause = all rows at once.

If you only plan to have one row, it won't matter.
Reply
#16

OWW, Update is useless if the table is empty.

Thank you guys all of. You made my day, You solve my problem, +REP to All of you.

EDIT: What is the maximum VARCHAR ?

If its not VARCHAR but Its a integer, What will be the varchar ?

For example: ShopTechPay %d , Query, ShopTechPay
CREATE TABLE IF NOT EXIST"("ShopTechPay VARCHAR(?)");
What will be ?
Reply
#17

Guys! Another Problem.
I do exploration in misc table and heres what i saw.

When clicking / browsing on misc table, Its empty, but When i click on structure.

Is it messed up?



And when i click on "Browse"


Really? Whats going on ? Im now massively confused. I dont know what to do guys.
@EiresJason

I think your queries are wrong there are different varchars in those screenshot. Help me guys!!!
Reply
#18

Anyone?
Reply
#19

up? (4chars)
Reply
#20

Browse allows you to browse any content within the table. Structure shows you how the layout of the table, allows you to add/remove fields/columns, rearrange them, etc.

Do this:
Click the 'SQL' tab.

Copy the below query into the input box and click 'Go' which is at the right hand side.
PHP код:
INSERT INTO `misc` (`gMOTD`) VALUES ('This is my first MOTD!'
Then click 'Browse' and see if it returns anything.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)