Tcl Starkit that Reads of off a Sqlite Database

1.4k Views Asked by At

I am trying to build a Tcl Application that reads off of a Sqlite database. When I build a starkit for the application and place the Sqlite database file next to the .tcl file within the .vfs folder and try to run the application (.exe), I receive the error, "can't find package sqlite3 while executing package require sqlite3".

I believe my application is unable to find the database file. Before building the starkit, the .tcl application is able to read the Sqlite database, but after I create the starkit, the .tcl file gets the error.

Does anyone know how to enable a Tcl application starkit to read a Sqlite database file?

Thanks,

DFM

3

There are 3 best solutions below

1
On

With the help of everyone who replied to my question and some thorough research, I figured out steps to create a starpack that wraps a Tcl App with a Sqlite back-end. The steps to create the starpack are as follows:

  1. Download and place in a folder tclkit-win32.upx.exe and sdx.kit.

  2. Make a copy of the tclkit-win32.upx.exe and rename it to tclkit.exe (leave in same folder)

  3. Add your .tcl (test.tcl) application to the folder (make sure that it has the code package require sqlite.

  4. Run the tclkit-win32.upx.exe file and type the following per line (do not close when done):

    source sdx.kit
    package require sdx
    sdx::sdx qwrap test.tcl
    sdx::sdx unwrap test.kit
    
  5. Download tclsqlite3.dll from the sqlite website and place in a separate folder. Name the folder sqlite.

  6. Use a text app like Notepad and add the following code:

    package ifneeded sqlite 3.6.18 [list load [file join $dir tclsqlite3.dll]].
    

    Save as pkgIndex.tcl and place in the sqlite folder with the tclsqlite3.dll.

  7. Go into your first folder in step one. You should see a .vfs folder. Open the .vfs folder, and then open the lib folder. Place the sqlite folder in the lib folder. The lib folder should have a app-test folder (corresponds with test.tcl) and your sqlite folder.

    Alternative to steps 5-7: copy the folder containing the sqlite dll from the tcl folder on C:\ into the lib folder. You can verify the path of the dll by using

      package ifneeded sqlite3 [package require sqlite3]
    

    The sqlite folder will have two files, the dll file and a pkgIndex.tcl. If you do it this way, you have to use package require sqlite3 in step 3.

  8. With tclkit-win32.upx.exe still running, type the following code:

    sdx::sdx wrap test.exe -runtime tclkit.exe
    
  9. Lastly, place your sqlite .db file next to your newly created application .exe (test.exe) and run the app.

Make sure to watch for version conflicts. I had major problems with the package require sqlite code snippet. Originally, I had package require sqlite3, which wasn't working. Also, when you create the pkgIndex.tcl file, make sure to have the correct version of sqlite (i.e. 3.2.18, etc...).

Thank you for everyone's assistance.

DFM

1
On

I think that it is more likely that your starkit can't load the sqlite3 package. Have you created a lib directory in your .vfs folder and copied the sqlite3 package into it?

4
On

It sounds like you're discussing two different things in your question.

The first is the ability to load the sqllite3 library. As noted by Jackson, you'll need to include the sqllite3 library (tcl and accompanying files) in the lib directory of your starpack. Once that is done correctly, the "package required sqlite3" command should work correctly.

The second is in regards to the -writable flag. If I'm understanding correctly, that just allows you to modify files within the starpack while it's running. It has nothing to do with the ability to load a library included in the starpack, but would be used to allow that library to modify files (like the database file you talked about).

I was under the impression that it wasn't possible to write to a (a file inside a) starkit that is running, due to certain OS constraints. That being said, I found the following from Brent Welch's amazing book "Practical programming in Tcl and Tk":

If you run the write.kit file more than once you will notice that the write.kit/data.new file not persist between runs. This is because, by default, the Metakit database is modified in main memory and it is not written out to the Starkit file. if you want to store file long term, use the -writable flag to sdx:

sdx wrap write.kit writable

Referece: Google Books