1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
TinyMUX 2.12: SQL
Last Update: July 2012
~~~~~~~~~~~~~~~~~~~~~~
TinyMUX 2.12 supports both asynchronous and synchronous SQL. The synchronous/
in-line support is similar to that of PennMUSH and TinyMUSH, namely the sql()
function. The asynchronous support is unique to TinyMUX at this time and is
the recommended method for SQL access.
Asynchronous SQL:
~~~~~~~~~~~~~~~~
1) To enable this functionality, you will need to pass --enable-stubslave
to the configure script. If your MySQL is not in the default location,
(namely, /usr/include/mysql and /usr/lib/mysql), then you will need to
tell configure where to find the headers and libraries with the
--with-mysql-include and --with-mysql-libs options. For instance:
./configure --enable-stubslave
--with-mysql-include=/usr/local/mysql/include
--with-mysql-libs=/usr/local/mysql/lib
2) Once the game has been compiled you will need to add six configuration
options to the .conf file. You can check the wizhelp file for more
information regarding the option. The six are listed below:
module sqlproxy
module sqlslave local
sql_database <name of database>
sql_server <localhost or address>
sql_user <MySQL username>
sql_password <MySQL password>
3) Start the game and check the log file. You should see two entries like
the following:
MUX NET/STUB : Stub slave started on fd 3
MUX INI/LOAD : Registered netmux modules.
MUX INI/LOAD : Opened interface for StubSlave management.
To perform MySQL queries you will use the @query command in conjunction
with the rsrelease(), rserror(), rsprev(), rsrecnext(), rsrows(),
rsrec(), rsnext() and rsrecprev() functions. Here's an example:
&FOO.TR me=
@if rserror()=
{
@pemit %#=Rows: [rsrows()];
@if rsrows()=
{
@trig me/bar.tr
}
},
{
@pemit %#=Error: [rserror()]
}
&BAR.TR me=
@pemit %#=rsrec(|);
@if rsnext()=
{
@trig me/bar.tr
}
@query/sql me/foo.tr=/show databases;
4) This method will allow SQL queries to occur without blocking the main game
process. If the SQL is on another machine, slow or even has been disabled
or crashed then the game will not hang while waiting on the result to be
returned.
In-Line/Synchronous SQL:
~~~~~~~~~~~~~~~~~~~~~~~
1) To enable this functionality, you will need to pass --enable-inlinesql
to the configure script. If your MySQL is not in the default location,
(namely, /usr/include/mysql and /usr/lib/mysql), then you will need to
tell configure where to find the headers and libraries with the
--with-mysql-include and --with-mysql-libs options. For instance:
./configure --enable-inlinesql
--with-mysql-include=/usr/local/mysql/include
--with-mysql-libs=/usr/local/mysql/lib
2) Once the game has been compiled you will need to add four configuration
options to the .conf file. The four are listed below:
sql_database <name of database>
sql_server <localhost or address>
sql_user <MySQL username>
sql_password <MySQL password>
3) Start the game and check the log file. You should see two entries like
the following:
SQL/CONN : Connecting: <database>@<address> as <user>
SQL/CONN : Connected to MySQL
You can use the sql() function to perform MySQL queries. See 'help sql()'.
4) The SQL code enabled with --enable-inlinesql runs synchronous with the
TinyMUX process. That means that in the game when you use the sql()
function to make a query, the whole game waits on the query to finish. If
you're on a server which is not overloaded and has good, free resources and
where the MySQL server is running on the same machine then this should not
be a problem as long as the MySQL server remains running. If the server is
overloaded and therefore slow or if the MySQL server is on a different
machine, then there can be a delay in getting the results. That delay will
mean the whole game hangs while waiting.
When using the in-line SQL functionality bear this potential problem in mind.
You should test your game with the SQL functionality first before using it in
a live environment.
|