wapptclsh custom C function - was: wapptclsh sqlite3 extension function
(1.2) By ufko.org on 2025-03-20 12:55:20 edited from 1.1 [link] [source]
I'll write this naively, but I would like to have a simple SQLite3 function hello in the statically linked wapptclsh, which returns a text value. Whenever a connection to the database is opened, function should be automatically available for use with db eval {}. Can someone suggest any documentation on how to do this? Where to start ...
(2.1) By Stephan Beal (stephan) on 2025-02-07 15:42:59 edited from 2.0 in reply to 1.1 [source]
Can someone suggest any documentation on how to do this?
SQLite auto-extensions can do that but i do not see them in the in the TCL bindings.
Edit: but if you're extending wapp with your own C code (IIRC you are?) then that would be the way to do it.
(3.1) By ufko.org on 2025-02-07 21:44:42 edited from 3.0 in reply to 2.1 [link] [source]
Thank you for your response, Stephan! Yes, I'm extending Wapp with my own C code, so I proceeded with creating the SQLite function in C and registering it using sqlite3_create_function().
I used the following template from SQLite as a base for my implementation: https://www.sqlite.org/src/file/ext/misc/rot13.c. The compilation was successful, but the function isn't available when using db eval, so I must be missing some initialization step or doing something wrong in the setup.
It seems that this might not be possible to statically compile and have the function available without using sqlite3_auto_extension. The error message I receive is: "Error: no such function: hello. I don't wanna stress drh out by inflating his projectš
(4.2) By ufko.org on 2025-03-20 12:56:04 edited from 4.1 in reply to 1.1 [link] [source]
It's not exactly what I wanted, but it's even better! Maybe not implemented perfectly, but it works, and I have my first built-in C function in wapptclsh! :) I added it to my ~70 Tcl wrappers, which I'm using to learn how to work with Tcl.
The function is located in additions.c https://github.com/ufko-org/wapp/blob/main/additions.c
and initialized in wapptclsh.c.in
https://github.com/ufko-org/wapp/blob/fd944601adf4d1a92628985b2637d286ffcf6a87/wapptclsh.c.in#L74
_ _ _
| | | |___ ___ ___
| | | | .'| . | . |
|_____|__,| _| _|
|_| |_|
Wapp 1.0 shell using SQLite version 3.50.0 and TCL 9.0
% hello
Hello, world!
%