Wiki

Clone wiki

DWScript / dwsDataBase

  1. 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:

Updated