[Tutorial] Using BlueG's MySQL plugin R7 (with cache)
#81

https://code.******.com/p/sa-mp-mysq...s/detail?id=25

Can someone help me with this?
Reply
#82

Hm - I've worked with similar grouping before. I think you should wrap up t1.time in MIN().

// Edit. Did not see you had solved it. However if you see this, feel free to post your solution to it. I remember such queries making me shiver all over a few years ago.
Reply
#83

Is is compulsory to give a function to function_query??

Can I do it like

Code:
CheckAccountExists(account[])
{
	new string[128];
	format(string, sizeof(string), "SELECT * FROM player_accounts WHERE Name = '%s'", account);
	mysql_function_query(dbHandle,string,FALSE, "", "");

	new value;
	value = mysql_num_rows();
	return value;
}
Reply
#84

Yes, it is in R7 or later.
Reply
#85

But it doesn't work for me
Reply
#86

You can do it this way;
pawn Code:
CheckAccountExists(account[])
{
    new string[128];
    format(string, sizeof(string), "SELECT * FROM player_accounts WHERE Name = '%s'", account);
    mysql_function_query(dbHandle, string, true, "CheckAccount", "s", account);
}

forward CheckAccount(account[]);
public CheckAccount(account[])
{
    new rows, fields;
    cache_get_data(rows, fields);
   
    if(!rows)
    {
        // account does not exist, register?
    }
    else
    {
        //proceed to login?
    }
    return 1; // To clear cache
}
If you want to do it the 'old' way, without CheckAccount callback, you can try y_inline which is supported in R31.
Reply
#87

Guys, I updated from R15 to R27 few days ago and now we have R31? Are those all bugfixes, or are there some new features? What's the status of mysql_format and linux (I'm using it extensively with %e instead of normal format + mysql_real_escape_string)? Is there some compact changelog (I'm not so comfortable in using ****** code instead of github), other than fixed issues list?

#e: 1k post, yay
Reply
#88

Quote:
Originally Posted by Misiur
View Post
Guys, I updated from R15 to R27 few days ago and now we have R31? Are those all bugfixes, or are there some new features? What's the status of mysql_format and linux (I'm using it extensively with %e instead of normal format + mysql_real_escape_string)? Is there some compact changelog (I'm not so comfortable in using ****** code instead of github), other than fixed issues list?

#e: 1k post, yay
I think you can use mysql_format without crashes now, I didn't tested it. Give it a try !

https://code.******.com/p/sa-mp-mysq...ce/detail?r=28
https://code.******.com/p/sa-mp-mysq...ce/detail?r=29
https://code.******.com/p/sa-mp-mysq...ce/detail?r=30
https://code.******.com/p/sa-mp-mysq...ce/detail?r=31

Quote:

- added '%%' specifier to native 'mysql_format'

- mysql_reconnect returns true if connection is established, else false

- added optional parameter "autoreconnect" to mysql_connect to control whether
the plugin should reconnect automatically if connection is lost

- added optional parameter "wait" to mysql_close to control whether the plugin
should wait till all pending queries are executed or not

- re-added our old and beloved native mysql_errno

Those are all things changed from R27-R28, the rest are improvements and fixes.
Reply
#89

Code:
forward AracYukle();
public AracYukle()
{
	new resultline[1024];
	new car[37][64];
	new query[100];
	mysql_real_escape_string("SELECT * FROM araclar ORDER BY id ASC",query);
	mysql_query(query);
	mysql_store_result();
    for(new h = 0; h < sizeof(DynamicCars); h++)
	{
		while(mysql_fetch_row(resultline)==1)
		{
			H_split(resultline, car, '|');
			h = AddStaticVehicleEx(strval(car[1]), floatstr(car[2]), floatstr(car[3]), floatstr(car[4]), floatstr(car[5]), strval(car[6]), strval(car[7]), -1);
			DynamicCars[h][cSQLid] = strval(car[0]);
			DynamicCars[h][CarModel] = strval(car[1]);
			DynamicCars[h][CarX] = floatstr(car[2]);
			DynamicCars[h][CarY] = floatstr(car[3]);
			DynamicCars[h][CarZ] = floatstr(car[4]);
			DynamicCars[h][CarAngle] = floatstr(car[5]);
			DynamicCars[h][CarColor1] = strval(car[6]);
			DynamicCars[h][CarColor2] = strval(car[7]);
			DynamicCars[h][FactionCar] = strval(car[8]);
			DynamicCars[h][CarType] = strval(car[9]);
			DynamicCars[h][CarValue] = strval(car[10]);
			DynamicCars[h][CarOwned] = strval(car[11]);
	        strmid(DynamicCars[h][CarOwner], car[12], 0, strlen(car[12]), 20);
	        strmid(DynamicCars[h][CarDescription],car[13], 0, strlen(car[13]), 20);
			DynamicCars[h][CarHealth] = floatstr(car[14]);
			DynamicCars[h][AracPatladi] = strval(car[15]);
			DynamicCars[h][AracKiraZaman] = strval(car[16]);
			DynamicCars[h][cSigorta] = strval(car[17]);
			DynamicCars[h][cKazaSayi] = strval(car[18]);
			DynamicCars[h][ModPaintjob] = strval(car[19]);
			DynamicCars[h][ModSpoiler] = strval(car[20]);
			DynamicCars[h][ModRoof] = strval(car[21]);
			DynamicCars[h][ModLeftSideSkirt] = strval(car[22]);
			DynamicCars[h][ModRightSideSkirt] = strval(car[23]);
			DynamicCars[h][ModExhaust] = strval(car[24]);
			DynamicCars[h][ModWheels] = strval(car[25]);
			DynamicCars[h][ModFrontBumper] = strval(car[26]);
			DynamicCars[h][ModRearBumper] = strval(car[27]);
			DynamicCars[h][ModStereo] = strval(car[28]);
			DynamicCars[h][ModHydraulics] = strval(car[29]);
			DynamicCars[h][ModNitro] = strval(car[30]);
			DynamicCars[h][ModNeon] = strval(car[31]);
			DynamicCars[h][ModAlarm] = strval(car[32]);
			DynamicCars[h][Panels] = strval(car[33]);
			DynamicCars[h][Doors] = strval(car[34]);
			DynamicCars[h][Lights] = strval(car[35]);
			DynamicCars[h][Tires] = strval(car[36]);
			AraciModifiyeEt(h);
			h++;
		}
	}
}
Can you give me to change it in the form of MySQL R7(BlueG's)?
Reply
#90

Have you tried to do it yourself? It's a big code and you should really be trying to convert it yourself.
Reply
#91

I'm working on it for a week and I could not, really.
Reply
#92

Quote:
Originally Posted by Richie©
View Post
You can do it this way;
pawn Code:
CheckAccountExists(account[])
{
    new string[128];
    format(string, sizeof(string), "SELECT * FROM player_accounts WHERE Name = '%s'", account);
    mysql_function_query(dbHandle, string, true, "CheckAccount", "s", account);
}

forward CheckAccount(account[]);
public CheckAccount(account[])
{
    new rows, fields;
    cache_get_data(rows, fields);
   
    if(!rows)
    {
        // account does not exist, register?
    }
    else
    {
        //proceed to login?
    }
    return 1; // To clear cache
}
If you want to do it the 'old' way, without CheckAccount callback, you can try y_inline which is supported in R31.
The problem I have are:
*First of all, I am updating from R5 to R7
*I have used if(CheckAccountExists(...))

How do make change to the code without effecting these ifs??
Thanks
Reply
#93

I have question: how to make function like GetPlayerInt(playerid, field[]) using cache? I don't want to create functions to all my queries.
Reply
#94

It gives me argument type mismatch (argument 1)

At line mysql_funtion_query

How to solve this?


HTML Code:
new
    count = 10,
    result[2][32], 
    string[(24 + 10) * 10];

mysql_function_query("SELECT `Score`, `PlayerName` FROM `"#MYSQL_TABLE"` ORDER BY `Score` ASC LIMIT 10");
mysql_store_result();

if (mysql_num_rows() < 1) return 0;

while (mysql_retrieve_row() && count > 0)
{
    mysql_fetch_field_row(result[0], "Score");
    mysql_fetch_field_row(result[1], "PlayerName");

    format(string, sizeof(string), "%s%d. %s: %d\n", string, count--, result[1], strval(result[0]));
}
ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Top 10", string, "Close", "");
Reply
#95

I'm lost. My script is for the r6 version. So now r33 r34... is for wich update?
Reply
#96

Hi,

How can I use "cache_get_row_int(0, 1);" with the R7 please ? Cause it was fine with R35 but now I got a lot of errors.
Reply
#97

Quote:
Originally Posted by anou1
View Post
Hi,

How can I use "cache_get_row_int(0, 1);" with the R7 please ? Cause it was fine with R35 but now I got a lot of errors.
You can't, cache_get_row_int and cache_get_row_float were added in R8.

So why don't you just use R35?
Reply
#98

Code:
Plugin version R8 and newer
BlueG has decided to use a public repository for the development of this plugin. This means that others can commit code as well, and some already have. Here are some of the changes:
* Added cache_get_row_int and cache_get_row_float (supported briefly in this tutorial, but I'll continue it some time).
* More security added to internal string handling to prevent buffer overflows.
* Fixed crash issue on gamemode restart (gmx).
* A few more internal issues cleared up.
Lol now my server(linux VPS) doesn't even start, and in the hosted slots the server still keeps restarting

Code:
[17:33:18] [MySQL] (Main Pipelines) Connecting to 5.231.45.5...
[17:33:18] [MySQL] (MainPipeline) Connection successful toward MySQL Database Server!
[17:33:18] [LoadHouses] Loading data from database...
[17:33:18] [LoadDynamicDoors] Loading data from database...
[17:33:18] [LoadDynamicMapIcons] Loading data from database...
[17:33:18] [LoadDynamicTexts] Loading data from database...
[17:33:19] [LoadTurfWars] 40 turfs loaded.
[17:33:19] [LoadPaintballArenas] 10 paintball arenas loaded.
[17:33:19] [LoadEventPoints] 0 event points loaded.
[17:33:19] [LoadGates] 4000 gates loaded.
[17:33:19] [LoadElevatorStuff] 20 floors loaded.
[17:33:19] [LoadFamilies] 16 families loaded.
[17:33:19] [LoadPoints] 9 points loaded.
[17:33:24] [LoadCDealerships] 15 dealerships loaded.
[17:33:24] [MiscLoad] Misc Loaded
[17:33:24] [Tax] Government Tax/Vault Loaded.
[17:33:36] [LoadCDealerships] 15 dealerships loaded.
[17:33:36] [MiscLoad] Misc Loaded
[17:33:36] [Tax] Government Tax/Vault Loaded.
Reply
#99

nice
Reply

great!!!
i really need this tutorial!
you're the only one who makes me understand what threaded MySQL is...
+REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)