Permalink
Browse files

zeos

  • Loading branch information...
vrybant committed Nov 28, 2017
1 parent ec01988 commit 122dfbe3cf8b52ccdd123d8ceac39b55c18346f0
Showing with 62 additions and 28 deletions.
  1. +9 −6 UnboundBible.lpi
  2. +8 −0 unitmain.pas
  3. +44 −19 unitshelf.pas
  4. +1 −3 unitsqliteex.pas
View
@@ -33,20 +33,23 @@
<FormatVersion Value="1"/>
</local>
</RunParams>
<RequiredPackages Count="4">
<RequiredPackages Count="5">
<Item1>
<PackageName Value="unboundmemopackage"/>
<PackageName Value="zcomponent"/>
</Item1>
<Item2>
<PackageName Value="Printer4Lazarus"/>
<PackageName Value="unboundmemopackage"/>
</Item2>
<Item3>
<PackageName Value="richmemopackage"/>
<MinVersion Major="1" Valid="True"/>
<PackageName Value="Printer4Lazarus"/>
</Item3>
<Item4>
<PackageName Value="LCL"/>
<PackageName Value="richmemopackage"/>
<MinVersion Major="1" Valid="True"/>
</Item4>
<Item5>
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="16">
<Unit0>
View
@@ -15,7 +15,15 @@ interface
TMainForm = class(TForm)
ActionInterline: TAction;
IdleTimer: TIdleTimer;
MenuItem4: TMenuItem;
miInterlinear: TMenuItem;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N9: TMenuItem;
pmInterlinear: TMenuItem;
miTranslate: TMenuItem;
PrintDialog: TPrintDialog;
View
@@ -1,10 +1,14 @@
unit UnitShelf;
{$ifdef linux}
{$define zeos}
{$endif}
interface
uses
Classes, SysUtils, Dialogs, Graphics, IniFiles, ClipBrd, LazUtf8,
DB, SQLdb, SQLite3conn, IBConnection,
Classes, SysUtils, Dialogs, Graphics, IniFiles, ClipBrd, LazUtf8, DB, SQLdb,
{$ifdef zeos} ZConnection, ZDataset, ZDbcSqLite, {$else} SQLite3conn, {$endif}
UnitLib, UnitTitle, UnitType;
const
@@ -20,9 +24,14 @@ TBook = class
end;
TBible = class(TList)
Connection : TSQLite3Connection;
Transaction : TSQLTransaction;
Query : TSQLQuery;
{$ifdef zeos}
Connection : TZConnection;
Query : TZReadOnlyQuery;
{$else}
Connection : TSQLite3Connection;
Transaction : TSQLTransaction;
Query : TSQLQuery;
{$endif}
{-}
info : string;
filePath : string;
@@ -144,14 +153,21 @@ constructor TBible.Create(filePath, fileName: string);
begin
inherited Create;
Connection := TSQLite3Connection.Create(nil);
Transaction := TSQLTransaction.Create(Connection);
Query := TSQLQuery.Create(nil);
Connection.DatabaseName := filePath + slash + fileName;
Connection.CharSet := 'UTF8';
Connection.Transaction := Transaction;
Query.DataBase := Connection;
{$ifdef zeos}
Connection := TZConnection.Create(nil);
Query := TZReadOnlyQuery.Create(nil);
Connection.Database := filePath + slash + fileName;
Connection.Protocol := 'sqlite-3';
Query.Connection := Connection;
{$else}
Connection := TSQLite3Connection.Create(nil);
Connection.CharSet := 'UTF8';
Connection.DatabaseName := filePath + slash + fileName;
Transaction := TSQLTransaction.Create(Connection);
Connection.Transaction := Transaction;
Query := TSQLQuery.Create(nil);
Query.DataBase := Connection;
{$endif}
self.filePath := filePath;
self.fileName := fileName;
@@ -178,14 +194,23 @@ constructor TBible.Create(filePath, fileName: string);
procedure TBible.OpenDatabase;
var
key, value : string;
dbhandle : Pointer;
begin
try
Connection.Open;
Transaction.Active := True;
{$ifdef zeos}
Connection.Connect;
dbhandle := (Connection.DbcConnection as TZSQLiteConnection).GetConnectionHandle();
{$else}
Connection.Open;
Transaction.Active := True;
dbhandle := Connection.Handle;
{$endif}
if not Connection.Connected then Exit;
SQLite3CreateFunctions(Connection.Handle);
Connection.ExecuteDirect('PRAGMA case_sensitive_like = 1');
SQLite3CreateFunctions(dbhandle);
// Connection.ExecuteDirect('PRAGMA case_sensitive_like = 1');
except
output('connection failed ' + self.fileName);
Exit;
end;
@@ -542,7 +567,7 @@ function TBible.Search(searchString: string; SearchOptions: TSearchOptions; Rang
try
try
Query.SQL.Text := 'SELECT * FROM ' + z.bible + ' WHERE super(' + z.text + ')=''1''' + queryRange; ;
Query.SQL.Text := 'SELECT * FROM ' + z.bible + ' WHERE super(' + z.text + ')=''1''' + queryRange;
Query.Open;
Query.Last; // must be called before RecordCount
@@ -680,7 +705,7 @@ destructor TBible.Destroy;
for i:=0 to Count-1 do Items[i].Free;
Query.Free;
Transaction.Free;
{$ifndef zeos} Transaction.Free; {$endif}
Connection.Free;
inherited Destroy;
View
@@ -53,10 +53,8 @@ procedure xSuper(ctx: psqlite3_context; {%H-}N: cint; V: ppsqlite3_value); cdecl
procedure SQLite3CreateFunctions(const Handle: pointer);
begin
{$ifdef windows}
if Assigned(Handle) then
sqlite3_create_function(Handle,'super',0,SQLITE_UTF8 or SQLITE_DETERMINISTIC,nil,@xSuper,nil,nil);
{$endif}
sqlite3_create_function(Handle,'super',1,SQLITE_UTF8 or SQLITE_DETERMINISTIC,nil,@xSuper,nil,nil);
end;
end.

0 comments on commit 122dfbe

Please sign in to comment.