Perhaps the list can help me to get beyond some fundamental igorance here.
What is the name for what Walter is doing in the two lines below, and can what Walter is doing be done in other languages, namely Adobe Flex AIR/ActionScript? proc sql_addnum { a b } { return [expr { $a + $b }] } db function addnum sql_addnum I see "function" documented here http://www.sqlite.org/tclsqlite.html and "proc" appears to create a TCL procedure. Is "return [expr { $a + $b }]" also written in TCL? Where does a function registered with the SQLite engine live? Is it stored inside the database? Do the functions one registers in SQLite with the "function" method have at their disposal only simple scalar operators, or can there be loop control structures? Thanks Tim Romano Walter Dnes wrote: > 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. > > > ------------------------------------------------------------------------ > > > No virus found in this incoming message. > Checked by AVG - www.avg.com > Version: 8.5.425 / Virus Database: 270.14.73/2512 - Release Date: 11/18/09 > 19:41:00 > > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users