Re: [sqlite] Query within user defined funtion / UDF in sqlite
RAKESH HEMRAJANIwrote: > for example: > > an user defined function is intended to get the rowcount of the input table. > > user can type the below command > > select rowcount('employee') from sqlite_master; What's the role of sqlite_master in this query? Accepting, for the sake of argument, that it's useful to encapsulate row count in a user-defined function, why isn't the query simply select rowcount('employee'); > actual code: > it fails since m unable to get call back reference from context variable What is this "callback reference" you speak of? Why can't you provide your own callback (if for some reason you insist on using sqlite3_exec), or use sqlite3_prepare / sqlite3_step interface? > and bcoz of that application terminates while printing > the value to the o/p interface (user screen) Why does a custom function need to print anything? It just needs to calculate its result, and report it using one of sqlite3_result_* functions. -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Query within user defined funtion / UDF in sqlite
Hello Experts, How can i execute a query from user defined function. the user defined function is defined inside sqlite itself (in shell.c opendb function, there is user defined function shellstatic but it doenst query the DB) for example: an user defined function is intended to get the rowcount of the input table. user can type the below command select rowcount('employee') from sqlite_master; the user defined function should replace rowcount('employee') with the actual rowcount of the employee table. pls note that the function should be defined within sqlite only and should be usable from sqlite command line interface as described above. actual code: it fails since m unable to get call back reference from context variable and bcoz of that application terminates while printing the value to the o/p interface (user screen) static void rowcount( sqlite3_context *context, int argc, sqlite3_value **argv ){ struct callback_data *p; char *rowcounttest; rowcounttest = "SELECT 10 from sqlite_master"; char *zErrMsg = 0; sqlite3 *db = sqlite3_context_db_handle(context); shell_exec(db, rowcounttest, shell_callback, context, ); }