[Home] [Downloads] [Search] [Help/forum]

MUSHclient scripting

Description of MUSHclient world function: world.DatabaseGetField

Name DatabaseGetField
Type Method
Summary Returns a single field from an SQL database
Prototype VARIANT DatabaseGetField(BSTR Name, BSTR Sql);

View list of data type meanings


This executes SQL on a database previously opened with DatabaseOpen.

It lets you obtain a single value more easily than doing a DatabasePrepare / DatabaseStep / DatabaseColumnValue / DatabaseFinalize in the cases where you just want to establish a single thing (eg. the count of spells in a table).

You need to supply the database id of an existing opened database, and the SQL statement to be executed.

You cannot call DatabaseGetField if you have called DatabasePrepare but not DatabaseFinalize, as a statement is currently being processed.

The function effectively does this:

DatabasePrepare (Name, Sql)

If unsuccessful, exit with null variant.

DatabaseStep (Name)

If successful, and a row was returned, then:
result = DatabaseColumnValue (Name, 1)

DatabaseFinalize (Name)

If successful, then the value for the first column of the first row is the return value, otherwise the null variant (nil in Lua).

Note: Available in version 4.65 onwards.

Lua example
DatabaseOpen ("db", GetInfo (82), 1)

value = DatabaseGetField ("db", 
                          "SELECT value FROM control WHERE name = 'Version' ")

DatabaseClose ("db")
Lua notes
Returns nil on error.
Returns The contents of the column, as a string, long, double or empty variant.

Returns the null variant if there is an error, such as invalid database id, no current row, etc.
Introduced in version 4.65

See also ...

Function Description
DatabaseClose Closes an SQLite database
DatabaseError Returns an English string describing the most recent SQL error
DatabaseExec Executes SQL code against an SQLite database
DatabaseFinalize Finalizes (wraps up) a previously-prepared SQL statement
DatabaseOpen Opens an SQLite database
DatabasePrepare Prepares an SQL statement for execution

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


Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]