sqlite3-ruby 1.2.5-x86-mswin32
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.txt +56 -0
- data/Rakefile +5 -0
- data/ext/sqlite3_api/extconf.rb +10 -0
- data/ext/sqlite3_api/sqlite3_api.i +362 -0
- data/ext/sqlite3_api/sqlite3_api_wrap.c +5018 -0
- data/faq/faq.rb +145 -0
- data/faq/faq.yml +426 -0
- data/lib/1.8/sqlite3_api.so +0 -0
- data/lib/1.9/sqlite3_api.so +0 -0
- data/lib/sqlite3.rb +1 -0
- data/lib/sqlite3/constants.rb +49 -0
- data/lib/sqlite3/database.rb +721 -0
- data/lib/sqlite3/driver/dl/api.rb +152 -0
- data/lib/sqlite3/driver/dl/driver.rb +307 -0
- data/lib/sqlite3/driver/native/driver.rb +219 -0
- data/lib/sqlite3/errors.rb +68 -0
- data/lib/sqlite3/pragmas.rb +271 -0
- data/lib/sqlite3/resultset.rb +180 -0
- data/lib/sqlite3/statement.rb +231 -0
- data/lib/sqlite3/translator.rb +109 -0
- data/lib/sqlite3/value.rb +57 -0
- data/lib/sqlite3/version.rb +16 -0
- 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/bm.rb +140 -0
- data/test/driver/dl/tc_driver.rb +292 -0
- data/test/helper.rb +67 -0
- data/test/native-vs-dl.rb +126 -0
- data/test/test_database.rb +217 -0
- data/test/test_errors.rb +17 -0
- 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 +143 -0
data/tasks/faq.rake
ADDED
data/tasks/gem.rake
ADDED
@@ -0,0 +1,32 @@
|
|
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/tasks/native.rake
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# use rake-compiler for building the extension
|
2
|
+
require 'rake/extensiontask'
|
3
|
+
|
4
|
+
# build sqlite3_api C extension
|
5
|
+
Rake::ExtensionTask.new('sqlite3_api', HOE.spec) do |ext|
|
6
|
+
# reference to the sqlite3 library
|
7
|
+
sqlite3_lib = File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'sqlite3'))
|
8
|
+
|
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
|
+
# automatically add build options to avoid need of manual input
|
16
|
+
if RUBY_PLATFORM =~ /mswin|mingw/ then
|
17
|
+
ext.config_options << "--with-sqlite3-dir=#{sqlite3_lib}"
|
18
|
+
else
|
19
|
+
ext.cross_compile = true
|
20
|
+
ext.cross_platform = ['i386-mswin32', 'i386-mingw32']
|
21
|
+
ext.cross_config_options << "--with-sqlite3-dir=#{sqlite3_lib}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
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
|
+
# ensure things are compiled prior testing
|
35
|
+
task :test => [:compile]
|
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'rake/clean'
|
2
|
+
require 'rake/extensioncompiler'
|
3
|
+
|
4
|
+
# download sqlite3 library and headers
|
5
|
+
|
6
|
+
# only on Windows or cross platform compilation
|
7
|
+
def dlltool(dllname, deffile, libfile)
|
8
|
+
# define if we are using GCC or not
|
9
|
+
if Rake::ExtensionCompiler.mingw_gcc_executable then
|
10
|
+
dir = File.dirname(Rake::ExtensionCompiler.mingw_gcc_executable)
|
11
|
+
tool = case RUBY_PLATFORM
|
12
|
+
when /mingw/
|
13
|
+
File.join(dir, 'dlltool.exe')
|
14
|
+
when /linux|darwin/
|
15
|
+
File.join(dir, "#{Rake::ExtensionCompiler.mingw_host}-dlltool")
|
16
|
+
end
|
17
|
+
return "#{tool} --dllname #{dllname} --def #{deffile} --output-lib #{libfile}"
|
18
|
+
else
|
19
|
+
if RUBY_PLATFORM =~ /mswin/ then
|
20
|
+
tool = 'lib.exe'
|
21
|
+
else
|
22
|
+
fail "Unsupported platform for cross-compilation (please, contribute some patches)."
|
23
|
+
end
|
24
|
+
return "#{tool} /DEF:#{deffile} /OUT:#{libfile}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
version = '3_6_16'
|
29
|
+
|
30
|
+
# required folder structure for --with-sqlite3-dir (include + lib)
|
31
|
+
directory "vendor/sqlite3/lib"
|
32
|
+
directory "vendor/sqlite3/include"
|
33
|
+
|
34
|
+
# download amalgamation version (for include files)
|
35
|
+
file "vendor/sqlite-amalgamation-#{version}.zip" => ['vendor'] do |t|
|
36
|
+
url = "http://www.sqlite.org/#{File.basename(t.name)}"
|
37
|
+
when_writing "downloading #{t.name}" do
|
38
|
+
cd File.dirname(t.name) do
|
39
|
+
system "wget -c #{url} || curl -C - -O #{url}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# download dll binaries
|
45
|
+
file "vendor/sqlitedll-#{version}.zip" => ['vendor'] do |t|
|
46
|
+
url = "http://www.sqlite.org/#{File.basename(t.name)}"
|
47
|
+
when_writing "downloading #{t.name}" do
|
48
|
+
cd File.dirname(t.name) do
|
49
|
+
system "wget -c #{url} || curl -C - -O #{url}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# extract header files into include folder
|
55
|
+
file "vendor/sqlite3/include/sqlite3.h" => ['vendor/sqlite3/include', "vendor/sqlite-amalgamation-#{version}.zip"] do |t|
|
56
|
+
full_file = File.expand_path(t.prerequisites.last)
|
57
|
+
when_writing "creating #{t.name}" do
|
58
|
+
cd File.dirname(t.name) do
|
59
|
+
sh "unzip #{full_file}"
|
60
|
+
# update file timestamp to avoid Rake perform this extraction again.
|
61
|
+
touch File.basename(t.name)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# extract dll files into lib folder
|
67
|
+
file "vendor/sqlite3/lib/sqlite3.dll" => ['vendor/sqlite3/lib', "vendor/sqlitedll-#{version}.zip"] do |t|
|
68
|
+
full_file = File.expand_path(t.prerequisites.last)
|
69
|
+
when_writing "creating #{t.name}" do
|
70
|
+
cd File.dirname(t.name) do
|
71
|
+
sh "unzip #{full_file}"
|
72
|
+
# update file timestamp to avoid Rake perform this extraction again.
|
73
|
+
touch File.basename(t.name)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# generate import library from definition and dll file
|
79
|
+
file "vendor/sqlite3/lib/sqlite3.lib" => ["vendor/sqlite3/lib/sqlite3.dll"] do |t|
|
80
|
+
libfile = t.name
|
81
|
+
dllname = libfile.ext('dll')
|
82
|
+
deffile = libfile.ext('def')
|
83
|
+
|
84
|
+
when_writing "creating #{t.name}" do
|
85
|
+
sh dlltool(dllname, deffile, libfile)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# clean and clobber actions
|
90
|
+
# All the uncompressed files must be removed at clean
|
91
|
+
CLEAN.include('vendor/sqlite3')
|
92
|
+
|
93
|
+
# clobber vendored packages
|
94
|
+
CLOBBER.include('vendor')
|
95
|
+
|
96
|
+
# vendor:sqlite3
|
97
|
+
task 'vendor:sqlite3' => ["vendor/sqlite3/lib/sqlite3.lib", "vendor/sqlite3/include/sqlite3.h"]
|
98
|
+
|
99
|
+
# hook into cross compilation vendored sqlite3 dependency
|
100
|
+
if RUBY_PLATFORM =~ /mingw|mswin/ then
|
101
|
+
Rake::Task['compile'].prerequisites.unshift 'vendor:sqlite3'
|
102
|
+
else
|
103
|
+
Rake::Task['cross'].prerequisites.unshift 'vendor:sqlite3'
|
104
|
+
end
|
data/test/bm.rb
ADDED
@@ -0,0 +1,140 @@
|
|
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
|
@@ -0,0 +1,292 @@
|
|
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
|