PDA

View Full Version : [Request] Database tutorial


sim242
10-05-2014, 11:23
Hey guys, some of you may know me but most probably don't. I really enjoy scripting plugins and it's a big hobby for me but I'm extremely limited on the complexity and functionality of plugins I create as I don't know how to implement database usage into plugins.

I'm not new to scripting using SourcePawn and as I said I really enjoy it so I'd be extremely grateful if a more experienced scripter that has some time on their hands could make a tutorial thread explaining how to use databases in SourcePawn e.g. How to connect to a db, how to close a connection, what threaded and non-threaded is, how to create tables within the plugin, how to retrieve data from the databases, etc.

I can understand people not wanting to create this tutorial as I'm aware it would probably be quite a drain on peoples time but like I've said I'd be extremely grateful to anyone willing to create this tutorial for all the less experienced scripters in order for them to get better.

P.S. I've taken a look at the Sourcemod wiki documentation but I find it to be quite confusing and personally I feel it lacks a lot of explanation on usage and proper implementation.

Neuro Toxin
10-05-2014, 19:16
https://wiki.alliedmods.net/SQL_(SourceMod_Scripting)

Neuro Toxin
10-05-2014, 19:20
This is the best documentation. I would just be explaining whats in the Wiki. Maybe you should ask specific questions where you are getting stuck?

In regards to Threaded V Non-Threaded. Just think of it this way. If your query is Non-Threaded and takes 1 second to complete. The whole game server is frozen for one second while the query completes.

If the quert is Threaded. The server is free to process during the second it takes for the query to complete, and a callback function is called once the query has completed, so your script can be notified of the completion for further processing.

sim242
10-05-2014, 19:37
Thanks for the help Neuro Toxin, what kind of situation would you use a Non-Threaded query if it freezes the game server?

xf117
10-05-2014, 19:51
Thanks for the help Neuro Toxin, what kind of situation would you use a Non-Threaded query if it freezes the game server?

It will only freeze if response is gonna be delayed.
If you have SqLite database, which is basically a local file, there is usually no need to make a threaded quarries.

Neuro Toxin
10-05-2014, 19:54
xf117 is spot on.

If you use SqLite, dont bother.

If you use MySQL, I suggest you make all queries threaded :)

sim242
10-05-2014, 19:56
Thanks for the help guys, going to look into this when I get some extra time.

psychonic
10-05-2014, 21:42
It will only freeze if response is gonna be delayed.
If you have SqLite database, which is basically a local file, there is usually no need to make a threaded quarries.

xf117 is spot on.

If you use SqLite, dont bother.
You wouldn't have network latency with SQLite, but disk IO isn't free and isn't necessarily instant, especially with other servers/services running on the server.

There is almost no case in which you should not use threaded queries.

Neuro Toxin
10-05-2014, 22:04
I can agree,

And some game service providers may not use RAID or SSD drives which could result in very slow read/write speeds.

You also need to consider if you end with with 1 million records, even the fastest SSD drives will have a delay even on very simple SELECT queries.