dbi.DBIThe main import module for DBI . Loading this module will automatically load all database backend that are built into DBI using command line version switches. Currently the following versions switches are functional:-dbi_mysql = loads the Mysql DBI package -dbi_sqlite = loads the Sqlite DBI packageTo connect to a database, use getDatabaseForURL() or a database's own connection method (see the documentation for the database you are using). The most basic database methods are the following: void query(char[] sql,...); bool fetchRow(...);query() takes template variadic parameters which are bound automatically to the provided sql and fetchRow() binds result-row fields to the provided parameters. Databases also provide the following convenience methods which dynamically generate sql and bind the provided variadic parameters to that sql (note: database implementations are written in such a way as to minimize or eliminate the need to dynamically allocate memory for sql generation - these methods should be fairly efficient) : void insert(char[] tablename, char[][] fields, ...); void update(char[] tablename, char[][] fields, char[] whereClause, ...); void select(char[] tablename, char[][] fields, char[] whereClause, ...); void remove(char[] tablename, char[] whereClause, ...);This simple example should show you how to get stated with DBI . auto db = getDatabaseForURL("sqlite://sqlite.db"); db.query(`CREATE TABLE "user" ("id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "name" TEXT)`); db.insert("user",["name"],"bob"); assert(db.affectedRows == 1); auto id = db.lastInsertID; db.update("user",["bob"],`WHERE "id" = ?`,"mike",id); assert(db.affectedRows == 1); db.select("user",["name"],`WHERE "id" = ?`,id); char[] name; assert(db.rowCount == 1); assert(db.fetchRow(name)); assert(name == "mike");
| ||
Documentation last updated Tue Jan 27 00:09:31 2009 |