|
| 1 | +Connection commands |
| 2 | +=================== |
| 3 | + |
| 4 | +dbCreateConnection configName |
| 5 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 6 | + |
| 7 | +Creates a connection based on details in the :doc:`config file </intro/config-file>` in ``accounts.<configName>`` |
| 8 | + |
| 9 | +.. note:: |
| 10 | + Connection is not established until the first query. |
| 11 | + |
| 12 | +:configName: ``<STRING>`` - The config name of the connection |
| 13 | + |
| 14 | +.. attention:: |
| 15 | + configName is case-sensitive |
| 16 | + |
| 17 | +Returns: <DBConnection> |
| 18 | + |
| 19 | + |
| 20 | +dbCreateConnection [ip, port, user, pw, db] |
| 21 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 22 | + |
| 23 | +Creates a connection. |
| 24 | + |
| 25 | +.. note:: |
| 26 | + Connection is not established until the first query. |
| 27 | + |
| 28 | +:ip: ``<STRING>`` - the IP Address or Domain of the database server |
| 29 | +:port: ``<NUMBER>`` - the port of the database server (usually 3306) |
| 30 | +:user: ``<STRING>`` - the user to log in with |
| 31 | +:pw: ``<STRING>`` - the password (duh) |
| 32 | +:db: ``<STRING>`` - the database to use (Equal to `use <db>` SQL command) |
| 33 | + |
| 34 | +Returns: <DBConnection> |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +dbIsConnected Connection |
| 39 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 40 | + |
| 41 | +| Returns whether the connection is currently connected to the database server. |
| 42 | +| Also checks if a worker thread is connected. |
| 43 | +
|
| 44 | +:connection: ``<DBCONNECTION>`` - A connection |
| 45 | + |
| 46 | +Returns: ``<BOOL>`` |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |
| 52 | +dbPing connection |
| 53 | +~~~~~~~~~~~~~~~~~ |
| 54 | + |
| 55 | +| Executes a ``SELECT 1;`` on the database server and returns true if it get's 1 back. Returns false on error. |
| 56 | +| Suspends in scheduled, freezes in unscheduled. |
| 57 | +| (Should this return the actual error string somehow?, Should this call error handlers?) |
| 58 | +
|
| 59 | +:connection: ``<DBCONNECTION>`` - A connection |
| 60 | + |
| 61 | +Returns: ``<BOOL>`` |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | + |
| 66 | +connection dbAddErrorHandler code |
| 67 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 68 | + |
| 69 | +| Registers a global error handler on the connection, if any query on the connection causes an error, that function will be called with ``_this = [errorString, errorCode, query]``. |
| 70 | +| There can be multiple error handlers, they will be executed from first to last added. |
| 71 | +| If one of the error handlers returns ``true`` the error will be considered handled and the other handlers won't be called. |
| 72 | +| If error handlers are present, errors won't be printed to RPT. |
| 73 | +| Example _this: |
| 74 | +| ``["Lost connection to MySQL server at 'reading authorization packet', system error: 10061",2013,"testQuery5"]`` |
| 75 | +| ``["You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'testQuery5' at line 1",1064,"testQuery5"]`` |
| 76 | +| ``["Unknown column 'none' in 'field list'",1054,"SELECT none"]`` |
| 77 | +| #TODO add the query config name to _this too. |
| 78 | +
|
| 79 | +:connection: ``<DBCONNECTION>`` - A connection |
| 80 | +:code: ``<CODE>`` - Script code. |
| 81 | + |
| 82 | +Returns: ``<NOTHING>`` |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +connection dbLoadSchema schemaName |
| 87 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 88 | + |
| 89 | +Executes a SQL file. Path is defined in config. |
| 90 | + |
| 91 | +:connection: ``<DBCONNECTION>`` - A connection |
| 92 | +:schemaName: ``<STRING>`` - schema name from config. |
| 93 | + |
| 94 | +.. attention:: |
| 95 | + schemaName is case-sensitive |
| 96 | + |
| 97 | +Returns: ``<NOTHING>`` |
| 98 | + |
0 commit comments