sqlite3-ruby 1.2.5 → 1.3.0.beta.1
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/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 +82 -48
- 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/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
@@ -1,219 +0,0 @@
|
|
1
|
-
# support multiple ruby version (fat binaries under windows)
|
2
|
-
begin
|
3
|
-
require 'sqlite3_api'
|
4
|
-
rescue LoadError
|
5
|
-
if RUBY_PLATFORM =~ /mingw|mswin/ then
|
6
|
-
RUBY_VERSION =~ /(\d+.\d+)/
|
7
|
-
require "#{$1}/sqlite3_api"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
module SQLite3 ; module Driver ; module Native
|
12
|
-
|
13
|
-
class Driver
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@callback_data = Hash.new
|
17
|
-
@authorizer = Hash.new
|
18
|
-
@busy_handler = Hash.new
|
19
|
-
@trace = Hash.new
|
20
|
-
end
|
21
|
-
|
22
|
-
def complete?( sql, utf16=false )
|
23
|
-
API.send( utf16 ? :sqlite3_complete16 : :sqlite3_complete, sql ) != 0
|
24
|
-
end
|
25
|
-
|
26
|
-
def busy_handler( db, data=nil, &block )
|
27
|
-
if block
|
28
|
-
cb = API::CallbackData.new
|
29
|
-
cb.proc = block
|
30
|
-
cb.data = data
|
31
|
-
result = API.sqlite3_busy_handler( db, API::Sqlite3_ruby_busy_handler, cb )
|
32
|
-
# Reference the Callback object so that
|
33
|
-
# it is not deleted by the GC
|
34
|
-
@busy_handler[db] = cb
|
35
|
-
else
|
36
|
-
# Unreference the callback *after* having removed it
|
37
|
-
# from sqlite
|
38
|
-
result = API.sqlite3_busy_handler( db, nil, nil )
|
39
|
-
@busy_handler.delete(db)
|
40
|
-
end
|
41
|
-
|
42
|
-
result
|
43
|
-
end
|
44
|
-
|
45
|
-
def set_authorizer( db, data=nil, &block )
|
46
|
-
if block
|
47
|
-
cb = API::CallbackData.new
|
48
|
-
cb.proc = block
|
49
|
-
cb.data = data
|
50
|
-
result = API.sqlite3_set_authorizer( db, API::Sqlite3_ruby_authorizer, cb )
|
51
|
-
@authorizer[db] = cb # see comments in busy_handler
|
52
|
-
else
|
53
|
-
result = API.sqlite3_set_authorizer( db, nil, nil )
|
54
|
-
@authorizer.delete(db) # see comments in busy_handler
|
55
|
-
end
|
56
|
-
|
57
|
-
result
|
58
|
-
end
|
59
|
-
|
60
|
-
def trace( db, data=nil, &block )
|
61
|
-
if block
|
62
|
-
cb = API::CallbackData.new
|
63
|
-
cb.proc = block
|
64
|
-
cb.data = data
|
65
|
-
result = API.sqlite3_trace( db, API::Sqlite3_ruby_trace, cb )
|
66
|
-
@trace[db] = cb # see comments in busy_handler
|
67
|
-
else
|
68
|
-
result = API.sqlite3_trace( db, nil, nil )
|
69
|
-
@trace.delete(db) # see comments in busy_handler
|
70
|
-
end
|
71
|
-
|
72
|
-
result
|
73
|
-
end
|
74
|
-
|
75
|
-
def open( filename, utf16=false )
|
76
|
-
API.send( utf16 ? :sqlite3_open16 : :sqlite3_open, filename )
|
77
|
-
end
|
78
|
-
|
79
|
-
def errmsg( db, utf16=false )
|
80
|
-
API.send( utf16 ? :sqlite3_errmsg16 : :sqlite3_errmsg, db )
|
81
|
-
end
|
82
|
-
|
83
|
-
def prepare( db, sql, utf16=false )
|
84
|
-
API.send( ( utf16 ? :sqlite3_prepare16 : :sqlite3_prepare ),
|
85
|
-
db, sql )
|
86
|
-
end
|
87
|
-
|
88
|
-
def bind_text( stmt, index, value, utf16=false )
|
89
|
-
API.send( ( utf16 ? :sqlite3_bind_text16 : :sqlite3_bind_text ),
|
90
|
-
stmt, index, value.to_s )
|
91
|
-
end
|
92
|
-
|
93
|
-
def column_name( stmt, index, utf16=false )
|
94
|
-
API.send( ( utf16 ? :sqlite3_column_name16 : :sqlite3_column_name ),
|
95
|
-
stmt, index )
|
96
|
-
end
|
97
|
-
|
98
|
-
def column_decltype( stmt, index, utf16=false )
|
99
|
-
API.send(
|
100
|
-
( utf16 ? :sqlite3_column_decltype16 : :sqlite3_column_decltype ),
|
101
|
-
stmt, index )
|
102
|
-
end
|
103
|
-
|
104
|
-
def column_text( stmt, index, utf16=false )
|
105
|
-
API.send( ( utf16 ? :sqlite3_column_text16 : :sqlite3_column_text ),
|
106
|
-
stmt, index )
|
107
|
-
end
|
108
|
-
|
109
|
-
def create_function( db, name, args, text, cookie, func, step, final )
|
110
|
-
if func || ( step && final )
|
111
|
-
cb = API::CallbackData.new
|
112
|
-
cb.proc = cb.proc2 = nil
|
113
|
-
cb.data = cookie
|
114
|
-
end
|
115
|
-
|
116
|
-
if func
|
117
|
-
cb.proc = func
|
118
|
-
|
119
|
-
func = API::Sqlite3_ruby_function_step
|
120
|
-
step = final = nil
|
121
|
-
elsif step && final
|
122
|
-
cb.proc = step
|
123
|
-
cb.proc2 = final
|
124
|
-
|
125
|
-
func = nil
|
126
|
-
step = API::Sqlite3_ruby_function_step
|
127
|
-
final = API::Sqlite3_ruby_function_final
|
128
|
-
end
|
129
|
-
|
130
|
-
result = API.sqlite3_create_function( db, name, args, text, cb, func, step, final )
|
131
|
-
|
132
|
-
# see comments in busy_handler
|
133
|
-
if cb
|
134
|
-
@callback_data[ name ] = cb
|
135
|
-
else
|
136
|
-
@callback_data.delete( name )
|
137
|
-
end
|
138
|
-
|
139
|
-
return result
|
140
|
-
end
|
141
|
-
|
142
|
-
def value_text( value, utf16=false )
|
143
|
-
method = case utf16
|
144
|
-
when nil, false then :sqlite3_value_text
|
145
|
-
when :le then :sqlite3_value_text16le
|
146
|
-
when :be then :sqlite3_value_text16be
|
147
|
-
else :sqlite3_value_text16
|
148
|
-
end
|
149
|
-
|
150
|
-
API.send( method, value )
|
151
|
-
end
|
152
|
-
|
153
|
-
def result_text( context, result, utf16=false )
|
154
|
-
method = case utf16
|
155
|
-
when nil, false then :sqlite3_result_text
|
156
|
-
when :le then :sqlite3_result_text16le
|
157
|
-
when :be then :sqlite3_result_text16be
|
158
|
-
else :sqlite3_result_text16
|
159
|
-
end
|
160
|
-
|
161
|
-
API.send( method, context, result.to_s )
|
162
|
-
end
|
163
|
-
|
164
|
-
def result_error( context, value, utf16=false )
|
165
|
-
API.send( ( utf16 ? :sqlite3_result_error16 : :sqlite3_result_error ),
|
166
|
-
context, value )
|
167
|
-
end
|
168
|
-
|
169
|
-
def self.api_delegate( name )
|
170
|
-
eval "def #{name} (*args) API.sqlite3_#{name}( *args ) ; end"
|
171
|
-
end
|
172
|
-
|
173
|
-
api_delegate :libversion
|
174
|
-
api_delegate :close
|
175
|
-
api_delegate :last_insert_rowid
|
176
|
-
api_delegate :changes
|
177
|
-
api_delegate :total_changes
|
178
|
-
api_delegate :interrupt
|
179
|
-
api_delegate :busy_timeout
|
180
|
-
api_delegate :errcode
|
181
|
-
api_delegate :bind_blob
|
182
|
-
api_delegate :bind_double
|
183
|
-
api_delegate :bind_int
|
184
|
-
api_delegate :bind_int64
|
185
|
-
api_delegate :bind_null
|
186
|
-
api_delegate :bind_parameter_count
|
187
|
-
api_delegate :bind_parameter_name
|
188
|
-
api_delegate :bind_parameter_index
|
189
|
-
api_delegate :column_count
|
190
|
-
api_delegate :step
|
191
|
-
api_delegate :data_count
|
192
|
-
api_delegate :column_blob
|
193
|
-
api_delegate :column_bytes
|
194
|
-
api_delegate :column_bytes16
|
195
|
-
api_delegate :column_double
|
196
|
-
api_delegate :column_int
|
197
|
-
api_delegate :column_int64
|
198
|
-
api_delegate :column_type
|
199
|
-
api_delegate :finalize
|
200
|
-
api_delegate :reset
|
201
|
-
api_delegate :aggregate_count
|
202
|
-
api_delegate :value_blob
|
203
|
-
api_delegate :value_bytes
|
204
|
-
api_delegate :value_bytes16
|
205
|
-
api_delegate :value_double
|
206
|
-
api_delegate :value_int
|
207
|
-
api_delegate :value_int64
|
208
|
-
api_delegate :value_type
|
209
|
-
api_delegate :result_blob
|
210
|
-
api_delegate :result_double
|
211
|
-
api_delegate :result_int
|
212
|
-
api_delegate :result_int64
|
213
|
-
api_delegate :result_null
|
214
|
-
api_delegate :result_value
|
215
|
-
api_delegate :aggregate_context
|
216
|
-
|
217
|
-
end
|
218
|
-
|
219
|
-
end ; end ; end
|
data/tasks/benchmark.rake
DELETED
data/tasks/gem.rake
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'rubygems/package_task'
|
2
|
-
require 'hoe'
|
3
|
-
|
4
|
-
HOE = Hoe.spec 'sqlite3-ruby' do
|
5
|
-
self.rubyforge_name = 'sqlite-ruby'
|
6
|
-
self.author = ['Jamis Buck']
|
7
|
-
self.email = %w[jamis@37signals.com]
|
8
|
-
self.readme_file = 'README.txt'
|
9
|
-
self.need_tar = false
|
10
|
-
self.need_zip = false
|
11
|
-
|
12
|
-
spec_extras[:required_ruby_version] = Gem::Requirement.new('> 1.8.5')
|
13
|
-
|
14
|
-
spec_extras[:extensions] = ["ext/sqlite3_api/extconf.rb"]
|
15
|
-
|
16
|
-
extra_dev_deps << 'mocha'
|
17
|
-
extra_dev_deps << ['rake-compiler', "~> 0.5.0"]
|
18
|
-
|
19
|
-
spec_extras['rdoc_options'] = proc do |rdoc_options|
|
20
|
-
rdoc_options << "--main=README.txt"
|
21
|
-
end
|
22
|
-
|
23
|
-
clean_globs.push('**/test.db')
|
24
|
-
end
|
25
|
-
|
26
|
-
file "#{HOE.spec.name}.gemspec" => ['Rakefile', 'tasks/gem.rake', 'lib/sqlite3/version.rb'] do |t|
|
27
|
-
puts "Generating #{t.name}"
|
28
|
-
File.open(t.name, 'w') { |f| f.puts HOE.spec.to_yaml }
|
29
|
-
end
|
30
|
-
|
31
|
-
desc "Generate or update the standalone gemspec file for the project"
|
32
|
-
task :gemspec => ["#{HOE.spec.name}.gemspec"]
|
data/test/bm.rb
DELETED
@@ -1,140 +0,0 @@
|
|
1
|
-
require 'benchmark'
|
2
|
-
|
3
|
-
N = 1000
|
4
|
-
|
5
|
-
$VERBOSE=nil
|
6
|
-
|
7
|
-
puts "file require"
|
8
|
-
Benchmark.bm( 7 ) do |x|
|
9
|
-
x.report('sqlite') do
|
10
|
-
N.times do
|
11
|
-
$".delete_if { |i| i =~ /sqlite/ }
|
12
|
-
require 'sqlite'
|
13
|
-
end
|
14
|
-
end
|
15
|
-
x.report('sqlite3') do
|
16
|
-
N.times do
|
17
|
-
$".delete_if { |i| i =~ /sqlite3/ }
|
18
|
-
require 'sqlite3'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
puts
|
24
|
-
puts "database creation..."
|
25
|
-
Benchmark.bm( 7 ) do |x|
|
26
|
-
x.report('sqlite') do
|
27
|
-
N.times do
|
28
|
-
File.delete "test.db" rescue nil
|
29
|
-
SQLite::Database.open( "test.db" ).close
|
30
|
-
end
|
31
|
-
end
|
32
|
-
x.report('sqlite3') do
|
33
|
-
N.times do
|
34
|
-
File.delete "test.db" rescue nil
|
35
|
-
SQLite3::Database.open( "test.db" ).close
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
File.delete "test.db" rescue nil
|
40
|
-
|
41
|
-
SQLite::Database.open( "test.db" ).close
|
42
|
-
SQLite3::Database.open( "test3.db" ).close
|
43
|
-
|
44
|
-
puts
|
45
|
-
puts "database open..."
|
46
|
-
Benchmark.bm( 7 ) do |x|
|
47
|
-
x.report('sqlite') do
|
48
|
-
N.times do
|
49
|
-
SQLite::Database.open( "test.db" ).close
|
50
|
-
end
|
51
|
-
end
|
52
|
-
x.report('sqlite3') do
|
53
|
-
N.times do
|
54
|
-
SQLite3::Database.open( "test3.db" ).close
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
File.delete "test.db" rescue nil
|
59
|
-
File.delete "test3.db" rescue nil
|
60
|
-
|
61
|
-
db = SQLite::Database.open( "test.db" )
|
62
|
-
db3 = SQLite3::Database.open( "test3.db" )
|
63
|
-
|
64
|
-
db.execute "create table foo (a,b)"
|
65
|
-
db3.execute "create table foo (a,b)"
|
66
|
-
|
67
|
-
puts
|
68
|
-
puts "insertions"
|
69
|
-
Benchmark.bm( 7 ) do |x|
|
70
|
-
x.report('sqlite') do
|
71
|
-
db.transaction do
|
72
|
-
N.times do |i|
|
73
|
-
db.execute "insert into foo values (#{i}, #{i+1})"
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
x.report('sqlite3') do
|
78
|
-
db3.transaction do
|
79
|
-
N.times do |i|
|
80
|
-
db3.execute "insert into foo values (#{i}, #{i+1})"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
puts
|
87
|
-
puts "insertions using prepared statement"
|
88
|
-
Benchmark.bm( 7 ) do |x|
|
89
|
-
x.report('sqlite') do
|
90
|
-
db.transaction do
|
91
|
-
stmt = db.prepare "insert into foo values (?,?)"
|
92
|
-
N.times { |i| stmt.execute i, i+1 }
|
93
|
-
end
|
94
|
-
end
|
95
|
-
x.report('sqlite3') do
|
96
|
-
db3.transaction do
|
97
|
-
db3.prepare( "insert into foo values (?,?)" ) do |stmt|
|
98
|
-
N.times { |i| stmt.execute i, i+1 }
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
db.close
|
105
|
-
db3.close
|
106
|
-
File.delete "test.db" rescue nil
|
107
|
-
File.delete "test3.db" rescue nil
|
108
|
-
|
109
|
-
db = SQLite::Database.open( "test.db" )
|
110
|
-
db3 = SQLite3::Database.open( "test3.db" )
|
111
|
-
|
112
|
-
db.execute "create table foo (a,b)"
|
113
|
-
db.execute "insert into foo values (1,2)"
|
114
|
-
db.execute "insert into foo values (3,4)"
|
115
|
-
db.execute "insert into foo values (5,6)"
|
116
|
-
|
117
|
-
db3.execute "create table foo (a,b)"
|
118
|
-
db3.execute "insert into foo values (1,2)"
|
119
|
-
db3.execute "insert into foo values (3,4)"
|
120
|
-
db3.execute "insert into foo values (5,6)"
|
121
|
-
|
122
|
-
puts
|
123
|
-
puts "queries"
|
124
|
-
Benchmark.bm( 7 ) do |x|
|
125
|
-
x.report('sqlite') do
|
126
|
-
N.times do
|
127
|
-
db.execute "select * from foo"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
x.report('sqlite3') do
|
131
|
-
N.times do
|
132
|
-
db3.execute "select * from foo"
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
db.close
|
138
|
-
db3.close
|
139
|
-
File.delete "test.db" rescue nil
|
140
|
-
File.delete "test3.db" rescue nil
|
data/test/driver/dl/tc_driver.rb
DELETED
@@ -1,292 +0,0 @@
|
|
1
|
-
if (ENV["SQLITE3_DRIVERS"] || "Native").split(/,/).include?("DL")
|
2
|
-
$:.unshift "../../../lib"
|
3
|
-
|
4
|
-
require 'sqlite3/constants'
|
5
|
-
require 'sqlite3/driver/dl/driver'
|
6
|
-
require 'test/unit'
|
7
|
-
|
8
|
-
class TC_DL_Driver < Test::Unit::TestCase
|
9
|
-
|
10
|
-
def utf16ify( str )
|
11
|
-
chars = str.split(//)
|
12
|
-
chars.zip(["\0"] * chars.length).flatten.join
|
13
|
-
end
|
14
|
-
|
15
|
-
def setup
|
16
|
-
@driver = SQLite3::Driver::DL::Driver.new
|
17
|
-
@dbname = "test.db"
|
18
|
-
@db = nil
|
19
|
-
end
|
20
|
-
|
21
|
-
def teardown
|
22
|
-
@driver.close( @db ) rescue nil
|
23
|
-
File.delete @dbname rescue nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_open
|
27
|
-
result, @db = @driver.open( @dbname )
|
28
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
29
|
-
assert File.exist?( @dbname )
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_open_utf16
|
33
|
-
name = utf16ify( @dbname )
|
34
|
-
result, @db = @driver.open( name, true )
|
35
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
36
|
-
assert File.exist?( @dbname )
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_errmsg
|
40
|
-
result, @db = @driver.open( @dbname )
|
41
|
-
msg = @driver.errmsg( @db )
|
42
|
-
assert_equal msg, "not an error"
|
43
|
-
end
|
44
|
-
|
45
|
-
def test_errmsg16
|
46
|
-
result, @db = @driver.open( @dbname )
|
47
|
-
msg = @driver.errmsg( @db, true )
|
48
|
-
assert_equal msg, utf16ify( "not an error" )
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_prepare
|
52
|
-
result, @db = @driver.open( @dbname )
|
53
|
-
sql = "create table foo ( a, b )"
|
54
|
-
result, handle, remainder = @driver.prepare( @db, sql )
|
55
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
56
|
-
assert_equal "", remainder
|
57
|
-
@driver.finalize( handle )
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_prepare_error
|
61
|
-
result, @db = @driver.open( @dbname )
|
62
|
-
sql = "create tble foo ( a, b )"
|
63
|
-
result, handle, remainder = @driver.prepare( @db, sql )
|
64
|
-
assert_equal SQLite3::Constants::ErrorCode::ERROR, result
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_prepare_remainder
|
68
|
-
result, @db = @driver.open( @dbname )
|
69
|
-
sql = "create table foo ( a, b ); select * from foo"
|
70
|
-
result, handle, remainder = @driver.prepare( @db, sql )
|
71
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
72
|
-
assert_equal " select * from foo", remainder
|
73
|
-
@driver.finalize( handle )
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_prepare16
|
77
|
-
result, @db = @driver.open( @dbname )
|
78
|
-
sql = utf16ify( "create table foo ( a, b )" )
|
79
|
-
result, handle, remainder = @driver.prepare( @db, sql, true )
|
80
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
81
|
-
assert_equal "", remainder
|
82
|
-
@driver.finalize( handle )
|
83
|
-
end
|
84
|
-
|
85
|
-
def test_prepare16_remainder
|
86
|
-
result, @db = @driver.open( @dbname )
|
87
|
-
sql = utf16ify( "create table foo ( a, b ); select * from foo" )
|
88
|
-
result, handle, remainder = @driver.prepare( @db, sql, true )
|
89
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
90
|
-
assert_equal utf16ify( " select * from foo" ), remainder
|
91
|
-
@driver.finalize( handle )
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_complete
|
95
|
-
assert @driver.complete?( "select * from foo;" )
|
96
|
-
end
|
97
|
-
|
98
|
-
def test_complete_fail
|
99
|
-
assert !@driver.complete?( "select * from foo" )
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_complete16
|
103
|
-
assert @driver.complete?( utf16ify("select * from foo;"), true )
|
104
|
-
end
|
105
|
-
|
106
|
-
def create_foo
|
107
|
-
result, @db = @driver.open( @dbname )
|
108
|
-
sql = "create table foo ( a, b )"
|
109
|
-
result, handle, = @driver.prepare( @db, sql )
|
110
|
-
@driver.step( handle )
|
111
|
-
@driver.finalize( handle )
|
112
|
-
end
|
113
|
-
|
114
|
-
def populate_foo
|
115
|
-
create_foo
|
116
|
-
sql = "insert into foo values ( 100, 200 )"
|
117
|
-
result, handle, = @driver.prepare( @db, sql )
|
118
|
-
@driver.step( handle )
|
119
|
-
@driver.finalize( handle )
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_step
|
123
|
-
populate_foo
|
124
|
-
sql = "select * from foo"
|
125
|
-
result, handle, = @driver.prepare( @db, sql )
|
126
|
-
result = @driver.step( handle )
|
127
|
-
assert_equal SQLite3::Constants::ErrorCode::ROW, result
|
128
|
-
result = @driver.step( handle )
|
129
|
-
assert_equal SQLite3::Constants::ErrorCode::DONE, result
|
130
|
-
@driver.finalize( handle )
|
131
|
-
end
|
132
|
-
|
133
|
-
def test_step_fail
|
134
|
-
populate_foo
|
135
|
-
sql = "select * from"
|
136
|
-
result, handle, = @driver.prepare( @db, sql )
|
137
|
-
result = @driver.step( handle )
|
138
|
-
assert_equal SQLite3::Constants::ErrorCode::MISUSE, result
|
139
|
-
@driver.finalize( handle )
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_bind_blob
|
143
|
-
create_foo
|
144
|
-
sql = "insert into foo (b) values (?)"
|
145
|
-
result, handle, = @driver.prepare( @db, sql )
|
146
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
147
|
-
result = @driver.bind_blob( handle, 1, "a\0b\1c\2d\0e" )
|
148
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
149
|
-
result = @driver.step( handle )
|
150
|
-
assert_equal SQLite3::Constants::ErrorCode::DONE, result
|
151
|
-
result = @driver.finalize( handle )
|
152
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
153
|
-
sql = "select b from foo"
|
154
|
-
result, handle, = @driver.prepare( @db, sql )
|
155
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
156
|
-
result = @driver.step( handle )
|
157
|
-
assert_equal SQLite3::Constants::ErrorCode::ROW, result
|
158
|
-
assert_equal "a\0b\1c\2d\0e", @driver.column_blob( handle, 0 )
|
159
|
-
result = @driver.finalize( handle )
|
160
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_bind_double
|
164
|
-
create_foo
|
165
|
-
sql = "insert into foo (b) values (?)"
|
166
|
-
result, handle, = @driver.prepare( @db, sql )
|
167
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
168
|
-
result = @driver.bind_double( handle, 1, 3.14 )
|
169
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
170
|
-
result = @driver.step( handle )
|
171
|
-
assert_equal SQLite3::Constants::ErrorCode::DONE, result
|
172
|
-
result = @driver.finalize( handle )
|
173
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
174
|
-
sql = "select b from foo"
|
175
|
-
result, handle, = @driver.prepare( @db, sql )
|
176
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
177
|
-
result = @driver.step( handle )
|
178
|
-
assert_equal SQLite3::Constants::ErrorCode::ROW, result
|
179
|
-
assert_equal 3.14, @driver.column_double( handle, 0 )
|
180
|
-
result = @driver.finalize( handle )
|
181
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
182
|
-
end
|
183
|
-
|
184
|
-
def test_bind_int
|
185
|
-
create_foo
|
186
|
-
sql = "insert into foo (b) values (?)"
|
187
|
-
result, handle, = @driver.prepare( @db, sql )
|
188
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
189
|
-
result = @driver.bind_int( handle, 1, 14 )
|
190
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
191
|
-
result = @driver.step( handle )
|
192
|
-
assert_equal SQLite3::Constants::ErrorCode::DONE, result
|
193
|
-
result = @driver.finalize( handle )
|
194
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
195
|
-
sql = "select b from foo"
|
196
|
-
result, handle, = @driver.prepare( @db, sql )
|
197
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
198
|
-
result = @driver.step( handle )
|
199
|
-
assert_equal SQLite3::Constants::ErrorCode::ROW, result
|
200
|
-
assert_equal 14, @driver.column_int( handle, 0 )
|
201
|
-
result = @driver.finalize( handle )
|
202
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_bind_null
|
206
|
-
create_foo
|
207
|
-
sql = "insert into foo (b) values (?)"
|
208
|
-
result, handle, = @driver.prepare( @db, sql )
|
209
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
210
|
-
result = @driver.bind_null( handle, 1 )
|
211
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
212
|
-
result = @driver.step( handle )
|
213
|
-
assert_equal SQLite3::Constants::ErrorCode::DONE, result
|
214
|
-
result = @driver.finalize( handle )
|
215
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
216
|
-
sql = "select b from foo"
|
217
|
-
result, handle, = @driver.prepare( @db, sql )
|
218
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
219
|
-
result = @driver.step( handle )
|
220
|
-
assert_equal SQLite3::Constants::ErrorCode::ROW, result
|
221
|
-
assert_equal SQLite3::Constants::ColumnType::NULL,
|
222
|
-
@driver.column_type( handle, 0 )
|
223
|
-
result = @driver.finalize( handle )
|
224
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
225
|
-
end
|
226
|
-
|
227
|
-
def test_bind_text
|
228
|
-
create_foo
|
229
|
-
sql = "insert into foo (b) values (?)"
|
230
|
-
result, handle, = @driver.prepare( @db, sql )
|
231
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
232
|
-
result = @driver.bind_text( handle, 1, "hello, world" )
|
233
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
234
|
-
result = @driver.step( handle )
|
235
|
-
assert_equal SQLite3::Constants::ErrorCode::DONE, result
|
236
|
-
result = @driver.finalize( handle )
|
237
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
238
|
-
sql = "select b from foo"
|
239
|
-
result, handle, = @driver.prepare( @db, sql )
|
240
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
241
|
-
result = @driver.step( handle )
|
242
|
-
assert_equal SQLite3::Constants::ErrorCode::ROW, result
|
243
|
-
assert_equal "hello, world", @driver.column_text( handle, 0 )
|
244
|
-
result = @driver.finalize( handle )
|
245
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
246
|
-
end
|
247
|
-
|
248
|
-
def test_bind_text16
|
249
|
-
create_foo
|
250
|
-
sql = "insert into foo (b) values (?)"
|
251
|
-
result, handle, = @driver.prepare( @db, sql )
|
252
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
253
|
-
result = @driver.bind_text( handle, 1, utf16ify("hello, world"), true )
|
254
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
255
|
-
result = @driver.step( handle )
|
256
|
-
assert_equal SQLite3::Constants::ErrorCode::DONE, result
|
257
|
-
result = @driver.finalize( handle )
|
258
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
259
|
-
sql = "select b from foo"
|
260
|
-
result, handle, = @driver.prepare( @db, sql )
|
261
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
262
|
-
result = @driver.step( handle )
|
263
|
-
assert_equal SQLite3::Constants::ErrorCode::ROW, result
|
264
|
-
assert_equal "hello, world", @driver.column_text( handle, 0 )
|
265
|
-
result = @driver.finalize( handle )
|
266
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_bind_parameter_index
|
270
|
-
create_foo
|
271
|
-
sql = "insert into foo (b) values (:hello)"
|
272
|
-
result, handle, = @driver.prepare( @db, sql )
|
273
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
274
|
-
result = @driver.bind_parameter_index( handle, ":hello" )
|
275
|
-
assert_equal 1, result
|
276
|
-
result = @driver.bind_parameter_index( handle, ":foo" )
|
277
|
-
assert_equal 0, result
|
278
|
-
@driver.finalize( handle )
|
279
|
-
end
|
280
|
-
|
281
|
-
def test_bind_parameter_name
|
282
|
-
create_foo
|
283
|
-
sql = "insert into foo (a,b) values (?,:foo)"
|
284
|
-
result, handle, = @driver.prepare( @db, sql )
|
285
|
-
assert_equal SQLite3::Constants::ErrorCode::OK, result
|
286
|
-
assert_nil nil, @driver.bind_parameter_name(handle,1)
|
287
|
-
assert_equal ":foo", @driver.bind_parameter_name(handle,2)
|
288
|
-
@driver.finalize( handle )
|
289
|
-
end
|
290
|
-
|
291
|
-
end
|
292
|
-
end
|