sqlite3-ruby 1.2.5-x86-mswin32 → 1.3.0.beta.1-x86-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- data/API_CHANGES.rdoc +48 -0
- data/{History.txt → CHANGELOG.rdoc} +24 -0
- data/Manifest.txt +14 -14
- data/{README.txt → README.rdoc} +1 -6
- data/Rakefile +8 -3
- data/ext/sqlite3/database.c +687 -0
- data/ext/sqlite3/database.h +15 -0
- data/ext/sqlite3/exception.c +94 -0
- data/ext/sqlite3/exception.h +8 -0
- data/ext/sqlite3/extconf.rb +26 -0
- data/ext/sqlite3/sqlite3.c +33 -0
- data/ext/sqlite3/sqlite3_ruby.h +43 -0
- data/ext/sqlite3/statement.c +412 -0
- data/ext/sqlite3/statement.h +16 -0
- data/lib/sqlite3.rb +9 -0
- data/lib/sqlite3/1.8/sqlite3_native.so +0 -0
- data/lib/sqlite3/1.9/sqlite3_native.so +0 -0
- data/lib/sqlite3/database.rb +94 -302
- data/lib/sqlite3/errors.rb +0 -24
- data/lib/sqlite3/pragmas.rb +16 -7
- data/lib/sqlite3/resultset.rb +25 -81
- data/lib/sqlite3/statement.rb +22 -107
- data/lib/sqlite3/version.rb +4 -4
- data/setup.rb +2 -2
- data/tasks/native.rake +13 -17
- data/tasks/vendor_sqlite3.rake +10 -7
- data/test/helper.rb +1 -65
- data/test/test_database.rb +239 -189
- data/test/test_encoding.rb +115 -0
- data/test/test_integration.rb +38 -35
- data/test/test_integration_open_close.rb +1 -1
- data/test/test_integration_pending.rb +6 -4
- data/test/test_integration_resultset.rb +20 -8
- data/test/test_integration_statement.rb +1 -2
- data/test/test_sqlite3.rb +9 -0
- data/test/test_statement.rb +193 -0
- metadata +84 -49
- data/ext/sqlite3_api/extconf.rb +0 -10
- data/ext/sqlite3_api/sqlite3_api.i +0 -362
- data/ext/sqlite3_api/sqlite3_api_wrap.c +0 -5018
- data/lib/1.8/sqlite3_api.so +0 -0
- data/lib/1.9/sqlite3_api.so +0 -0
- data/lib/sqlite3/driver/dl/api.rb +0 -152
- data/lib/sqlite3/driver/dl/driver.rb +0 -307
- data/lib/sqlite3/driver/native/driver.rb +0 -219
- data/tasks/benchmark.rake +0 -9
- data/tasks/gem.rake +0 -32
- data/test/bm.rb +0 -140
- data/test/driver/dl/tc_driver.rb +0 -292
- data/test/native-vs-dl.rb +0 -126
- data/test/test_errors.rb +0 -17
data/tasks/native.rake
CHANGED
@@ -1,19 +1,22 @@
|
|
1
1
|
# use rake-compiler for building the extension
|
2
2
|
require 'rake/extensiontask'
|
3
3
|
|
4
|
-
# build
|
5
|
-
Rake::ExtensionTask.new('
|
4
|
+
# build sqlite3_native C extension
|
5
|
+
Rake::ExtensionTask.new('sqlite3_native', HOE.spec) do |ext|
|
6
|
+
# where to locate the extension
|
7
|
+
ext.ext_dir = 'ext/sqlite3'
|
8
|
+
|
9
|
+
# where native extension will be copied (matches makefile)
|
10
|
+
ext.lib_dir = "lib/sqlite3"
|
11
|
+
|
6
12
|
# reference to the sqlite3 library
|
7
13
|
sqlite3_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'sqlite3'))
|
8
14
|
|
9
|
-
# define target for extension (supporting fat binaries)
|
10
|
-
if RUBY_PLATFORM =~ /mingw/ then
|
11
|
-
ruby_ver = RUBY_VERSION.match(/(\d+\.\d+)/)[1]
|
12
|
-
ext.lib_dir = "lib/#{ruby_ver}"
|
13
|
-
end
|
14
|
-
|
15
15
|
# automatically add build options to avoid need of manual input
|
16
16
|
if RUBY_PLATFORM =~ /mswin|mingw/ then
|
17
|
+
# define target for extension (supporting fat binaries)
|
18
|
+
RUBY_VERSION =~ /(\d+\.\d+)/
|
19
|
+
ext.lib_dir = "lib/sqlite3/#{$1}"
|
17
20
|
ext.config_options << "--with-sqlite3-dir=#{sqlite3_lib}"
|
18
21
|
else
|
19
22
|
ext.cross_compile = true
|
@@ -22,14 +25,7 @@ Rake::ExtensionTask.new('sqlite3_api', HOE.spec) do |ext|
|
|
22
25
|
end
|
23
26
|
end
|
24
27
|
|
25
|
-
# C wrapper depends on swig file to be generated
|
26
|
-
file 'ext/sqlite3_api/sqlite3_api_wrap.c' => ['ext/sqlite3_api/sqlite3_api.i'] do |t|
|
27
|
-
begin
|
28
|
-
sh "swig -ruby -o #{t.name} #{t.prerequisites.first}"
|
29
|
-
rescue
|
30
|
-
fail "could not build wrapper via swig (perhaps swig is not installed?)"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
28
|
# ensure things are compiled prior testing
|
35
29
|
task :test => [:compile]
|
30
|
+
|
31
|
+
# vim: syntax=ruby
|
data/tasks/vendor_sqlite3.rake
CHANGED
@@ -25,14 +25,15 @@ def dlltool(dllname, deffile, libfile)
|
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
|
28
|
+
SQLITE_VERSION = '3.6.22'
|
29
|
+
url_version = SQLITE_VERSION.gsub('.', '_')
|
29
30
|
|
30
31
|
# required folder structure for --with-sqlite3-dir (include + lib)
|
31
32
|
directory "vendor/sqlite3/lib"
|
32
33
|
directory "vendor/sqlite3/include"
|
33
34
|
|
34
35
|
# download amalgamation version (for include files)
|
35
|
-
file "vendor/sqlite-amalgamation-#{
|
36
|
+
file "vendor/sqlite-amalgamation-#{url_version}.zip" => ['vendor'] do |t|
|
36
37
|
url = "http://www.sqlite.org/#{File.basename(t.name)}"
|
37
38
|
when_writing "downloading #{t.name}" do
|
38
39
|
cd File.dirname(t.name) do
|
@@ -42,7 +43,7 @@ file "vendor/sqlite-amalgamation-#{version}.zip" => ['vendor'] do |t|
|
|
42
43
|
end
|
43
44
|
|
44
45
|
# download dll binaries
|
45
|
-
file "vendor/sqlitedll-#{
|
46
|
+
file "vendor/sqlitedll-#{url_version}.zip" => ['vendor'] do |t|
|
46
47
|
url = "http://www.sqlite.org/#{File.basename(t.name)}"
|
47
48
|
when_writing "downloading #{t.name}" do
|
48
49
|
cd File.dirname(t.name) do
|
@@ -52,7 +53,7 @@ file "vendor/sqlitedll-#{version}.zip" => ['vendor'] do |t|
|
|
52
53
|
end
|
53
54
|
|
54
55
|
# extract header files into include folder
|
55
|
-
file "vendor/sqlite3/include/sqlite3.h" => ['vendor/sqlite3/include', "vendor/sqlite-amalgamation-#{
|
56
|
+
file "vendor/sqlite3/include/sqlite3.h" => ['vendor/sqlite3/include', "vendor/sqlite-amalgamation-#{url_version}.zip"] do |t|
|
56
57
|
full_file = File.expand_path(t.prerequisites.last)
|
57
58
|
when_writing "creating #{t.name}" do
|
58
59
|
cd File.dirname(t.name) do
|
@@ -64,7 +65,7 @@ file "vendor/sqlite3/include/sqlite3.h" => ['vendor/sqlite3/include', "vendor/sq
|
|
64
65
|
end
|
65
66
|
|
66
67
|
# extract dll files into lib folder
|
67
|
-
file "vendor/sqlite3/lib/sqlite3.dll" => ['vendor/sqlite3/lib', "vendor/sqlitedll-#{
|
68
|
+
file "vendor/sqlite3/lib/sqlite3.dll" => ['vendor/sqlite3/lib', "vendor/sqlitedll-#{url_version}.zip"] do |t|
|
68
69
|
full_file = File.expand_path(t.prerequisites.last)
|
69
70
|
when_writing "creating #{t.name}" do
|
70
71
|
cd File.dirname(t.name) do
|
@@ -88,7 +89,7 @@ end
|
|
88
89
|
|
89
90
|
# clean and clobber actions
|
90
91
|
# All the uncompressed files must be removed at clean
|
91
|
-
|
92
|
+
CLEAN.include('vendor/sqlite3')
|
92
93
|
|
93
94
|
# clobber vendored packages
|
94
95
|
CLOBBER.include('vendor')
|
@@ -100,5 +101,7 @@ task 'vendor:sqlite3' => ["vendor/sqlite3/lib/sqlite3.lib", "vendor/sqlite3/incl
|
|
100
101
|
if RUBY_PLATFORM =~ /mingw|mswin/ then
|
101
102
|
Rake::Task['compile'].prerequisites.unshift 'vendor:sqlite3'
|
102
103
|
else
|
103
|
-
Rake::Task
|
104
|
+
if Rake::Task.task_defined?(:cross)
|
105
|
+
Rake::Task['cross'].prerequisites.unshift 'vendor:sqlite3'
|
106
|
+
end
|
104
107
|
end
|
data/test/helper.rb
CHANGED
@@ -1,67 +1,3 @@
|
|
1
|
-
# add lib folder to the path
|
2
|
-
$:.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
-
|
4
1
|
require 'sqlite3'
|
5
|
-
|
6
|
-
require 'rubygems'
|
7
2
|
require 'test/unit'
|
8
|
-
|
9
|
-
# define mocks to be used
|
10
|
-
require 'mocha'
|
11
|
-
|
12
|
-
class Driver < Mocha::Mock
|
13
|
-
def initialize
|
14
|
-
super
|
15
|
-
stubs( :open ).returns([0, 'cookie'])
|
16
|
-
stubs( :close ).returns(0)
|
17
|
-
stubs( :complete? ).returns(0)
|
18
|
-
stubs( :errmsg ).returns('')
|
19
|
-
stubs( :errcode ).returns(0)
|
20
|
-
stubs( :trace ).returns(nil)
|
21
|
-
stubs( :set_authorizer ).returns(0)
|
22
|
-
stubs( :prepare ).returns([0, 'stmt', 'remainder'])
|
23
|
-
stubs( :finalize ).returns(0)
|
24
|
-
stubs( :changes ).returns(14)
|
25
|
-
stubs( :total_changes ).returns(28)
|
26
|
-
stubs( :interrupt ).returns(0)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class MockResultSet < Mocha::Mock
|
31
|
-
def initialize
|
32
|
-
super
|
33
|
-
stubs( :each ).yields(['foo'])
|
34
|
-
stubs( :columns ).returns(['name'])
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class Statement < Mocha::Mock
|
39
|
-
attr_reader :handle
|
40
|
-
attr_reader :sql
|
41
|
-
attr_reader :last_result
|
42
|
-
|
43
|
-
def initialize( handle, sql )
|
44
|
-
super()
|
45
|
-
@handle = handle
|
46
|
-
@sql = sql
|
47
|
-
stubs( :close ).returns(0)
|
48
|
-
stubs( :remainder ).returns('')
|
49
|
-
stubs( :execute ).returns(MockResultSet.new)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
# UTF conversion extensions
|
54
|
-
class String
|
55
|
-
def to_utf16(terminate=false)
|
56
|
-
self.split(//).map { |c| c[0] }.pack("v*") +
|
57
|
-
(terminate ? "\0\0" : "")
|
58
|
-
end
|
59
|
-
|
60
|
-
def from_utf16
|
61
|
-
result = ""
|
62
|
-
length.times do |i|
|
63
|
-
result << self[i,1] if i % 2 == 0 && self[i] != 0
|
64
|
-
end
|
65
|
-
result
|
66
|
-
end
|
67
|
-
end
|
3
|
+
require 'iconv'
|
data/test/test_database.rb
CHANGED
@@ -1,217 +1,267 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class TC_Database_Init < Test::Unit::TestCase
|
4
|
-
def test_new
|
5
|
-
# any_instance fails here...
|
6
|
-
driver = Driver.new
|
7
|
-
driver.expects(:open).once.with('foo.db', false).returns([0, 'cookie'])
|
8
|
-
Driver.stubs(:new).returns(driver)
|
9
|
-
db = SQLite3::Database.new( 'foo.db', :driver => Driver )
|
10
|
-
assert !db.closed?
|
11
|
-
assert !db.results_as_hash
|
12
|
-
assert !db.type_translation
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_new_with_block
|
16
|
-
driver = Driver.new
|
17
|
-
driver.expects(:open).once.with('foo.db', false).returns([0, 'cookie'])
|
18
|
-
Driver.stubs(:new).returns(driver)
|
19
|
-
returned_db = SQLite3::Database.new( "foo.db", :driver => Driver ) do |db|
|
20
|
-
assert !db.closed?
|
21
|
-
assert !db.results_as_hash
|
22
|
-
assert !db.type_translation
|
23
|
-
end
|
24
|
-
assert returned_db.closed?
|
25
|
-
end
|
1
|
+
require 'helper'
|
2
|
+
require 'iconv'
|
26
3
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
assert !db.closed?
|
33
|
-
assert !db.results_as_hash
|
34
|
-
assert !db.type_translation
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_open_with_block
|
38
|
-
driver = Driver.new
|
39
|
-
driver.expects(:open).once.with('foo.db', false).returns([0, 'cookie'])
|
40
|
-
Driver.stubs(:new).returns(driver)
|
41
|
-
returned_db = SQLite3::Database.open( "foo.db", :driver => Driver ) do |db|
|
42
|
-
assert !db.closed?
|
43
|
-
assert !db.results_as_hash
|
44
|
-
assert !db.type_translation
|
45
|
-
end
|
46
|
-
assert returned_db.closed?
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_with_type_translation
|
50
|
-
db = SQLite3::Database.open( "foo.db", :driver => Driver,
|
51
|
-
:type_translation => true )
|
52
|
-
assert db.type_translation
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_with_results_as_hash
|
56
|
-
db = SQLite3::Database.open( "foo.db", :driver => Driver,
|
57
|
-
:results_as_hash => true )
|
58
|
-
assert db.results_as_hash
|
59
|
-
end
|
60
|
-
|
61
|
-
def test_with_type_translation_and_results_as_hash
|
62
|
-
db = SQLite3::Database.open( "foo.db", :driver => Driver,
|
63
|
-
:results_as_hash => true,
|
64
|
-
:type_translation => true )
|
65
|
-
assert db.results_as_hash
|
66
|
-
assert db.type_translation
|
67
|
-
end
|
68
|
-
end
|
4
|
+
module SQLite3
|
5
|
+
class TestDatabase < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@db = SQLite3::Database.new(':memory:')
|
8
|
+
end
|
69
9
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
end
|
10
|
+
def test_new
|
11
|
+
db = SQLite3::Database.new(':memory:')
|
12
|
+
assert db
|
13
|
+
end
|
75
14
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
15
|
+
def test_new_yields_self
|
16
|
+
thing = nil
|
17
|
+
SQLite3::Database.new(':memory:') do |db|
|
18
|
+
thing = db
|
19
|
+
end
|
20
|
+
assert_instance_of(SQLite3::Database, thing)
|
21
|
+
end
|
80
22
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
23
|
+
def test_new_with_options
|
24
|
+
db = SQLite3::Database.new(Iconv.conv('UTF-16LE', 'UTF-8', ':memory:'),
|
25
|
+
:utf16 => true)
|
26
|
+
assert db
|
27
|
+
end
|
85
28
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
29
|
+
def test_close
|
30
|
+
db = SQLite3::Database.new(':memory:')
|
31
|
+
db.close
|
32
|
+
assert db.closed?
|
33
|
+
end
|
90
34
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
35
|
+
def test_block_closes_self
|
36
|
+
thing = nil
|
37
|
+
SQLite3::Database.new(':memory:') do |db|
|
38
|
+
thing = db
|
39
|
+
assert !thing.closed?
|
40
|
+
end
|
41
|
+
assert thing.closed?
|
42
|
+
end
|
95
43
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
44
|
+
def test_prepare
|
45
|
+
db = SQLite3::Database.new(':memory:')
|
46
|
+
stmt = db.prepare('select "hello world"')
|
47
|
+
assert_instance_of(SQLite3::Statement, stmt)
|
48
|
+
end
|
100
49
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
end
|
50
|
+
def test_total_changes
|
51
|
+
db = SQLite3::Database.new(':memory:')
|
52
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
53
|
+
db.execute("insert into foo (b) values ('hello')")
|
54
|
+
assert_equal 1, db.total_changes
|
55
|
+
end
|
108
56
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
57
|
+
def test_execute_returns_list_of_hash
|
58
|
+
db = SQLite3::Database.new(':memory:', :results_as_hash => true)
|
59
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
60
|
+
db.execute("insert into foo (b) values ('hello')")
|
61
|
+
rows = db.execute("select * from foo")
|
62
|
+
assert_equal [{0=>1, "a"=>1, "b"=>"hello", 1=>"hello"}], rows
|
63
|
+
end
|
114
64
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
65
|
+
def test_execute_yields_hash
|
66
|
+
db = SQLite3::Database.new(':memory:', :results_as_hash => true)
|
67
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
68
|
+
db.execute("insert into foo (b) values ('hello')")
|
69
|
+
db.execute("select * from foo") do |row|
|
70
|
+
assert_equal({0=>1, "a"=>1, "b"=>"hello", 1=>"hello"}, row)
|
71
|
+
end
|
72
|
+
end
|
120
73
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
74
|
+
def test_table_info
|
75
|
+
db = SQLite3::Database.new(':memory:', :results_as_hash => true)
|
76
|
+
db.execute("create table foo ( a integer primary key, b text )")
|
77
|
+
info = [{
|
78
|
+
"name" => "a",
|
79
|
+
"pk" => 1,
|
80
|
+
"notnull" => 0,
|
81
|
+
"type" => "integer",
|
82
|
+
"dflt_value" => nil,
|
83
|
+
"cid" => 0
|
84
|
+
},
|
85
|
+
{
|
86
|
+
"name" => "b",
|
87
|
+
"pk" => 0,
|
88
|
+
"notnull" => 0,
|
89
|
+
"type" => "text",
|
90
|
+
"dflt_value" => nil,
|
91
|
+
"cid" => 1
|
92
|
+
}]
|
93
|
+
assert_equal info, db.table_info('foo')
|
94
|
+
end
|
125
95
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
assert called
|
134
|
-
end
|
96
|
+
def test_total_changes_closed
|
97
|
+
db = SQLite3::Database.new(':memory:')
|
98
|
+
db.close
|
99
|
+
assert_raise(SQLite3::Exception) do
|
100
|
+
db.total_changes
|
101
|
+
end
|
102
|
+
end
|
135
103
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
result = @db.execute( "foo", "bar", "baz" )
|
143
|
-
assert_equal [["foo"]], result
|
144
|
-
end
|
104
|
+
def test_trace_requires_opendb
|
105
|
+
@db.close
|
106
|
+
assert_raise(SQLite3::Exception) do
|
107
|
+
@db.trace { |x| }
|
108
|
+
end
|
109
|
+
end
|
145
110
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
Statement.stubs(:new).returns(statement)
|
152
|
-
@db.execute( "foo", "bar", "baz" ) do |row|
|
153
|
-
called = true
|
154
|
-
assert_equal ["foo"], row
|
111
|
+
def test_trace_with_block
|
112
|
+
result = nil
|
113
|
+
@db.trace { |sql| result = sql }
|
114
|
+
@db.execute "select 'foo'"
|
115
|
+
assert_equal "select 'foo'", result
|
155
116
|
end
|
156
117
|
|
157
|
-
|
158
|
-
|
118
|
+
def test_trace_with_object
|
119
|
+
obj = Class.new {
|
120
|
+
attr_accessor :result
|
121
|
+
def call sql; @result = sql end
|
122
|
+
}.new
|
159
123
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
Statement.stubs(:new).returns(statement)
|
165
|
-
MockResultSet.any_instance.stubs(:inject).returns([['name'], ['foo']])
|
166
|
-
result = @db.execute2( "foo", "bar", "baz" )
|
167
|
-
assert_equal [["name"],["foo"]], result
|
168
|
-
end
|
124
|
+
@db.trace(obj)
|
125
|
+
@db.execute "select 'foo'"
|
126
|
+
assert_equal "select 'foo'", obj.result
|
127
|
+
end
|
169
128
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
# any_instance fails here...
|
174
|
-
statement = Statement.new('cookie', 'foo')
|
175
|
-
statement.expects(:execute).with('bar', 'baz').returns(MockResultSet.new)
|
176
|
-
Statement.stubs(:new).returns(statement)
|
177
|
-
@db.execute2( "foo", "bar", "baz" ) do |row|
|
178
|
-
called = true
|
179
|
-
assert_equal parts.shift, row
|
129
|
+
def test_trace_takes_nil
|
130
|
+
@db.trace(nil)
|
131
|
+
@db.execute "select 'foo'"
|
180
132
|
end
|
181
133
|
|
182
|
-
|
183
|
-
|
134
|
+
def test_last_insert_row_id_closed
|
135
|
+
@db.close
|
136
|
+
assert_raise(SQLite3::Exception) do
|
137
|
+
@db.last_insert_row_id
|
138
|
+
end
|
139
|
+
end
|
184
140
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
141
|
+
def test_define_function
|
142
|
+
called_with = nil
|
143
|
+
@db.define_function("hello") do |value|
|
144
|
+
called_with = value
|
145
|
+
end
|
146
|
+
@db.execute("select hello(10)")
|
147
|
+
assert_equal 10, called_with
|
148
|
+
end
|
192
149
|
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
150
|
+
def test_call_func_arg_type
|
151
|
+
called_with = nil
|
152
|
+
@db.define_function("hello") do |b, c, d|
|
153
|
+
called_with = [b, c, d]
|
154
|
+
nil
|
155
|
+
end
|
156
|
+
@db.execute("select hello(2.2, 'foo', NULL)")
|
157
|
+
assert_equal [2.2, 'foo', nil], called_with
|
158
|
+
end
|
197
159
|
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
160
|
+
def test_define_varargs
|
161
|
+
called_with = nil
|
162
|
+
@db.define_function("hello") do |*args|
|
163
|
+
called_with = args
|
164
|
+
nil
|
165
|
+
end
|
166
|
+
@db.execute("select hello(2.2, 'foo', NULL)")
|
167
|
+
assert_equal [2.2, 'foo', nil], called_with
|
168
|
+
end
|
202
169
|
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
170
|
+
def test_function_return
|
171
|
+
@db.define_function("hello") { |a| 10 }
|
172
|
+
assert_equal [10], @db.execute("select hello('world')").first
|
173
|
+
end
|
207
174
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
175
|
+
def test_function_return_types
|
176
|
+
[10, 2.2, nil, "foo"].each do |thing|
|
177
|
+
@db.define_function("hello") { |a| thing }
|
178
|
+
assert_equal [thing], @db.execute("select hello('world')").first
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_define_function_closed
|
183
|
+
@db.close
|
184
|
+
assert_raise(SQLite3::Exception) do
|
185
|
+
@db.define_function('foo') { }
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_inerrupt_closed
|
190
|
+
@db.close
|
191
|
+
assert_raise(SQLite3::Exception) do
|
192
|
+
@db.interrupt
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_define_aggregate
|
197
|
+
@db.execute "create table foo ( a integer primary key, b text )"
|
198
|
+
@db.execute "insert into foo ( b ) values ( 'foo' )"
|
199
|
+
@db.execute "insert into foo ( b ) values ( 'bar' )"
|
200
|
+
@db.execute "insert into foo ( b ) values ( 'baz' )"
|
201
|
+
|
202
|
+
acc = Class.new {
|
203
|
+
attr_reader :sum
|
204
|
+
alias :finalize :sum
|
205
|
+
def initialize
|
206
|
+
@sum = 0
|
207
|
+
end
|
208
|
+
|
209
|
+
def step a
|
210
|
+
@sum += a
|
211
|
+
end
|
212
|
+
}.new
|
213
|
+
|
214
|
+
@db.define_aggregator("accumulate", acc)
|
215
|
+
value = @db.get_first_value( "select accumulate(a) from foo" )
|
216
|
+
assert_equal 6, value
|
217
|
+
end
|
218
|
+
|
219
|
+
def test_authorizer_ok
|
220
|
+
@db.authorizer = Class.new {
|
221
|
+
def call action, a, b, c, d; true end
|
222
|
+
}.new
|
223
|
+
@db.prepare("select 'fooooo'")
|
224
|
+
|
225
|
+
@db.authorizer = Class.new {
|
226
|
+
def call action, a, b, c, d; 0 end
|
227
|
+
}.new
|
228
|
+
@db.prepare("select 'fooooo'")
|
229
|
+
end
|
212
230
|
|
213
|
-
|
214
|
-
|
215
|
-
|
231
|
+
def test_authorizer_ignore
|
232
|
+
@db.authorizer = Class.new {
|
233
|
+
def call action, a, b, c, d; nil end
|
234
|
+
}.new
|
235
|
+
stmt = @db.prepare("select 'fooooo'")
|
236
|
+
assert_equal nil, stmt.step
|
237
|
+
end
|
238
|
+
|
239
|
+
def test_authorizer_fail
|
240
|
+
@db.authorizer = Class.new {
|
241
|
+
def call action, a, b, c, d; false end
|
242
|
+
}.new
|
243
|
+
assert_raises(SQLite3::AuthorizationException) do
|
244
|
+
@db.prepare("select 'fooooo'")
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
def test_remove_auth
|
249
|
+
@db.authorizer = Class.new {
|
250
|
+
def call action, a, b, c, d; false end
|
251
|
+
}.new
|
252
|
+
assert_raises(SQLite3::AuthorizationException) do
|
253
|
+
@db.prepare("select 'fooooo'")
|
254
|
+
end
|
255
|
+
|
256
|
+
@db.authorizer = nil
|
257
|
+
@db.prepare("select 'fooooo'")
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_close_with_open_statements
|
261
|
+
stmt = @db.prepare("select 'foo'")
|
262
|
+
assert_raises(SQLite3::BusyException) do
|
263
|
+
@db.close
|
264
|
+
end
|
265
|
+
end
|
216
266
|
end
|
217
267
|
end
|