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的截圖:


浙公網安備 33010602011771號