Main Page | Class Hierarchy | Compound List | Compound Members | Related Pages

Database Class Reference

List of all members.

Detailed Description

Connection to an SQLite database.


Command Execution

These commands manage sending commands to the SQLite database.

void exec (char[] sql, bit(*callback)(char[][char[]] columns))
 (This function takes a delegate, not a function pointer) Execute the SQL command.

void exec (char[] sql, void(*callback)(char[][char[]] columns))
 (This function takes a delegate, not a function pointer) Execute the SQL command.

void exec (char[] sql)
 (This function takes a delegate, not a function pointer) Execute the SQL command that has no queries.

void exec (char[] sql, bit(*callback)(char[][] columns))
 (This function takes a delegate, not a function pointer) Execute the SQL command.

void exec (char[] sql, void(*callback)(char[][] columns))
 (This function takes a delegate, not a function pointer) Execute the SQL command.

void exec (char[] sql, bit(*callback)(char[][] names, char[][] values))
 (This function takes a delegate, not a function pointer) Execute the SQL command, running a callback that takes parallel names and values columns.

SQLite Query query (char[] sql)
 Execute the SQL command and return a query matrix from the results.


Public Member Functions

 this (char[] filename)
 Open the database and read the tables.

 ~this ()
 Close the database.

void close ()
 Close the database if it is currently open.

void busyHandler (bit(*func)(char[] tableName, uint busyCount))
 (This method takes a delegate, not a function pointer) Assign a busy handler that is called if the database is currently locked.

void busyNone ()
 Reset the busy handler to the default.

void busyTimeout (uint milliseconds)
 Set the busy handler to a function that sleeps when a table is locked, giving control to other threads and processes.

void attachDatabase (char[] filename, char[] name)
 Add a pre-existing database file to the current database connection.

void detachDatabase (char[] databaseName)
 Detach a table previously attached using the attachDatabase () method.

void begin (SQLite.OnConflict onConflict)
 Manually start a transaction.

void begin ()
 Begin a transaction with the OnConflict.Abort conflict resolution algorithm.

void beginRollback ()
 Begin a transaction with the OnConflict.Rollback conflict resolution algorithm.

void end ()
 End a transaction normally.

void commit ()
 Commit all changes so far done by a transaction and close it.

void rollback ()
 Roll back any changes made within a transaction and close it.

void createFunction (char[] name, int argumentCount, char[](*func)(char[][] arguments))
 (This method takes a delegate, not a function pointer) Create a user-defined function that can be used in all SQL commands for this database.

Table Management
These methods create and access tables in the database.

Tables are created through the #createTable method. Initially they don't exist in the database; you need to call Table.flush () to store them. See the Table documentation for more details.

Because the tables are extracted from the database, they can get out-of-date to it if another process or thread writes to the database. You can cause a database table to be reloaded using #reloadTables.

Table createTable (char[] tableName)
 Create a table object, that is not registered.

Table table (char[] tableName)
 Find the table in the database.

Table table (int index)
 Return the indexed table.

bit tableExists (char[] tableName)
 Return whether a table with this name exists in the database.

int tableCount ()
 Return the number of tables in all attached databases.

void reloadTables (char[] databaseName)
 Reload tables from either the main database or an attached database.


Static Public Member Functions

void privateFunctionBaseString (sqlite_func *sqfunc, int argumentCount, char **argumentPointers)


Constructor & Destructor Documentation

Database.~this  ) 
 

Close the database.


Member Function Documentation

void Database.attachDatabase charfilename  [],
charname  []
 

Add a pre-existing database file to the current database connection.

The names 'main' and 'temp' refer to the main database and the database used for temporary tables. These cannot be detached. Attached databases are removed using the detachDatabase () method.

You can read from and write to an attached database, but you cannot alter the schema of an attached database. You can only create () and drop () in the original database.

You cannot create a new table with the same name as a table in an attached database, but you can attach a database which contains tables whose names are duplicates of tables in the main database. It is also permissible to attach the same database file multiple times.

Tables in an attached database can be referred to using the syntax database-name.table-name. If an attached table doesn't have a duplicate table name in the main database, it doesn't require a database name prefix. When a database is attached, all of its tables which don't have duplicate names become the 'default' table of that name. Any tables of that name attached afterwards require the table prefix. If the 'default' table of a given name is detached, then the last table of that name attached becomes the new default.

When there are attached databases, transactions are not atomic. Transactions continue to be atomic within each individual database file. But if your machine crashes in the middle of a commit () where you have updated two or more database files, some of those files might get the changes where others might not.

There is an SQLite compile-time limit of 10 attached database files.

Executing beginTransaction () locks all database files, so this feature cannot (currently) be used to increase concurrency.

Parameters:
filename Filename to the pre-existing database.
name Name to use to refer to the database.

void Database.begin  ) 
 

Begin a transaction with the OnConflict.Abort conflict resolution algorithm.

void Database.begin SQLite.OnConflict  onConflict  ) 
 

Manually start a transaction.

No changes can be made to the database except within a transaction. Any command that changes the database (basically, any SQL command other than select ()) will automatically start a transaction if one is not already in effect. Automatically started transactions are committed at the conclusion of the command.

Transactions started with this command usually persist until the next commit () or rollback () command. But a transaction will also rollback () if the database is closed or if an error occurs and the OnConflict.Rollback conflict resolution algorithm is specified.

Manual transactions are the key to efficient use of SQLite.

Parameters:
onConflict The conflict resolution algorithm to use on failure.

void Database.beginRollback  ) 
 

Begin a transaction with the OnConflict.Rollback conflict resolution algorithm.

void Database.busyHandler bit(*  func)(char[] tableName, uint busyCount)  ) 
 

(This method takes a delegate, not a function pointer) Assign a busy handler that is called if the database is currently locked.

The default is no handle (a value returned to by calling busyNone ()), in which case a locked database will immediately abort the command and cause an exception.

Parameters:
func The function to call if the database being accessed is locked. tableName is the name of the table which is being accessed. busyCount is the number of times the table has been busy. It should return true to continue trying the database or false to abort. If it returns true, it is with the expectation that you've wasted some time so that the other user can unlock.

void Database.busyNone  ) 
 

Reset the busy handler to the default.

If a table is locked with the default set, the command is aborted and will cause an exception.

void Database.busyTimeout uint  milliseconds  ) 
 

Set the busy handler to a function that sleeps when a table is locked, giving control to other threads and processes.

Once a certain number of milliseconds have been slept through without the table unlocking, the handler aborts the command with failure.

Parameters:
milliseconds The number of milliseconds to sleep on a single table before failing the command.

void Database.close  ) 
 

Close the database if it is currently open.

Once closed, no method calls are valid.

void Database.commit  ) 
 

Commit all changes so far done by a transaction and close it.

Exceptions:
CommitError This will be thrown if there is no currently opened transaction through begin ().

void Database.createFunction charname  [],
int  argumentCount,
char(*  func[])(char[][] arguments)
 

(This method takes a delegate, not a function pointer) Create a user-defined function that can be used in all SQL commands for this database.

Parameters:
name The name of the function to create.
argumentCount The number of parameters that the function expects to be called with.
func Delegate function to call. The unquoted arguments will be passed in arguments and should return an unquoted result.

Table Database.createTable chartableName  []  ) 
 

Create a table object, that is not registered.

You need to call create () on the table to register it.

Parameters:
tableName The name of the table to create.
Exceptions:
TableExistsError A table with this name already exists in the database.

void Database.detachDatabase chardatabaseName  []  ) 
 

Detach a table previously attached using the attachDatabase () method.

This statement will fail if currently within a transaction.

Parameters:
databaseName The name of the database as provided to attachDatabase ().

void Database.end  ) 
 

End a transaction normally.

Exceptions:
CommitError This will be thrown if there is no currently opened transaction through begin ().

void Database.exec charsql  [],
bit(*  callback)(char[][] names, char[][] values)
 

(This function takes a delegate, not a function pointer) Execute the SQL command, running a callback that takes parallel names and values columns.

Parameters:
sql The SQL command(s) to execute.
callback A callback function called on each line of the query. The names array is matched by the values array. This should return true to continue processing or false to abort the transaction and skip all subsequent SQL statements.

void Database.exec charsql  [],
void(*  callback)(char[][] columns)
 

(This function takes a delegate, not a function pointer) Execute the SQL command.

Parameters:
sql The SQL command(s) to execute.
callback A callback function called on each line of a query. The name of each column is defined by the command you're executing.

void Database.exec charsql  [],
bit(*  callback)(char[][] columns)
 

(This function takes a delegate, not a function pointer) Execute the SQL command.

Parameters:
sql The SQL command(s) to execute.
callback A callback function called on each line of a query. The name of each column is defined by the command you're executing. This should return true to continue processing or false to abort the query and skip all subsequent SQL statements.

void Database.exec charsql  []  ) 
 

(This function takes a delegate, not a function pointer) Execute the SQL command that has no queries.

Parameters:
sql The SQL command(s) to execute.

void Database.exec charsql  [],
void(*  callback)(char[][char[]] columns)
 

(This function takes a delegate, not a function pointer) Execute the SQL command.

Parameters:
sql The SQL command(s) to execute.
callback A callback function called on each line of a query. This is passed an associative array attaching the value of a column to its name.

void Database.exec charsql  [],
bit(*  callback)(char[][char[]] columns)
 

(This function takes a delegate, not a function pointer) Execute the SQL command.

Parameters:
sql The SQL command(s) to execute.
callback A callback function called on each line of a query. This should return true to continue to the next query, or false to abort the query and skip all subsequent SQL statements. It is passed an associative array attaching the value of a column to its name.

SQLite Query Database.query charsql  []  ) 
 

Execute the SQL command and return a query matrix from the results.

Either there must be a single query in the commands or the columns and column order must be the same in all of them. If this is not true, it will throw an exception.

Parameters:
sql The SQL command(s) to execute.
Returns:
The query matrix resulting from this command.

void Database.reloadTables chardatabaseName  []  ) 
 

Reload tables from either the main database or an attached database.

Parameters:
databaseName The name of the database to reload the tables for. If this is null, this will reload the tables in the main database. Otherwise it will reload the tables from the database name referred to from attachDatabase ().

void Database.rollback  ) 
 

Roll back any changes made within a transaction and close it.

Exceptions:
CommitError This will be thrown if there is no currently opened transaction through begin ().

Table Database.table int  index  ) 
 

Return the indexed table.

Table Database.table chartableName  []  ) 
 

Find the table in the database.

If it doesn't exist, throw an error.

Exceptions:
TableNotExistsError The table requested doesn't exist.

int Database.tableCount  ) 
 

Return the number of tables in all attached databases.

bit Database.tableExists chartableName  []  ) 
 

Return whether a table with this name exists in the database.

Database.this charfilename  []  ) 
 

Open the database and read the tables.

If the file doesn't exist, it is created.

Exceptions:
OpenError If the database cannot be opened, this is thrown.


The documentation for this class was generated from the following file:
Generated on Thu Jul 31 08:40:54 2003 for sqlite by doxygen 1.3.2