sqlite3 1.3.3-x86-mingw32

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/API_CHANGES.rdoc +50 -0
  2. data/CHANGELOG.rdoc +177 -0
  3. data/ChangeLog.cvs +88 -0
  4. data/LICENSE +27 -0
  5. data/Manifest.txt +50 -0
  6. data/README.rdoc +103 -0
  7. data/Rakefile +10 -0
  8. data/ext/sqlite3/backup.c +164 -0
  9. data/ext/sqlite3/backup.h +15 -0
  10. data/ext/sqlite3/database.c +762 -0
  11. data/ext/sqlite3/database.h +15 -0
  12. data/ext/sqlite3/exception.c +94 -0
  13. data/ext/sqlite3/exception.h +8 -0
  14. data/ext/sqlite3/extconf.rb +47 -0
  15. data/ext/sqlite3/sqlite3.c +36 -0
  16. data/ext/sqlite3/sqlite3_ruby.h +44 -0
  17. data/ext/sqlite3/statement.c +419 -0
  18. data/ext/sqlite3/statement.h +16 -0
  19. data/faq/faq.rb +145 -0
  20. data/faq/faq.yml +426 -0
  21. data/lib/sqlite3.rb +10 -0
  22. data/lib/sqlite3/1.8/sqlite3_native.so +0 -0
  23. data/lib/sqlite3/1.9/sqlite3_native.so +0 -0
  24. data/lib/sqlite3/constants.rb +49 -0
  25. data/lib/sqlite3/database.rb +587 -0
  26. data/lib/sqlite3/errors.rb +44 -0
  27. data/lib/sqlite3/pragmas.rb +280 -0
  28. data/lib/sqlite3/resultset.rb +126 -0
  29. data/lib/sqlite3/statement.rb +148 -0
  30. data/lib/sqlite3/translator.rb +118 -0
  31. data/lib/sqlite3/value.rb +57 -0
  32. data/lib/sqlite3/version.rb +25 -0
  33. data/setup.rb +1333 -0
  34. data/tasks/faq.rake +9 -0
  35. data/tasks/gem.rake +31 -0
  36. data/tasks/native.rake +61 -0
  37. data/tasks/vendor_sqlite3.rake +104 -0
  38. data/test/helper.rb +3 -0
  39. data/test/test_backup.rb +33 -0
  40. data/test/test_collation.rb +82 -0
  41. data/test/test_database.rb +312 -0
  42. data/test/test_database_readonly.rb +29 -0
  43. data/test/test_deprecated.rb +37 -0
  44. data/test/test_encoding.rb +119 -0
  45. data/test/test_integration.rb +544 -0
  46. data/test/test_integration_open_close.rb +30 -0
  47. data/test/test_integration_pending.rb +115 -0
  48. data/test/test_integration_resultset.rb +156 -0
  49. data/test/test_integration_statement.rb +194 -0
  50. data/test/test_sqlite3.rb +9 -0
  51. data/test/test_statement.rb +207 -0
  52. data/test/test_statement_execute.rb +35 -0
  53. metadata +202 -0
@@ -0,0 +1,30 @@
1
+ require 'helper'
2
+
3
+ class TC_OpenClose < Test::Unit::TestCase
4
+ def test_create_close
5
+ begin
6
+ db = SQLite3::Database.new( "test-create.db" )
7
+ assert File.exist?( "test-create.db" )
8
+ assert_nothing_raised { db.close }
9
+ ensure
10
+ File.delete( "test-create.db" ) rescue nil
11
+ end
12
+ end
13
+
14
+ def test_open_close
15
+ begin
16
+ File.open( "test-open.db", "w" ) { |f| }
17
+ assert File.exist?( "test-open.db" )
18
+ db = SQLite3::Database.new( "test-open.db" )
19
+ assert_nothing_raised { db.close }
20
+ ensure
21
+ File.delete( "test-open.db" ) rescue nil
22
+ end
23
+ end
24
+
25
+ def test_bad_open
26
+ assert_raise( SQLite3::CantOpenException ) do
27
+ SQLite3::Database.new( "." )
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,115 @@
1
+ require 'helper'
2
+
3
+ require 'thread'
4
+ require 'benchmark'
5
+
6
+ class TC_Integration_Pending < Test::Unit::TestCase
7
+ def setup
8
+ @db = SQLite3::Database.new("test.db")
9
+ @db.transaction do
10
+ @db.execute "create table foo ( a integer primary key, b text )"
11
+ @db.execute "insert into foo ( b ) values ( 'foo' )"
12
+ @db.execute "insert into foo ( b ) values ( 'bar' )"
13
+ @db.execute "insert into foo ( b ) values ( 'baz' )"
14
+ end
15
+ end
16
+
17
+ def teardown
18
+ @db.close
19
+ File.delete( "test.db" )
20
+ end
21
+
22
+ def test_busy_handler_outwait
23
+ skip("not working in 1.9") if RUBY_VERSION >= '1.9'
24
+
25
+ busy = Mutex.new
26
+ busy.lock
27
+ handler_call_count = 0
28
+
29
+ t = Thread.new(busy) do |locker|
30
+ begin
31
+ db2 = SQLite3::Database.open( "test.db" )
32
+ db2.transaction( :exclusive ) do
33
+ locker.lock
34
+ end
35
+ ensure
36
+ db2.close if db2
37
+ end
38
+ end
39
+
40
+ @db.busy_handler do |data,count|
41
+ handler_call_count += 1
42
+ busy.unlock
43
+ true
44
+ end
45
+
46
+ assert_nothing_raised do
47
+ @db.execute "insert into foo (b) values ( 'from 2' )"
48
+ end
49
+
50
+ t.join
51
+
52
+ assert_equal 1, handler_call_count
53
+ end
54
+
55
+ def test_busy_handler_impatient
56
+ busy = Mutex.new
57
+ busy.lock
58
+ handler_call_count = 0
59
+
60
+ t = Thread.new do
61
+ begin
62
+ db2 = SQLite3::Database.open( "test.db" )
63
+ db2.transaction( :exclusive ) do
64
+ busy.lock
65
+ end
66
+ ensure
67
+ db2.close if db2
68
+ end
69
+ end
70
+ sleep 1
71
+
72
+ @db.busy_handler do |count|
73
+ handler_call_count += 1
74
+ false
75
+ end
76
+
77
+ assert_raise( SQLite3::BusyException ) do
78
+ @db.execute "insert into foo (b) values ( 'from 2' )"
79
+ end
80
+
81
+ busy.unlock
82
+ t.join
83
+
84
+ assert_equal 1, handler_call_count
85
+ end
86
+
87
+ def test_busy_timeout
88
+ @db.busy_timeout 1000
89
+ busy = Mutex.new
90
+ busy.lock
91
+
92
+ t = Thread.new do
93
+ begin
94
+ db2 = SQLite3::Database.open( "test.db" )
95
+ db2.transaction( :exclusive ) do
96
+ busy.lock
97
+ end
98
+ ensure
99
+ db2.close if db2
100
+ end
101
+ end
102
+
103
+ sleep 1
104
+ time = Benchmark.measure do
105
+ assert_raise( SQLite3::BusyException ) do
106
+ @db.execute "insert into foo (b) values ( 'from 2' )"
107
+ end
108
+ end
109
+
110
+ busy.unlock
111
+ t.join
112
+
113
+ assert time.real*1000 >= 1000
114
+ end
115
+ end
@@ -0,0 +1,156 @@
1
+ require 'helper'
2
+
3
+ class TC_ResultSet < Test::Unit::TestCase
4
+ def setup
5
+ @db = SQLite3::Database.new(":memory:")
6
+ @db.transaction do
7
+ @db.execute "create table foo ( a integer primary key, b text )"
8
+ @db.execute "insert into foo ( b ) values ( 'foo' )"
9
+ @db.execute "insert into foo ( b ) values ( 'bar' )"
10
+ @db.execute "insert into foo ( b ) values ( 'baz' )"
11
+ end
12
+ @stmt = @db.prepare( "select * from foo where a in ( ?, ? )" )
13
+ @result = @stmt.execute
14
+ end
15
+
16
+ def teardown
17
+ @stmt.close
18
+ @db.close
19
+ end
20
+
21
+ def test_reset_unused
22
+ assert_nothing_raised { @result.reset }
23
+ assert @result.to_a.empty?
24
+ end
25
+
26
+ def test_reset_used
27
+ @result.to_a
28
+ assert_nothing_raised { @result.reset }
29
+ assert @result.to_a.empty?
30
+ end
31
+
32
+ def test_reset_with_bind
33
+ @result.to_a
34
+ assert_nothing_raised { @result.reset( 1, 2 ) }
35
+ assert_equal 2, @result.to_a.length
36
+ end
37
+
38
+ def test_eof_inner
39
+ @result.reset( 1 )
40
+ assert !@result.eof?
41
+ end
42
+
43
+ def test_eof_edge
44
+ @result.reset( 1 )
45
+ @result.next # to first row
46
+ @result.next # to end of result set
47
+ assert @result.eof?
48
+ end
49
+
50
+ def test_next_eof
51
+ @result.reset( 1 )
52
+ assert_not_nil @result.next
53
+ assert_nil @result.next
54
+ end
55
+
56
+ def test_next_no_type_translation_no_hash
57
+ @result.reset( 1 )
58
+ assert_equal [ 1, "foo" ], @result.next
59
+ end
60
+
61
+ def test_next_type_translation
62
+ @result.reset( 1 )
63
+ assert_equal [ 1, "foo" ], @result.next
64
+ end
65
+
66
+ def test_next_type_translation_with_untyped_column
67
+ @db.query( "select count(*) from foo" ) do |result|
68
+ assert_equal [3], result.next
69
+ end
70
+ end
71
+
72
+ def test_type_translation_with_null_column
73
+ time = '1974-07-25 14:39:00'
74
+
75
+ @db.execute "create table bar ( a integer, b time, c string )"
76
+ @db.execute "insert into bar (a, b, c) values (NULL, '#{time}', 'hello')"
77
+ @db.execute "insert into bar (a, b, c) values (1, NULL, 'hello')"
78
+ @db.execute "insert into bar (a, b, c) values (2, '#{time}', NULL)"
79
+ @db.query( "select * from bar" ) do |result|
80
+ assert_equal [nil, time, 'hello'], result.next
81
+ assert_equal [1, nil, 'hello'], result.next
82
+ assert_equal [2, time, nil], result.next
83
+ end
84
+ end
85
+
86
+ def test_real_translation
87
+ @db.execute('create table foo_real(a real)')
88
+ @db.execute('insert into foo_real values (42)' )
89
+ @db.query('select a, sum(a), typeof(a), typeof(sum(a)) from foo_real') do |result|
90
+ result = result.next
91
+ assert result[0].is_a?(Float)
92
+ assert result[1].is_a?(Float)
93
+ assert result[2].is_a?(String)
94
+ assert result[3].is_a?(String)
95
+ end
96
+ end
97
+
98
+ def test_next_results_as_hash
99
+ @db.results_as_hash = true
100
+ @result.reset( 1 )
101
+ assert_equal( { "a" => 1, "b" => "foo", 0 => 1, 1 => "foo" },
102
+ @result.next )
103
+ end
104
+
105
+ def test_tainted_results_as_hash
106
+ @db.results_as_hash = true
107
+ @result.reset( 1 )
108
+ row = @result.next
109
+ row.each do |_, v|
110
+ assert(v.tainted?) if String === v
111
+ end
112
+ end
113
+
114
+ def test_tainted_row_values
115
+ @result.reset( 1 )
116
+ row = @result.next
117
+ row.each do |v|
118
+ assert(v.tainted?) if String === v
119
+ end
120
+ end
121
+
122
+ def test_each
123
+ called = 0
124
+ @result.reset( 1, 2 )
125
+ @result.each { |row| called += 1 }
126
+ assert_equal 2, called
127
+ end
128
+
129
+ def test_enumerable
130
+ @result.reset( 1, 2 )
131
+ assert_equal 2, @result.to_a.length
132
+ end
133
+
134
+ def test_types
135
+ assert_equal [ "integer", "text" ], @result.types
136
+ end
137
+
138
+ def test_columns
139
+ assert_equal [ "a", "b" ], @result.columns
140
+ end
141
+
142
+ def test_close
143
+ stmt = @db.prepare( "select * from foo" )
144
+ result = stmt.execute
145
+ assert !result.closed?
146
+ result.close
147
+ assert result.closed?
148
+ assert stmt.closed?
149
+ assert_raise( SQLite3::Exception ) { result.reset }
150
+ assert_raise( SQLite3::Exception ) { result.next }
151
+ assert_raise( SQLite3::Exception ) { result.each }
152
+ assert_raise( SQLite3::Exception ) { result.close }
153
+ assert_raise( SQLite3::Exception ) { result.types }
154
+ assert_raise( SQLite3::Exception ) { result.columns }
155
+ end
156
+ end
@@ -0,0 +1,194 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class TC_Statement < Test::Unit::TestCase
4
+ def setup
5
+ @db = SQLite3::Database.new(":memory:")
6
+ @db.transaction do
7
+ @db.execute "create table foo ( a integer primary key, b text )"
8
+ @db.execute "insert into foo ( b ) values ( 'foo' )"
9
+ @db.execute "insert into foo ( b ) values ( 'bar' )"
10
+ @db.execute "insert into foo ( b ) values ( 'baz' )"
11
+ end
12
+ @stmt = @db.prepare( "select * from foo where a in ( ?, :named )" )
13
+ end
14
+
15
+ def teardown
16
+ @stmt.close
17
+ @db.close
18
+ end
19
+
20
+ def test_remainder_empty
21
+ assert_equal "", @stmt.remainder
22
+ end
23
+
24
+ def test_remainder_nonempty
25
+ called = false
26
+ @db.prepare( "select * from foo;\n blah" ) do |stmt|
27
+ called = true
28
+ assert_equal "\n blah", stmt.remainder
29
+ end
30
+ assert called
31
+ end
32
+
33
+ def test_bind_params_empty
34
+ assert_nothing_raised { @stmt.bind_params }
35
+ assert @stmt.execute!.empty?
36
+ end
37
+
38
+ def test_bind_params_array
39
+ @stmt.bind_params 1, 2
40
+ assert_equal 2, @stmt.execute!.length
41
+ end
42
+
43
+ def test_bind_params_hash
44
+ @stmt.bind_params ":named" => 2
45
+ assert_equal 1, @stmt.execute!.length
46
+ end
47
+
48
+ def test_bind_params_hash_without_colon
49
+ @stmt.bind_params "named" => 2
50
+ assert_equal 1, @stmt.execute!.length
51
+ end
52
+
53
+ def test_bind_params_hash_as_symbol
54
+ @stmt.bind_params :named => 2
55
+ assert_equal 1, @stmt.execute!.length
56
+ end
57
+
58
+ def test_bind_params_mixed
59
+ @stmt.bind_params( 1, ":named" => 2 )
60
+ assert_equal 2, @stmt.execute!.length
61
+ end
62
+
63
+ def test_bind_param_by_index
64
+ @stmt.bind_params( 1, 2 )
65
+ assert_equal 2, @stmt.execute!.length
66
+ end
67
+
68
+ def test_bind_param_by_name_bad
69
+ assert_raise( SQLite3::Exception ) { @stmt.bind_param( "@named", 2 ) }
70
+ end
71
+
72
+ def test_bind_param_by_name_good
73
+ @stmt.bind_param( ":named", 2 )
74
+ assert_equal 1, @stmt.execute!.length
75
+ end
76
+
77
+ def test_bind_param_with_various_types
78
+ @db.transaction do
79
+ @db.execute "create table all_types ( a integer primary key, b float, c string, d integer )"
80
+ @db.execute "insert into all_types ( b, c, d ) values ( 1.4, 'hello', 68719476735 )"
81
+ end
82
+
83
+ assert_equal 1, @db.execute( "select * from all_types where b = ?", 1.4 ).length
84
+ assert_equal 1, @db.execute( "select * from all_types where c = ?", 'hello').length
85
+ assert_equal 1, @db.execute( "select * from all_types where d = ?", 68719476735).length
86
+ end
87
+
88
+ def test_execute_no_bind_no_block
89
+ assert_instance_of SQLite3::ResultSet, @stmt.execute
90
+ end
91
+
92
+ def test_execute_with_bind_no_block
93
+ assert_instance_of SQLite3::ResultSet, @stmt.execute( 1, 2 )
94
+ end
95
+
96
+ def test_execute_no_bind_with_block
97
+ called = false
98
+ @stmt.execute { |row| called = true }
99
+ assert called
100
+ end
101
+
102
+ def test_execute_with_bind_with_block
103
+ called = 0
104
+ @stmt.execute( 1, 2 ) { |row| called += 1 }
105
+ assert_equal 1, called
106
+ end
107
+
108
+ def test_reexecute
109
+ r = @stmt.execute( 1, 2 )
110
+ assert_equal 2, r.to_a.length
111
+ assert_nothing_raised { r = @stmt.execute( 1, 2 ) }
112
+ assert_equal 2, r.to_a.length
113
+ end
114
+
115
+ def test_execute_bang_no_bind_no_block
116
+ assert @stmt.execute!.empty?
117
+ end
118
+
119
+ def test_execute_bang_with_bind_no_block
120
+ assert_equal 2, @stmt.execute!( 1, 2 ).length
121
+ end
122
+
123
+ def test_execute_bang_no_bind_with_block
124
+ called = 0
125
+ @stmt.execute! { |row| called += 1 }
126
+ assert_equal 0, called
127
+ end
128
+
129
+ def test_execute_bang_with_bind_with_block
130
+ called = 0
131
+ @stmt.execute!( 1, 2 ) { |row| called += 1 }
132
+ assert_equal 2, called
133
+ end
134
+
135
+ def test_columns
136
+ c1 = @stmt.columns
137
+ c2 = @stmt.columns
138
+ assert_same c1, c2
139
+ assert_equal 2, c1.length
140
+ end
141
+
142
+ def test_columns_computed
143
+ called = false
144
+ @db.prepare( "select count(*) from foo" ) do |stmt|
145
+ called = true
146
+ assert_equal [ "count(*)" ], stmt.columns
147
+ end
148
+ assert called
149
+ end
150
+
151
+ def test_types
152
+ t1 = @stmt.types
153
+ t2 = @stmt.types
154
+ assert_same t1, t2
155
+ assert_equal 2, t1.length
156
+ end
157
+
158
+ def test_types_computed
159
+ called = false
160
+ @db.prepare( "select count(*) from foo" ) do |stmt|
161
+ called = true
162
+ assert_equal [ nil ], stmt.types
163
+ end
164
+ assert called
165
+ end
166
+
167
+ def test_close
168
+ stmt = @db.prepare( "select * from foo" )
169
+ assert !stmt.closed?
170
+ stmt.close
171
+ assert stmt.closed?
172
+ assert_raise( SQLite3::Exception ) { stmt.execute }
173
+ assert_raise( SQLite3::Exception ) { stmt.execute! }
174
+ assert_raise( SQLite3::Exception ) { stmt.close }
175
+ assert_raise( SQLite3::Exception ) { stmt.bind_params 5 }
176
+ assert_raise( SQLite3::Exception ) { stmt.bind_param 1, 5 }
177
+ assert_raise( SQLite3::Exception ) { stmt.columns }
178
+ assert_raise( SQLite3::Exception ) { stmt.types }
179
+ end
180
+
181
+ def test_committing_tx_with_statement_active
182
+ called = false
183
+ @db.prepare( "select count(*) from foo" ) do |stmt|
184
+ called = true
185
+ count = stmt.execute!.first.first.to_i
186
+ @db.transaction do
187
+ @db.execute "insert into foo ( b ) values ( 'hello' )"
188
+ end
189
+ new_count = stmt.execute!.first.first.to_i
190
+ assert_equal new_count, count+1
191
+ end
192
+ assert called
193
+ end
194
+ end