[Plugin] [REL] SA:MP MySQL Plugin 2.1.1 - Released (1/25/2011
#61

Awesome, good to see you keep updating it!
Reply
#62

mysql_fetch_field()
Code:
	delete cfield;
	char
		*err = new char[128];
	sprintf((char *)err, "'mysql_fetch_field' could not find field: '%s'.", cfield);
	GenerateError(h, (const char *)err, P_ERROR_NOFIELD);
	delete [] err;
	return 0;
You free *cfield and then use it for logging. There's also a typo in, afair, mysql_connect, being "verson" instead of "version".
I'll test the plugin soon
Reply
#63

Hi again! I've got another request.
As we know, the plugin doesn't require mysql_fetch_row() before fetching separate fields. It's obviously a proper behaviour, but you do a little thing, which makes the plugin less compatible and may cause problems for people trying to switch to it.
What I mean is my[h].row = NULL in n_mysql_fetch_row(). As you know, there are people using while(mysql_fetch_row(..)) to fetch their data, but even though they use this function, they also use fetching single fields, so their code looks like:
Code:
while(mysql_fetch_row(..))
{
mysql_fetch_field("blah",dest);
mysql_fetch_field("blah",dest);
mysql_fetch_field("blah",dest);
}
This code, however, will not work properly and it will retrieve only half of actual rows, because mysql_fetch_row() fetches one row and "frees" it, and then the first mysql_fetch_field() fetches another row.

To fix that, you can simply remove my[h].row = NULL from n_mysql_fetch_row(). You do it anyway in mysql_free_result(), so it definitely won't cause any problems.
And if there's something, which can make users want to switch, then why not?

Actually, you could also provide a native which they could put in a while() instead of b_mysql_fetch_row(), which would simply call the mysql_fetch_row() in order to fill my[h].row without returning any PAWN string. It would make users to be able to switch really easily, it would be a mix of efficiency and compatibility.
Reply
#64

Thanks for the mysql_fetch_field catch and the idea, I've fixed mysql_fetch_field, and added mysql_fetch_row_data, which will be able to work with mysql_fetch_field. I want to test it a little more, I'll be uploading it soon.

EDIT:

Updated.

[anchor=mysql_fetch_row_data]_________________________________________________

How to use mysql_fetch_row_data

Example usage:

(Although I suggest you to use mysql_fetch_row with split or sscanf)

Here is an example of loading all the houses from a table:
Code:
mysql_query("SELECT * FROM `houses`");
mysql_store_result();
new buffer[64];
new int i = 0;
while(mysql_fetch_row_data())
{
	mysql_fetch_field("X", buffer);
	// Here you would set the house X coord to: floatstr(buffer);
	mysql_fetch_field("Y", buffer);
	// Here you would set the house Y coord to: floatstr(buffer);
	mysql_fetch_field("Z", buffer);
	// Here you would set the house Z coord to: floatstr(buffer);


	mysql_fetch_field("owner", buffer);
	// Here you would set the house owner to: strval(buffer);
	mysql_fetch_field("price", buffer);
	// Here you would set the house price to: strval(buffer);

	i++;
}
printf("%d total houses loaded.", i);
mysql_free_result();
Here is an example on loading a players info for login:

Code:
mysql_query("SELECT * FROM `accounts` where `name` = 'PLAYERNAME'");
mysql_store_result();
new buffer[64];
if(mysql_fetch_row_data())
{
	mysql_fetch_field("money", buffer);
	// Here you would set the players money to: strval(buffer);

	mysql_fetch_field("kills", buffer);
	// Here you would set the players kills to: strval(buffer);

	mysql_fetch_field("deaths", buffer);
	// Here you would set the players deaths to: strval(buffer);

	// Set variable that the player is logged in.

	mysql_free_result();
}
else
{
	// No rows could be fetched thus the account does not exist.
}
Reply
#65

Great

Damn i love this plugin
Reply
#66

Код:
mysql.inc(24) : error 010: invalid function or declaration
mysql.inc(24) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(25) : error 010: invalid function or declaration
mysql.inc(25) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(26) : error 010: invalid function or declaration
mysql.inc(26) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(30) : error 010: invalid function or declaration
mysql.inc(31) : error 010: invalid function or declaration
mysql.inc(31) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(32) : error 010: invalid function or declaration
mysql.inc(32) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(33) : error 010: invalid function or declaration
mysql.inc(33) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(34) : error 010: invalid function or declaration
mysql.inc(34) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(35) : error 010: invalid function or declaration
mysql.inc(35) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(36) : error 010: invalid function or declaration
mysql.inc(36) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(37) : error 010: invalid function or declaration
mysql.inc(37) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(38) : error 010: invalid function or declaration
mysql.inc(38) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(39) : error 010: invalid function or declaration
mysql.inc(39) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(40) : error 010: invalid function or declaration
wtf ?
Reply
#67

Quote:
Originally Posted by Bacovsky
Код:
mysql.inc(24) : error 010: invalid function or declaration
mysql.inc(24) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(25) : error 010: invalid function or declaration
mysql.inc(25) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(26) : error 010: invalid function or declaration
mysql.inc(26) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(30) : error 010: invalid function or declaration
mysql.inc(31) : error 010: invalid function or declaration
mysql.inc(31) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(32) : error 010: invalid function or declaration
mysql.inc(32) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(33) : error 010: invalid function or declaration
mysql.inc(33) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(34) : error 010: invalid function or declaration
mysql.inc(34) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(35) : error 010: invalid function or declaration
mysql.inc(35) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(36) : error 010: invalid function or declaration
mysql.inc(36) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(37) : error 010: invalid function or declaration
mysql.inc(37) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(38) : error 010: invalid function or declaration
mysql.inc(38) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(39) : error 010: invalid function or declaration
mysql.inc(39) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(40) : error 010: invalid function or declaration
wtf ?
You changed what?
Reply
#68

pawn Код:
[Tue Feb 16 21:51:27 2010] Error (0): Callback: OnMysqlQuery not found.
I'm getting this error when the function is in my script..

pawn Код:
public OnMysqlQuery(resultid, spareid, MySQL:connection)
{
    switch(resultid)
    {
      // Code
    }
    return 1;
}
Reply
#69

Quote:
Originally Posted by MenaceX^
Quote:
Originally Posted by Bacovsky
Код:
mysql.inc(24) : error 010: invalid function or declaration
mysql.inc(24) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(25) : error 010: invalid function or declaration
mysql.inc(25) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(26) : error 010: invalid function or declaration
mysql.inc(26) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(30) : error 010: invalid function or declaration
mysql.inc(31) : error 010: invalid function or declaration
mysql.inc(31) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(32) : error 010: invalid function or declaration
mysql.inc(32) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(33) : error 010: invalid function or declaration
mysql.inc(33) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(34) : error 010: invalid function or declaration
mysql.inc(34) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(35) : error 010: invalid function or declaration
mysql.inc(35) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(36) : error 010: invalid function or declaration
mysql.inc(36) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(37) : error 010: invalid function or declaration
mysql.inc(37) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(38) : error 010: invalid function or declaration
mysql.inc(38) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(39) : error 010: invalid function or declaration
mysql.inc(39) : error 001: expected token: ";", but found "-identifier-"
mysql.inc(40) : error 010: invalid function or declaration
wtf ?
You changed what?
nothing
Reply
#70

nvm fixed, <3 Ash
Reply
#71

Nice work Ethan.
Reply
#72

how to read an txt?
Reply
#73

Inline assembly is not always the best choice.

Edit:
Oops that comment should be direct towards the SDK developers.

_beginthreadex calls CreateThread/CreateThreadEx, since you have all the pp macros why not use the win32 equivalent as opposed to the CRT functions?
in n_mysql_connect(...) you have:
Код:
if (!mysql_real_connect(my[h].mysql, host, user, pass, db, 0, NULL, 0))
	{
		delete host;
		delete user;
		delete pass;
		delete db;
		GenerateError(h, "Failed to connect.", mysql_errno(my[h].mysql));
		return -1;
	}
	mysql_options(my[h].mysql, MYSQL_OPT_RECONNECT, &my[h].reconnect);
	logprintf("MySQL: Connected (%d) to %s @ %s. MySQL version %s.", h, user, mysql_get_host_info(my[h].mysql), mysql_get_server_info(my[h].mysql));
	if (my[h].logging == LOG_ALL)
		Log("Connected (%d) to %s @ %s. MySQL version %s.", h, user, mysql_get_host_info(my[h].mysql), mysql_get_server_info(my[h].mysql));
	delete host;
	delete user;
	delete pass;
	delete db;
	my[h].connected = true;
	return h;
wouldnt the code below have the same result but less instructions?:
Код:
if (mysql_real_connect(my[h].mysql, host, user, pass, db, 0, NULL, 0))
	{
		mysql_options(my[h].mysql, MYSQL_OPT_RECONNECT, &my[h].reconnect);
		logprintf("MySQL: Connected (%d) to %s @ %s. MySQL version %s.", h, user, mysql_get_host_info(my[h].mysql), mysql_get_server_info(my[h].mysql));
		if (my[h].logging == LOG_ALL)
			Log("Connected (%d) to %s @ %s. MySQL version %s.", h, user, mysql_get_host_info(my[h].mysql), mysql_get_server_info(my[h].mysql));
		my[h].connected = true;
	} else {
		GenerateError(h, "Failed to connect.", mysql_errno(my[h].mysql));
		h = -1;
	}
	delete host;
	delete user;
	delete pass;
	delete db;
	return h;
And does GetParam(...) return a COPY of the parameter?

Overall i saw alot of redundant code. This is not very fast at all...
Reply
#74

Hi,

I'm having problems with my gothfather script, when I send 6 UPDATE queries, it stops and starts updating all the stats over and over again... (but not all of them)
Maybe because the memory is full or something else.. will it help when I put them in threads?

Grrtz,
Jack_fox
Reply
#75

Quote:
Originally Posted by Jack_Fox
Hi,

I'm having problems with my gothfather script, when I send 6 UPDATE queries, it stops and starts updating all the stats over and over again... (but not all of them)
Maybe because the memory is full or something else.. will it help when I put them in threads?

Grrtz,
Jack_fox
It would help a lot if you posted the 6 queries (code) that you're having a problem with and I can help.
Reply
#76

Quote:
Originally Posted by »Julian™«
Ok guys due I am not a pro MYSQL coder I need someone to add me on msn and go true my GM to transfer hole it into MYSQL I know you want money for that but to bad I got no cash for it .. What can I offer them? Admin , Scripter position , Credits or something similar just add my msn
brunchy@serverz4life.co.uk and we can discuss about it . I would appreciate if stricten added me on msn and helped me out or anyone else to :P
Admin is a job, none will do it for you if you don't pay him/her.
Reply
#77

Quote:
Originally Posted by MenaceX^
Quote:
Originally Posted by »Julian™«
Ok guys due I am not a pro MYSQL coder I need someone to add me on msn and go true my GM to transfer hole it into MYSQL I know you want money for that but to bad I got no cash for it .. What can I offer them? Admin , Scripter position , Credits or something similar just add my msn
brunchy@serverz4life.co.uk and we can discuss about it . I would appreciate if stricten added me on msn and helped me out or anyone else to :P
Admin is a job, none will do it for you if you don't pay him/her.
I'm not asking him/her to re code my GM I'm asking him/her to go true it and explain for me how it works .. As I am not the best reader I need someone to explain and give me hints..
Reply
#78

Quote:
Originally Posted by »Julian™«
Quote:
Originally Posted by MenaceX^
Quote:
Originally Posted by »Julian™«
Ok guys due I am not a pro MYSQL coder I need someone to add me on msn and go true my GM to transfer hole it into MYSQL I know you want money for that but to bad I got no cash for it .. What can I offer them? Admin , Scripter position , Credits or something similar just add my msn
brunchy@serverz4life.co.uk and we can discuss about it . I would appreciate if stricten added me on msn and helped me out or anyone else to :P
Admin is a job, none will do it for you if you don't pay him/her.
I'm not asking him/her to re code my GM I'm asking him/her to go true it and explain for me how it works .. As I am not the best reader I need someone to explain and give me hints..
Learn, like everyone does.
Reply
#79

Quote:
Originally Posted by MenaceX^
Quote:
Originally Posted by »Julian™«
Quote:
Originally Posted by MenaceX^
Quote:
Originally Posted by »Julian™«
Ok guys due I am not a pro MYSQL coder I need someone to add me on msn and go true my GM to transfer hole it into MYSQL I know you want money for that but to bad I got no cash for it .. What can I offer them? Admin , Scripter position , Credits or something similar just add my msn
brunchy@serverz4life.co.uk and we can discuss about it . I would appreciate if stricten added me on msn and helped me out or anyone else to :P
Admin is a job, none will do it for you if you don't pay him/her.
I'm not asking him/her to re code my GM I'm asking him/her to go true it and explain for me how it works .. As I am not the best reader I need someone to explain and give me hints..
Learn, like everyone does.
That's why I want a "mentor" that can explain than tutorials and reading of books when I won't understand a small thing .. If you want to give me some information then add my msn..
Reply
#80

no i know what that means but... idk how to connect
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)