world.DatabaseError

MUSHclient script function (Method) — introduced in version 4.40

Returns an English string describing the most recent SQL error

Prototype

BSTR DatabaseError(BSTR DbName);

Data type meanings

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

Database (SQLite)

See also

FunctionDescription
DatabaseColumnNameFind the name of a specified column returned by an SQL statement
DatabaseColumnNamesReturn a table of all the columns returned by an SQL statement
DatabaseColumnTextReturns the contents of an SQL column, as text
DatabaseColumnTypeReturns the type of data in an SQL column
DatabaseColumnValueReturns the contents of an SQL column, as text, float, integer, or null
DatabaseColumnValuesReturns the contents of all the SQL columns after a step
DatabaseColumnsFind how many columns will be returned by an SQL statement
DatabaseExecExecutes SQL code against an SQLite database
DatabaseFinalizeFinalizes (wraps up) a previously-prepared SQL statement
DatabaseLastInsertRowidReturns the most recently automatically allocated database key
DatabaseOpenOpens an SQLite database
DatabasePreparePrepares an SQL statement for execution
DatabaseResetResets a previously-prepared SQL statement to the start
DatabaseStepExecutes a previously-prepared SQL statement