Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | The default entry point for loadable extensions is now always sqlite3_extension_init(). (CVS 3268) |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
059b1f61406ca60fdbd3ec59c5b15fad |
User & Date: | drh 2006-06-17 13:21:32.000 |
Context
2006-06-17
| ||
14:12 | Add the load_extension() SQL function. (CVS 3269) (check-in: e08e2ddafe user: drh tags: trunk) | |
13:21 | The default entry point for loadable extensions is now always sqlite3_extension_init(). (CVS 3268) (check-in: 059b1f6140 user: drh tags: trunk) | |
11:30 | Add newly created virtual tables to the current transaction. (CVS 3267) (check-in: ea7e4eca10 user: danielk1977 tags: trunk) | |
Changes
Changes to src/loadext.c.
︙ | ︙ | |||
193 194 195 196 197 198 199 | # define SQLITE_OPEN_LIBRARY(A) dlopen(A, RTLD_NOW | RTLD_GLOBAL) # define SQLITE_FIND_SYMBOL(A,B) dlsym(A,B) # define SQLITE_CLOSE_LIBRARY(A) dlclose(A) #endif /* ** Attempt to load an SQLite extension library contained in the file | | | > < < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < | | 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | # define SQLITE_OPEN_LIBRARY(A) dlopen(A, RTLD_NOW | RTLD_GLOBAL) # define SQLITE_FIND_SYMBOL(A,B) dlsym(A,B) # define SQLITE_CLOSE_LIBRARY(A) dlclose(A) #endif /* ** Attempt to load an SQLite extension library contained in the file ** zFile. The entry point is zProc. zProc may be 0 in which case a ** default entry point name (sqlite3_extension_init) is used. Use ** of the default name is recommended. ** ** Return SQLITE_OK on success and SQLITE_ERROR if something goes wrong. ** ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with ** error message text. The calling function should free this memory ** by calling sqlite3_free(). */ int sqlite3_load_extension( sqlite3 *db, /* Load the extension into this database connection */ const char *zFile, /* Name of the shared library containing extension */ const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */ char **pzErrMsg /* Put error message here if not 0 */ ){ #ifdef SQLITE_LIBRARY_TYPE SQLITE_LIBRARY_TYPE handle; int (*xInit)(sqlite3*,char**,const sqlite3_api_routines*); char *zErrmsg = 0; SQLITE_LIBRARY_TYPE *aHandle; if( zProc==0 ){ zProc = "sqlite3_extension_init"; } handle = SQLITE_OPEN_LIBRARY(zFile); if( handle==0 ){ if( pzErrMsg ){ *pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile); } |
︙ | ︙ |
Changes to src/test_schema.c.
︙ | ︙ | |||
9 10 11 12 13 14 15 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the virtual table interfaces. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** | | | | | | 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | ** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the virtual table interfaces. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** ** $Id: test_schema.c,v 1.4 2006/06/17 13:21:33 drh Exp $ */ /* The code in this file defines a sqlite3 virtual-table module that ** provides a read-only view of the current database schema. There is one ** row in the schema table for each column in the database schema. */ #define SCHEMA \ "CREATE TABLE x(" \ "database," /* Name of database (i.e. main, temp etc.) */ \ "tablename," /* Name of table */ \ "cid," /* Column number (from left-to-right, 0 upward) */ \ "name," /* Column name */ \ |
︙ | ︙ | |||
328 329 330 331 332 333 334 | } #else /* ** Extension load function. */ | | | 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 | } #else /* ** Extension load function. */ int sqlite3_extension_init( sqlite3 *db, char **pzErrMsg, const sqlite3_api_routines *pApi ){ SQLITE_EXTENSION_INIT2(pApi); sqlite3_create_module(db, "schema", &schemaModule, 0); return 0; } #endif |
Changes to test/loadext.test.
1 2 3 4 5 6 7 8 9 10 11 12 13 | # 2006 July 14 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is in-memory database backend. # | | > > | | > > > > > > > > > | > | | > | | | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # 2006 July 14 # # The author disclaims copyright to this source code. In place of # a legal notice, here is a blessing: # # May you do good and not evil. # May you find forgiveness for yourself and forgive others. # May you share freely, never taking more than you give. # #*********************************************************************** # This file implements regression tests for SQLite library. The # focus of this script is in-memory database backend. # # $Id: loadext.test,v 1.2 2006/06/17 13:21:33 drh Exp $ set testdir [file dirname $argv0] source $testdir/tester.tcl # The name of the test extension varies by operating system. # if {$::tcl_platform(platform) eq "windows"} { set testextension ./testloadext.dll } else { set testextension ./libtestloadext.so } # Make sure the test extension actually exists. If it does not # exist, try to create it. If unable to create it, then skip this # test file. # if {![file exists $testextension]} { set srcdir [file dir $testdir]/src set testextsrc $srcdir/test_loadext.c if {[catch { exec gcc -shared $testextsrc -o $testextension } msg]} { puts "Skipping loadext tests: Test extension not built..." puts $msg finish_test return } } # Test that loading the extension produces the expected results - adding # the half() function to the specified database handle. # do_test loadext-1.1 { catchsql { SELECT half(1.0); } } {1 {no such function: half}} do_test loadext-1.2 { sqlite3_load_extension db $testextension testloadext_init catchsql { SELECT half(1.0); } } {0 0.5} # Test that a second database connection (db2) can load the extension also. # do_test loadext-1.3 { sqlite3 db2 test.db catchsql { SELECT half(1.0); } db2 } {1 {no such function: half}} do_test loadext-1.4 { sqlite3_load_extension db2 $testextension testloadext_init catchsql { SELECT half(1.0); } db2 } {0 0.5} # Close the first database connection. Then check that the second database # can still use the half() function without a problem. |
︙ | ︙ | |||
71 72 73 74 75 76 77 | db2 close sqlite3 db test.db # Try to load an extension for which the file does not exist. # do_test loadext-2.1 { set rc [catch { | | | | | | | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | db2 close sqlite3 db test.db # Try to load an extension for which the file does not exist. # do_test loadext-2.1 { set rc [catch { sqlite3_load_extension db "${testextension}xx" } msg] list $rc $msg } [list 1 [subst -nocommands \ {unable to open shared library [${testextension}xx]} ]] # Try to load an extension for which the file is not a shared object # do_test loadext-2.2 { set fd [open "${testextension}xx" w] puts $fd blah close $fd set rc [catch { sqlite3_load_extension db "${testextension}xx" } msg] list $rc $msg } [list 1 [subst -nocommands \ {unable to open shared library [${testextension}xx]} ]] # Try to load an extension for which the file is present but the # entry point is not. # do_test loadext-2.3 { set rc [catch { |
︙ | ︙ | |||
114 115 116 117 118 119 120 | set rc [catch { sqlite3_load_extension db $testextension testbrokenext_init } msg] list $rc $msg } {1 {error during initialization: broken!}} finish_test | < | 127 128 129 130 131 132 133 | set rc [catch { sqlite3_load_extension db $testextension testbrokenext_init } msg] list $rc $msg } {1 {error during initialization: broken!}} finish_test |