[Plugin] [REL] MySQL Plugin (Now on github!)

Quote:
Originally Posted by AndreT
View Post
Maxips2, there's a bug with the sizeof operator and enums used together.

pawn Code:
enum e_TOP_TEN
{
    FINISH_MS,
    PLAYER_REGID,
    PLAYER_NAME[MAX_PLAYER_NAME]
}
new raceTopTen[10][e_TOP_TEN];
Using this example enumeration, you would expect
pawn Code:
sizeof(raceTopTen[0][PLAYER_NAME])
to return something it is not going to return.

So you'll have to explicitly (as of plugin R8 or something like that) specify the 4th and 5th parameters (connection and sizeof destination) in your cache_get_row_line.
pawn Code:
cache_get_row(0, 0, gServerInfo[serverHostname], 1, 64);
// or...
cache_get_row(0, 0, gServerInfo[serverHostname], .max_len=64);
Source

I was actually thinking of releasing a plugin myself, perhaps called "Simple MySQL plugin" or something due to its stripped down nature (everything except for the cache-related and required functions are removed). Also never have I had to face a crash due to the plugin.
I can vouch, but still I would call it minor if you can specify the parameters and make it, which is easy to do.
Reply

Код:
public OnPlayerConnect( playerid )
{
	format( gsQuery, 128, "SELECT * FROM `Banlist` WHERE `IP` = '%s' OR `Name` = '%s'", GetPlayerIPEx( playerid ), PlayerName( playerid ) );
    mysql_function_query( g_Handle, gsQuery, true, "BanListCheck", "i", playerid );
    return 1;
}
Callback:
Код:
SQL_Function BanListCheck( playerid )
{
    if ( !IsPlayerConnected( playerid ) )
        return 1;

	new count_rows, fields;
    cache_get_data( count_rows, fields, g_Handle );

    if ( !count_rows )
		OnPlayerConnectEx( playerid );
	else
	{
		new bField[ 6 ][ 128 ];

	    cache_get_field_content( 0, "Reason", bField[ 0 ] );
	    cache_get_field_content( 0, "Admin", bField[ 1 ] );
	    cache_get_field_content( 0, "BanDate", bField[ 2 ] );
	    cache_get_field_content( 0, "BanTime", bField[ 3 ] );
	    cache_get_field_content( 0, "BanDays", bField[ 4 ] );
	    cache_get_field_content( 0, "Aproove", bField[ 5 ] );

		if ( strval( bField[ 4 ] ) < getdate( ) )
			OnPlayerConnectEx( playerid );
		else
		{
			if ( strval( bField[ 5 ] ) != 0 )
			    OnPlayerConnectEx( playerid );
			else
			{
			    TextDrawShowForPlayer( playerid, Ban_Backround );
		        TextDrawShowForPlayer( playerid, Ban_Info );
		        TextDrawShowForPlayer( playerid, Ban_Message );
		        TextDrawShowForPlayer( playerid, Ban_Details_TD );
		        TextDrawShowForPlayer( playerid, Ban_Mistake );

		        format( gsString, 512, "~y~~h~Banned by Administrator: %s~n~Ban Date: %s~n~Ban Time: %s~n~Ban Reason: %s", bField[ 1 ], bField[ 2 ], bField[ 3 ], bField[ 0 ] );
				TextDrawSetString( Ban_Details[ playerid ], gsString );
				TextDrawShowForPlayer( playerid, Ban_Details[ playerid ] );

				SetTimerEx( "KickPlayer", 3500, false, "e", playerid );
			}
		}
	}
	return 1;
}
- After this callback is called, my server getting a nice crash ...
Reply

Found a bug (only Linux Server)

Current Version: Linux r14 (Static Build)

Код:
mysql_format(cH,string,"UPDATE Accounts SET Pos_y=%f WHERE Nummer=15808 LIMIT 1;",-1705.123456);
-> Servercrash, I don't know why, I think theres a bug in the plugin.
But only if the script is running on a linux server, there isn't a problem with windows.
Reply

Quote:
Originally Posted by Pille_
Посмотреть сообщение
Found a bug (only Linux Server)

Current Version: Linux r14 (Static Build)

Код:
mysql_format(cH,string,"UPDATE Accounts SET Pos_y=%f WHERE Nummer=15808 LIMIT 1;",-1705.123456);
-> Servercrash, I don't know why, I think theres a bug in the plugin.
But only if the script is running on a linux server, there isn't a problem with windows.
My Server crashes also on windows ...
Reply

Are you sure?
Maybe it causes another bug.
Reply

Quote:
Originally Posted by Pille_
Посмотреть сообщение
Are you sure?
Maybe it causes another bug.
I don't know. That's the reason why i asking. And the crashdetect outputs me strange warnings:
Код:
[16:58:44] [debug] Server crashed due to an unknown error
[16:58:44] [debug] Thread backtrace:
[16:58:45] [debug] #0  0049D286 in ?? () from E:\WOS\Build 29\samp-server.exe
[16:58:45] [debug] #1  004966C1 in ?? () from E:\WOS\Build 29\samp-server.exe
[16:58:45] [debug] #2  75C01154 in BaseThreadInitThunk () from C:\Windows\system32\kernel32.dll
[16:58:45] [debug] #3  778BB299 in RtlInitializeExceptionChain () from C:\Windows\SYSTEM32\ntdll.dll
[16:58:45] [debug] #4  778BB26C in RtlInitializeExceptionChain () from C:\Windows\SYSTEM32\ntdll.dll
...
Reply

Anyone got the latest MySQL plugin .so for CentOS?
Reply

Quote:
Originally Posted by Edvin
Посмотреть сообщение
I don't know. That's the reason why i asking. And the crashdetect outputs me strange...
I can help you, but you have to show more information.
When is the server crashing?
Show me the code where it happens.
Reply

Quote:
Originally Posted by RobinOwnz
Посмотреть сообщение
Anyone got the latest MySQL plugin .so for CentOS?
You can use the static version of the plugin, it works pretty well for me using CentOS 6.3
Reply

Quote:
Originally Posted by Vladeksh
Посмотреть сообщение
You can use the static version of the plugin, it works pretty well for me using CentOS 6.3
Using the static version or the normal one, I get this:

"/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by plugins/mysql.so)"
Reply

Quote:
Originally Posted by RobinOwnz
Посмотреть сообщение
Using the static version or the normal one, I get this:

"/usr/lib/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by plugins/mysql.so)"
Use:
Код:
yum provides libstdc++.so.6
And install the package that contains the necessary file, if you do not find the package with the file, you should install additional repositories.
Reply

Quote:
Originally Posted by Pille_
Посмотреть сообщение
I can help you, but you have to show more information.
When is the server crashing?
Show me the code where it happens.
It crashing when i connect at the server and when the thread is pharsing... i will show more info (also the OnPlayerConnectEx)
Reply

Okey, nice..
But, it work to debian-5.0 linux ?
Reply

Quote:
Originally Posted by Edvin
Посмотреть сообщение
Код:
public OnPlayerConnect( playerid )
{
	format( gsQuery, 128, "SELECT * FROM `Banlist` WHERE `IP` = '%s' OR `Name` = '%s'", GetPlayerIPEx( playerid ), PlayerName( playerid ) );
    mysql_function_query( g_Handle, gsQuery, true, "BanListCheck", "i", playerid );
    return 1;
}
Callback:
Код:
SQL_Function BanListCheck( playerid )
{
    if ( !IsPlayerConnected( playerid ) )
        return 1;

	new count_rows, fields;
    cache_get_data( count_rows, fields, g_Handle );

    if ( !count_rows )
		OnPlayerConnectEx( playerid );
	else
	{
		new bField[ 6 ][ 128 ];

	    cache_get_field_content( 0, "Reason", bField[ 0 ] );
	    cache_get_field_content( 0, "Admin", bField[ 1 ] );
	    cache_get_field_content( 0, "BanDate", bField[ 2 ] );
	    cache_get_field_content( 0, "BanTime", bField[ 3 ] );
	    cache_get_field_content( 0, "BanDays", bField[ 4 ] );
	    cache_get_field_content( 0, "Aproove", bField[ 5 ] );

		if ( strval( bField[ 4 ] ) < getdate( ) )
			OnPlayerConnectEx( playerid );
		else
		{
			if ( strval( bField[ 5 ] ) != 0 )
			    OnPlayerConnectEx( playerid );
			else
			{
			    TextDrawShowForPlayer( playerid, Ban_Backround );
		        TextDrawShowForPlayer( playerid, Ban_Info );
		        TextDrawShowForPlayer( playerid, Ban_Message );
		        TextDrawShowForPlayer( playerid, Ban_Details_TD );
		        TextDrawShowForPlayer( playerid, Ban_Mistake );

		        format( gsString, 512, "~y~~h~Banned by Administrator: %s~n~Ban Date: %s~n~Ban Time: %s~n~Ban Reason: %s", bField[ 1 ], bField[ 2 ], bField[ 3 ], bField[ 0 ] );
				TextDrawSetString( Ban_Details[ playerid ], gsString );
				TextDrawShowForPlayer( playerid, Ban_Details[ playerid ] );

				SetTimerEx( "KickPlayer", 3500, false, "e", playerid );
			}
		}
	}
	return 1;
}
- After this callback is called, my server getting a nice crash ...
It's most likely your textdraw string. Maximum string length is like 256, 1024 without any colours.
Reply

R7 and libmysql Mirror pls?
i cant download it from http://files.g-stylezzz.com.
Reply

BlueG you should post mirrors man we need it.
Reply

Can you please, PLEASE, add mysql_wait(handle) function? I NEED to return last insert ID. But instead I have to go through lots of stuff because apparently multi-threading is better. I need a function to damn delay my own server if I want to.
Reply

The R7 on the thread causes crashes, here is R8/R7 (stable) versions:

https://code.******.com/p/sa-mp-mysq...downloads/list

They don't crash on me
Reply

Quote:
Originally Posted by Morozzzko
Посмотреть сообщение
Can you please, PLEASE, add mysql_wait(handle) function? I NEED to return last insert ID. But instead I have to go through lots of stuff because apparently multi-threading is better. I need a function to damn delay my own server if I want to.
You can use mysql_insert_id:
https://sampwiki.blast.hk/wiki/MySQL#mysql_insert_id

But in your threaded query you must not use the cache feature (I haven't tested with cache)
pawn Код:
public SomeQuery()
{
    // ...
    mysql_format(mysql, query, "INSERT INTO vehicle (Model) VALUES (%i)", model);
    mysql_function_query(mysql, query, false, "InsertMySQL", "i", playerid);
    return 1;
}

public InsertMySQL(playerid)
{
    SendFormatMessage(playerid, -1, "SERVER: INSERT registered with ID %d", mysql_insert_id());
    return 1;
}
Reply

Seems like you did not quite understand me. I said RETURN last insert id. Not just use it. I am not completely stupid.
Let me give you an example of what I need.
Код:
stock foo() {
    mysql_query(...);
    ...
    return mysql_insert_id();
}

main() {
     printf("Last insert ID: %d", foo());
}
I can not do that anymore, can I? The stuff is threaded and I need the result right now. And when I say right now I mean it.
---
Yeah I know the code makes no sense. But that is just an example. I use returns in more complex scripts. I want everything organized and good. This threaded-only stuff just makes me write bad, disorganized code.
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)