On Thu, Nov 19, 2009 at 10:58:55AM -0500, Tim Romano scratched on the wall: > 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,
He is defining a custom SQL function. > and can what Walter is doing be done in other languages, namely Adobe Flex > AIR/ActionScript? Only with C wrappers. He's using TCL wrappers to the published SQLite C API. In specific, see the API call "sqlite3_create_function()": http://sqlite.org/c3ref/create_function.html > 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? Yes, but there is a lot of TCL/C glue between the TCL environment and the published SQLite C API. It just happens that the folks that developed SQLite are big TCL people. > Where does a function registered with the SQLite engine live? Anywhere you want. There are lots of options: 1) Custom compiled version of the SQLite library. 2) External dynamic-library/shared-object/DLL. 3) In the application code that interfaces with SQLite. > Is it stored inside the database? Typically, no. Somewhere there needs to be compiled C code, and that clearly cannot go into the database. On the other hand, if you're using the TCL wrappers (or some other scripting language) you could put the script code into the database. Something still needs to extract it and register it, however, and provide a run-time environment. > 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? Via the C API, anything you can do in C or C wrapper out to a different language. You can write a custom SQL function that sends Tweets, if you want. This is what everyone is talking about when they've been saying "just put it in your application." They don't mean in your application business logic, they're saying that whatever code that opens and manipulates the SQLite API can simply register a simple C function with the SQLite engine to provide your own custom fit SQL function. It is also worth pointing out that this is *exactly* how "built-in" functions work. They use the exact same registration process to import the "built-in" SQL functions into the SQL environment. The only difference is that the C code that actually implements the function sits in the SQLite library, rather than in your application code or in an external library. You can do the same. You could also just write your own custom collation, but that's a whole different story. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "Our opponent is an alien starship packed with atomic bombs. We have a protractor." "I'll go home and see if I can scrounge up a ruler and a piece of string." --from Anathem by Neal Stephenson _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users