world.DatabaseError
Returns an English string describing the most recent SQL error
Prototype
BSTR DatabaseError(BSTR DbName);
Description
Call this after one of the other Database routines returns an error code (generally, a code other than 0, 100 or 101).
This will return an explanatory string.
To help with debugging however, codes 100 and 101 also return:
100: "row ready"
101: "finished"
Warning: Since you do not pass the error code into this function, it will not correctly handle the "internal" MUSHclient errors (such as database not open). To handle them correctly you need to test for negative error numbers, as shown in the Lua example below.
Lua example
print (DatabaseError ("db"))
--
---
--- Example of handling internal errors, and SQLite3 errors
---
local MUSHclient_Database_Errors = {
[-1] = "Database id not found",
[-2] = "Database not open",
[-3] = "Already have prepared statement",
[-4] = "Do not have prepared statement",
[-5] = "Do not have a valid row",
[-6] = "Database already exists under a different disk name",
[-7] = "Column number out of range",
} -- end of MUSHclient_Database_Errors
-- check for errors on a DatabaseXXXXX call
function dbcheck (code)
if code == sqlite3.OK or -- no error
code == sqlite3.ROW or -- completed OK with another row of data
code == sqlite3.DONE then -- completed OK, no more rows
return code
end -- if code OK
-- DatabaseError won't return the negative errors
local err = MUSHclient_Database_Errors [code] or DatabaseError(db)
DatabaseExec (db, "ROLLBACK") -- rollback any transaction to unlock the database
error (err, 2) -- show error in caller's context
end -- dbcheck
Return value
The error message.
Related topic
See also
| Function | Description |
|---|---|
| DatabaseColumnName | Find the name of a specified column returned by an SQL statement |
| DatabaseColumnNames | Return a table of all the columns returned by an SQL statement |
| DatabaseColumnText | Returns the contents of an SQL column, as text |
| DatabaseColumnType | Returns the type of data in an SQL column |
| DatabaseColumnValue | Returns the contents of an SQL column, as text, float, integer, or null |
| DatabaseColumnValues | Returns the contents of all the SQL columns after a step |
| DatabaseColumns | Find how many columns will be returned by an SQL statement |
| DatabaseExec | Executes SQL code against an SQLite database |
| DatabaseFinalize | Finalizes (wraps up) a previously-prepared SQL statement |
| DatabaseLastInsertRowid | Returns the most recently automatically allocated database key |
| DatabaseOpen | Opens an SQLite database |
| DatabasePrepare | Prepares an SQL statement for execution |
| DatabaseReset | Resets a previously-prepared SQL statement to the start |
| DatabaseStep | Executes a previously-prepared SQL statement |