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

Hello, all
I have special function written to R6 MySQL plugin
How can I rewrite it on R7 version?

Quote:

stock fromUnixTime(time)
{
new unbantime[25];
format(str, sizeof(str), "SELECT FROM_UNIXTIME( %d )", time);
if(mysql_query(str) && mysql_store_result())
{
mysql_fetch_row_format(unbantime);
}
mysql_free_result();
return unbantime;
}

Sorry for my English
Reply

The memory leaking isnt fixed in the R7-2 version.
http://pastebin.com/raw.php?i=LGkJexAq
Reply

Quote:
Originally Posted by xxmitsu
Посмотреть сообщение
@kar, comment the entire callback
Sorry the server still restarts
Reply

I am trying to use this feature:

pawn Код:
new string[100];
    format(string, sizeof(string), "SELECT * FROM accounts WHERE Username='Darren'");

    if(mysql_function_query(1, string, true, "Tester", "ss", "1", "1")) print("yes");
    else print("no");
    return 1;
}

forward Tester(playerid[], number[]);
public Tester(playerid[], number[]){
    print("Number:");
    return 1;
}
And what is happening, is the mysql_function_query is return True and saying "yes" in the console. But the "tester" function doesn't get called at all! anyone know why this might be happening?
Reply

Quote:
Originally Posted by DarrenReeder
Посмотреть сообщение
I am trying to use this feature:

pawn Код:
new string[100];
    format(string, sizeof(string), "SELECT * FROM accounts WHERE Username='Darren'");

    if(mysql_function_query(1, string, true, "Tester", "ss", "1", "1")) print("yes");
    else print("no");
    return 1;
}

forward Tester(playerid[], number[]);
public Tester(playerid[], number[]){
    print("Number:");
    return 1;
}
And what is happening, is the mysql_function_query is return True and saying "yes" in the console. But the "tester" function doesn't get called at all! anyone know why this might be happening?
Try without cache (3th parameter set to false)
If its dont work, enable mysql debug (in OnGameModeInit add: mysql_debug(true); ) and check the errors.
Reply

If you want to use threads for queries in a loop (especially with multiple indexes), then it differs a lot from the thread example on the Wiki. I faced this problem today (my queries also had to execute in a pattern) and luckily I solved it. I could not find any additional information about this in this forum so that is why I am sharing it here.

The solution I came up with is recursion. The idea was to keep calling the same function after a query had finished until it matches certain criteria. I will show some snippets below to illustrate what I have done.

This can be improved using mysql_function_query (R7 only).

Код:
#define MAX_STREETS 5
#define MAX_HOUSES 5

new streetHouses[MAX_STREETS][MAX_HOUSES];

#define S_THREAD_STREETS 1

new houseid = 0;

stock CreateStreet(streetid) {
	if(houseid == 0) {
		Thread_CreateStreet(streetid);
	}
	else {		
		print("[CreateStreet]: Thread is busy.");
	}
}

stock Thread_CreateStreet(streetid) {
	if(houseid == MAX_HOUSES) {
		houseid = 0;
		return 1;
	}
	else {
		new query[99];
		
		format(query, sizeof query, 
		"INSERT INTO streets (street_id, house_id, value)\
		VALUES ('%i', '%i', %i)", 
		streetid, houseid, streetHouses[streetid][houseid]);
		
		houseid++;
		mysql_query(query, S_THREAD_STREETS, streetid);
	}
	return 0;
}

public OnQueryFinish(query[], resultid, extraid, connectionHandle) {
    switch(resultid) {
        case S_THREAD_STREETS: {
		if(Thread_CreateStreet(extraid)) {			
			print("[Thread_CreateStreet]: "#MAX_HOUSES" houses have been saved");
		}
        }
        default: {
		printf("Unknown query: (Resultid %d, Connection ID %d, Query: %s)",resultid, connectionHandle, query);
        }
    }
    return 1;
}
A loop using the same variable names would look like this:
Код:
for(new houseid = 0; houseid < MAX_HOUSES; houseid++) {
    // insert houses
}
Reply

Mirror MySQL Plugin R5 for linux ?
Reply

I uploaded R6-2 for windows:

http://www.solidfiles.com/d/b27395ff17/
Reply

@Tr1viUm
What's the advantage of using your recursive method instead of a loop?
Reply

Quote:
Originally Posted by Cank
Посмотреть сообщение
@Tr1viUm
What's the advantage of using your recursive method instead of a loop?
The advantage is that you can actually loop while it is threaded. It is not possible the normal way. I will be using R7 though!
Reply

Quote:

Error: Function not registered: 'mysql_store_result'
Error: Function not registered: 'mysql_retrieve_row'
Error: Function not registered: 'mysql_fetch_field_row'
Error: Function not registered: 'mysql_free_result'
Error: Function not registered: 'mysql_num_rows'
Error: Function not registered: 'mysql_query'
Error: Function not registered: 'mysql_debug'
Error: Function not registered: 'mysql_connect'
Error: Function not registered: 'mysql_ping'
Error: Function not registered: 'mysql_close'
Error: Function not registered: 'mysql_real_escape_string'
Error: Function not registered: 'mysql_fetch_int'

In my window works perfectly in linux gives me these errors.
Someone help me? : (
Reply

There are a few things to make sure of:
1. Does the log say something about the plugin failing to load or loading properly?
2. Is there a .so extension for the plugin in the server.cfg file? This is a common pitfall.

Also, for some awkward reason, the nativechecker plugin constantly keeps reporting that my natives are missing (on Linux) while they actually are present and loaded.
Reply

Yes, I have everything.
Now change the plugin and the errors are:
Quote:

Error: Function not registered: 'mysql_retrieve_row'
Error: Function not registered: 'mysql_fetch_field_row'
Error: Function not registered: 'mysql_debug'

Reply

Which version of this should I be using at the moment to avoid most of these problems, or at least which is the best one currently?


Thanks in advance, MickeyB.
Reply

Mirror MySQL Plugin R5 for linux ?
Reply

BlueG, when you will fix the Memory leak in R7?
Its really annoying.

Ps.: Isnt fixed in R7-2 fully ...
Reply

Quote:
Originally Posted by Sabio
Посмотреть сообщение
Yes, I have everything.
Now change the plugin and the errors are:
Uhuh, but regardless of getting these errors (which, as I said, sometimes can be falsely generated), does the plugin work? Can you post what the console gives when it is trying to load the plugin?

Quote:
Originally Posted by Reboma
Посмотреть сообщение
BlueG, when you will fix the Memory leak in R7?
Its really annoying.

Ps.: Isnt fixed in R7-2 fully ...
I am positive that BlueG also has his own private life and other projects going on. As a side note, how large is this memory leak and have you used some sort of a tracer to perhaps help and find its source (note that I am not exactly familiar with the process)? This could possibly help fixing the memory leak.

Also look at the posts made shortly after BlueG put R7-2 online. Someone describes another situation which could possibly be a memory leak. This could be helpful!
Reply

Please reupload all
Reply

Quote:
Originally Posted by AndreT
Посмотреть сообщение
Uhuh, but regardless of getting these errors (which, as I said, sometimes can be falsely generated), does the plugin work? Can you post what the console gives when it is trying to load the plugin?


I am positive that BlueG also has his own private life and other projects going on. As a side note, how large is this memory leak and have you used some sort of a tracer to perhaps help and find its source (note that I am not exactly familiar with the process)? This could possibly help fixing the memory leak.

Also look at the posts made shortly after BlueG put R7-2 online. Someone describes another situation which could possibly be a memory leak. This could be helpful!
It adds up now

R7-2 fixes, + Zeex's fix, has anyone compiled that yet?
Reply

Please reupload plugin.
Reply


Forum Jump:


Users browsing this thread: 9 Guest(s)