GetNextSQL Conversion/update Gstyle to BlueG?
#1

G'day!

I am just trying to make something simlilar to this.

pawn Code:
stock GetNextSQL(id[],table[])
{
    format(query,sizeof(query), "SELECT `%s` FROM `%s` ORDER BY `id` ASC", id,table);
    mysql_query(query);
    mysql_store_result();
    new str[256];
    new index = 0;
    new tmp;
    new firstresult;
    new tmpnum;
    if(mysql_num_rows() >= 1)
    {
        while(mysql_fetch_row(str) && !firstresult)
        {
            sscanf(str, "d", tmp);
            tmpnum = index+1;
            if(tmp == 0 && mysql_num_rows() == 1) firstresult = 1;
            else if(tmp == index && tmpnum == mysql_num_rows())
            {
                firstresult = tmpnum;
            }
            else if(tmp == index)
            {
                index++;
            }
            else
            {
                firstresult = index;
            }
        }
    }
    else firstresult = 0;
    return firstresult;
}
However as I believe this is from gstyyllllez Plugin with store_result ect, would someone please be able to show me a conversion or maybe something that does the same as this stock for BlueG's Pluggin and preferably threaded if possible!

Explanations on why or why not it can or can't be made would be great as well as an explanation as to how and what you converted would be great if it's not asking too much :P (Saves me from having to ask a similar question in a few days when I need something converted again :P)

Cheers!
Reply
#2

****** : Of course posting help request here about SQL isn't very clever, because as you've said, it's a forum about the PAWN language, but I don't see like 100 help request per day about SQL for samp elsewhere than here. Lemme explain myself : about %90 of the SQL help posted here are about SAMP, so it's not really the best place to ask, but it's not the worst place anyway.

And, as you said, "SQL Language" is redundant because SQL means "Structured Query Language".

I've made a tutorial in French on "how to optimize your queries", and it's usually a "*" problem. '*' means "all" in MySQL, selecting all the data in the table/database only to use the password (maybe the salt), and the username, it's a little bit idiot, because it's performance wasting.

Author : You're using a very old release of BlueG's plugin. Get the cache functions, it would be better for the performances.
Reply
#3

Quote:
Originally Posted by S4t3K
View Post
'*' means "all" in MySQL, selecting all the data in the table/database only to use the password (maybe the salt), and the username, it's a little bit idiot, because it's performance wasting.
It isn't! You can do the same thing with 1 query instead with 2 your way would use. A query with SELECT clause for all the data for that player, assign them to variables and then comparing the password than selecting the password and if they do match to execute another query with all the data and assign them to variables.
Reply
#4

-.- thank you all! You've all helped greatly! Telling me what type of forum this is, what sql means and that it's completely separate from samp! This all helped heaps!

Okay, on all seriousness, I apologise for the attitude, it's late, I'm tired and clearly I am asking on the wrong forums. Just to me thought that knowledge, is knowledge where ever it is, where ever you source it. Just thought someone with a better understanding of what I am trying to achieve would be able to 'help' me. But again, seems like I am in the wrong forums for 'help'.
Reply
#5

Code:
SELECT `%s` FROM `%s` ORDER BY `id` ASC
This and the whole function you posted in general is -bad practice-! Don't use it. Not every table has an 'id' field. Aswell, only a small portion of your SELECT-queries will actually look like this query.

pawn Code:
return firstresult;
Returning results like that won't work with BlueG's plugin in combinantion with threaded queries as the plugin will call a callback once the query is completed successfully. You'll have to think about another way to process your presented wish.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)