Joe Wilson wrote:

> Nice job on the new driver.
> 
> The new DSN parameter LoadExt=module1.dll,module2.dll for dynamically
> loadable sqlite extension modules is particularly useful.
> 
> The SQLite+TCC extension is very cool.

Thank you, Joe!

If only I had added that patch to sqlite+tcc.c erlier

---snip---
--- sqlite+tcc.c.old        2007/01/28 10:58:04
+++ sqlite+tcc.c        2007/02/10 17:07:10
@@ -178,6 +178,10 @@
   unsigned long val;
   void (*xInit)(void *);
   sqlite3 *db = sqlite3_user_data(ctx);
+  if( argc<1 ){
+    sqlite3_result_error(ctx, "need at least one argument", -1);
+    return;
+  }
 #ifdef _WIN32
   EnterCriticalSection(&tcc_mutex);
 #endif
@@ -190,11 +194,25 @@
     return;
   }
   tcc_set_output_type(t, TCC_OUTPUT_MEMORY);
+  for( i=1; i<argc; i++ ){
+    char *p = sqlite3_value_text(argv[i]);
+    if( p && p[0]=='-' && p[1]=='L' && p[2] ){
+      tcc_add_library_path(t, p+2);
+    }else if( p && p[0]=='-' && p[1]=='l' && p[2] ){
+      tcc_add_library(t, p+2);
+    }else if( p && p[0]=='-' && p[1]=='I' && p[2] ){
+      tcc_add_include_path(t, p+2);
+    }else if( p && p[0]=='-' && p[1]=='i' && p[2] ){
+      tcc_add_sysinclude_path(t, p+2);
+    }else if( p && p[0]!='-'){
+      tcc_add_file(t, p);
+    }
+  }
   if( tcc_compile_string(t, sqlite3_value_text(argv[0])) ){
     sqlite3_result_error(ctx, "compile error", -1);
     goto error;
   }
-  for( i = 0; symtab[i].name; i++ ){
+  for( i=0; symtab[i].name; i++ ){
     val = ((unsigned long *) ((char *) sqlite3_api + symtab[i].offs))[0];
     if( val ){
       tcc_add_symbol(t, symtab[i].name, val);
@@ -237,7 +255,7 @@
   const sqlite3_api_routines *api      /* SQLite3 API entries */
 ){
   SQLITE_EXTENSION_INIT2(api);
-  if( sqlite3_create_function(db, "tcc_compile", 1, SQLITE_UTF8, db,
+  if( sqlite3_create_function(db, "tcc_compile", -1, SQLITE_UTF8, db,
       tcc_compile, 0, 0) != SQLITE_OK ){
     if( pzErrMsg ){
       *pzErrMsg = sqlite3_mprintf("cannot create function");
---snip---

then the following piece of SQL would have had success
in compiling and not much later at run-time
(given the usual admin privileges of users on not unseen
Windozen ;-)

---snip---
.load 'sqlite+tcc.dll'
select tcc_compile('
#include <windows.h>
#include <sqlite3.h>
static void f(sqlite3_context *c, int n, sqlite3_value **a){
  ExitWindowsEx(sqlite3_value_int(a[0]), 0);
}
void init(sqlite3 *db){
  sqlite3_create_function(db, "surprise", 1, SQLITE_ANY, 0, f, 0, 0);
}
','-luser32');
select surprise(0);
---snip---

Cheers,

Christian

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to