#1

Hi guys. Well I'm not that familiar with MySQL (I'm using R7 Plugin and one friend helped me to create a system using it). Ofcourse, I know that my question is really stupid, but what does actually mean Threaded query and could you give me please, an example.

Edit: before linking to me tutorials how to use search button, let me tell that I already did it and I didn't find anything to help myself.
Reply
#2

Quote:
Originally Posted by x96664
Посмотреть сообщение
Edit: before linking to me tutorials how to use search button, let me tell that I already did it and I didn't find anything to help myself.
Sorry to burst your bubble but there's a tutorial in the BlueG MySQL thread that explains everything.

https://sampforum.blast.hk/showthread.php?tid=337810

Next time you just need to search harder.
Reply
#3

If you know almost nothing about MySQL, you shouldn't be using it!
Reply
#4

Quote:
Originally Posted by ViruZz
Посмотреть сообщение
Sorry to burst your bubble but there's a tutorial in the BlueG MySQL thread that explains everything.

https://sampforum.blast.hk/showthread.php?tid=337810

Next time you just need to search harder.
Actually it's not in his thread, he warns not to use plugin R7 or above if I don't know what threading is. But thank you.

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
If you know almost nothing about MySQL, you shouldn't be using it!
Well I'm learning fast, so this is the only way to learn more.
Reply
#5

For example?

pawn Код:
new query[128];

format(query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%s'", GetName(playerid));
mysql_function_query(dbHandle, query, true, "LoadPlayerStats", "i", playerid);


forward LoadPlayerStats(playerid);
public LoadPlayerStats(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows) //If a row with the player name was found
    {

    }
    else //If not
    {

    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
If you know almost nothing about MySQL, you shouldn't be using it!
Why not? Did you stopped using it when you started using MySQL? Please explain the logic behind your comment.. I'm eager to know.
Reply
#7

Threading means that the plugin will go and run the query while allowing your script to resume execution.
Scenario:
You have two servers running the same gamemode, but using a MySQL server to store common data. In this case we will be handling player house data. You want this data to be loaded into the game mode all the time so that if a player buys a house on server A, server B will also show the house icon. Well if you're running a fairly popular server then you will end up having a lot of housing data. You want this data synchronized about every minute (for purpose of this example), however this is causing much lag while the plugin is going to the MySQL server to fetch the data. The script is waiting for the plugin to get the data before it can do anything else. So player updates are frozen during this time.
This is where threaded queries would help out. If you were to launch a threaded query to fetch the house data the plugin would run the query, while allowing the script to execute. Once the query has ran and the plugin has all the data, it will execute the specified callback in the script. Once this callback gets executed then your script will get all the data from the query, and you can process it as efficiently as you can.
Any questions?
Reply
#8

@Prodigy: Learn the language itself. Read up on how to use queries effectively and stuff like that. Learn what threading is and why it has such a benefit. I mean like seriously, do I have to explain this?
Reply
#9

Quote:
Originally Posted by PaulDinam
Посмотреть сообщение
For example?

pawn Код:
new query[128];

format(query, sizeof(query), "SELECT * FROM `users` WHERE `name` = '%s'", GetName(playerid));
mysql_function_query(dbHandle, query, true, "LoadPlayerStats", "i", playerid);


forward LoadPlayerStats(playerid);
public LoadPlayerStats(playerid)
{
    new rows, fields;
    cache_get_data(rows, fields);
    if(rows) //If a row with the player name was found
    {

    }
    else //If not
    {

    }
    return 1;
}
Quote:
Originally Posted by dowster
Посмотреть сообщение
Threading means that the plugin will go and run the query while allowing your script to resume execution.
Scenario:
You have two servers running the same gamemode, but using a MySQL server to store common data. In this case we will be handling player house data. You want this data to be loaded into the game mode all the time so that if a player buys a house on server A, server B will also show the house icon. Well if you're running a fairly popular server then you will end up having a lot of housing data. You want this data synchronized about every minute (for purpose of this example), however this is causing much lag while the plugin is going to the MySQL server to fetch the data. The script is waiting for the plugin to get the data before it can do anything else. So player updates are frozen during this time.
This is where threaded queries would help out. If you were to launch a threaded query to fetch the house data the plugin would run the query, while allowing the script to execute. Once the query has ran and the plugin has all the data, it will execute the specified callback in the script. Once this callback gets executed then your script will get all the data from the query, and you can process it as efficiently as you can.
Any questions?
This 2 answers were, what I exactly needed. Thank you!
Reply
#10

Quote:
Originally Posted by x96664
Посмотреть сообщение
This 2 answers were, what I exactly needed. Thank you!
Glad I could help. There is one problem with what you have there. There is no reference to the result and you may want to read more into how this works.

Quote:
Originally Posted by ******
Посмотреть сообщение
The plugins are not provided for people to learn SQL, they are provided for people who already know SQL. It is an incredibly powerful language, but one that is very hard to get right, even for the experts. If you learn as you go, there's a high chance you will miss out on all the information regarding potential security holes littering your code as a result of using it (and no, one basic tutorial mentioning escaping strings is not adequate protection). 90% of the SQL on these forums is insecure, inefficient rubbish because people tried to learn on the job instead of learning first then using that knowledge.
These are very wise words. I resemble the pretty much what ****** depicted and it is not the way to do things. Granted you can learn from your mistakes, but often it is better to just start out by looking at as many tutorials as you can and taking notes. Note taking is a skill which should be retained all throughout life and is not something that should be tossed aside as you finish school. Figure out what you want to accomplish, find the tools you need, and learn the basics and best practices of utilizing such tools.

Now is learning by doing a bad thing? Certainly not. However, when learning by doing you should never be working on the actual project. Start with simpler side projects and then step up once you are comfortable that you know what you're doing.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)