sqlite3-ruby 1.2.3-x86-mingw32 → 1.2.5-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog.cvs +88 -0
- data/History.txt +68 -0
- data/LICENSE +27 -0
- data/Manifest.txt +41 -0
- data/{README.rdoc → README.txt} +6 -1
- data/Rakefile +5 -0
- data/ext/sqlite3_api/extconf.rb +3 -9
- data/ext/sqlite3_api/sqlite3_api.i +4 -0
- data/ext/sqlite3_api/sqlite3_api_wrap.c +4977 -3053
- data/{doc/faq → faq}/faq.rb +0 -0
- data/{doc/faq → faq}/faq.yml +0 -0
- data/lib/1.8/sqlite3_api.so +0 -0
- data/lib/1.9/sqlite3_api.so +0 -0
- data/lib/sqlite3/database.rb +13 -7
- data/lib/sqlite3/driver/dl/api.rb +1 -1
- data/lib/sqlite3/driver/native/driver.rb +9 -1
- data/lib/sqlite3/resultset.rb +5 -1
- data/lib/sqlite3/statement.rb +3 -2
- data/lib/sqlite3/version.rb +4 -2
- data/setup.rb +1333 -0
- data/tasks/benchmark.rake +9 -0
- data/tasks/faq.rake +9 -0
- data/tasks/gem.rake +32 -0
- data/tasks/native.rake +35 -0
- data/tasks/vendor_sqlite3.rake +104 -0
- data/test/{mocks.rb → helper.rb} +23 -1
- data/test/{tc_database.rb → test_database.rb} +25 -6
- data/test/{tc_errors.rb → test_errors.rb} +1 -5
- data/test/test_integration.rb +542 -0
- data/test/test_integration_open_close.rb +30 -0
- data/test/test_integration_pending.rb +111 -0
- data/test/test_integration_resultset.rb +159 -0
- data/test/test_integration_statement.rb +195 -0
- metadata +90 -43
- data/doc/faq/faq.html +0 -408
- data/ext/sqlite3_api/MANIFEST +0 -4
- data/ext/sqlite3_api/Makefile +0 -142
- data/ext/sqlite3_api/mkmf.log +0 -66
- data/ext/sqlite3_api/sqlite3_api.so +0 -0
- data/ext/sqlite3_api/sqlite3_api_wrap.o +0 -0
- data/ext/sqlite3_api/win32/build.bat +0 -7
- data/test/tc_integration.rb +0 -1044
- data/test/tests.rb +0 -6
data/ext/sqlite3_api/MANIFEST
DELETED
data/ext/sqlite3_api/Makefile
DELETED
@@ -1,142 +0,0 @@
|
|
1
|
-
|
2
|
-
SHELL = /bin/sh
|
3
|
-
|
4
|
-
#### Start of system configuration section. ####
|
5
|
-
|
6
|
-
srcdir = .
|
7
|
-
topdir = c:/ruby18/lib/ruby/1.8/i386-mingw32
|
8
|
-
hdrdir = $(topdir)
|
9
|
-
VPATH = $(srcdir);$(topdir);$(hdrdir)
|
10
|
-
|
11
|
-
DESTDIR = c:
|
12
|
-
prefix = $(DESTDIR)/ruby18
|
13
|
-
exec_prefix = $(prefix)
|
14
|
-
sitedir = $(prefix)/lib/ruby/site_ruby
|
15
|
-
rubylibdir = $(libdir)/ruby/$(ruby_version)
|
16
|
-
archdir = $(rubylibdir)/$(arch)
|
17
|
-
sbindir = $(exec_prefix)/sbin
|
18
|
-
datadir = $(prefix)/share
|
19
|
-
includedir = $(prefix)/include
|
20
|
-
infodir = $(prefix)/info
|
21
|
-
sysconfdir = $(prefix)/etc
|
22
|
-
mandir = $(prefix)/man
|
23
|
-
libdir = $(exec_prefix)/lib
|
24
|
-
sharedstatedir = $(prefix)/com
|
25
|
-
oldincludedir = $(DESTDIR)/usr/include
|
26
|
-
sitearchdir = $(sitelibdir)/$(sitearch)
|
27
|
-
bindir = $(exec_prefix)/bin
|
28
|
-
localstatedir = $(prefix)/var
|
29
|
-
sitelibdir = $(sitedir)/$(ruby_version)
|
30
|
-
libexecdir = $(exec_prefix)/libexec
|
31
|
-
|
32
|
-
CC = gcc
|
33
|
-
LIBRUBY = lib$(LIBRUBY_SO).a
|
34
|
-
LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
|
35
|
-
LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
|
36
|
-
LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
37
|
-
|
38
|
-
RUBY_EXTCONF_H =
|
39
|
-
CFLAGS = -g -O2
|
40
|
-
INCFLAGS = -I. -I. -Ic:/ruby18/lib/ruby/1.8/i386-mingw32 -I.
|
41
|
-
DEFS =
|
42
|
-
CPPFLAGS = -DHAVE_SQLITE3_H -Ic:/src/include
|
43
|
-
CXXFLAGS = $(CFLAGS)
|
44
|
-
DLDFLAGS = -L. -Wl,--enable-auto-image-base,--enable-auto-import,--export-all
|
45
|
-
LDSHARED = gcc -shared -s
|
46
|
-
AR = ar
|
47
|
-
EXEEXT = .exe
|
48
|
-
|
49
|
-
RUBY_INSTALL_NAME = ruby
|
50
|
-
RUBY_SO_NAME = msvcrt-ruby18
|
51
|
-
arch = i386-mingw32
|
52
|
-
sitearch = i386-msvcrt
|
53
|
-
ruby_version = 1.8
|
54
|
-
ruby = c:/ruby18/bin/ruby
|
55
|
-
RUBY = $(ruby)
|
56
|
-
RM = rm -f
|
57
|
-
MAKEDIRS = mkdir -p
|
58
|
-
INSTALL = /bin/install -c
|
59
|
-
INSTALL_PROG = $(INSTALL) -m 0755
|
60
|
-
INSTALL_DATA = $(INSTALL) -m 644
|
61
|
-
COPY = cp
|
62
|
-
|
63
|
-
#### End of system configuration section. ####
|
64
|
-
|
65
|
-
preload =
|
66
|
-
|
67
|
-
libpath = . $(libdir) c:/src/lib
|
68
|
-
LIBPATH = -L. -L$(libdir) -Lc:/src/lib
|
69
|
-
DEFFILE =
|
70
|
-
|
71
|
-
CLEANFILES = mkmf.log
|
72
|
-
DISTCLEANFILES =
|
73
|
-
|
74
|
-
extout =
|
75
|
-
extout_prefix =
|
76
|
-
target_prefix =
|
77
|
-
LOCAL_LIBS =
|
78
|
-
LIBS = $(LIBRUBYARG_SHARED) -lsqlite3 -lshell32 -lws2_32
|
79
|
-
SRCS = sqlite3_api_wrap.c
|
80
|
-
OBJS = sqlite3_api_wrap.o
|
81
|
-
TARGET = sqlite3_api
|
82
|
-
DLLIB = $(TARGET).so
|
83
|
-
EXTSTATIC =
|
84
|
-
STATIC_LIB =
|
85
|
-
|
86
|
-
RUBYCOMMONDIR = $(sitedir)$(target_prefix)
|
87
|
-
RUBYLIBDIR = $(sitelibdir)$(target_prefix)
|
88
|
-
RUBYARCHDIR = $(sitearchdir)$(target_prefix)
|
89
|
-
|
90
|
-
TARGET_SO = $(DLLIB)
|
91
|
-
CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
|
92
|
-
CLEANOBJS = *.o *.a *.s[ol] *.pdb *.exp *.bak
|
93
|
-
|
94
|
-
all: $(DLLIB)
|
95
|
-
static: $(STATIC_LIB)
|
96
|
-
|
97
|
-
clean:
|
98
|
-
@-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
|
99
|
-
|
100
|
-
distclean: clean
|
101
|
-
@-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
|
102
|
-
@-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
|
103
|
-
|
104
|
-
realclean: distclean
|
105
|
-
install: install-so install-rb
|
106
|
-
|
107
|
-
install-so: $(RUBYARCHDIR)
|
108
|
-
install-so: $(RUBYARCHDIR)/$(DLLIB)
|
109
|
-
$(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
|
110
|
-
$(INSTALL_PROG) $(DLLIB) $(RUBYARCHDIR)
|
111
|
-
install-rb: pre-install-rb install-rb-default
|
112
|
-
install-rb-default: pre-install-rb-default
|
113
|
-
pre-install-rb: Makefile
|
114
|
-
pre-install-rb-default: Makefile
|
115
|
-
$(RUBYARCHDIR):
|
116
|
-
$(MAKEDIRS) $@
|
117
|
-
|
118
|
-
site-install: site-install-so site-install-rb
|
119
|
-
site-install-so: install-so
|
120
|
-
site-install-rb: install-rb
|
121
|
-
|
122
|
-
.SUFFIXES: .c .m .cc .cxx .cpp .o
|
123
|
-
|
124
|
-
.cc.o:
|
125
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
126
|
-
|
127
|
-
.cxx.o:
|
128
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
129
|
-
|
130
|
-
.cpp.o:
|
131
|
-
$(CXX) $(INCFLAGS) $(CPPFLAGS) $(CXXFLAGS) -c $<
|
132
|
-
|
133
|
-
.c.o:
|
134
|
-
$(CC) $(INCFLAGS) $(CPPFLAGS) $(CFLAGS) -c $<
|
135
|
-
|
136
|
-
$(DLLIB): $(OBJS)
|
137
|
-
@-$(RM) $@
|
138
|
-
$(LDSHARED) -o $@ $(OBJS) $(LIBPATH) $(DLDFLAGS) $(LOCAL_LIBS) $(LIBS)
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
$(OBJS): ruby.h defines.h
|
data/ext/sqlite3_api/mkmf.log
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
have_library: checking for fdatasync() in -lrt... -------------------- no
|
2
|
-
|
3
|
-
"gcc -o conftest -I. -Ic:/ruby18/lib/ruby/1.8/i386-mingw32 -I. -Ic:/src/include -g -O2 conftest.c -L. -Lc:/ruby18/lib -Lc:/src/lib -L. -lmsvcrt-ruby18-static -lrt -lshell32 -lws2_32 "
|
4
|
-
conftest.c: In function `t':
|
5
|
-
conftest.c:6: error: `fdatasync' undeclared (first use in this function)
|
6
|
-
conftest.c:6: error: (Each undeclared identifier is reported only once
|
7
|
-
conftest.c:6: error: for each function it appears in.)
|
8
|
-
checked program was:
|
9
|
-
/* begin */
|
10
|
-
1: #include <windows.h>
|
11
|
-
2: #include <winsock.h>
|
12
|
-
3:
|
13
|
-
4: /*top*/
|
14
|
-
5: int main() { return 0; }
|
15
|
-
6: int t() { void ((*volatile p)()); p = (void ((*)()))fdatasync; return 0; }
|
16
|
-
/* end */
|
17
|
-
|
18
|
-
"gcc -o conftest -I. -Ic:/ruby18/lib/ruby/1.8/i386-mingw32 -I. -Ic:/src/include -g -O2 conftest.c -L. -Lc:/ruby18/lib -Lc:/src/lib -L. -lmsvcrt-ruby18-static -lrt -lshell32 -lws2_32 "
|
19
|
-
C:\Ruby18\devkit\mingw\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\mingw32\bin\ld.exe: cannot find -lrt
|
20
|
-
collect2: ld returned 1 exit status
|
21
|
-
checked program was:
|
22
|
-
/* begin */
|
23
|
-
1: /*top*/
|
24
|
-
2: int main() { return 0; }
|
25
|
-
3: int t() { fdatasync(); return 0; }
|
26
|
-
/* end */
|
27
|
-
|
28
|
-
--------------------
|
29
|
-
|
30
|
-
have_header: checking for sqlite3.h... -------------------- yes
|
31
|
-
|
32
|
-
"gcc -E -I. -Ic:/ruby18/lib/ruby/1.8/i386-mingw32 -I. -Ic:/src/include -g -O2 conftest.c -o conftest.i"
|
33
|
-
checked program was:
|
34
|
-
/* begin */
|
35
|
-
1: #include <sqlite3.h>
|
36
|
-
/* end */
|
37
|
-
|
38
|
-
--------------------
|
39
|
-
|
40
|
-
have_library: checking for sqlite3_open() in -lsqlite3... -------------------- yes
|
41
|
-
|
42
|
-
"gcc -o conftest -I. -Ic:/ruby18/lib/ruby/1.8/i386-mingw32 -I. -Ic:/src/include -g -O2 conftest.c -L. -Lc:/ruby18/lib -Lc:/src/lib -L. -lmsvcrt-ruby18-static -lsqlite3 -lshell32 -lws2_32 "
|
43
|
-
conftest.c: In function `t':
|
44
|
-
conftest.c:6: error: `sqlite3_open' undeclared (first use in this function)
|
45
|
-
conftest.c:6: error: (Each undeclared identifier is reported only once
|
46
|
-
conftest.c:6: error: for each function it appears in.)
|
47
|
-
checked program was:
|
48
|
-
/* begin */
|
49
|
-
1: #include <windows.h>
|
50
|
-
2: #include <winsock.h>
|
51
|
-
3:
|
52
|
-
4: /*top*/
|
53
|
-
5: int main() { return 0; }
|
54
|
-
6: int t() { void ((*volatile p)()); p = (void ((*)()))sqlite3_open; return 0; }
|
55
|
-
/* end */
|
56
|
-
|
57
|
-
"gcc -o conftest -I. -Ic:/ruby18/lib/ruby/1.8/i386-mingw32 -I. -Ic:/src/include -g -O2 conftest.c -L. -Lc:/ruby18/lib -Lc:/src/lib -L. -lmsvcrt-ruby18-static -lsqlite3 -lshell32 -lws2_32 "
|
58
|
-
checked program was:
|
59
|
-
/* begin */
|
60
|
-
1: /*top*/
|
61
|
-
2: int main() { return 0; }
|
62
|
-
3: int t() { sqlite3_open(); return 0; }
|
63
|
-
/* end */
|
64
|
-
|
65
|
-
--------------------
|
66
|
-
|
Binary file
|
Binary file
|
@@ -1,7 +0,0 @@
|
|
1
|
-
REM This is not guaranteed to work, ever. It's just a little helper
|
2
|
-
REM script that I threw together to help me build the win32 version of
|
3
|
-
REM the library. If someone with more win32-fu than I wants to make
|
4
|
-
REM something more robust, please feel free! I'd love to include it.
|
5
|
-
REM -- Jamis Buck
|
6
|
-
|
7
|
-
cl /LD /Ie:\WinSDK\Include /Ic:\ruby\lib\ruby\1.8\i386-mswin32 /Ic:\ruby\sqlite3 /Ic:\ruby\src\ruby-1.8.4_2006-04-14 sqlite3_api_wrap.c /link /LIBPATH:c:\ruby\sqlite3 /LIBPATH:e:\WinSDK\Lib /LIBPATH:c:\ruby\lib sqlite3.lib msvcrt-ruby18.lib
|
data/test/tc_integration.rb
DELETED
@@ -1,1044 +0,0 @@
|
|
1
|
-
$:.unshift "#{File.dirname(__FILE__)}/../lib"
|
2
|
-
$:.unshift "#{File.dirname(__FILE__)}/../ext/sqlite3_api"
|
3
|
-
|
4
|
-
require 'test/unit'
|
5
|
-
require 'benchmark'
|
6
|
-
require 'sqlite3/database'
|
7
|
-
require 'thread'
|
8
|
-
|
9
|
-
class String
|
10
|
-
def to_utf16(terminate=false)
|
11
|
-
self.split(//).map { |c| c[0] }.pack("v*") +
|
12
|
-
(terminate ? "\0\0" : "")
|
13
|
-
end
|
14
|
-
|
15
|
-
def from_utf16
|
16
|
-
result = ""
|
17
|
-
length.times do |i|
|
18
|
-
result << self[i,1] if i % 2 == 0 && self[i] != 0
|
19
|
-
end
|
20
|
-
result
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module Integration
|
25
|
-
|
26
|
-
drivers_to_test = ( ENV["SQLITE3_DRIVERS"] || "Native" ).split(',')
|
27
|
-
drivers_to_test.each do |driver|
|
28
|
-
|
29
|
-
# == TC_OpenClose =========================================================
|
30
|
-
|
31
|
-
test_case = Class.new( Test::Unit::TestCase ) do
|
32
|
-
define_method( "test_create_close" ) do
|
33
|
-
begin
|
34
|
-
db = SQLite3::Database.new( "test-create.db",
|
35
|
-
:driver => driver )
|
36
|
-
assert File.exist?( "test-create.db" )
|
37
|
-
assert_nothing_raised { db.close }
|
38
|
-
ensure
|
39
|
-
File.delete( "test-create.db" ) rescue nil
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
define_method( "test_open_close" ) do
|
44
|
-
begin
|
45
|
-
File.open( "test-open.db", "w" ) { |f| }
|
46
|
-
assert File.exist?( "test-open.db" )
|
47
|
-
db = SQLite3::Database.new( "test-open.db",
|
48
|
-
:driver => driver )
|
49
|
-
assert_nothing_raised { db.close }
|
50
|
-
ensure
|
51
|
-
File.delete( "test-open.db" ) rescue nil
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
define_method( "test_bad_open" ) do
|
56
|
-
assert_raise( SQLite3::CantOpenException ) do
|
57
|
-
SQLite3::Database.new( ".", :driver => driver )
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
const_set( "TC_OpenClose_#{driver}", test_case )
|
62
|
-
|
63
|
-
# == TC_Database ==========================================================
|
64
|
-
|
65
|
-
test_case = Class.new( Test::Unit::TestCase ) do
|
66
|
-
define_method( "setup" ) do
|
67
|
-
@db = SQLite3::Database.new( "test.db", :driver=>driver )
|
68
|
-
@db.transaction do
|
69
|
-
@db.execute "create table foo ( a integer primary key, b text )"
|
70
|
-
@db.execute "insert into foo ( b ) values ( 'foo' )"
|
71
|
-
@db.execute "insert into foo ( b ) values ( 'bar' )"
|
72
|
-
@db.execute "insert into foo ( b ) values ( 'baz' )"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
define_method( "teardown" ) do
|
77
|
-
@db.close
|
78
|
-
File.delete( "test.db" )
|
79
|
-
end
|
80
|
-
|
81
|
-
define_method( "test_table_info_with_type_translation_active" ) do
|
82
|
-
@db.type_translation = true
|
83
|
-
assert_nothing_raised { @db.table_info("foo") }
|
84
|
-
end
|
85
|
-
|
86
|
-
define_method( "test_table_info_with_defaults_for_version_3_3_8_and_higher" ) do
|
87
|
-
@db.transaction do
|
88
|
-
@db.execute "create table defaults_test ( a string default NULL, b string default 'Hello' )"
|
89
|
-
data = @db.table_info( "defaults_test" )
|
90
|
-
assert_equal({"name" => "a", "type" => "string", "dflt_value" => nil, "notnull" => "0", "cid" => "0", "pk" => "0"},
|
91
|
-
data[0])
|
92
|
-
assert_equal({"name" => "b", "type" => "string", "dflt_value" => "Hello", "notnull" => "0", "cid" => "1", "pk" => "0"},
|
93
|
-
data[1])
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
define_method( "test_table_info_without_defaults_for_version_3_3_8_and_higher" ) do
|
98
|
-
@db.transaction do
|
99
|
-
@db.execute "create table no_defaults_test ( a integer default 1, b integer )"
|
100
|
-
data = @db.table_info( "no_defaults_test" )
|
101
|
-
assert_equal({"name" => "a", "type" => "integer", "dflt_value" => "1", "notnull" => "0", "cid" => "0", "pk" => "0"},
|
102
|
-
data[0])
|
103
|
-
assert_equal({"name" => "b", "type" => "integer", "dflt_value" => nil, "notnull" => "0", "cid" => "1", "pk" => "0"},
|
104
|
-
data[1])
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
define_method( "test_complete_fail" ) do
|
109
|
-
assert !@db.complete?( "select * from foo" )
|
110
|
-
end
|
111
|
-
define_method( "test_complete_success" ) do
|
112
|
-
assert @db.complete?( "select * from foo;" )
|
113
|
-
end
|
114
|
-
|
115
|
-
define_method( "test_complete_fail_utf16" ) do
|
116
|
-
assert !@db.complete?( "select * from foo".to_utf16(false), true )
|
117
|
-
end
|
118
|
-
|
119
|
-
define_method( "test_complete_success_utf16" ) do
|
120
|
-
assert @db.complete?( "select * from foo;".to_utf16(true), true )
|
121
|
-
end
|
122
|
-
|
123
|
-
define_method( "test_errmsg" ) do
|
124
|
-
assert_equal "not an error", @db.errmsg
|
125
|
-
end
|
126
|
-
|
127
|
-
define_method( "test_errmsg_utf16" ) do
|
128
|
-
assert_equal "not an error".to_utf16, @db.errmsg(true)
|
129
|
-
end
|
130
|
-
|
131
|
-
define_method( "test_errcode" ) do
|
132
|
-
assert_equal 0, @db.errcode
|
133
|
-
end
|
134
|
-
|
135
|
-
define_method( "test_trace" ) do
|
136
|
-
result = nil
|
137
|
-
@db.trace( "data" ) { |data,sql| result = [ data, sql ]; 0 }
|
138
|
-
@db.execute "select * from foo"
|
139
|
-
assert_equal ["data","select * from foo"], result
|
140
|
-
end
|
141
|
-
|
142
|
-
define_method( "test_authorizer_okay" ) do
|
143
|
-
@db.authorizer( "data" ) { |data,type,a,b,c,d| 0 }
|
144
|
-
rows = @db.execute "select * from foo"
|
145
|
-
assert_equal 3, rows.length
|
146
|
-
end
|
147
|
-
|
148
|
-
define_method( "test_authorizer_error" ) do
|
149
|
-
@db.authorizer( "data" ) { |data,type,a,b,c,d| 1 }
|
150
|
-
assert_raise( SQLite3::AuthorizationException ) do
|
151
|
-
@db.execute "select * from foo"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
# FIXME: this test is failing with sqlite3 3.2.5
|
156
|
-
# define_method( "test_authorizer_silent" ) do
|
157
|
-
# @db.authorizer( "data" ) { |data,type,a,b,c,d| 2 }
|
158
|
-
# rows = @db.execute "select * from foo"
|
159
|
-
# assert rows.empty?
|
160
|
-
# end
|
161
|
-
|
162
|
-
define_method( "test_prepare_invalid_syntax" ) do
|
163
|
-
assert_raise( SQLite3::SQLException ) do
|
164
|
-
@db.prepare "select from foo"
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
define_method( "test_prepare_invalid_column" ) do
|
169
|
-
assert_raise( SQLite3::SQLException ) do
|
170
|
-
@db.prepare "select k from foo"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
define_method( "test_prepare_invalid_table" ) do
|
175
|
-
assert_raise( SQLite3::SQLException ) do
|
176
|
-
@db.prepare "select * from barf"
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
define_method( "test_prepare_no_block" ) do
|
181
|
-
stmt = @db.prepare "select * from foo"
|
182
|
-
assert stmt.respond_to?(:execute)
|
183
|
-
stmt.close
|
184
|
-
end
|
185
|
-
|
186
|
-
define_method( "test_prepare_with_block" ) do
|
187
|
-
called = false
|
188
|
-
@db.prepare "select * from foo" do |stmt|
|
189
|
-
called = true
|
190
|
-
assert stmt.respond_to?(:execute)
|
191
|
-
end
|
192
|
-
assert called
|
193
|
-
end
|
194
|
-
|
195
|
-
define_method( "test_execute_no_block_no_bind_no_match" ) do
|
196
|
-
rows = @db.execute( "select * from foo where a > 100" )
|
197
|
-
assert rows.empty?
|
198
|
-
end
|
199
|
-
|
200
|
-
define_method( "test_execute_with_block_no_bind_no_match" ) do
|
201
|
-
called = false
|
202
|
-
@db.execute( "select * from foo where a > 100" ) do |row|
|
203
|
-
called = true
|
204
|
-
end
|
205
|
-
assert !called
|
206
|
-
end
|
207
|
-
|
208
|
-
define_method( "test_execute_no_block_with_bind_no_match" ) do
|
209
|
-
rows = @db.execute( "select * from foo where a > ?", 100 )
|
210
|
-
assert rows.empty?
|
211
|
-
end
|
212
|
-
|
213
|
-
define_method( "test_execute_with_block_with_bind_no_match" ) do
|
214
|
-
called = false
|
215
|
-
@db.execute( "select * from foo where a > ?", 100 ) do |row|
|
216
|
-
called = true
|
217
|
-
end
|
218
|
-
assert !called
|
219
|
-
end
|
220
|
-
|
221
|
-
define_method( "test_execute_no_block_no_bind_with_match" ) do
|
222
|
-
rows = @db.execute( "select * from foo where a = 1" )
|
223
|
-
assert_equal 1, rows.length
|
224
|
-
end
|
225
|
-
|
226
|
-
define_method( "test_execute_with_block_no_bind_with_match" ) do
|
227
|
-
called = 0
|
228
|
-
@db.execute( "select * from foo where a = 1" ) do |row|
|
229
|
-
called += 1
|
230
|
-
end
|
231
|
-
assert_equal 1, called
|
232
|
-
end
|
233
|
-
|
234
|
-
define_method( "test_execute_no_block_with_bind_with_match" ) do
|
235
|
-
rows = @db.execute( "select * from foo where a = ?", 1 )
|
236
|
-
assert_equal 1, rows.length
|
237
|
-
end
|
238
|
-
|
239
|
-
define_method( "test_execute_with_block_with_bind_with_match" ) do
|
240
|
-
called = 0
|
241
|
-
@db.execute( "select * from foo where a = ?", 1 ) do |row|
|
242
|
-
called += 1
|
243
|
-
end
|
244
|
-
assert_equal 1, called
|
245
|
-
end
|
246
|
-
|
247
|
-
define_method( "test_execute2_no_block_no_bind_no_match" ) do
|
248
|
-
columns, *rows = @db.execute2( "select * from foo where a > 100" )
|
249
|
-
assert rows.empty?
|
250
|
-
assert [ "a", "b" ], columns
|
251
|
-
end
|
252
|
-
|
253
|
-
define_method( "test_execute2_with_block_no_bind_no_match" ) do
|
254
|
-
called = 0
|
255
|
-
@db.execute2( "select * from foo where a > 100" ) do |row|
|
256
|
-
assert [ "a", "b" ], row unless called == 0
|
257
|
-
called += 1
|
258
|
-
end
|
259
|
-
assert_equal 1, called
|
260
|
-
end
|
261
|
-
|
262
|
-
define_method( "test_execute2_no_block_with_bind_no_match" ) do
|
263
|
-
columns, *rows = @db.execute2( "select * from foo where a > ?", 100 )
|
264
|
-
assert rows.empty?
|
265
|
-
assert [ "a", "b" ], columns
|
266
|
-
end
|
267
|
-
|
268
|
-
define_method( "test_execute2_with_block_with_bind_no_match" ) do
|
269
|
-
called = 0
|
270
|
-
@db.execute2( "select * from foo where a > ?", 100 ) do |row|
|
271
|
-
assert [ "a", "b" ], row unless called == 0
|
272
|
-
called += 1
|
273
|
-
end
|
274
|
-
assert_equal 1, called
|
275
|
-
end
|
276
|
-
|
277
|
-
define_method( "test_execute2_no_block_no_bind_with_match" ) do
|
278
|
-
columns, *rows = @db.execute2( "select * from foo where a = 1" )
|
279
|
-
assert_equal 1, rows.length
|
280
|
-
assert [ "a", "b" ], columns
|
281
|
-
end
|
282
|
-
|
283
|
-
define_method( "test_execute2_with_block_no_bind_with_match" ) do
|
284
|
-
called = 0
|
285
|
-
@db.execute2( "select * from foo where a = 1" ) do |row|
|
286
|
-
assert [ "a", "b" ], row unless called == 0
|
287
|
-
called += 1
|
288
|
-
end
|
289
|
-
assert_equal 2, called
|
290
|
-
end
|
291
|
-
|
292
|
-
define_method( "test_execute2_no_block_with_bind_with_match" ) do
|
293
|
-
columns, *rows = @db.execute2( "select * from foo where a = ?", 1 )
|
294
|
-
assert_equal 1, rows.length
|
295
|
-
assert [ "a", "b" ], columns
|
296
|
-
end
|
297
|
-
|
298
|
-
define_method( "test_execute2_with_block_with_bind_with_match" ) do
|
299
|
-
called = 0
|
300
|
-
@db.execute2( "select * from foo where a = ?", 1 ) do |row|
|
301
|
-
called += 1
|
302
|
-
end
|
303
|
-
assert_equal 2, called
|
304
|
-
end
|
305
|
-
|
306
|
-
define_method( "test_execute_batch_empty" ) do
|
307
|
-
assert_nothing_raised { @db.execute_batch "" }
|
308
|
-
end
|
309
|
-
|
310
|
-
define_method( "test_execute_batch_no_bind" ) do
|
311
|
-
@db.transaction do
|
312
|
-
@db.execute_batch <<-SQL
|
313
|
-
create table bar ( a, b, c );
|
314
|
-
insert into bar values ( 'one', 2, 'three' );
|
315
|
-
insert into bar values ( 'four', 5, 'six' );
|
316
|
-
insert into bar values ( 'seven', 8, 'nine' );
|
317
|
-
SQL
|
318
|
-
end
|
319
|
-
rows = @db.execute( "select * from bar" )
|
320
|
-
assert_equal 3, rows.length
|
321
|
-
end
|
322
|
-
|
323
|
-
define_method( "test_execute_batch_with_bind" ) do
|
324
|
-
@db.execute_batch( <<-SQL, 1 )
|
325
|
-
create table bar ( a, b, c );
|
326
|
-
insert into bar values ( 'one', 2, ? );
|
327
|
-
insert into bar values ( 'four', 5, ? );
|
328
|
-
insert into bar values ( 'seven', 8, ? );
|
329
|
-
SQL
|
330
|
-
rows = @db.execute( "select * from bar" ).map { |a,b,c| c }
|
331
|
-
assert_equal %w{1 1 1}, rows
|
332
|
-
end
|
333
|
-
|
334
|
-
define_method( "test_query_no_block_no_bind_no_match" ) do
|
335
|
-
result = @db.query( "select * from foo where a > 100" )
|
336
|
-
assert_nil result.next
|
337
|
-
result.close
|
338
|
-
end
|
339
|
-
|
340
|
-
define_method( "test_query_with_block_no_bind_no_match" ) do
|
341
|
-
r = nil
|
342
|
-
@db.query( "select * from foo where a > 100" ) do |result|
|
343
|
-
assert_nil result.next
|
344
|
-
r = result
|
345
|
-
end
|
346
|
-
assert r.closed?
|
347
|
-
end
|
348
|
-
|
349
|
-
define_method( "test_query_no_block_with_bind_no_match" ) do
|
350
|
-
result = @db.query( "select * from foo where a > ?", 100 )
|
351
|
-
assert_nil result.next
|
352
|
-
result.close
|
353
|
-
end
|
354
|
-
|
355
|
-
define_method( "test_query_with_block_with_bind_no_match" ) do
|
356
|
-
r = nil
|
357
|
-
@db.query( "select * from foo where a > ?", 100 ) do |result|
|
358
|
-
assert_nil result.next
|
359
|
-
r = result
|
360
|
-
end
|
361
|
-
assert r.closed?
|
362
|
-
end
|
363
|
-
|
364
|
-
define_method( "test_query_no_block_no_bind_with_match" ) do
|
365
|
-
result = @db.query( "select * from foo where a = 1" )
|
366
|
-
assert_not_nil result.next
|
367
|
-
assert_nil result.next
|
368
|
-
result.close
|
369
|
-
end
|
370
|
-
|
371
|
-
define_method( "test_query_with_block_no_bind_with_match" ) do
|
372
|
-
r = nil
|
373
|
-
@db.query( "select * from foo where a = 1" ) do |result|
|
374
|
-
assert_not_nil result.next
|
375
|
-
assert_nil result.next
|
376
|
-
r = result
|
377
|
-
end
|
378
|
-
assert r.closed?
|
379
|
-
end
|
380
|
-
|
381
|
-
define_method( "test_query_no_block_with_bind_with_match" ) do
|
382
|
-
result = @db.query( "select * from foo where a = ?", 1 )
|
383
|
-
assert_not_nil result.next
|
384
|
-
assert_nil result.next
|
385
|
-
result.close
|
386
|
-
end
|
387
|
-
|
388
|
-
define_method( "test_query_with_block_with_bind_with_match" ) do
|
389
|
-
r = nil
|
390
|
-
@db.query( "select * from foo where a = ?", 1 ) do |result|
|
391
|
-
assert_not_nil result.next
|
392
|
-
assert_nil result.next
|
393
|
-
r = result
|
394
|
-
end
|
395
|
-
assert r.closed?
|
396
|
-
end
|
397
|
-
|
398
|
-
define_method( "test_get_first_row_no_bind_no_match" ) do
|
399
|
-
result = @db.get_first_row( "select * from foo where a=100" )
|
400
|
-
assert_nil result
|
401
|
-
end
|
402
|
-
|
403
|
-
define_method( "test_get_first_row_no_bind_with_match" ) do
|
404
|
-
result = @db.get_first_row( "select * from foo where a=1" )
|
405
|
-
assert_equal [ "1", "foo" ], result
|
406
|
-
end
|
407
|
-
|
408
|
-
define_method( "test_get_first_row_with_bind_no_match" ) do
|
409
|
-
result = @db.get_first_row( "select * from foo where a=?", 100 )
|
410
|
-
assert_nil result
|
411
|
-
end
|
412
|
-
|
413
|
-
define_method( "test_get_first_row_with_bind_with_match" ) do
|
414
|
-
result = @db.get_first_row( "select * from foo where a=?", 1 )
|
415
|
-
assert_equal [ "1", "foo" ], result
|
416
|
-
end
|
417
|
-
|
418
|
-
define_method( "test_get_first_value_no_bind_no_match" ) do
|
419
|
-
result = @db.get_first_value( "select b, a from foo where a=100" )
|
420
|
-
assert_nil result
|
421
|
-
end
|
422
|
-
|
423
|
-
define_method( "test_get_first_value_no_bind_with_match" ) do
|
424
|
-
result = @db.get_first_value( "select b, a from foo where a=1" )
|
425
|
-
assert_equal "foo", result
|
426
|
-
end
|
427
|
-
|
428
|
-
define_method( "test_get_first_value_with_bind_no_match" ) do
|
429
|
-
result = @db.get_first_value( "select b, a from foo where a=?", 100 )
|
430
|
-
assert_nil result
|
431
|
-
end
|
432
|
-
|
433
|
-
define_method( "test_get_first_value_with_bind_with_match" ) do
|
434
|
-
result = @db.get_first_value( "select b, a from foo where a=?", 1 )
|
435
|
-
assert_equal "foo", result
|
436
|
-
end
|
437
|
-
|
438
|
-
define_method( "test_last_insert_row_id" ) do
|
439
|
-
@db.execute "insert into foo ( b ) values ( 'test' )"
|
440
|
-
assert_equal 4, @db.last_insert_row_id
|
441
|
-
@db.execute "insert into foo ( b ) values ( 'again' )"
|
442
|
-
assert_equal 5, @db.last_insert_row_id
|
443
|
-
end
|
444
|
-
|
445
|
-
define_method( "test_changes" ) do
|
446
|
-
@db.execute "insert into foo ( b ) values ( 'test' )"
|
447
|
-
assert_equal 1, @db.changes
|
448
|
-
@db.execute "delete from foo where 1=1"
|
449
|
-
assert_equal 4, @db.changes
|
450
|
-
end
|
451
|
-
|
452
|
-
define_method( "test_total_changes" ) do
|
453
|
-
assert_equal 3, @db.total_changes
|
454
|
-
@db.execute "insert into foo ( b ) values ( 'test' )"
|
455
|
-
@db.execute "delete from foo where 1=1"
|
456
|
-
assert_equal 8, @db.total_changes
|
457
|
-
end
|
458
|
-
|
459
|
-
define_method( "test_transaction_nest" ) do
|
460
|
-
assert_raise( SQLite3::SQLException ) do
|
461
|
-
@db.transaction do
|
462
|
-
@db.transaction do
|
463
|
-
end
|
464
|
-
end
|
465
|
-
end
|
466
|
-
end
|
467
|
-
|
468
|
-
define_method( "test_transaction_rollback" ) do
|
469
|
-
@db.transaction
|
470
|
-
@db.execute_batch <<-SQL
|
471
|
-
insert into foo (b) values ( 'test1' );
|
472
|
-
insert into foo (b) values ( 'test2' );
|
473
|
-
insert into foo (b) values ( 'test3' );
|
474
|
-
insert into foo (b) values ( 'test4' );
|
475
|
-
SQL
|
476
|
-
assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
|
477
|
-
@db.rollback
|
478
|
-
assert_equal 3, @db.get_first_value("select count(*) from foo").to_i
|
479
|
-
end
|
480
|
-
|
481
|
-
define_method( "test_transaction_commit" ) do
|
482
|
-
@db.transaction
|
483
|
-
@db.execute_batch <<-SQL
|
484
|
-
insert into foo (b) values ( 'test1' );
|
485
|
-
insert into foo (b) values ( 'test2' );
|
486
|
-
insert into foo (b) values ( 'test3' );
|
487
|
-
insert into foo (b) values ( 'test4' );
|
488
|
-
SQL
|
489
|
-
assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
|
490
|
-
@db.commit
|
491
|
-
assert_equal 7, @db.get_first_value("select count(*) from foo").to_i
|
492
|
-
end
|
493
|
-
|
494
|
-
define_method( "test_transaction_rollback_in_block" ) do
|
495
|
-
assert_raise( SQLite3::SQLException ) do
|
496
|
-
@db.transaction do
|
497
|
-
@db.rollback
|
498
|
-
end
|
499
|
-
end
|
500
|
-
end
|
501
|
-
|
502
|
-
define_method( "test_transaction_commit_in_block" ) do
|
503
|
-
assert_raise( SQLite3::SQLException ) do
|
504
|
-
@db.transaction do
|
505
|
-
@db.commit
|
506
|
-
end
|
507
|
-
end
|
508
|
-
end
|
509
|
-
|
510
|
-
define_method( "test_transaction_active" ) do
|
511
|
-
assert !@db.transaction_active?
|
512
|
-
@db.transaction
|
513
|
-
assert @db.transaction_active?
|
514
|
-
@db.commit
|
515
|
-
assert !@db.transaction_active?
|
516
|
-
end
|
517
|
-
|
518
|
-
define_method( "no_tests_at" ) do |file,line,method|
|
519
|
-
warn "[(#{self.class}):#{file}:#{line}] no tests for #{method}"
|
520
|
-
end
|
521
|
-
|
522
|
-
define_method( "test_interrupt" ) do
|
523
|
-
@db.create_function( "abort", 1 ) do |func,x|
|
524
|
-
@db.interrupt
|
525
|
-
func.result = x
|
526
|
-
end
|
527
|
-
|
528
|
-
assert_raise( SQLite3::SQLException ) do
|
529
|
-
@db.execute "select abort(a) from foo"
|
530
|
-
end
|
531
|
-
end
|
532
|
-
|
533
|
-
define_method( "test_busy_handler_outwait" ) do
|
534
|
-
busy = Mutex.new
|
535
|
-
busy.lock
|
536
|
-
handler_call_count = 0
|
537
|
-
|
538
|
-
t = Thread.new do
|
539
|
-
begin
|
540
|
-
db2 = SQLite3::Database.open( "test.db", :driver=>driver )
|
541
|
-
db2.transaction( :exclusive ) do
|
542
|
-
busy.lock
|
543
|
-
end
|
544
|
-
ensure
|
545
|
-
db2.close if db2
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
@db.busy_handler do |data,count|
|
550
|
-
handler_call_count += 1
|
551
|
-
busy.unlock
|
552
|
-
true
|
553
|
-
end
|
554
|
-
|
555
|
-
assert_nothing_raised do
|
556
|
-
@db.execute "insert into foo (b) values ( 'from 2' )"
|
557
|
-
end
|
558
|
-
|
559
|
-
t.join
|
560
|
-
|
561
|
-
assert_equal 1, handler_call_count
|
562
|
-
end
|
563
|
-
|
564
|
-
define_method( "test_busy_handler_impatient" ) do
|
565
|
-
busy = Mutex.new
|
566
|
-
busy.lock
|
567
|
-
handler_call_count = 0
|
568
|
-
|
569
|
-
t = Thread.new do
|
570
|
-
begin
|
571
|
-
db2 = SQLite3::Database.open( "test.db", :driver=>driver )
|
572
|
-
db2.transaction( :exclusive ) do
|
573
|
-
busy.lock
|
574
|
-
end
|
575
|
-
ensure
|
576
|
-
db2.close if db2
|
577
|
-
end
|
578
|
-
end
|
579
|
-
|
580
|
-
@db.busy_handler do |data, count|
|
581
|
-
handler_call_count += 1
|
582
|
-
false
|
583
|
-
end
|
584
|
-
|
585
|
-
assert_raise( SQLite3::BusyException ) do
|
586
|
-
@db.execute "insert into foo (b) values ( 'from 2' )"
|
587
|
-
end
|
588
|
-
|
589
|
-
busy.unlock
|
590
|
-
t.join
|
591
|
-
|
592
|
-
assert_equal 1, handler_call_count
|
593
|
-
end
|
594
|
-
|
595
|
-
define_method( "test_busy_timeout" ) do
|
596
|
-
@db.busy_timeout 1000
|
597
|
-
busy = Mutex.new
|
598
|
-
busy.lock
|
599
|
-
|
600
|
-
t = Thread.new do
|
601
|
-
begin
|
602
|
-
db2 = SQLite3::Database.open( "test.db", :driver=>driver )
|
603
|
-
db2.transaction( :exclusive ) do
|
604
|
-
busy.lock
|
605
|
-
end
|
606
|
-
ensure
|
607
|
-
db2.close if db2
|
608
|
-
end
|
609
|
-
end
|
610
|
-
|
611
|
-
time = Benchmark.measure do
|
612
|
-
assert_raise( SQLite3::BusyException ) do
|
613
|
-
@db.execute "insert into foo (b) values ( 'from 2' )"
|
614
|
-
end
|
615
|
-
end
|
616
|
-
|
617
|
-
busy.unlock
|
618
|
-
t.join
|
619
|
-
|
620
|
-
assert time.real*1000 >= 1000
|
621
|
-
end
|
622
|
-
|
623
|
-
define_method( "test_create_function" ) do
|
624
|
-
@db.create_function( "munge", 1 ) do |func,x|
|
625
|
-
func.result = ">>>#{x}<<<"
|
626
|
-
end
|
627
|
-
|
628
|
-
value = @db.get_first_value( "select munge(b) from foo where a=1" )
|
629
|
-
assert_match( />>>.*<<</, value )
|
630
|
-
end
|
631
|
-
|
632
|
-
define_method( "test_create_aggregate_without_block" ) do
|
633
|
-
step = proc do |ctx,a|
|
634
|
-
ctx[:sum] ||= 0
|
635
|
-
ctx[:sum] += a.to_i
|
636
|
-
end
|
637
|
-
|
638
|
-
final = proc { |ctx| ctx.result = ctx[:sum] }
|
639
|
-
|
640
|
-
@db.create_aggregate( "accumulate", 1, step, final )
|
641
|
-
|
642
|
-
value = @db.get_first_value( "select accumulate(a) from foo" )
|
643
|
-
assert_equal "6", value
|
644
|
-
end
|
645
|
-
|
646
|
-
define_method( "test_create_aggregate_with_block" ) do
|
647
|
-
@db.create_aggregate( "accumulate", 1 ) do
|
648
|
-
step do |ctx,a|
|
649
|
-
ctx[:sum] ||= 0
|
650
|
-
ctx[:sum] += a.to_i
|
651
|
-
end
|
652
|
-
|
653
|
-
finalize { |ctx| ctx.result = ctx[:sum] }
|
654
|
-
end
|
655
|
-
|
656
|
-
value = @db.get_first_value( "select accumulate(a) from foo" )
|
657
|
-
assert_equal "6", value
|
658
|
-
end
|
659
|
-
|
660
|
-
define_method( "test_create_aggregate_with_no_data" ) do
|
661
|
-
@db.create_aggregate( "accumulate", 1 ) do
|
662
|
-
step do |ctx,a|
|
663
|
-
ctx[:sum] ||= 0
|
664
|
-
ctx[:sum] += a.to_i
|
665
|
-
end
|
666
|
-
|
667
|
-
finalize { |ctx| ctx.result = ctx[:sum] || 0 }
|
668
|
-
end
|
669
|
-
|
670
|
-
value = @db.get_first_value(
|
671
|
-
"select accumulate(a) from foo where a = 100" )
|
672
|
-
assert_equal "0", value
|
673
|
-
end
|
674
|
-
|
675
|
-
define_method( "test_create_aggregate_handler" ) do
|
676
|
-
handler = Class.new do
|
677
|
-
class << self
|
678
|
-
define_method( "arity" ) { 1 }
|
679
|
-
define_method( "text_rep" ) { SQLite3::Constants::TextRep::ANY }
|
680
|
-
define_method( "name" ) { "multiply" }
|
681
|
-
end
|
682
|
-
define_method( "step" ) do |ctx,a|
|
683
|
-
ctx[:buffer] ||= 1
|
684
|
-
ctx[:buffer] *= a.to_i
|
685
|
-
end
|
686
|
-
define_method( "finalize" ) { |ctx| ctx.result = ctx[:buffer] }
|
687
|
-
end
|
688
|
-
|
689
|
-
@db.create_aggregate_handler( handler )
|
690
|
-
value = @db.get_first_value( "select multiply(a) from foo" )
|
691
|
-
assert_equal "6", value
|
692
|
-
end
|
693
|
-
|
694
|
-
define_method( "test_bind_array_parameter" ) do
|
695
|
-
result = @db.get_first_value( "select b from foo where a=? and b=?",
|
696
|
-
[ 1, "foo" ] )
|
697
|
-
assert_equal "foo", result
|
698
|
-
end
|
699
|
-
end
|
700
|
-
const_set( "TC_Database_#{driver}", test_case )
|
701
|
-
|
702
|
-
# == TC_Statement =========================================================
|
703
|
-
|
704
|
-
test_case = Class.new( Test::Unit::TestCase ) do
|
705
|
-
define_method( "setup" ) do
|
706
|
-
@db = SQLite3::Database.new( "test.db", :driver=>driver )
|
707
|
-
@db.transaction do
|
708
|
-
@db.execute "create table foo ( a integer primary key, b text )"
|
709
|
-
@db.execute "insert into foo ( b ) values ( 'foo' )"
|
710
|
-
@db.execute "insert into foo ( b ) values ( 'bar' )"
|
711
|
-
@db.execute "insert into foo ( b ) values ( 'baz' )"
|
712
|
-
end
|
713
|
-
@stmt = @db.prepare( "select * from foo where a in ( ?, :named )" )
|
714
|
-
end
|
715
|
-
|
716
|
-
define_method( "teardown" ) do
|
717
|
-
@stmt.close
|
718
|
-
@db.close
|
719
|
-
File.delete( "test.db" )
|
720
|
-
end
|
721
|
-
|
722
|
-
define_method( "test_remainder_empty" ) do
|
723
|
-
assert_equal "", @stmt.remainder
|
724
|
-
end
|
725
|
-
|
726
|
-
define_method( "test_remainder_nonempty" ) do
|
727
|
-
called = false
|
728
|
-
@db.prepare( "select * from foo;\n blah" ) do |stmt|
|
729
|
-
called = true
|
730
|
-
assert_equal "\n blah", stmt.remainder
|
731
|
-
end
|
732
|
-
assert called
|
733
|
-
end
|
734
|
-
|
735
|
-
define_method( "test_bind_params_empty" ) do
|
736
|
-
assert_nothing_raised { @stmt.bind_params }
|
737
|
-
assert @stmt.execute!.empty?
|
738
|
-
end
|
739
|
-
|
740
|
-
define_method( "test_bind_params_array" ) do
|
741
|
-
@stmt.bind_params 1, 2
|
742
|
-
assert_equal 2, @stmt.execute!.length
|
743
|
-
end
|
744
|
-
|
745
|
-
define_method( "test_bind_params_hash" ) do
|
746
|
-
@stmt.bind_params ":named" => 2
|
747
|
-
assert_equal 1, @stmt.execute!.length
|
748
|
-
end
|
749
|
-
|
750
|
-
define_method( "test_bind_params_hash_without_colon" ) do
|
751
|
-
@stmt.bind_params "named" => 2
|
752
|
-
assert_equal 1, @stmt.execute!.length
|
753
|
-
end
|
754
|
-
|
755
|
-
define_method( "test_bind_params_hash_as_symbol" ) do
|
756
|
-
@stmt.bind_params :named => 2
|
757
|
-
assert_equal 1, @stmt.execute!.length
|
758
|
-
end
|
759
|
-
|
760
|
-
define_method( "test_bind_params_mixed" ) do
|
761
|
-
@stmt.bind_params( 1, ":named" => 2 )
|
762
|
-
assert_equal 2, @stmt.execute!.length
|
763
|
-
end
|
764
|
-
|
765
|
-
define_method( "test_bind_param_by_index" ) do
|
766
|
-
@stmt.bind_params( 1, 2 )
|
767
|
-
assert_equal 2, @stmt.execute!.length
|
768
|
-
end
|
769
|
-
|
770
|
-
define_method( "test_bind_param_by_name_bad" ) do
|
771
|
-
assert_raise( SQLite3::Exception ) { @stmt.bind_param( "@named", 2 ) }
|
772
|
-
end
|
773
|
-
|
774
|
-
define_method( "test_bind_param_by_name_good" ) do
|
775
|
-
@stmt.bind_param( ":named", 2 )
|
776
|
-
assert_equal 1, @stmt.execute!.length
|
777
|
-
end
|
778
|
-
|
779
|
-
define_method( "test_bind_param_with_various_types" ) do
|
780
|
-
@db.transaction do
|
781
|
-
@db.execute "create table all_types ( a integer primary key, b float, c string, d integer )"
|
782
|
-
@db.execute "insert into all_types ( b, c, d ) values ( 1.4, 'hello', 68719476735 )"
|
783
|
-
end
|
784
|
-
|
785
|
-
assert_equal 1, @db.execute( "select * from all_types where b = ?", 1.4 ).length
|
786
|
-
assert_equal 1, @db.execute( "select * from all_types where c = ?", 'hello').length
|
787
|
-
assert_equal 1, @db.execute( "select * from all_types where d = ?", 68719476735).length
|
788
|
-
end
|
789
|
-
|
790
|
-
define_method( "test_execute_no_bind_no_block" ) do
|
791
|
-
assert_instance_of SQLite3::ResultSet, @stmt.execute
|
792
|
-
end
|
793
|
-
|
794
|
-
define_method( "test_execute_with_bind_no_block" ) do
|
795
|
-
assert_instance_of SQLite3::ResultSet, @stmt.execute( 1, 2 )
|
796
|
-
end
|
797
|
-
|
798
|
-
define_method( "test_execute_no_bind_with_block" ) do
|
799
|
-
called = false
|
800
|
-
@stmt.execute { |row| called = true }
|
801
|
-
assert called
|
802
|
-
end
|
803
|
-
|
804
|
-
define_method( "test_execute_with_bind_with_block" ) do
|
805
|
-
called = 0
|
806
|
-
@stmt.execute( 1, 2 ) { |row| called += 1 }
|
807
|
-
assert_equal 1, called
|
808
|
-
end
|
809
|
-
|
810
|
-
define_method( "test_reexecute" ) do
|
811
|
-
r = @stmt.execute( 1, 2 )
|
812
|
-
assert_equal 2, r.to_a.length
|
813
|
-
assert_nothing_raised { r = @stmt.execute( 1, 2 ) }
|
814
|
-
assert_equal 2, r.to_a.length
|
815
|
-
end
|
816
|
-
|
817
|
-
define_method( "test_execute_bang_no_bind_no_block" ) do
|
818
|
-
assert @stmt.execute!.empty?
|
819
|
-
end
|
820
|
-
|
821
|
-
define_method( "test_execute_bang_with_bind_no_block" ) do
|
822
|
-
assert_equal 2, @stmt.execute!( 1, 2 ).length
|
823
|
-
end
|
824
|
-
|
825
|
-
define_method( "test_execute_bang_no_bind_with_block" ) do
|
826
|
-
called = 0
|
827
|
-
@stmt.execute! { |row| called += 1 }
|
828
|
-
assert_equal 0, called
|
829
|
-
end
|
830
|
-
|
831
|
-
define_method( "test_execute_bang_with_bind_with_block" ) do
|
832
|
-
called = 0
|
833
|
-
@stmt.execute!( 1, 2 ) { |row| called += 1 }
|
834
|
-
assert_equal 2, called
|
835
|
-
end
|
836
|
-
|
837
|
-
define_method( "test_columns" ) do
|
838
|
-
c1 = @stmt.columns
|
839
|
-
c2 = @stmt.columns
|
840
|
-
assert_same c1, c2
|
841
|
-
assert_equal 2, c1.length
|
842
|
-
end
|
843
|
-
|
844
|
-
define_method( "test_columns_computed" ) do
|
845
|
-
called = false
|
846
|
-
@db.prepare( "select count(*) from foo" ) do |stmt|
|
847
|
-
called = true
|
848
|
-
assert_equal [ "count(*)" ], stmt.columns
|
849
|
-
end
|
850
|
-
assert called
|
851
|
-
end
|
852
|
-
|
853
|
-
define_method( "test_types" ) do
|
854
|
-
t1 = @stmt.types
|
855
|
-
t2 = @stmt.types
|
856
|
-
assert_same t1, t2
|
857
|
-
assert_equal 2, t1.length
|
858
|
-
end
|
859
|
-
|
860
|
-
define_method( "test_types_computed" ) do
|
861
|
-
called = false
|
862
|
-
@db.prepare( "select count(*) from foo" ) do |stmt|
|
863
|
-
called = true
|
864
|
-
assert_equal [ nil ], stmt.types
|
865
|
-
end
|
866
|
-
assert called
|
867
|
-
end
|
868
|
-
|
869
|
-
define_method( "test_close" ) do
|
870
|
-
stmt = @db.prepare( "select * from foo" )
|
871
|
-
assert !stmt.closed?
|
872
|
-
stmt.close
|
873
|
-
assert stmt.closed?
|
874
|
-
assert_raise( SQLite3::Exception ) { stmt.execute }
|
875
|
-
assert_raise( SQLite3::Exception ) { stmt.execute! }
|
876
|
-
assert_raise( SQLite3::Exception ) { stmt.close }
|
877
|
-
assert_raise( SQLite3::Exception ) { stmt.bind_params 5 }
|
878
|
-
assert_raise( SQLite3::Exception ) { stmt.bind_param 1, 5 }
|
879
|
-
assert_raise( SQLite3::Exception ) { stmt.columns }
|
880
|
-
assert_raise( SQLite3::Exception ) { stmt.types }
|
881
|
-
end
|
882
|
-
|
883
|
-
define_method( "test_committing_tx_with_statement_active" ) do
|
884
|
-
called = false
|
885
|
-
@db.prepare( "select count(*) from foo" ) do |stmt|
|
886
|
-
called = true
|
887
|
-
count = stmt.execute!.first.first.to_i
|
888
|
-
@db.transaction do
|
889
|
-
@db.execute "insert into foo ( b ) values ( 'hello' )"
|
890
|
-
end
|
891
|
-
new_count = stmt.execute!.first.first.to_i
|
892
|
-
assert_equal new_count, count+1
|
893
|
-
end
|
894
|
-
assert called
|
895
|
-
end
|
896
|
-
end
|
897
|
-
const_set( "TC_Statement_#{driver}", test_case )
|
898
|
-
|
899
|
-
# == TC_ResultSet =========================================================
|
900
|
-
|
901
|
-
test_case = Class.new( Test::Unit::TestCase ) do
|
902
|
-
define_method( "setup" ) do
|
903
|
-
@db = SQLite3::Database.new( "test.db", :driver=>driver )
|
904
|
-
@db.transaction do
|
905
|
-
@db.execute "create table foo ( a integer primary key, b text )"
|
906
|
-
@db.execute "insert into foo ( b ) values ( 'foo' )"
|
907
|
-
@db.execute "insert into foo ( b ) values ( 'bar' )"
|
908
|
-
@db.execute "insert into foo ( b ) values ( 'baz' )"
|
909
|
-
end
|
910
|
-
@stmt = @db.prepare( "select * from foo where a in ( ?, ? )" )
|
911
|
-
@result = @stmt.execute
|
912
|
-
end
|
913
|
-
|
914
|
-
define_method( "teardown" ) do
|
915
|
-
@stmt.close
|
916
|
-
@db.close
|
917
|
-
File.delete( "test.db" )
|
918
|
-
end
|
919
|
-
|
920
|
-
define_method( "test_reset_unused" ) do
|
921
|
-
assert_nothing_raised { @result.reset }
|
922
|
-
assert @result.to_a.empty?
|
923
|
-
end
|
924
|
-
|
925
|
-
define_method( "test_reset_used" ) do
|
926
|
-
@result.to_a
|
927
|
-
assert_nothing_raised { @result.reset }
|
928
|
-
assert @result.to_a.empty?
|
929
|
-
end
|
930
|
-
|
931
|
-
define_method( "test_reset_with_bind" ) do
|
932
|
-
@result.to_a
|
933
|
-
assert_nothing_raised { @result.reset( 1, 2 ) }
|
934
|
-
assert_equal 2, @result.to_a.length
|
935
|
-
end
|
936
|
-
|
937
|
-
define_method( "test_eof_inner" ) do
|
938
|
-
@result.reset( 1 )
|
939
|
-
assert !@result.eof?
|
940
|
-
end
|
941
|
-
|
942
|
-
define_method( "test_eof_edge" ) do
|
943
|
-
@result.reset( 1 )
|
944
|
-
@result.next # to first row
|
945
|
-
@result.next # to end of result set
|
946
|
-
assert @result.eof?
|
947
|
-
end
|
948
|
-
|
949
|
-
define_method( "test_next_eof" ) do
|
950
|
-
@result.reset( 1 )
|
951
|
-
assert_not_nil @result.next
|
952
|
-
assert_nil @result.next
|
953
|
-
end
|
954
|
-
|
955
|
-
define_method( "test_next_no_type_translation_no_hash" ) do
|
956
|
-
@result.reset( 1 )
|
957
|
-
assert_equal [ "1", "foo" ], @result.next
|
958
|
-
end
|
959
|
-
|
960
|
-
define_method( "test_next_type_translation" ) do
|
961
|
-
@db.type_translation = true
|
962
|
-
@result.reset( 1 )
|
963
|
-
assert_equal [ 1, "foo" ], @result.next
|
964
|
-
end
|
965
|
-
|
966
|
-
define_method( "test_next_type_translation_with_untyped_column" ) do
|
967
|
-
@db.type_translation = true
|
968
|
-
@db.query( "select count(*) from foo" ) do |result|
|
969
|
-
assert_equal ["3"], result.next
|
970
|
-
end
|
971
|
-
end
|
972
|
-
|
973
|
-
define_method( "test_type_translation_with_null_column" ) do
|
974
|
-
@db.type_translation = true
|
975
|
-
@db.execute "create table bar ( a integer, b time, c string )"
|
976
|
-
@db.execute "insert into bar (a, b, c) values (NULL, '1974-07-25 14:39:00', 'hello')"
|
977
|
-
@db.execute "insert into bar (a, b, c) values (1, NULL, 'hello')"
|
978
|
-
@db.execute "insert into bar (a, b, c) values (2, '1974-07-25 14:39:00', NULL)"
|
979
|
-
@db.query( "select * from bar" ) do |result|
|
980
|
-
assert_equal [nil, Time.local(1974, 7, 25, 14, 39, 0), 'hello'], result.next
|
981
|
-
assert_equal [1, nil, 'hello'], result.next
|
982
|
-
assert_equal [2, Time.local(1974, 7, 25, 14, 39, 0), nil], result.next
|
983
|
-
end
|
984
|
-
end
|
985
|
-
|
986
|
-
define_method( "test_date_and_time_translation" ) do
|
987
|
-
@db.type_translation = true
|
988
|
-
@db.execute "create table bar ( a date, b datetime, c time, d timestamp )"
|
989
|
-
@db.execute "insert into bar (a, b, c, d) values ('1999-01-08', '1997-12-17 07:37:16', '07:37:16', '2004-10-19 10:23:54')"
|
990
|
-
@db.query( "select * from bar" ) do |result|
|
991
|
-
result = result.next
|
992
|
-
assert result[0].is_a?(Date)
|
993
|
-
assert result[1].is_a?(DateTime)
|
994
|
-
assert result[2].is_a?(Time)
|
995
|
-
assert result[3].is_a?(Time)
|
996
|
-
end
|
997
|
-
end
|
998
|
-
|
999
|
-
define_method( "test_next_results_as_hash" ) do
|
1000
|
-
@db.results_as_hash = true
|
1001
|
-
@result.reset( 1 )
|
1002
|
-
assert_equal( { "a" => "1", "b" => "foo", 0 => "1", 1 => "foo" },
|
1003
|
-
@result.next )
|
1004
|
-
end
|
1005
|
-
|
1006
|
-
define_method( "test_each" ) do
|
1007
|
-
called = 0
|
1008
|
-
@result.reset( 1, 2 )
|
1009
|
-
@result.each { |row| called += 1 }
|
1010
|
-
assert_equal 2, called
|
1011
|
-
end
|
1012
|
-
|
1013
|
-
define_method( "test_enumerable" ) do
|
1014
|
-
@result.reset( 1, 2 )
|
1015
|
-
assert_equal 2, @result.to_a.length
|
1016
|
-
end
|
1017
|
-
|
1018
|
-
define_method( "test_types" ) do
|
1019
|
-
assert_equal [ "integer", "text" ], @result.types
|
1020
|
-
end
|
1021
|
-
|
1022
|
-
define_method( "test_columns" ) do
|
1023
|
-
assert_equal [ "a", "b" ], @result.columns
|
1024
|
-
end
|
1025
|
-
|
1026
|
-
define_method( "test_close" ) do
|
1027
|
-
stmt = @db.prepare( "select * from foo" )
|
1028
|
-
result = stmt.execute
|
1029
|
-
assert !result.closed?
|
1030
|
-
result.close
|
1031
|
-
assert result.closed?
|
1032
|
-
assert stmt.closed?
|
1033
|
-
assert_raise( SQLite3::Exception ) { result.reset }
|
1034
|
-
assert_raise( SQLite3::Exception ) { result.next }
|
1035
|
-
assert_raise( SQLite3::Exception ) { result.each }
|
1036
|
-
assert_raise( SQLite3::Exception ) { result.close }
|
1037
|
-
assert_raise( SQLite3::Exception ) { result.types }
|
1038
|
-
assert_raise( SQLite3::Exception ) { result.columns }
|
1039
|
-
end
|
1040
|
-
end
|
1041
|
-
const_set( "TC_ResultSet_#{driver}", test_case )
|
1042
|
-
end
|
1043
|
-
|
1044
|
-
end
|