⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 loadext.test

📁 sqlite-3.4.1,嵌入式数据库.是一个功能强大的开源数据库,给学习和研发以及小型公司的发展带来了全所未有的好处.
💻 TEST
字号:
# 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 extension loading.## $Id: loadext.test,v 1.9 2007/04/06 21:42:22 drh Exp $set testdir [file dirname $argv0]source $testdir/tester.tclifcapable !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  set testextsrc $srcdir/test_loadext.c  if {[catch {    exec gcc -Wall -I$srcdir -I. -g -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 {  db enable_load_extension 1  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  sqlite3_enable_load_extension db2 1  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.#do_test loadext-1.5 {  db close  catchsql {    SELECT half(1.0);  } db2} {0 0.5}db2 closesqlite3 db test.dbsqlite3_enable_load_extension db 1# 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]  list $rc $msg} {1 {error during initialization: broken!}}############################################################################# Tests for the load_extension() SQL function#db closesqlite3 db test.dbsqlite3_enable_load_extension db 1do_test loadext-3.1 {  catchsql {    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 {    SELECT half(5);  }} {0 2.5}# Ticket #1863# Make sure the extension loading mechanism will not work unless it# is explicitly enabled.#db closesqlite3 db test.dbdo_test loadext-4.1 {  catchsql {    SELECT load_extension($::testextension,'testloadext_init')  }} {1 {not authorized}}do_test loadext-4.2 {  sqlite3_enable_load_extension db 1  catchsql {    SELECT load_extension($::testextension,'testloadext_init')  }} {0 {{}}}do_test loadext-4.3 {  sqlite3_enable_load_extension db 0  catchsql {    SELECT load_extension($::testextension,'testloadext_init')  }} {1 {not authorized}}finish_test

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -