Whilst trying to get a TCL script to create a function in SQLite I ran
into problems and did a lot of Googling. I got very tired of seeing the
same old same old...
proc sql_sqrt {x} {return [expr {sqrt($x)}]}
db function sqrt sql_sqrt
It didn't help me because it used only one parameter. It didn't say
anything about you
- *MUST NOT* have commas between parameters in the function definition
- *MUST* have commas between parameters when actually calling it
I spent several hours figuring this out. Here's a working example...
package require sqlite3
sqlite3 db :memory:
db eval {create table dual(x varchar(1))}
db eval {insert into dual values(' ')}
proc sql_addnum { a b } { return [expr { $a + $b }] }
db function addnum sql_addnum
db eval {select 'Hello world' as x from dual} {puts stdout "$x"}
db eval {select 99999999999 as y from dual} {puts stdout "$y"}
db eval {select addnum(1, 2) as z from dual} {puts stdout "$z"}
db close
And the output is...
Hello world
99999999999
3
Use this code as an example, and it may save someone else some time
down the road.
--
Walter Dnes <[email protected]>
_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users