Jump to content
BobW

How to deploy a simple Win 32 app with SQLite file

Recommended Posts

How to deploy a simple Win  32 app with SQLite file?

I just want to be able to set up the deployment to be able to create an executable Windows 32 bit app that has one Sqlite file that I can copy to another machine and execute.

Is there a simple way of doing that?

Share this post


Link to post

Bob, it's not clear to me what you're asking.

Are you saying you have two files

1. MyProgram.exe

 

and

 

2. sqllite.dll

 

And you want to have create an installer that installs these two files on your target machine?

Look into Inno, a free installer that many, many of us use.

 

 

Share this post


Link to post

MyProgram.exe and database.db are what I am trying to install on a naive machine and have it run the *exe using the SQLite *.db file locally.

Share this post


Link to post

You just need to adjust the path on the db connection to allow for the path on the new machine. 

Options:

  1. TPath to build the path --preferred
  2. fdcsqlite.Params.Database := TPath.Combine(TPath.GetHomePath, 'RTTKCaddie.db');

     

  3. adjust the file name to mydbfile.db with no directory and put it in the same directory as the exe
fdcsqlite.Params.Database :=  'RTTKCaddie.db';

 

Share this post


Link to post
2 minutes ago, Cristian Peța said:

does FireDAC is doing the same?

Default in Firedac is to static link.  To change it you add a  TFDPhysSQLiteDriverLink component and then set the option.

 

4 minutes ago, Cristian Peța said:

Then you need to statically link SQLite code in your executable.

Valid point, depending on the data layer it is something to consider.

Share this post


Link to post

You can even link the database into the exe as a resource and write it to disk if it doesn't exist.

Share this post


Link to post

If I use this code it doesn't find my table within my database:

  DriversConnection.DriverName:='SQLite';
  DriversConnection.ConnectionDefName:='Drivers';
  DriversConnection.Params.Database:='Drivers.db';
  DriversConnection.Params.DriverID:='SQLite';
  DriversConnection.Open;

Share this post


Link to post
43 minutes ago, BobW said:

DriversConnection.ConnectionDefName:='Drivers';

What are the settings in the connection definition with name Drivers?

Share this post


Link to post
41 minutes ago, BobW said:

If I use this code it doesn't find my table within my database:

Sounds like it is not finding the database file, do it is starting with an empty database. 

Is the Drivers.db in the same directory as the EXE?  If yes, then you need to set the working directory.  Test it by going to a command line and running the Exe, and make sure in dir *.db your file shows.

 

 

Share this post


Link to post

Thanks for all of the suggestions.  I looked at Inno Setup and it looks like easiest way to deploy a simple Win32 application with a SQLite database file.

What settings would I need in my TFDConnection so that it looks locally where it is installed?  Just use Inno Setup with the exe and db file, so that the applications looks in the same location as the exe file.

image.thumb.png.b4d18b4f1d4361198649df9c8a815ccf.png

Share this post


Link to post

Uwe,

Thanks for the response.  

Could you go into more detail for this:

Set Params.Database to $(RUN)\Drivers.db

How do I use the above?  Is that hard coded in the application or a macro definition in Inno SetUp?

Share this post


Link to post

  e.g.

  {$IF DEFINED(IOS) or DEFINED(ANDROID)}
    FDConnection.Params.Database:=TPath.Combine(TPath.GetDocumentsPath,'xxx.db');
  {$ELSE}
    FDConnection.Params.Database:=ExtractFilePath(ParamStr(0))+'xxx.db';
  {$ENDIF}
  FDConnection.Connected:=True;

 

Share this post


Link to post
1 hour ago, BobW said:

How do I use the above?  Is that hard coded in the application or a macro definition in Inno SetUp?

You showed a screenshot of the Object Inspector for the TFDConnection. There can be seen the Params.Database value with c:\temp\drivers.db. Change that to $(RUN)\Drivers.db and your program will look for Drivers.db in the folder where the exe is. (I don't know how to explain it better.)

Share this post


Link to post

When I put $(RUN)\Drivers.db in TFDConnection.Params.Database the application gives me an error saying it can't find the Drivers2 table anymore.

 

Sorry........

Share this post


Link to post

Ok, now when I put the application on another machine it says I need a driver definition file..................

How do I create one of those and where do I tell the application to use it?

Share this post


Link to post
7 hours ago, BobW said:

Ok, now when I put the application on another machine it says I need a driver definition file..................

That is because you give a ConnectionDefName:

On 4/14/2022 at 6:01 PM, BobW said:

DriversConnection.ConnectionDefName:='Drivers';

The given value is the name of an entry in the definition file with the required values for that connection. My first question was targeting exactly that, simply because you gave most of the entries in your code as well - so why the def name.

 

If you remove this assignment in your code as well as in the object inspector of the connection, this message should disappear.

Share this post


Link to post
9 hours ago, BobW said:

When I put $(RUN)\Drivers.db in TFDConnection.Params.Database the application gives me an error saying it can't find the Drivers2 table anymore.

Well, I cannot see what db is in the exe path and what tables it contains. The $(RUN) variable is simply expanded to the path of the exe file. So the cause of your problem is most likely the db found in that folder.

 

Note that the $(RUN) expansion will only give correct results at runtime and not while in the designer.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×