C
C#6d ago
reeeeeee

Calling SQLite query inside Inno Setup (update db on application uninstall)

Basically title. I tried with sqlite dll and exe, but nothing seem to work. dll:
function sqlite3_open(DBName: PAnsiChar; var DB: Integer): Integer;
external 'sqlite3_open@files:sqlite3.dll stdcall';

function sqlite3_exec(DB: Integer; SQL: String; Callback, Arg, ErrMsg: Integer): Integer;
external 'sqlite3_exec@files:sqlite3.dll stdcall';

function sqlite3_close(DB: Integer): Integer;
external 'sqlite3_close@files:sqlite3.dll stdcall';

procedure ExecuteSQLQuery(DatabasePath: string; ServiceId: string);
var
SQLQuery: string;
Res: Integer;
begin
MsgBox(DatabasePath, mbInformation, MB_OK);
if sqlite3_open(PAnsiChar(AnsiString(DatabasePath)), SQLiteDB) <> 0 then // 0 = OK
begin
MsgBox('Failed to open database!', mbError, MB_OK);
Exit;
end;

SQLQuery := 'DELETE FROM Settings WHERE ServiceId = ''' + ServiceId + ''';';
MsgBox(SQLQuery, mbInformation, MB_OK);

MsgBox('Executing query', mbInformation, MB_OK);
Res := sqlite3_exec(SQLiteDB, SQLQuery, 0, 0, 0);
if Res <> 0 then
MsgBox('Error executing DELETE query!', mbError, MB_OK)
else
MsgBox('Record deleted!', mbInformation, MB_OK);

// Close database
sqlite3_close(SQLiteDB);
end;

function sqlite3_open(DBName: PAnsiChar; var DB: Integer): Integer;
external 'sqlite3_open@files:sqlite3.dll stdcall';

function sqlite3_exec(DB: Integer; SQL: String; Callback, Arg, ErrMsg: Integer): Integer;
external 'sqlite3_exec@files:sqlite3.dll stdcall';

function sqlite3_close(DB: Integer): Integer;
external 'sqlite3_close@files:sqlite3.dll stdcall';

procedure ExecuteSQLQuery(DatabasePath: string; ServiceId: string);
var
SQLQuery: string;
Res: Integer;
begin
MsgBox(DatabasePath, mbInformation, MB_OK);
if sqlite3_open(PAnsiChar(AnsiString(DatabasePath)), SQLiteDB) <> 0 then // 0 = OK
begin
MsgBox('Failed to open database!', mbError, MB_OK);
Exit;
end;

SQLQuery := 'DELETE FROM Settings WHERE ServiceId = ''' + ServiceId + ''';';
MsgBox(SQLQuery, mbInformation, MB_OK);

MsgBox('Executing query', mbInformation, MB_OK);
Res := sqlite3_exec(SQLiteDB, SQLQuery, 0, 0, 0);
if Res <> 0 then
MsgBox('Error executing DELETE query!', mbError, MB_OK)
else
MsgBox('Record deleted!', mbInformation, MB_OK);

// Close database
sqlite3_close(SQLiteDB);
end;

It gives me Could not call proc error on sqlite3_open. I also tried with this function which uses exe file:
function RunSQLiteCommand(const dbPath: String; const sqlQuery: String): Boolean;
var
ResultCode: Integer;
Command: String;
begin
// Construct the command to run sqlite3.exe with the desired SQL query
Command := '"' + ExpandConstant('{app}\sqlite3.exe') + '" "' + dbPath + '" "' + sqlQuery + '"';
MsgBox(Command,mbInformation, MB_OK);
// Execute the command and get the result
Exec(Command, '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
function RunSQLiteCommand(const dbPath: String; const sqlQuery: String): Boolean;
var
ResultCode: Integer;
Command: String;
begin
// Construct the command to run sqlite3.exe with the desired SQL query
Command := '"' + ExpandConstant('{app}\sqlite3.exe') + '" "' + dbPath + '" "' + sqlQuery + '"';
MsgBox(Command,mbInformation, MB_OK);
// Execute the command and get the result
Exec(Command, '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
end;
which doesnt give me any error, but also doesnt do anything. How can i test these things outside of "inno setup" file, because its really annoying to always rebuild installer, install app and uninstall...
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?