With much anticipation, here is my SQL code: it allows both blocking and non-blocking SQL sockets to be used simultaneously. I’ve tried to be very verbose in my commenting, and I will include some examples later on, too.
This stuff works to the best of my knowledge. If not, leave me a comment and I’ll try to look at it.
- “Non-blocking SQL sockets” are sockets that execute a callback function once the SQL data is retrieved. Ideally, this is how you will access all SQL data. (Technically: This type of socket uses extern_cmds to pipe data to and from the ‘mysql’ command through the use of callbacks)
- “Blocking SQL sockets”, however, are sockets that take 100% of the driver’s attention until the SQL data is received. Nothing else is executed while it is in use. The ONLY reason you would use this type of socket is when you NEED a
response from the SQL server before continuing to the next line of code. (Technically: This type of socket uses efuns compiled into the driver to communicate with the SQL server directly)
- Allow MSSQL, Oracle, and other databases
- Transaction support (Partially implemented so far)
The code contains three distinct sections:
- Shared code
- Exclusively “Non-blocking” code
- Exclusively “Blocking” code
Steps you will need to take to make this usable:
- Compile a driver with SQL support
- Make sure you have a usable SQL server
- Create a database for MUD-related stuff, default ‘mud‘
- Create a user for general-purpose access with only the required permissions (ie, SELECT, INSERT, UPDATE on non-sensitive tables only) and restrict the user to the ‘mud‘ database.
- (Optional, strongly recommended): Create a user for mud-admin access with only the required permissions (ie, SELECT, INSERT, UPDATE, DELETE) and restrict the user to the ‘mud‘ database.
- Place db.h in /secure/include/ and edit it to suit your installation
- Place sql.c in /secure/daemon/
- Edit /secure/daemon/master.c to allow the SQL daemon to access a socket (See attachment)
- Add “external_cmd_1: /usr/bin/mysql” (without the quotes) to /secure/cfg/mudos.cfg
- Create tables to support data for your mud (See attached “mud.sql“)
- Add SQL support to files that you want to be able to access the database (See attached examples)