Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

SQLite - pointer to function question

 [1/2] from: rebol-list2::seznam::cz at: 29-Feb-2004 20:55


Hello rebol-list, I've been playing a bit with SQLite.dll ( http://sqlite.org ) and even I'm not expert in this filed at all, I manage to open db and execute SQL commands using this DLL. But the problem is that if you want to use SELECT command you must send pointer to a callback function which should be evaluated for each result row. Is there any change to get a pointer to a Rebol function? Here are are my SQLite routine(s)! ================================== rebol [] sqlite: load/library %/j/sqlite.dll sqlite_open: make routine! [ zFilename [string! ] mode [integer!] pzErr [string! ] return: [integer!] ] sqlite "sqlite_open" sqlite_close: make routine! [db [integer!]] sqlite "sqlite_close" sqlite_exec: make routine! [ db [integer!] "pointer to open database" sql [string! ] "SQL to be executed" callback [integer!] "pointer to Callback function" cb_arg [integer!] "1st argument to callback function" errmsg [string! ] "Error msg written here" return: [integer!] ] sqlite "sqlite_exec" sqlite_version: make routine! [ return: [string!] ] sqlite "sqlite_libversion" sqlite_error_string: make routine! [ int [integer!] return: [string! ] ] sqlite "sqlite_error_string" err: copy "" db: sqlite_open "test" 0 err sqlite_exec db "create table t (f text);" 0 0 err sqlite_exec db "insert into t values('test');" 0 0 err -- Best regards, rebOldes -----------------[ http://oldes.multimedia.cz/ ]

 [2/2] from: nitsch-lists:netcologne at: 1-Mar-2004 22:05


Am Sonntag, 29. Februar 2004 20:55 schrieben Sie:
> Hello rebol-list, > I've been playing a bit with SQLite.dll ( http://sqlite.org ) and
<<quoted lines omitted: 3>>
> function which should be evaluated for each result row. > Is there any change to get a pointer to a Rebol function?
No AFAIK. BUT youmay read the docs further and note a second interface which works callback-free ;) http://www.sqlite.org/c_interface.html 2.0 Accessing Data Without Using A Callback Function The sqlite_exec routine described above used to be the only way to retrieve data from an SQLite database. But many programmers found it inconvenient to use a callback function to obtain results. So beginning with SQLite version 2.7.7, a second access interface is available that does not use callbacks. The new interface uses three separate functions to replace the single sqlite_exec function. typedef struct sqlite_vm sqlite_vm; int sqlite_compile( sqlite *db, /* The open database */ const char *zSql, /* SQL statement to be compiled */ const char **pzTail, /* OUT: uncompiled tail of zSql */ sqlite_vm **ppVm, /* OUT: the virtual machine to execute zSql */ char **pzErrmsg /* OUT: Error message. */ ); int sqlite_step( sqlite_vm *pVm, /* The virtual machine to execute */ int *pN, /* OUT: Number of columns in result */ const char ***pazValue, /* OUT: Column data */ const char ***pazColName /* OUT: Column names and datatypes */ ); int sqlite_finalize( sqlite_vm *pVm, /* The virtual machine to be finalized */ char **pzErrMsg /* OUT: Error message */ ); The strategy is to compile a single SQL statement using sqlite_compile then invoke sqlite_step multiple times, once for each row of output, and finally call sqlite_finalize to clean up after the SQL has finished execution. //and now have fun ;) //-Volker

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted