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

There is some way to get cache fields result and sscanf it to an enum?

Like i was doing on R6 using mysql_store_result + retrieve row then sscanf all recieved data for enum... Or i have to do it manually?


Ex:
Quote:

enum Data
{
name[24],
pass[32],
money
}

new PlayerInfo[MAX_PLAYERS][Data];

on query execute:

format: "SELECT * FROM `users` WHERE NAME = 'n0minal';
then send mysql query, store data and retrieve row
use sscanf(query, "all formats for enum here", PlayerInfo[playerid]);

Is possible with cache or i have to do like:

PlayerInfo[playerid][name] = cache_get_content(bla bla bla bla);

Reply

Quote:
Originally Posted by n0minal
Посмотреть сообщение
There is some way to get cache fields result and sscanf it to an enum?

Like i was doing on R6 using mysql_store_result + retrieve row then sscanf all recieved data for enum... Or i have to do it manually?


Ex:
You don't need to use sscanf to store the result, just use cache_get_* natives to get your data.

I'd recommend checking out this tutorial (click me) by AndreT.
Reply

Quote:
Originally Posted by n0minal
Посмотреть сообщение
There is some way to get cache fields result and sscanf it to an enum?

Like i was doing on R6 using mysql_store_result + retrieve row then sscanf all recieved data for enum... Or i have to do it manually?


Ex:
pawn Код:
enum Data
{
    name[24],
    pass[32],
    money
}

new PlayerInfo[MAX_PLAYERS][Data];

function SQL_GetsInf(...){

    for(new q; q < 1; q++){
        sscanf(Data, "p<§>s[24]s[32]d",PlayerInfo[q]);
        printf("%s",PlayerInfo[i][name]);
                printf(...);
    }

    return true;
}
Reply

Quote:
Originally Posted by iZN
Посмотреть сообщение
You don't need to use sscanf to store the result, just use cache_get_* natives to get your data.

I'd recommend checking out this tutorial (click me) by AndreT.
This is the point, my enums have a lot of params and i don't want to do it manually, i prefer to use sscanf instead use 100 times cache_get_content without it...
Reply

@Dusk : What if the "i" index is pointing on a Float: tagged variable in the enum ? And what about booleans, or about arrays ? (In both the database AND the server variables)

My way to fix it was to check what tag does the variable has using tagof and then using the good function (or, about booleans, just adding a bool: before the cache_get_row_int).
To fix it for arrays, I checked out whether the variable[1] index existed. If so, then that was a string. Else, then it wasn't a string (by saying "string" I also refer to arrays).
Reply

Update links please
Reply

You can still concatenate a whole row into a single string and use sscanf to split it up again (kind of pointless, but if you prefer it this way, okay):
Код:
public OnDataLoad()
{
	new 
		rows = cache_num_rows(),
		fields = cache_num_fields();
	
	for(new r; r < rows; r++)
	{
		new 
			data[2048],
			field_tmp[128];
		for(new f; f < fields; f++)
		{
			cache_get_row(r, f, field_tmp);
			if(f != 0)
				strcat(data, "|");
			strcat(data, field_tmp);
		}
		
		sscanf(data, "...", PlayerData[r]);
	}
}
Reply

Quote:
Originally Posted by maddinat0r
Посмотреть сообщение
You can now access every row independently by its index through cache_get_row and cache_get_field_content.
What was
Код:
new data[4];
new row_data[128];
while(mysql_fetch_row_format(row_data))
{
    sscanf("p<|>...", data[0], data[1], ...);
}
is now
Код:
new data[4];
for(new r=0; r < cache_num_rows(); r++)
{
    data[0] = cache_get_row_int(r, 0); //store the first field (index '0') into data[0]
    data[1] = cache_get...
}
Okay, tried this but this makes the script stuck. As in it doesnt advance on, I am printing "Loading bla bla" and once everything is loaded I print "Loaded bla bla" but with the code you gave it doesnt proceed ahead from "Loading bla bla". Any reasons or whatever ?
Reply

Quote:
Originally Posted by iReacheR
Посмотреть сообщение
Okay, tried this but this makes the script stuck. As in it doesnt advance on, I am printing "Loading bla bla" and once everything is loaded I print "Loaded bla bla" but with the code you gave it doesnt proceed ahead from "Loading bla bla". Any reasons or whatever ?
You may want to show your code.
Reply

Hi, I'm new in MySQL(R39-2) and I don't know how to load strings, ints and floats from database... I made code by some tutorial from 2012(R7 is used in tutorial). I made this:

Код:
			if(mysql_num_rows())
			{
				if(mysql_retrive_row())
				{
					mysql_fetch_field_row(dbQUERY, "ID"); Korisnik[playerid][kID] = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Novac"); Korisnik[playerid][kNovac] = floatstr(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Spol"); _HRP_kSpol{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Godine"); _HRP_kGodine{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(Korisnik[playerid][kGPCI], "GPCI");
					mysql_fetch_field_row(Korisnik[playerid][kRegistracijski_Kod], "Reg_Kod");
					mysql_fetch_field_row(Korisnik[playerid][kIP], "IP");
					mysql_fetch_field_row(dbQUERY, "Skin"); Korisnik[playerid][kSkin] = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Staff"); _HRP_kStaff{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Dan"); _HRP_kDan{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Mjesec"); _HRP_kMjesec{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Godina"); Korisnik[playerid][kGodina] = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Sat"); _HRP_kSat{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Minuta"); _HRP_kMinuta{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Sekunda"); _HRP_kSekunda{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Mute"); Korisnik[playerid][kMute] = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Online_Brojac"); Korisnik[playerid][kOnline_Counter] = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Melee"); _HRP_kMelee{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Melee_Municija"); _HRP_kMelee_Ammo{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Pistolj"); _HRP_kPistol{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Pistolj_Municija"); _HRP_kPistol_Ammo{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Automatik"); _HRP_kAutomatic{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Automatik_Municija"); _HRP_kAutomatic_Ammo{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Eksploziv"); _HRP_kExplosion{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Eksploziv_Municija"); _HRP_kExplosion_Ammo{playerid} = strval(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Pistolj_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY);	
					mysql_fetch_field_row(dbQUERY, "Shotgun_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY);	
					mysql_fetch_field_row(dbQUERY, "UZI_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY);	
					mysql_fetch_field_row(dbQUERY, "Automatik_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY);	
					mysql_fetch_field_row(dbQUERY, "Rifle_Skill"); Korisnik[playerid][kPistol_Skill] = floatstr(dbQUERY);
					mysql_fetch_field_row(dbQUERY, "Kickova"); _HRP_kKickova{playerid} = strval(dbQUERY);	
					mysql_fetch_field_row(dbQUERY, "Banova"); _HRP_kBanova{playerid} = strval(dbQUERY);	
					mysql_fetch_field_row(dbQUERY, "Warnova"); _HRP_kWarnova{playerid} = strval(dbQUERY);										
				}
			}

			mysql_free_result();
I got 26 errors because ''mysql_fetch_field_row'' isn't defined. So, how I can load field then?
Reply

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
Hi, I'm new in MySQL(R39-2) and I don't know how to load strings, ints and floats from database... I made code by some tutorial from 2012(R7 is used in tutorial). I made this:
I got 26 errors because ''mysql_fetch_field_row'' isn't defined. So, how I can load field then?
I just gave an example to someone above you, you may want to see that.

http://forum.sa-mp.com/showpost.php?...postcount=5265

If you have any questions, just ask.
Reply

I don't understand why I need use loop :/
I just need load files of logged player, if u understand me
Reply

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
I don't understand why I need use loop :/
I just need load files of logged player, if u understand me
Don't use loop then.

pawn Код:
mysql_tquery(handle, "SELECT ....", "OnLoadData", "i", playerid);

forward OnLoadData(playerid);
public OnLoadData(playerid)
{
    if(cache_get_row_count())
    {
        // string
        cache_get_field_content(0, "Name", PlayerInfo[playerid][name]); /* OR */ cache_get_row(0, 0, PlayerInfo[playerid][name]);
       
        // integer
        PlayerInfo[playerid][money] = cache_get_field_content_int(0, "Money"); /* OR */ PlayerInfo[playerid][money] = cache_get_row_int(0, 1);

        // float
        PlayerInfo[playerid][health] = cache_get_field_content_float(0, "HP"); /* OR */ PlayerInfo[playerid][health] = cache_get_row_float(0, 2);

        // continue...
    }
    else
    {
        // no data found.. registration stuff here maybe?
    }
    return true;
}
Reply

It'll aThen it'll be like this?

Код:
mysql_format(_HRP_srv_db_conn, sifra, 86, "SELECT * FROM `"_USER_DB"` WHERE Ime = '%e'", _name);
mysql_tquery(_HRP_srv_db_conn, sifra, "_HRP_LoadUser", "dd", playerid, false);

{ ... }

Korisnik[playerid][kID] = cache_get_field_content(dbQUERY, "ID");
Reply

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
It'll aThen it'll be like this?

Код:
mysql_format(_HRP_srv_db_conn, sifra, 86, "SELECT * FROM `"_USER_DB"` WHERE Ime = '%e'", _name);
mysql_tquery(_HRP_srv_db_conn, sifra, "_HRP_LoadUser", "dd", playerid, false);

{ ... }

Korisnik[playerid][kID] = cache_get_field_content(dbQUERY, "ID");
I edited the post above you.
Reply

I don't know what now... I got undefined symbols ''mysql_store_result'' and ''mysql_num_rows'' and ''mysql_retrive_row'' and ''mysql_free_result''....
Reply

Quote:
Originally Posted by vannesenn
Посмотреть сообщение
I don't know what now... I got undefined symbols ''mysql_store_result'' and ''mysql_num_rows'' and ''mysql_retrive_row'' and ''mysql_free_result''....
You must be using it somewhere? I think you haven't converted your script yet, I mean the other MySQL related code.
Reply

So, it'll something happend if I delete that functions?
Reply

Quote:
Originally Posted by iZN
Посмотреть сообщение
You may want to show your code.
pawn Код:
loadStuff()
{
    new rows, fields;
    print("==> Loading the Required Items.");
    cache_get_data(rows, fields);
    if(!rows)
    {
        print("ERROR: The Table you called the query on can't be found. Skipping the loading.");
    }
    else
    {
        if(rows > MAX_CHECKS)
        {
            print("ERROR: Limit exceeded.");
            return 1;
        }
        for(new i = 0; i < rows; i++)
        {
            cache_get_field_content(i, "Name", stuffInfo[i][Name], mysql, 60);
            cache_get_field_content(i, "stuffC", string, mysql, 30); //string declared before the start of the callback.
            stuffInfo[i][ID] = cache_get_field_content_int(i, "stuffID");
        }
        printf("==> Loaded %i of the required stuff", rows);
    }
    return 1;
}
so it gives me the printf("Loading required Items."); After that the console just stucks up there. I know a way of making it work and I have already been using it since forever now but I just was curious as to why the loop stucks up when it should be working.
Reply

Where I can find register system with this plugin?
Reply


Forum Jump:


Users browsing this thread: 4 Guest(s)