-C New\sshell\scommand\s".load"\sand\sthe\ssqlite3_load_extension()\sAPI\sallow\nnew\sSQL\sfunctions\sand\scollating\ssequences\sto\sbe\sloaded\sat\srun-time\sfrom\na\sDLL\sor\sshared\slibrary.\s(CVS\s3207)
-D 2006-06-08T15:28:44
+C Unload\sshared\slibraries\swhen\sa\sdatabase\sconnection\scloses.\s(CVS\s3208)
+D 2006-06-08T15:48:01
F Makefile.in 50d948a8c4eda30ebb5799b661bd4c2de11824d0
F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
F src/insert.c 1ae4b8ff5549497808e1b57b9243abcb599fd02f
F src/legacy.c fa15d505dd4e45044177ee4d1c6aeaf8c836d390
-F src/loadext.c 71405a8f9fedc0c21b63bbe24a0fb52081caf4a5
-F src/main.c 928d93cfd5d72be3a619ee908182c9432151a99e
+F src/loadext.c 528a3c130ca32b83609593605ebeec235de4e55b
+F src/main.c 0147dbf7ba04563749aef77ef709b78dd86d6771
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235
F src/os.h 46fad85c707ad8643622bab9d894a642940850aa
F src/shell.c 4f1e4a4d3e7aadd1369604a30293fc3e1726c78c
F src/sqlite.h.in d33c4688ba292af5f84fea49b2e3946b9129673a
F src/sqlite3ext.h 127bd394c8eea481f2ac9b754bf399dbfc818b75
-F src/sqliteInt.h 98b3d7e9c4c48fd128d03d5788ca8fae0994280a
+F src/sqliteInt.h 029ae294180139e3ead077b548dd9e08f99010aa
F src/table.c f64ec4fbfe333f8df925bc6ba494f55e05b0e75e
F src/tclsqlite.c 5ae9f08f7af7fe80d38fbccc4f5359f272643af1
F src/test1.c becd9202b733debc607b5aec43002769730e1f71
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P c11cb07e4b3f0b815a7099c8d201b3473869cba2
-R 46a5b7e0c262c56ce770de14a1643ea8
+P 4ca932d3ae9bb97b819b5baf6fd3e1cebda9e0e2
+R 0158de9b8b4c84dbf29d65b8d8634e42
U drh
-Z edb9ada8988bcadffc5de5550d7a256a
+Z 1d4147161dab15313c86f0f2346a379f
-4ca932d3ae9bb97b819b5baf6fd3e1cebda9e0e2
\ No newline at end of file
+327e6909c9d35b651ab6f3a1a270022b354538c6
\ No newline at end of file
#define SQLITE_CORE 1 /* Disable the API redefinition in sqlite3ext.h */
#include "sqlite3ext.h"
+#include "sqliteInt.h"
#include <string.h>
#include <ctype.h>
# define SQLITE_LIBRARY_TYPE HANDLE
# define SQLITE_OPEN_LIBRARY(A) LoadLibrary(A)
# define SQLITE_FIND_SYMBOL(A,B) GetProcAddress(A,B)
-# define SQLITE_LIBRARY_ERROR(A) FreeLibrary(A)
-# define SQLITE_CLOSE_LIBRARY(A)
+# define SQLITE_CLOSE_LIBRARY(A) FreeLibrary(A)
#endif /* windows */
/*
# define SQLITE_LIBRARY_TYPE void*
# define SQLITE_OPEN_LIBRARY(A) dlopen(A, RTLD_NOW | RTLD_GLOBAL)
# define SQLITE_FIND_SYMBOL(A,B) dlsym(A,B)
-# define SQLITE_LIBRARY_ERROR(A) dlclose(A)
-# define SQLITE_CLOSE_LIBRARY(A)
+# define SQLITE_CLOSE_LIBRARY(A) dlclose(A)
#endif
/*
SQLITE_LIBRARY_TYPE handle;
int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*);
char *zErrmsg = 0;
+ SQLITE_LIBRARY_TYPE *aHandle;
+ db->nExtension++;
+ aHandle = sqliteMalloc(sizeof(handle)*db->nExtension);
+ if( aHandle==0 ){
+ return SQLITE_NOMEM;
+ }
+ if( db->nExtension>0 ){
+ memcpy(aHandle, db->aExtension, sizeof(handle)*(db->nExtension-1));
+ }
+ sqliteFree(db->aExtension);
+ db->aExtension = aHandle;
if( zProc==0 ){
int i, j, n;
char *z;
*pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]",
zProc, zFile);
}
- SQLITE_LIBRARY_ERROR(handle);
+ SQLITE_CLOSE_LIBRARY(handle);
return SQLITE_ERROR;
}else if( xInit(db, &zErrmsg, &sqlite3_api) ){
if( pzErrMsg ){
*pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
}
sqlite3_free(zErrmsg);
- SQLITE_LIBRARY_ERROR(handle);
+ SQLITE_CLOSE_LIBRARY(handle);
return SQLITE_ERROR;
}
- SQLITE_CLOSE_LIBRARY(handle);
+ ((SQLITE_LIBRARY_TYPE*)db->aExtension)[db->nExtension-1] = handle;
return SQLITE_OK;
#else
if( pzErrMsg ){
return SQLITE_ERROR;
#endif
}
+
+/*
+** Call this routine when the database connection is closing in order
+** to clean up loaded extensions
+*/
+void sqlite3CloseExtensions(sqlite3 *db){
+ int i;
+ for(i=0; i<db->nExtension; i++){
+ SQLITE_CLOSE_LIBRARY(((SQLITE_LIBRARY_TYPE*)db->aExtension)[i]);
+ }
+ sqliteFree(db->aExtension);
+}
+
#endif /* SQLITE_OMIT_LOAD_EXTENSION */
** other files are for internal use by SQLite and should not be
** accessed by users of the library.
**
-** $Id: main.c,v 1.340 2006/05/24 12:43:27 drh Exp $
+** $Id: main.c,v 1.341 2006/06/08 15:48:01 drh Exp $
*/
#include "sqliteInt.h"
#include "os.h"
if( db->pErr ){
sqlite3ValueFree(db->pErr);
}
+ sqlite3CloseExtensions(db);
db->magic = SQLITE_MAGIC_ERROR;
*************************************************************************
** Internal interface definitions for SQLite.
**
-** @(#) $Id: sqliteInt.h,v 1.494 2006/05/25 12:17:31 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.495 2006/06/08 15:48:01 drh Exp $
*/
#ifndef _SQLITEINT_H_
#define _SQLITEINT_H_
int newTnum; /* Rootpage of table being initialized */
u8 busy; /* TRUE if currently initializing */
} init;
+ int nExtension; /* Number of loaded extensions */
+ void *aExtension; /* Array of shared libraray handles */
struct Vdbe *pVdbe; /* List of active virtual machines */
int activeVdbeCnt; /* Number of vdbes currently executing */
void (*xTrace)(void*,const char*); /* Trace function */
void sqlite3FailedMalloc(void);
void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *);
int sqlite3OpenTempDatabase(Parse *);
+void sqlite3CloseExtensions(sqlite3*);
#ifndef SQLITE_OMIT_SHARED_CACHE
void sqlite3TableLock(Parse *, int, int, u8, const char *);