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

DatabaseOpen

Script function

world.DatabaseOpen

Read about scripting

Type

Method

Summary

Opens an SQLite database

Prototype

long DatabaseOpen(BSTR DbName, BSTR Filename, long Flags);

View list of data type meanings

Description

Opens or creates a database. Databases can be held in memory or on disk. You need read or write permissions to access the database, as it is stored on disk as a normal disk file.

DbName - a unique ID you choose to identify this database for all other operations on it (Eg. "db").

Filename - the file name on disk. The special filename ":memory:" opens an in-memory database. This can be used to manipulate data (or play with SQL) without actually writing to disk.

Flags -

Open_ReadOnly = 0x00000001
Open_ReadWrite = 0x00000002
Open_Create = 0x00000004
Open_DeleteOnClose = 0x00000008
Open_Exclusive = 0x00000010
Open_Main_db = 0x00000100
Open_Temp_db = 0x00000200
Open_Transient_db = 0x00000400
Open_Main_Journal = 0x00000800
Open_Temp_Journal = 0x00001000
Open_SubJournal = 0x00002000
Open_Master_Journal = 0x00004000
Open_NoMutex = 0x00008000
Open_FullMutex = 0x00010000

Warning - the SQLite documentation suggests that you choose one of:

Open_ReadOnly (1)
Open_ReadWrite (2) or
Open_ReadWrite + Open_Create (6)

If not, the behaviour of the open may be undefined.

Use DatabaseClose to close the database when you are finished with it.

If the database is still open when the world file is closed, the database is automatically closed.

It is not an error to re-open the same database ID of an existing, open, database, provided the disk file name is the same. This will be treated as a no-operation, so that triggers and aliases can open the database without having to check first if it was already open.


Available in MUSHclient version 4.40 onwards.



Lua example

DatabaseOpen ("db",   -- database ID
              GetInfo (66) .. "mytestdb.sqlite",   -- file name
              6)      -- flags

-- do stuff with the database here

DatabaseClose ("db")  -- close it


Lua notes

The Flags parameter can be omitted, and defaults to 6 (Open_ReadWrite + Open_Create).

The return codes are available in the sqlite3 table in Lua, as follows:

sqlite3.OK = 0
sqlite3.INTEGER = 1
sqlite3.INTERNAL = 2
sqlite3.PERM = 3
sqlite3.ABORT = 4
sqlite3.BUSY = 5
sqlite3.LOCKED = 6
sqlite3.NOMEM = 7
sqlite3.READONLY = 8
sqlite3.INTERRUPT = 9
sqlite3.IOERR = 10
sqlite3.CORRUPT = 11
sqlite3.NOTFOUND = 12
sqlite3.FULL = 13
sqlite3.CANTOPEN = 14
sqlite3.PROTOCOL = 15
sqlite3.EMPTY = 16
sqlite3.SCHEMA = 17
sqlite3.TOOBIG = 18
sqlite3.CONSTRAINT = 19
sqlite3.MISMATCH = 20
sqlite3.MISUSE = 21
sqlite3.NOLFS = 22
sqlite3.FORMAT = 24
sqlite3.RANGE = 25
sqlite3.NOTADB = 26
sqlite3.ROW = 100
sqlite3.DONE = 101


Return value

0 : success

-6 : Database already exists under a different disk name

Otherwise, an SQLite error code, and the database ID cannot be used


See Also ...

Topics

Database (SQLite)
Lua SQLite (database) interface
Scripting

Functions

(DatabaseChanges) Returns a count of the changes to the database by the most recent SQL statement
(DatabaseClose) Closes an SQLite database
(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
(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
(DatabaseGetField) Returns a single field from an SQL database
(DatabaseInfo) Returns information about a database
(DatabaseLastInsertRowid) Returns the most recently automatically allocated database key
(DatabaseList) Lists all databases
(DatabasePrepare) Prepares an SQL statement for execution
(DatabaseReset) Resets a previously-prepared SQL statement to the start
(DatabaseStep) Executes a previously-prepared SQL statement
(DatabaseTotalChanges) Returns a count of the total changes to the database

(Help topic: function=DatabaseOpen)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

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.

[Home]


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]