library database;
uses
SysUtils,
Classes,
IBCustomDataSet,
IBQuery,
IBDatabase,
inifiles,
dialogs,
db,
IBServices;
{$R *.res}
var qrmain:TIBQuery;
trmain:TIBTransaction;
dbmain:TIBDatabase;
procedure dll_initdatabase;
var ini:TIniFile;
begin;
ini := TInifile.create('
./config.ini');
try
dbmain := TIBDatabase.Create(
nil);
trmain := TIBTransaction.Create(
nil);
qrmain := TIBQuery.Create(
nil);
dbmain.LoginPrompt := false;
dbmain.DefaultTransaction := trmain;
dbmain.IdleTimer := 0;
dbmain.AllowStreamedConnected := false;
trmain.DefaultDatabase := dbmain;
trmain.Params.Add('
concurrency');
trmain.Params.Add('
nowait');
trmain.AutoStopAction := saNone;
qrmain.Database := dbmain;
qrmain.Transaction := trmain;
qrmain.CachedUpdates := false;
dbmain.DatabaseName := ini.ReadString('
database','
databasename','
');
dbmain.SQLDialect := ini.ReadInteger('
database','
sqldialect',3);
dbmain.Params.Text :=
'
password='+ini.ReadString('
database','
password','
')+#10#13+
'
lc_ctype='+ini.ReadString('
database','
charset','
')+#10#13+
'
user_name='+ini.ReadString('
database','
user_name','
');
dbmain.Connected := true;
trmain.Active := true;
finally
ini.Free;
end;
end;
procedure dll_execquery(str:pchar;passv:boolean);
begin;
qrmain.Close;
qrmain.SQL.Clear;
qrmain.SQL.Add(str);
if (passv)
then qrmain.Open
else qrmain.ExecSQL;
end;
procedure dll_commit;
begin;
if trmain.intransaction
then trmain.Commit;
Trmain.StartTransaction;
end;
function dll_getinsertid(tab:pchar;fi:pchar):integer;
begin;
dll_execquery(pchar('
SELECT max('+fi+'
) as m FROM '+tab+'
;'),true);
result := database.qrmain.fieldbyname('
m').AsInteger;
end;
procedure dll_next;
begin;
qrmain.Next;
end;
function dll_eof:boolean;
begin;
result := qrmain.Eof;
end;
function dll_recordcount:integer;
begin;
result:= qrmain.RecordCount;
end;
function dll_fieldbyname(
name:pchar):TField;
begin;
result:=qrmain.fieldbyname(
name);
end;
procedure dll_desinit;
begin;
qrmain.Free;
trmain.Free;
dbmain.Free;
end;
exports dll_initdatabase,dll_execquery,dll_commit,dll_getinsertid,dll_next,dll_eof,dll_recordcount,dll_fieldbyname,dll_desinit;
begin
end.