The D DBI project

enum DbiFeature ;


class Database : dbi.model.Result.Result, dbi.model.Statement.IStatementProvider;
The database interface that all databases must inherit from.

See Also:
The documentation for dbi.model.Result - Database inherits from Result.

The database class for the specific database you are using. Many databases have functions that are specific to themselves, as they wouldn't make sense in any man other databases. Please reference the documentation for the database you will be using to discover these functions.

void query (Types...)(char[] sql, Types bind);
Sends a query to the database server. Queries can use ? to represent parameters that will be filled in by the variadic argument parameters that can be passed to query .

Arguments of the following types can be used as bind arguments: bool byte ubyte short ushort int uint long ulong float double char[] void[] ubyte[] tango.time.Time tango.time.DateTime dbi.model.BindType.BindInfo

		db.query("SELECT name FROM user WHERE id = ?", 15);

		uint limit = 15;
		uint offset = 100;
		db.query("SELECT id,name FROM user WHERE 1 LIMIT ? OFFSET ?", limit, offset);

sql The sql query that will be sent to the server, can use ?'s to represent parameters that will be bound autmotically by DBI using the variadic parameters passed by bind.
bind Variadic arguments that bind to ?'s used in the query text. (optional)

true if the query was successful, false otherwise

DBIException on a serious error executing the query

alias execute ;
Alias for query

void insert (Types...)(char[] tablename, char[][] fields, Types bind);

void update (Types...)(char[] tablename, char[][] fields, char[] where, Types bind);

void select (Types...)(char[] tablename, char[][] fields, char[] where, Types bind);

void remove (Types...)(char[] tablename, char[] where, Types bind);

abstract ulong lastInsertID ();

Statement prepare (char[] sql);
Prepares a statement with the given sql

abstract bool enabled (DbiFeature feature);
Returns true if the given feature has been enabled in this Database instance.

abstract void close ();
Close the current connection to the database.

void uncacheStatement (Statement st);

void uncacheStatement (char[] sql);

abstract char[] escapeString (char[] str, char[] dst = null);

abstract void startTransaction ();

alias begin ;
Alias for startTransaction

abstract void rollback ();

abstract void commit ();

protected final char[][char[]] getKeywords (char[] string, char[] split = ";");
Split a string into keywords and values.

char[] string A string in the form keyword1=value1;keyword2=value2;etc.

An associative array containing keywords and their values.

DBIException if string is malformed.

abstract bool hasTable (char[] tablename);

abstract ColumnInfo[] getTableInfo (char[] tablename);

abstract SqlGenerator getSqlGenerator ();

alias sqlGen ;
Alias for getSqlGenerator

abstract char[] type ();
The database type for this instance (i.e. Mysql, Sqlite, Postgresql, etc.)

abstract void initQuery (char[] sql, bool haveParams);

abstract void doQuery ();

abstract void setParam (bool);

abstract void setParam (ubyte);

abstract void setParam (byte);

abstract void setParam (ushort);

abstract void setParam (short);

abstract void setParam (uint);

abstract void setParam (int);

abstract void setParam (ulong);

abstract void setParam (long);

abstract void setParam (float);

abstract void setParam (double);

abstract void setParam (char[]);

abstract void setParam (ubyte[]);

abstract void setParam (Time);

abstract void setParam (DateTime);

abstract void setParamNull ();

void setParams (Types...)(Types bind);

abstract void initInsert (char[] tablename, char[][] fields);

abstract void initUpdate (char[] tablename, char[][] fields, char[] where);

abstract void initSelect (char[] tablename, char[][] fields, char[] where, bool haveParams);

abstract void initRemove (char[] tablename, char[] where, bool haveParams);

abstract bool startWritingMultipleStatements ();
Initializes the writing of multiple statements using DBI's Sql generation interface.

Should only be called once before writing any statements for the given query. Note that there should be no danger in calling startWritingMultipleStatements () when only one statement is actually written. Multi-statement must be done in this order -

  // startWritingMultipleStatements

  // for each statement that is to be written:
		// initQuery() or one of its variants initInsert, initUpdate, initSelect, or initRemove
		// is called for the statement that is being written

 		// setParams, setParam, or setParamNull are called the correct number of times
 		// for the given statement

  // doQuery is called to send the full query to the server and execute it


			db.initInsert("myTable", ["number", "name"]);

			db.initSelect("myTable",["number", "name"],"WHERE 1",false);

The call to doQuery() ends the writing of multiple statements and executes all of the statements that were written since the call to startWritingMultipleStatements (). startWritingMultipleStatements () will have to be called again to enable it for the next query. If a query is written using (initQuery and setParam(s)) and startWritingMultipleStatements () is called afterwards, that query will be lost.

true if multiple statement writing was successfully initialized, false if the database doesn't support this feature

DBIException if the database does support this feature but the command was called out of order (i.e. more than once) or if there was some sort of error initializing this feature

abstract bool isWritingMultipleStatements ();
true if the database instance in the write multiple statements mode, false otherwise

abstract Statement doPrepare (char[] sql);

Documentation last updated Tue Jan 27 00:09:27 2009