dclvquery10.lpk在aarch64等linux平台安装出错。
解决方法:
打开source/VirtualQuery.inc添加
{$ifdef linux} {$if defined(cpuloongarch64) or defined(cpuaarch64) or defined(cpuarm) or defined(cpuriscv64)} {$DEFINE NOSTATIC} {$endif} {$endif}
unidac 9.x.x不支持lazarus for linux(loongarch64或arm64)SQLite,因unidac SQLite默认使用静态连接方式,但UNIDAC官方SQLite未提供arm64或loongarch64静态库,造成linux forloongarch64/arm64无法安装liteprovider10.lpk,经跟踪unidac源码发现在source/uniProviders/SQLite/LiteDac.inc添加
{$ifdef linux}
{$if defined(cpuloongarch64) or defined(cpuaarch64) or defined(cpuarm) or defined(cpuriscv64)}
{$DEFINE NOSTATIC}
{$endif}
{$endif}
就可以安装liteprovider10.lpk,SQLite的libsqlite3.so可以用这个带加密功能的版本:linux编译加密版sqlite - 秋·风 - 博客园 (cnblogs.com)
unidac官方提供静态库前先用这个方法解决sqlite使用问题。
////////////////////////////////////////////////// // SQLite Data Access Components // Copyright © 2008-2022 Devart. All right reserved. ////////////////////////////////////////////////// {$I Dac.inc}
{$ifdef linux}
{$if defined(cpuloongarch64) or defined(cpuaarch64) or defined(cpuarm) or defined(cpuriscv64) }
{$DEFINE NOSTATIC}
{$endif}
{$endif}
{$DEFINE UNIDACPRO} {$IFNDEF NOSTATIC} {$IFDEF STD} {$IFNDEF LITE} {$DEFINE NOSTATIC} {$ENDIF} {$ENDIF}
使用方式:
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, DB, Forms, Controls, Graphics, Dialogs, StdCtrls, DBGrids, CnSM4, CnNative, SQLiteUniProvider, Uni,LiteConstsUni,inifiles; type { TForm1 } TForm1 = class(TForm) Button1: TButton; Button2: TButton; Button3: TButton; DataSource1: TDataSource; DBGrid1: TDBGrid; Edit1: TEdit; Label1: TLabel; SQLiteUniProvider1: TSQLiteUniProvider; UniConnection1: TUniConnection; UniQuery1: TUniQuery; UniTable1: TUniTable; procedure Button3Click(Sender: TObject); procedure FormClose(Sender: TObject; var CloseAction: TCloseAction); procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } function IsSQLite3File(const FileName: TFileName): boolean; var F: THandle; Header:array [0..15] of char ; begin F := FileOpen(FileName,fmOpenRead or fmShareDenyNone); if F= THandle(-1) then result := false else begin FileRead(F,Header,15); if Header='SQLite format 3' then result:=true; FileClose(F); end; end; procedure TForm1.Button3Click(Sender: TObject); begin TLiteUtils.EncryptDatabase(UniConnection1,edit1.Text);//修改密码 end; procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction); var MYIniFile:TIniFile; begin MYIniFile := TIniFile.Create(Extractfilepath(Paramstr(0)) + 'config.ini'); MyIniFile.writestring('数据库', '密码',edit1.Text); MYIniFile.Free; end; procedure TForm1.FormCreate(Sender: TObject); var MYIniFile:TIniFile; begin MYIniFile := TIniFile.Create(Extractfilepath(Paramstr(0)) + 'config.ini'); edit1.text:=MyIniFile.readstring('数据库', '密码','1231asd'); MYIniFile.Free; end; procedure TForm1.Button1Click(Sender: TObject); begin if not FileExists(ExtractFilePath(Application.ExeName)+'demo.db3') then begin with UniConnection1 do begin ConnectString:='Provider Name=SQLite'; Database:=ExtractFilePath(Application.ExeName)+'demo.db3'; SpecificOptions.Values['ForceCreateDatabase']:='True'; SpecificOptions.Values['EncryptionAlgorithm']:='leAES256';//设置加密方式 SpecificOptions.Values['EncryptionKey']:=edit1.Text; SpecificOptions.Values['ClientLibrary']:=ExtractFilePath(Application.ExeName)+'libsqlite3.so'; Connect; Close; end; UniQuery1.SQL.Clear; UniQuery1.SQL.Add('CREATE TABLE hardware (id INTEGER PRIMARY KEY, compname VARCHAR(30), username VARCHAR(30), model VARCHAR(30));'); UniQuery1.SQL.Add('CREATE INDEX sHardware ON hardware(compname);'); UniQuery1.SQL.Add('INSERT INTO hardware(id, compname, username, model) VALUES (1, "AMD8537", "OMonge", "Gigabyte");'); UniQuery1.SQL.Add('INSERT INTO hardware(id, compname, username, model) VALUES (2, "英特尔", "OMonge", "Gigabyte");'); UniQuery1.ExecSQL; end; end; procedure TForm1.Button2Click(Sender: TObject); begin UniConnection1.Connected:=false; with UniConnection1 do begin ConnectString:='Provider Name=SQLite'; Database:=ExtractFilePath(Application.ExeName)+'demo.db3'; SpecificOptions.Values['ClientLibrary']:=ExtractFilePath(Application.ExeName)+'libsqlite3.so'; SpecificOptions.Values['EncryptionAlgorithm']:='leAES256';//设置加密方式,如果没加密,则设置为leDefault SpecificOptions.Values['EncryptionKey']:=edit1.Text;//设置加密密码,加密方式为leDefault时不能设置密码,否则运行时会有出错提示 //leTripleDES, leBlowfish, leAES128, leAES192, leAES256, leCast128, leRC4, leDefault UniTable1.TableName:='hardware'; UniTable1.Open; end; end; end.
未修改前安装出错截图:
在龙芯电脑使用UNIDAC SQLite的截图: