sqlite3 1.7.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +182 -1
  3. data/CONTRIBUTING.md +23 -1
  4. data/FAQ.md +0 -43
  5. data/INSTALLATION.md +15 -5
  6. data/LICENSE +18 -22
  7. data/README.md +75 -4
  8. data/dependencies.yml +10 -11
  9. data/ext/sqlite3/aggregator.c +142 -145
  10. data/ext/sqlite3/aggregator.h +2 -4
  11. data/ext/sqlite3/backup.c +74 -65
  12. data/ext/sqlite3/backup.h +2 -2
  13. data/ext/sqlite3/database.c +535 -482
  14. data/ext/sqlite3/database.h +7 -4
  15. data/ext/sqlite3/exception.c +111 -92
  16. data/ext/sqlite3/exception.h +3 -1
  17. data/ext/sqlite3/extconf.rb +21 -22
  18. data/ext/sqlite3/sqlite3.c +159 -115
  19. data/ext/sqlite3/sqlite3_ruby.h +2 -2
  20. data/ext/sqlite3/statement.c +516 -300
  21. data/ext/sqlite3/statement.h +3 -3
  22. data/ext/sqlite3/timespec.h +20 -0
  23. data/lib/sqlite3/constants.rb +171 -47
  24. data/lib/sqlite3/database.rb +106 -166
  25. data/lib/sqlite3/errors.rb +26 -1
  26. data/lib/sqlite3/pragmas.rb +126 -136
  27. data/lib/sqlite3/resultset.rb +14 -97
  28. data/lib/sqlite3/statement.rb +58 -13
  29. data/lib/sqlite3/value.rb +17 -20
  30. data/lib/sqlite3/version.rb +1 -21
  31. data/lib/sqlite3.rb +6 -4
  32. data/ports/archives/sqlite-autoconf-3460000.tar.gz +0 -0
  33. metadata +10 -35
  34. data/API_CHANGES.md +0 -49
  35. data/ChangeLog.cvs +0 -88
  36. data/Gemfile +0 -10
  37. data/LICENSE-DEPENDENCIES +0 -20
  38. data/lib/sqlite3/translator.rb +0 -117
  39. data/ports/archives/sqlite-autoconf-3450000.tar.gz +0 -0
  40. data/test/helper.rb +0 -27
  41. data/test/test_backup.rb +0 -33
  42. data/test/test_collation.rb +0 -82
  43. data/test/test_database.rb +0 -668
  44. data/test/test_database_flags.rb +0 -95
  45. data/test/test_database_readonly.rb +0 -36
  46. data/test/test_database_readwrite.rb +0 -41
  47. data/test/test_deprecated.rb +0 -49
  48. data/test/test_encoding.rb +0 -165
  49. data/test/test_integration.rb +0 -507
  50. data/test/test_integration_aggregate.rb +0 -336
  51. data/test/test_integration_open_close.rb +0 -30
  52. data/test/test_integration_pending.rb +0 -115
  53. data/test/test_integration_resultset.rb +0 -142
  54. data/test/test_integration_statement.rb +0 -194
  55. data/test/test_pragmas.rb +0 -22
  56. data/test/test_result_set.rb +0 -47
  57. data/test/test_sqlite3.rb +0 -30
  58. data/test/test_statement.rb +0 -290
  59. data/test/test_statement_execute.rb +0 -39
@@ -1,194 +0,0 @@
1
- require 'helper'
2
-
3
- class TC_Statement < SQLite3::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.5, 'hello', 68719476735 )"
81
- end
82
-
83
- assert_equal 1, @db.execute( "select * from all_types where b = ?", 1.5 ).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
data/test/test_pragmas.rb DELETED
@@ -1,22 +0,0 @@
1
- require 'helper'
2
-
3
- module SQLite3
4
- class TestPragmas < SQLite3::TestCase
5
- def setup
6
- super
7
- @db = SQLite3::Database.new(":memory:")
8
- end
9
-
10
- def test_get_boolean_pragma
11
- refute(@db.get_boolean_pragma("read_uncommitted"))
12
- end
13
-
14
- def test_set_boolean_pragma
15
- @db.set_boolean_pragma("read_uncommitted", 1)
16
-
17
- assert(@db.get_boolean_pragma("read_uncommitted"))
18
- ensure
19
- @db.set_boolean_pragma("read_uncommitted", 0)
20
- end
21
- end
22
- end
@@ -1,47 +0,0 @@
1
- require 'helper'
2
-
3
- module SQLite3
4
- class TestResultSet < SQLite3::TestCase
5
- def setup
6
- @db = SQLite3::Database.new ':memory:'
7
- super
8
- end
9
-
10
- def teardown
11
- super
12
- @db.close
13
- end
14
-
15
- def test_each_hash
16
- @db.execute "create table foo ( a integer primary key, b text )"
17
- list = ('a'..'z').to_a
18
- list.each do |t|
19
- @db.execute "insert into foo (b) values (\"#{t}\")"
20
- end
21
-
22
- rs = @db.prepare('select * from foo').execute
23
- rs.each_hash do |hash|
24
- assert_equal list[hash['a'] - 1], hash['b']
25
- end
26
- rs.close
27
- end
28
-
29
- def test_next_hash
30
- @db.execute "create table foo ( a integer primary key, b text )"
31
- list = ('a'..'z').to_a
32
- list.each do |t|
33
- @db.execute "insert into foo (b) values (\"#{t}\")"
34
- end
35
-
36
- rs = @db.prepare('select * from foo').execute
37
- rows = []
38
- while row = rs.next_hash
39
- rows << row
40
- end
41
- rows.each do |hash|
42
- assert_equal list[hash['a'] - 1], hash['b']
43
- end
44
- rs.close
45
- end
46
- end
47
- end
data/test/test_sqlite3.rb DELETED
@@ -1,30 +0,0 @@
1
- require 'helper'
2
-
3
- module SQLite3
4
- class TestSQLite3 < SQLite3::TestCase
5
- def test_libversion
6
- assert_not_nil SQLite3.libversion
7
- end
8
-
9
- def test_threadsafe
10
- assert_not_nil SQLite3.threadsafe
11
- end
12
-
13
- def test_threadsafe?
14
- if SQLite3.threadsafe > 0
15
- assert SQLite3.threadsafe?
16
- else
17
- refute SQLite3.threadsafe?
18
- end
19
- end
20
-
21
- def test_version_strings
22
- skip if SQLite3::VERSION.include?("test") # see set-version-to-timestamp rake task
23
- assert_equal(SQLite3::VERSION, SQLite3::VersionProxy::STRING)
24
- end
25
-
26
- def test_compiled_version_and_loaded_version
27
- assert_equal(SQLite3::SQLITE_VERSION, SQLite3::SQLITE_LOADED_VERSION)
28
- end
29
- end
30
- end
@@ -1,290 +0,0 @@
1
- require 'helper'
2
-
3
- module SQLite3
4
- class TestStatement < SQLite3::TestCase
5
- def setup
6
- @db = SQLite3::Database.new(':memory:')
7
- @stmt = SQLite3::Statement.new(@db, "select 'foo'")
8
- end
9
-
10
- def teardown
11
- @stmt.close if !@stmt.closed?
12
- @db.close
13
- end
14
-
15
- def test_double_close_does_not_segv
16
- @db.execute 'CREATE TABLE "things" ("number" float NOT NULL)'
17
-
18
- stmt = @db.prepare 'INSERT INTO things (number) VALUES (?)'
19
- assert_raises(SQLite3::ConstraintException) { stmt.execute(nil) }
20
-
21
- stmt.close
22
-
23
- assert_raises(SQLite3::Exception) { stmt.close }
24
- end
25
-
26
- def test_raises_type_error
27
- assert_raises(TypeError) do
28
- SQLite3::Statement.new( @db, nil )
29
- end
30
- end
31
-
32
- def test_insert_duplicate_records
33
- @db.execute 'CREATE TABLE "things" ("name" varchar(20) CONSTRAINT "index_things_on_name" UNIQUE)'
34
- stmt = @db.prepare("INSERT INTO things(name) VALUES(?)")
35
- stmt.execute('ruby')
36
-
37
- exception = assert_raises(SQLite3::ConstraintException) { stmt.execute('ruby') }
38
- # SQLite 3.8.2 returns new error message:
39
- # UNIQUE constraint failed: *table_name*.*column_name*
40
- # Older versions of SQLite return:
41
- # column *column_name* is not unique
42
- assert_match(/(column(s)? .* (is|are) not unique|UNIQUE constraint failed: .*)/, exception.message)
43
-
44
- stmt.close
45
- end
46
-
47
- ###
48
- # This method may not exist depending on how sqlite3 was compiled
49
- def test_database_name
50
- @db.execute('create table foo(text BLOB)')
51
- @db.execute('insert into foo(text) values (?)',SQLite3::Blob.new('hello'))
52
- stmt = @db.prepare('select text from foo')
53
- if stmt.respond_to?(:database_name)
54
- assert_equal 'main', stmt.database_name(0)
55
- end
56
- stmt.close
57
- end
58
-
59
- def test_prepare_blob
60
- @db.execute('create table foo(text BLOB)')
61
- stmt = @db.prepare('insert into foo(text) values (?)')
62
- stmt.bind_param(1, SQLite3::Blob.new('hello'))
63
- stmt.step
64
- stmt.close
65
- end
66
-
67
- def test_select_blob
68
- @db.execute('create table foo(text BLOB)')
69
- @db.execute('insert into foo(text) values (?)',SQLite3::Blob.new('hello'))
70
- assert_equal 'hello', @db.execute('select * from foo').first.first
71
- end
72
-
73
- def test_new
74
- assert @stmt
75
- end
76
-
77
- def test_new_closed_handle
78
- @db = SQLite3::Database.new(':memory:')
79
- @db.close
80
- assert_raises(ArgumentError) do
81
- SQLite3::Statement.new(@db, 'select "foo"')
82
- end
83
- end
84
-
85
- def test_new_with_remainder
86
- stmt = SQLite3::Statement.new(@db, "select 'foo';bar")
87
- assert_equal 'bar', stmt.remainder
88
- stmt.close
89
- end
90
-
91
- def test_empty_remainder
92
- assert_equal '', @stmt.remainder
93
- end
94
-
95
- def test_close
96
- @stmt.close
97
- assert @stmt.closed?
98
- end
99
-
100
- def test_double_close
101
- @stmt.close
102
- assert_raises(SQLite3::Exception) do
103
- @stmt.close
104
- end
105
- end
106
-
107
- def test_bind_param_string
108
- stmt = SQLite3::Statement.new(@db, "select ?")
109
- stmt.bind_param(1, "hello")
110
- result = nil
111
- stmt.each { |x| result = x }
112
- assert_equal ['hello'], result
113
- stmt.close
114
- end
115
-
116
- def test_bind_param_int
117
- stmt = SQLite3::Statement.new(@db, "select ?")
118
- stmt.bind_param(1, 10)
119
- result = nil
120
- stmt.each { |x| result = x }
121
- assert_equal [10], result
122
- stmt.close
123
- end
124
-
125
- def test_bind_nil
126
- stmt = SQLite3::Statement.new(@db, "select ?")
127
- stmt.bind_param(1, nil)
128
- result = nil
129
- stmt.each { |x| result = x }
130
- assert_equal [nil], result
131
- stmt.close
132
- end
133
-
134
- def test_bind_blob
135
- @db.execute('create table foo(text BLOB)')
136
- stmt = SQLite3::Statement.new(@db, 'insert into foo(text) values (?)')
137
- stmt.bind_param(1, SQLite3::Blob.new('hello'))
138
- stmt.execute
139
- row = @db.execute('select * from foo')
140
- stmt.close
141
-
142
- assert_equal ['hello'], row.first
143
- capture_io do # hush deprecation warning
144
- assert_equal ['blob'], row.first.types
145
- end
146
- end
147
-
148
- def test_bind_64
149
- stmt = SQLite3::Statement.new(@db, "select ?")
150
- stmt.bind_param(1, 2 ** 31)
151
- result = nil
152
- stmt.each { |x| result = x }
153
- assert_equal [2 ** 31], result
154
- stmt.close
155
- end
156
-
157
- def test_bind_double
158
- stmt = SQLite3::Statement.new(@db, "select ?")
159
- stmt.bind_param(1, 2.2)
160
- result = nil
161
- stmt.each { |x| result = x }
162
- assert_equal [2.2], result
163
- stmt.close
164
- end
165
-
166
- def test_named_bind
167
- stmt = SQLite3::Statement.new(@db, "select :foo")
168
- stmt.bind_param(':foo', 'hello')
169
- result = nil
170
- stmt.each { |x| result = x }
171
- assert_equal ['hello'], result
172
- stmt.close
173
- end
174
-
175
- def test_named_bind_no_colon
176
- stmt = SQLite3::Statement.new(@db, "select :foo")
177
- stmt.bind_param('foo', 'hello')
178
- result = nil
179
- stmt.each { |x| result = x }
180
- assert_equal ['hello'], result
181
- stmt.close
182
- end
183
-
184
- def test_named_bind_symbol
185
- stmt = SQLite3::Statement.new(@db, "select :foo")
186
- stmt.bind_param(:foo, 'hello')
187
- result = nil
188
- stmt.each { |x| result = x }
189
- assert_equal ['hello'], result
190
- stmt.close
191
- end
192
-
193
- def test_named_bind_not_found
194
- stmt = SQLite3::Statement.new(@db, "select :foo")
195
- assert_raises(SQLite3::Exception) do
196
- stmt.bind_param('bar', 'hello')
197
- end
198
- stmt.close
199
- end
200
-
201
- def test_each
202
- r = nil
203
- @stmt.each do |row|
204
- r = row
205
- end
206
- assert_equal(['foo'], r)
207
- end
208
-
209
- def test_reset!
210
- r = []
211
- @stmt.each { |row| r << row }
212
- @stmt.reset!
213
- @stmt.each { |row| r << row }
214
- assert_equal [['foo'], ['foo']], r
215
- end
216
-
217
- def test_step
218
- r = @stmt.step
219
- assert_equal ['foo'], r
220
- end
221
-
222
- def test_step_twice
223
- assert_not_nil @stmt.step
224
- assert !@stmt.done?
225
- assert_nil @stmt.step
226
- assert @stmt.done?
227
-
228
- @stmt.reset!
229
- assert !@stmt.done?
230
- end
231
-
232
- def test_step_never_moves_past_done
233
- 10.times { @stmt.step }
234
- @stmt.done?
235
- end
236
-
237
- def test_column_count
238
- assert_equal 1, @stmt.column_count
239
- end
240
-
241
- def test_column_name
242
- assert_equal "'foo'", @stmt.column_name(0)
243
- assert_nil @stmt.column_name(10)
244
- end
245
-
246
- def test_bind_parameter_count
247
- stmt = SQLite3::Statement.new(@db, "select ?, ?, ?")
248
- assert_equal 3, stmt.bind_parameter_count
249
- stmt.close
250
- end
251
-
252
- def test_execute_with_varargs
253
- stmt = @db.prepare('select ?, ?')
254
- assert_equal [[nil, nil]], stmt.execute(nil, nil).to_a
255
- stmt.close
256
- end
257
-
258
- def test_execute_with_hash
259
- stmt = @db.prepare('select :n, :h')
260
- assert_equal [[10, nil]], stmt.execute('n' => 10, 'h' => nil).to_a
261
- stmt.close
262
- end
263
-
264
- def test_with_error
265
- @db.execute('CREATE TABLE "employees" ("name" varchar(20) NOT NULL CONSTRAINT "index_employees_on_name" UNIQUE)')
266
- stmt = @db.prepare("INSERT INTO Employees(name) VALUES(?)")
267
- stmt.execute('employee-1')
268
- stmt.execute('employee-1') rescue SQLite3::ConstraintException
269
- stmt.reset!
270
- assert stmt.execute('employee-2')
271
- stmt.close
272
- end
273
-
274
- def test_clear_bindings!
275
- stmt = @db.prepare('select ?, ?')
276
- stmt.bind_param 1, "foo"
277
- stmt.bind_param 2, "bar"
278
-
279
- # We can't fetch bound parameters back out of sqlite3, so just call
280
- # the clear_bindings! method and assert that nil is returned
281
- stmt.clear_bindings!
282
-
283
- while x = stmt.step
284
- assert_equal [nil, nil], x
285
- end
286
-
287
- stmt.close
288
- end
289
- end
290
- end
@@ -1,39 +0,0 @@
1
- require 'helper'
2
-
3
- module SQLite3
4
- class TestStatementExecute < SQLite3::TestCase
5
- def setup
6
- @db = SQLite3::Database.new(':memory:')
7
- @db.execute_batch(
8
- "CREATE TABLE items (id integer PRIMARY KEY, number integer)")
9
- end
10
-
11
- def teardown
12
- @db.close
13
- end
14
-
15
- def test_execute_insert
16
- ps = @db.prepare("INSERT INTO items (number) VALUES (:n)")
17
- ps.execute('n'=>10)
18
- assert_equal 1, @db.get_first_value("SELECT count(*) FROM items")
19
- ps.close
20
- end
21
-
22
- def test_execute_update
23
- @db.execute("INSERT INTO items (number) VALUES (?)", [10])
24
-
25
- ps = @db.prepare("UPDATE items SET number = :new WHERE number = :old")
26
- ps.execute('old'=>10, 'new'=>20)
27
- assert_equal 20, @db.get_first_value("SELECT number FROM items")
28
- ps.close
29
- end
30
-
31
- def test_execute_delete
32
- @db.execute("INSERT INTO items (number) VALUES (?)", [20])
33
- ps = @db.prepare("DELETE FROM items WHERE number = :n")
34
- ps.execute('n' => 20)
35
- assert_equal 0, @db.get_first_value("SELECT count(*) FROM items")
36
- ps.close
37
- end
38
- end
39
- end