• Print

Author Topic: MySQL Question  (Read 4454 times)

0 Members and 1 Guest are viewing this topic.

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
MySQL Question
« on: May 16, 2017, 06:17:58 am »
So I'm new to MySQL (and MySQLOO for gmod) and I'm writing up an addon that will utilize this. It syncs bans between servers, using a MySQL database. Let's say for example, my script runs a query:


Code: Lua
  1. "SELECT * FROM bsync_bans WHERE steamid = %s"


(The query is then string.format'd with the player's SID)


Table setup:


Code: Lua
  1. [[
  2.  
  3.         CREATE TABLE IF NOT EXISTS bsync_bans(        
  4.         steamid VARCHAR( 255 ) NOT NULL,
  5.         nick VARCHAR( 255 ) NOT NULL,
  6.         admin VARCHAR( 255 ) NOT NULL,
  7.         unban VARCHAR( 255 ) NOT NULL,
  8.         reason VARCHAR( 255 ) NOT NULL,
  9.         time VARCHAR( 255 ) NOT NULL,
  10.         PRIMARY KEY ( steamid )
  11.     )
  12. ]]


So let's say for example a player joins. A PlayerInitialSpawn hook checks if the player is in the database anywhere, and if they are, it will ban them. But if they aren't, will the query throw an error, or throw an empty table? I assume that it would throw an error, but I haven't had a chance to test it myself yet, but I'm going to do so in a few hours once I have the chance.
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

Offline captain1342

  • Full Member
  • ***
  • Posts: 104
  • Karma: 6
  • Quality is our standard
    • Aperture Development - Quality is our standard
Re: MySQL Question
« Reply #1 on: May 16, 2017, 06:24:53 am »
You need a check if there was no or an empty response and No it doesen't throw an error it just gives an empty response.

I made such a script actually ;)
Aperture Development
Quality is our standard

Website - GitHub  - Forum  - Steam  - Discord

Offline iViscosity

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 803
  • Karma: 58
Re: MySQL Question
« Reply #2 on: May 16, 2017, 08:06:45 am »
Good to know. I also have another question about ULib. I know there is the ULibCommandCalled to check if a command is called, but what about the specific "ULib.ban" (or addBan or kickban)? Is there a way to check for the call on these and not the "ulx ban" (or "ulx banid") commands?


EDIT: Never mind, I found it.
« Last Edit: May 16, 2017, 08:12:44 am by iViscosity »
I'm iViscosity. I like gaming and programming. Need some help? Shoot me PM.

  • Print