/ Check-in [3d74256c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Call sqlite3OsDlError to obtain error information after DlOpen or DlSym fail. (CVS 4358)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:3d74256c9123e8434c68e6a0c5b61686b34a4328
User & Date: danielk1977 2007-09-01 05:57:50
Context
2007-09-01
06:19
Fix a bug in loadext.test. (CVS 4359) check-in: 2be8af9d user: danielk1977 tags: trunk
05:57
Call sqlite3OsDlError to obtain error information after DlOpen or DlSym fail. (CVS 4358) check-in: 3d74256c user: danielk1977 tags: trunk
02:13
Change the windows tempfile name generator so that it uses 119 bits of randomness and does not bother to check to see if the file already exists. Ticket #2608. (Unable to test from this machine, but the changes are simple and isolated. Hope it works.) (CVS 4357) check-in: ca6c1e3f user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/loadext.c.

323
324
325
326
327
328
329



330


331
332
333
334
335
336
337



338
339
340


341

342
343
344
345
346
347
348
  if( zProc==0 ){
    zProc = "sqlite3_extension_init";
  }

  handle = sqlite3OsDlOpen(pVfs, zFile);
  if( handle==0 ){
    if( pzErrMsg ){



      *pzErrMsg = sqlite3_mprintf("unable to open shared library [%s]", zFile);


    }
    return SQLITE_ERROR;
  }
  xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
                   sqlite3OsDlSym(pVfs, handle, zProc);
  if( xInit==0 ){
    if( pzErrMsg ){



       *pzErrMsg = sqlite3_mprintf("no entry point [%s] in shared library [%s]",
                                   zProc, zFile);
    }


    sqlite3OsDlClose(pVfs, handle);

    return SQLITE_ERROR;
  }else if( xInit(db, &zErrmsg, &sqlite3_apis) ){
    if( pzErrMsg ){
      *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
    }
    sqlite3_free(zErrmsg);
    sqlite3OsDlClose(pVfs, handle);







>
>
>
|
>
>







>
>
>
|
<
<
>
>
|
>







323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346


347
348
349
350
351
352
353
354
355
356
357
  if( zProc==0 ){
    zProc = "sqlite3_extension_init";
  }

  handle = sqlite3OsDlOpen(pVfs, zFile);
  if( handle==0 ){
    if( pzErrMsg ){
      char zErr[256];
      zErr[sizeof(zErr)-1] = '\0';
      sqlite3_snprintf(sizeof(zErr)-1, zErr, 
          "unable to open shared library [%s]", zFile);
      sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr);
      *pzErrMsg = sqlite3DbStrDup(db, zErr);
    }
    return SQLITE_ERROR;
  }
  xInit = (int(*)(sqlite3*,char**,const sqlite3_api_routines*))
                   sqlite3OsDlSym(pVfs, handle, zProc);
  if( xInit==0 ){
    if( pzErrMsg ){
      char zErr[256];
      zErr[sizeof(zErr)-1] = '\0';
      sqlite3_snprintf(sizeof(zErr)-1, zErr,
          "no entry point [%s] in shared library [%s]", zProc,zFile);


      sqlite3OsDlError(pVfs, sizeof(zErr)-1, zErr);
      *pzErrMsg = sqlite3DbStrDup(db, zErr);
      sqlite3OsDlClose(pVfs, handle);
    }
    return SQLITE_ERROR;
  }else if( xInit(db, &zErrmsg, &sqlite3_apis) ){
    if( pzErrMsg ){
      *pzErrMsg = sqlite3_mprintf("error during initialization: %s", zErrmsg);
    }
    sqlite3_free(zErrmsg);
    sqlite3OsDlClose(pVfs, handle);

Changes to test/loadext.test.

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
24
25
26
27
28
29
30

















31
32
33
34
35
36
37
..
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#    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 extension loading.
#
# $Id: loadext.test,v 1.9 2007/04/06 21:42:22 drh Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !load_ext {
  finish_test
  return
................................................................................
# 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
................................................................................
# 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 {
    sqlite3_load_extension db $testextension icecream
  } msg]
  list $rc $msg
} [list 1 [subst -nocommands \
  {no entry point [icecream] in shared library [$testextension]}
]]

# Try to load an extension for which the entry point fails (returns non-zero) 
#
do_test loadext-2.4 {
  set rc [catch {
    sqlite3_load_extension db $testextension testbrokenext_init
  } msg]
................................................................................
    SELECT half(5);
  }
} {1 {no such function: half}}
do_test loadext-3.2 {
  catchsql {
    SELECT load_extension($::testextension)
  }
} [list 1 "no entry point \[sqlite3_extension_init\]\
           in shared library \[$testextension\]"]
do_test loadext-3.3 {
  catchsql {
    SELECT load_extension($::testextension,'testloadext_init')
  }
} {0 {{}}}
do_test loadext-3.4 {
  catchsql {







|







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
<
<











|
<
<









|
<
<







 







|
<







7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
..
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
...
112
113
114
115
116
117
118
119


120
121
122
123
124
125
126
127
128
129
130
131


132
133
134
135
136
137
138
139
140
141


142
143
144
145
146
147
148
...
161
162
163
164
165
166
167
168

169
170
171
172
173
174
175
#    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 extension loading.
#
# $Id: loadext.test,v 1.10 2007/09/01 05:57:50 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

ifcapable !load_ext {
  finish_test
  return
................................................................................
# 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
}

# The error messages tested by this file are operating system dependent
# (because they are returned by sqlite3OsDlError()). For now, they only
# work with UNIX (and probably only certain kinds of UNIX).
#
# When a shared-object cannot be opened, we expect the error message to
# be:
#
#      [format $dlerror_cantopen <shared-object-name>]
#
# When a symbol cannot be found within an open shared-object, the error
# message should be:
#
#      [format $dlerror_nosymbol <shared-object-name> <symbol-name>]
#
set dlerror_cantopen {%s: file too short}
set dlerror_nosymbol {%s: undefined symbol: %s}

# 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
................................................................................
# 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 [format $dlerror_cantopen ${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 [format $dlerror_cantopen ${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 {
    sqlite3_load_extension db $testextension icecream
  } msg]
  list $rc $msg
} [list 1 [format $dlerror_nosymbol $testextension icecream]]



# Try to load an extension for which the entry point fails (returns non-zero) 
#
do_test loadext-2.4 {
  set rc [catch {
    sqlite3_load_extension db $testextension testbrokenext_init
  } msg]
................................................................................
    SELECT half(5);
  }
} {1 {no such function: half}}
do_test loadext-3.2 {
  catchsql {
    SELECT load_extension($::testextension)
  }
} [list 1 [format $dlerror_nosymbol $testextension sqlite3_extension_init]]

do_test loadext-3.3 {
  catchsql {
    SELECT load_extension($::testextension,'testloadext_init')
  }
} {0 {{}}}
do_test loadext-3.4 {
  catchsql {

Changes to test/sqllimits1.test.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
87
88
89
90
91
92
93





94
95
96
97
98
99
100
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains tests to verify that the limits defined in
# sqlite source file limits.h are enforced.
#
# $Id: sqllimits1.test,v 1.11 2007/08/31 17:42:48 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Test organization:
#
#     sqllimits-1.*:  SQLITE_MAX_LENGTH
................................................................................
# Todo:
#
#     sqllimits-5.*:   SQLITE_MAX_EXPR_DEPTH            (sqlite todo)
#     sqllimits-6.*:   SQLITE_MAX_VDBE_OP               (sqlite todo)
#     sqllimits-12.*:  SQLITE_MAX_PAGE_COUNT            (sqlite todo)
#

set SQLITE_MAX_LENGTH                1000000
set SQLITE_MAX_COLUMN
set SQLITE_MAX_SQL_LENGTH             100000
set SQLITE_MAX_EXPR_DEPTH               1000
set SQLITE_MAX_COMPOUND_SELECT             5
set SQLITE_MAX_VDBE_OP
set SQLITE_MAX_FUNCTION_ARG
set SQLITE_MAX_VARIABLE_NUMBER
................................................................................

do_test sqllimits-1.9 {
  set ::str [string repeat A 65537]
  set ::rep [string repeat B 65537]
  catchsql { SELECT replace($::str, 'A', $::rep) }
} {1 {string or blob too big}}






#--------------------------------------------------------------------
# Test cases sqllimits-2.* test that the SQLITE_MAX_SQL_LENGTH limit
# is enforced.
#
do_test sqllimits-2.1 {
  set    sql "SELECT 1 WHERE 1==1"
  set N [expr {$::SQLITE_MAX_SQL_LENGTH / [string length " AND 1==1"]}]







|







 







|







 







>
>
>
>
>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#    May you share freely, never taking more than you give.
#
#***********************************************************************
#
# This file contains tests to verify that the limits defined in
# sqlite source file limits.h are enforced.
#
# $Id: sqllimits1.test,v 1.12 2007/09/01 05:57:50 danielk1977 Exp $

set testdir [file dirname $argv0]
source $testdir/tester.tcl

# Test organization:
#
#     sqllimits-1.*:  SQLITE_MAX_LENGTH
................................................................................
# Todo:
#
#     sqllimits-5.*:   SQLITE_MAX_EXPR_DEPTH            (sqlite todo)
#     sqllimits-6.*:   SQLITE_MAX_VDBE_OP               (sqlite todo)
#     sqllimits-12.*:  SQLITE_MAX_PAGE_COUNT            (sqlite todo)
#

set SQLITE_MAX_LENGTH                 100000
set SQLITE_MAX_COLUMN
set SQLITE_MAX_SQL_LENGTH             100000
set SQLITE_MAX_EXPR_DEPTH               1000
set SQLITE_MAX_COMPOUND_SELECT             5
set SQLITE_MAX_VDBE_OP
set SQLITE_MAX_FUNCTION_ARG
set SQLITE_MAX_VARIABLE_NUMBER
................................................................................

do_test sqllimits-1.9 {
  set ::str [string repeat A 65537]
  set ::rep [string repeat B 65537]
  catchsql { SELECT replace($::str, 'A', $::rep) }
} {1 {string or blob too big}}

do_test sqllimits-1.10 {
  set ::str [string repeat %J 2100]
  catchsql { SELECT strftime($::str, '2003-10-31') }
} {1 {string or blob too big}}

#--------------------------------------------------------------------
# Test cases sqllimits-2.* test that the SQLITE_MAX_SQL_LENGTH limit
# is enforced.
#
do_test sqllimits-2.1 {
  set    sql "SELECT 1 WHERE 1==1"
  set N [expr {$::SQLITE_MAX_SQL_LENGTH / [string length " AND 1==1"]}]