1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

The default entry point for loadable extensions is now

always sqlite3_extension_init(). (CVS 3268)

FossilOrigin-Name: 059b1f61406ca60fdbd3ec59c5b15fadc6552564
This commit is contained in:
drh
2006-06-17 13:21:32 +00:00
parent e7ff403ab1
commit 428397c143
5 changed files with 46 additions and 74 deletions

View File

@ -1,5 +1,5 @@
C Add\snewly\screated\svirtual\stables\sto\sthe\scurrent\stransaction.\s(CVS\s3267) C The\sdefault\sentry\spoint\sfor\sloadable\sextensions\sis\snow\nalways\ssqlite3_extension_init().\s(CVS\s3268)
D 2006-06-17T11:30:32 D 2006-06-17T13:21:32
F Makefile.in f839b470345d3cb4b0644068474623fe2464b5d3 F Makefile.in f839b470345d3cb4b0644068474623fe2464b5d3
F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -48,7 +48,7 @@ F src/hash.c 449f3d6620193aa557f5d86cbc5cc6b87702b185
F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564 F src/hash.h 1b3f7e2609141fd571f62199fc38687d262e9564
F src/insert.c 5c1fddd7e4d05805e02e12bdced2a3841d2bd8dc F src/insert.c 5c1fddd7e4d05805e02e12bdced2a3841d2bd8dc
F src/legacy.c fa15d505dd4e45044177ee4d1c6aeaf8c836d390 F src/legacy.c fa15d505dd4e45044177ee4d1c6aeaf8c836d390
F src/loadext.c 676257ae268457e7f03261d8ca0d1e72968a26c8 F src/loadext.c 3a730b22dfb6ba2c261848c72fb96a5c3195defd
F src/main.c 7101314a365120465bf5e308caaf518b7776430c F src/main.c 7101314a365120465bf5e308caaf518b7776430c
F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235 F src/os.c 59f05de8c5777c34876607114a2fbe55ae578235
@ -88,7 +88,7 @@ F src/test8.c 9641e41a7d35588fc0a834439b6c404700e7c148
F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3 F src/test_async.c e3deaedd4d86a56391b81808fde9e44fbd92f1d3
F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8 F src/test_loadext.c 22065d601a18878e5542191001f0eaa5d77c0ed8
F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3 F src/test_md5.c 6c42bc0a3c0b54be34623ff77a0eec32b2fa96e3
F src/test_schema.c 3b9fb30f0fed8297097c9b7bd3df484d0cd5e639 F src/test_schema.c 7026296434de0c3c531c0eb65f8990555575a764
F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c F src/test_server.c a6460daed0b92ecbc2531b6dc73717470e7a648c
F src/test_tclvar.c c52f67fbe06d32804af2ba9a2d7aadfc15f5910c F src/test_tclvar.c c52f67fbe06d32804af2ba9a2d7aadfc15f5910c
F src/tokenize.c 6ebcafa6622839968dda4418a7b6945f277a128f F src/tokenize.c 6ebcafa6622839968dda4418a7b6945f277a128f
@ -196,7 +196,7 @@ F test/lastinsert.test 9d7241f562d7adcf61730de83176417d7e30d76b
F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17 F test/laststmtchanges.test 19a6d0c11f7a31dc45465b495f7b845a62cbec17
F test/like.test 5f7d76574752a9101cac13372c8a85999d0d91e6 F test/like.test 5f7d76574752a9101cac13372c8a85999d0d91e6
F test/limit.test 71884068d47b18f614735f0686690319b32cdc22 F test/limit.test 71884068d47b18f614735f0686690319b32cdc22
F test/loadext.test 1704f48b39ba6d9d15b46bf0c0eb1ea82fb06f1f F test/loadext.test 30b38ddaf4ca0703833903bf8ab2e9a680d9cfeb
F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107 F test/lock.test 9b7afcb24f53d24da502abb33daaad2cd6d44107
F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55 F test/lock2.test d83ba79d3c4fffdb5b926c7d8ca7a36c34288a55
F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9 F test/lock3.test 615111293cf32aa2ed16d01c6611737651c96fb9
@ -370,7 +370,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
P ca541ef3c464c5627596a48ee7f1ec40948cf65d P ea7e4eca106cea27d5dc447d2afcd45448152151
R faa9d9cb2a77be8fd7c7ebc5ab33c027 R 02aad4e8db5989bcc93408708ac41194
U danielk1977 U drh
Z 34ba78ce8d03975fc32264aceaa96871 Z 306df56e80d8ad47056ba5abd005e0af

View File

@ -1 +1 @@
ea7e4eca106cea27d5dc447d2afcd45448152151 059b1f61406ca60fdbd3ec59c5b15fadc6552564

View File

@ -197,37 +197,20 @@ const sqlite3_api_routines sqlite3_api = {
/* /*
** Attempt to load an SQLite extension library contained in the file ** Attempt to load an SQLite extension library contained in the file
** zFile. The entry point is zProc. zProc may be 0 in which case the ** zFile. The entry point is zProc. zProc may be 0 in which case a
** name of the entry point is derived from the filename. ** 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. ** 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 ** If an error occurs and pzErrMsg is not 0, then fill *pzErrMsg with
** error message text. The calling function should free this memory ** error message text. The calling function should free this memory
** by calling sqlite3_free(). ** by calling sqlite3_free().
**
** The entry point name is derived from the filename according to the
** following steps:
**
** * Convert the name to lower case
** * Remove the path prefix from the name
** * Remove the first "." and all following characters from the name
** * If the name begins with "lib" remove the first 3 characters
** * Remove all characters that are not US-ASCII alphanumerics
** or underscores
** * Remove any leading digits and underscores from the name
** * Append "_init" to the name
**
** So, for example, if the input filename is "/home/drh/libtest1.52.so"
** then the entry point would be computed as "test1_init".
**
** The derived entry point name is limited to a reasonable number of
** characters (currently 200).
*/ */
int sqlite3_load_extension( int sqlite3_load_extension(
sqlite3 *db, /* Load the extension into this database connection */ sqlite3 *db, /* Load the extension into this database connection */
const char *zFile, /* Name of the shared library containing extension */ const char *zFile, /* Name of the shared library containing extension */
const char *zProc, /* Entry point. Derived from zFile if 0 */ const char *zProc, /* Entry point. Use "sqlite3_extension_init" if 0 */
char **pzErrMsg /* Put error message here if not 0 */ char **pzErrMsg /* Put error message here if not 0 */
){ ){
#ifdef SQLITE_LIBRARY_TYPE #ifdef SQLITE_LIBRARY_TYPE
@ -237,30 +220,7 @@ int sqlite3_load_extension(
SQLITE_LIBRARY_TYPE *aHandle; SQLITE_LIBRARY_TYPE *aHandle;
if( zProc==0 ){ if( zProc==0 ){
int i, j, n; zProc = "sqlite3_extension_init";
char *z;
char zBuf[200];
n = strlen(zFile);
for(i=n-1; i>0 && zFile[i-1]!='/'; i--){}
for(j=i; zFile[j] && zFile[j]!='.'; j++){}
if( j-i > sizeof(zBuf)-10 ) j = i + sizeof(zBuf) - 10;
memcpy(zBuf, &zFile[i], j - i);
zBuf[j - i] = 0;
z = zBuf;
for(i=j=0; z[i]; i++){
int c = z[i];
if( (c & 0x80)!=0 || (!isalnum(c) && c!='_') ) continue;
z[j++] = tolower(c);
}
z[j] = 0;
if( strncmp(z, "lib", 3)==0 ){
z += 3;
}
while( z[0] && !isalpha(z[0]) ){
z++;
}
strcat(z, "_init");
zProc = z;
} }
handle = SQLITE_OPEN_LIBRARY(zFile); handle = SQLITE_OPEN_LIBRARY(zFile);

View File

@ -13,12 +13,12 @@
** is not included in the SQLite library. It is used for automated ** is not included in the SQLite library. It is used for automated
** testing of the SQLite library. ** testing of the SQLite library.
** **
** $Id: test_schema.c,v 1.3 2006/06/16 06:17:47 danielk1977 Exp $ ** $Id: test_schema.c,v 1.4 2006/06/17 13:21:33 drh Exp $
*/ */
/* The code in this file defines a sqlite3 module that provides /* The code in this file defines a sqlite3 virtual-table module that
** a read-only view of the current database schema. There is one ** provides a read-only view of the current database schema. There is one
** row in the schema table for each column in the database. ** row in the schema table for each column in the database schema.
*/ */
#define SCHEMA \ #define SCHEMA \
"CREATE TABLE x(" \ "CREATE TABLE x(" \
@ -332,7 +332,7 @@ int Sqlitetestschema_Init(Tcl_Interp *interp){
/* /*
** Extension load function. ** Extension load function.
*/ */
int schema_init( int sqlite3_extension_init(
sqlite3 *db, sqlite3 *db,
char **pzErrMsg, char **pzErrMsg,
const sqlite3_api_routines *pApi const sqlite3_api_routines *pApi

View File

@ -11,22 +11,35 @@
# This file implements regression tests for SQLite library. The # This file implements regression tests for SQLite library. The
# focus of this script is in-memory database backend. # focus of this script is in-memory database backend.
# #
# $Id: loadext.test,v 1.1 2006/06/14 10:38:03 danielk1977 Exp $ # $Id: loadext.test,v 1.2 2006/06/17 13:21:33 drh Exp $
set testdir [file dirname $argv0] set testdir [file dirname $argv0]
source $testdir/tester.tcl source $testdir/tester.tcl
# The name of the test extension varies by operating system.
#
if {$::tcl_platform(platform) eq "windows"} { if {$::tcl_platform(platform) eq "windows"} {
set testextension testloadext.dll set testextension ./testloadext.dll
} else { } else {
set testextension libtestloadext.so 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]} { 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 "Skipping loadext tests: Test extension not built..."
puts $msg
finish_test finish_test
return return
} }
}
# Test that loading the extension produces the expected results - adding # Test that loading the extension produces the expected results - adding
# the half() function to the specified database handle. # the half() function to the specified database handle.
@ -37,7 +50,7 @@ do_test loadext-1.1 {
} }
} {1 {no such function: half}} } {1 {no such function: half}}
do_test loadext-1.2 { do_test loadext-1.2 {
sqlite3_load_extension db $testextension sqlite3_load_extension db $testextension testloadext_init
catchsql { catchsql {
SELECT half(1.0); SELECT half(1.0);
} }
@ -52,7 +65,7 @@ do_test loadext-1.3 {
} db2 } db2
} {1 {no such function: half}} } {1 {no such function: half}}
do_test loadext-1.4 { do_test loadext-1.4 {
sqlite3_load_extension db2 $testextension sqlite3_load_extension db2 $testextension testloadext_init
catchsql { catchsql {
SELECT half(1.0); SELECT half(1.0);
} db2 } db2
@ -75,25 +88,25 @@ sqlite3 db test.db
# #
do_test loadext-2.1 { do_test loadext-2.1 {
set rc [catch { set rc [catch {
sqlite3_load_extension db "xx${testextension}" sqlite3_load_extension db "${testextension}xx"
} msg] } msg]
list $rc $msg list $rc $msg
} [list 1 [subst -nocommands \ } [list 1 [subst -nocommands \
{unable to open shared library [xx${testextension}]} {unable to open shared library [${testextension}xx]}
]] ]]
# Try to load an extension for which the file is not a shared object # Try to load an extension for which the file is not a shared object
# #
do_test loadext-2.2 { do_test loadext-2.2 {
set fd [open "xx${testextension}" w] set fd [open "${testextension}xx" w]
puts $fd blah puts $fd blah
close $fd close $fd
set rc [catch { set rc [catch {
sqlite3_load_extension db "xx${testextension}" sqlite3_load_extension db "${testextension}xx"
} msg] } msg]
list $rc $msg list $rc $msg
} [list 1 [subst -nocommands \ } [list 1 [subst -nocommands \
{unable to open shared library [xx${testextension}]} {unable to open shared library [${testextension}xx]}
]] ]]
# Try to load an extension for which the file is present but the # Try to load an extension for which the file is present but the
@ -118,4 +131,3 @@ do_test loadext-2.4 {
} {1 {error during initialization: broken!}} } {1 {error during initialization: broken!}}
finish_test finish_test