© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•12mo 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 
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...
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Inno Setup script - Calling SQLite query
C#CC# / help
12mo ago
❔ Inno Setup ...SetupIconFile
C#CC# / help
3y ago
✅ sqlite local db file
C#CC# / help
2y ago
Handling DB migrations for desktop app sqlite db
C#CC# / help
8mo ago