Wiki
Clone wikiDWScript / dwsDataBase
- summary dwsDataBase module
Introduction
This module exposes simple classes that allow to connect and run query against various databases.
- [DataBase]
- [DataSet]
- [DataField]
Sample
Connect to a local SQLite database and print two fields from a table
var db := DataBase.Create('SQLite', ['d:\db\base.sql3']); var query := db.Query('select field1, field2 from mytable where field3=?', ['filter']); while query.Step do PrintLn(query.AsString(0)+', '+query.AsString(1)); query.Close; // optional, only if you need it closed ASAP
Delete everything from mytable and insert in a transaction
db.BeginTransaction; db.Exec('delete from mytable'); db.Exec('insert into mytable (field1, field3) values (?, ?)', ['hello', 'world']); db.Commit;
Datasets and databases are automatically closed, but you can use the *Close* destructor to force-close at any time.
Transactions that not manually committed are automatically rollbacked.
Usage
In order to use the DataBase object in a script, an TdwsDatabaseLib component must be linked to the TDelphiWebScript, and appropriate driver units (dwsUIBDatabase for the "UIB" driver, dwsSynSQLiteDatabase for the "SQLLite" driver etc) must be used by the host program.
Details
Currently supported database drivers:
- [http://synopse.info/ Synopse] / [http://synopse.info/fossil/wiki?name=SQLite3+Framework mORMot]
- [http://www.sqlite.org/ SQLite] (native)
- [http://en.wikipedia.org/wiki/ODBC ODBC] (native)
- Oracle (native)
- [http://en.wikipedia.org/wiki/OLE_DB OleDB]
- Oracle (via OleDB)
- MSOracle
- MSSQL
- MySQL
- Jet (Access)
- AS400
- ODBC (via OleDB)
- [http://sourceforge.net/projects/uib/ Unified Interbase] / [http://www.progdigy.com/ progdigy]
- UIB (native [http://www.firebirdsql.org/ FireBird] and [http://www.embarcadero.com/products/interbase Interbase])
- GUID (pseudo-database that generates GUIDs)
Updated