Register forum user name Search FAQ

MUSHclient scripting

Description of MUSHclient world function: world.DatabaseError


Name DatabaseError
Type Method
Summary 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.


Note: Available in version 4.40 onwards.


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
Returns The error message.
Introduced in version 4.40

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
DatabaseColumns Find how many columns will be 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
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

Search for script function

Enter a word or phrase in the box below to narrow the list down to those that match.

The function name, prototype, summary, and description are searched.

Search for:   

Leave blank to show all functions.


Return codes

Many functions return a "code" which indicates the success or otherwise of the function.

You can view a list of the return codes


Function prototypes

The "prototype" part of each function description lists exactly how the function is called (what arguments, if any, to pass to it).

You can view a list of the data types used in function prototypes


View all functions

[Back]

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.