Skip to content

Commit 870f3b9

Browse files
committed
Merge branch 'master' into statement-timeout
2 parents 3ba847c + 0345753 commit 870f3b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1428
-1417
lines changed

.rubocop.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# from https://evilmartians.com/chronicles/rubocoping-with-legacy-bring-your-ruby-code-up-to-standard
2+
require:
3+
- standard
4+
- standard-custom
5+
- standard-performance
6+
- rubocop-performance
7+
- rubocop-minitest
8+
9+
inherit_gem:
10+
standard: config/base.yml
11+
standard-custom: config/base.yml
12+
standard-performance: config/base.yml
13+
14+
AllCops:
15+
SuggestExtensions: false
16+
TargetRubyVersion: 3.0
17+
18+
Naming/InclusiveLanguage:
19+
Enabled: true
20+
21+
Minitest/AssertInDelta: # new in 0.10
22+
Enabled: true
23+
Minitest/AssertKindOf: # new in 0.10
24+
Enabled: true
25+
Minitest/AssertOperator: # new in 0.32
26+
Enabled: true
27+
Minitest/AssertOutput: # new in 0.10
28+
Enabled: true
29+
Minitest/AssertPathExists: # new in 0.10
30+
Enabled: true
31+
Minitest/AssertPredicate: # new in 0.18
32+
Enabled: true
33+
Minitest/AssertRaisesCompoundBody: # new in 0.21
34+
Enabled: true
35+
Minitest/AssertRaisesWithRegexpArgument: # new in 0.22
36+
Enabled: true
37+
Minitest/AssertSame: # new in 0.26
38+
Enabled: true
39+
Minitest/AssertSilent: # new in 0.10
40+
Enabled: true
41+
Minitest/AssertWithExpectedArgument: # new in 0.11
42+
Enabled: true
43+
Minitest/AssertionInLifecycleHook: # new in 0.10
44+
Enabled: true
45+
Minitest/DuplicateTestRun: # new in 0.19
46+
Enabled: true
47+
Minitest/EmptyLineBeforeAssertionMethods: # new in 0.23
48+
Enabled: false
49+
Minitest/LifecycleHooksOrder: # new in 0.28
50+
Enabled: true
51+
Minitest/LiteralAsActualArgument: # new in 0.10
52+
Enabled: true
53+
Minitest/MultipleAssertions: # new in 0.10
54+
Enabled: true
55+
Minitest/NonExecutableTestMethod: # new in 0.34
56+
Enabled: true
57+
Minitest/NonPublicTestMethod: # new in 0.27
58+
Enabled: true
59+
Minitest/RedundantMessageArgument: # new in 0.34
60+
Enabled: true
61+
Minitest/RefuteInDelta: # new in 0.10
62+
Enabled: true
63+
Minitest/RefuteKindOf: # new in 0.10
64+
Enabled: true
65+
Minitest/RefuteOperator: # new in 0.32
66+
Enabled: true
67+
Minitest/RefutePathExists: # new in 0.10
68+
Enabled: true
69+
Minitest/RefutePredicate: # new in 0.18
70+
Enabled: true
71+
Minitest/RefuteSame: # new in 0.26
72+
Enabled: true
73+
Minitest/ReturnInTestMethod: # new in 0.31
74+
Enabled: true
75+
Minitest/SkipEnsure: # new in 0.20
76+
Enabled: true
77+
Minitest/SkipWithoutReason: # new in 0.24
78+
Enabled: true
79+
Minitest/TestFileName: # new in 0.26
80+
Enabled: true
81+
Minitest/TestMethodName: # new in 0.10
82+
Enabled: true
83+
Minitest/UnreachableAssertion: # new in 0.14
84+
Enabled: true
85+
Minitest/UnspecifiedException: # new in 0.10
86+
Enabled: true
87+
Minitest/UselessAssertion: # new in 0.26
88+
Enabled: true

CHANGELOG.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,72 @@ This release drops support for Ruby 2.7. [#453] @flavorjones
2020
- Moved some C code into Ruby. [#451, #455] @tenderlove
2121

2222

23+
### Changed
24+
25+
- Raise `StandardError` in a few places where `Exception` was previously raised.
26+
- `Database#columns` returns a list of frozen strings now
27+
28+
2329
### Removed
2430

2531
- Remove `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones
26-
32+
- Remove `SQLite3::Translator` and all related type translation methods.
33+
If you need to do type translation on values returned from the statement object,
34+
please wrap it with a delegate object. Here is an example of using a delegate
35+
class to implement type translation:
36+
37+
```ruby
38+
require "sqlite3"
39+
require "delegate"
40+
41+
db = SQLite3::Database.new(":memory:")
42+
43+
return_value = db.execute_batch2 <<-EOSQL
44+
CREATE TABLE items (id integer PRIMARY KEY AUTOINCREMENT, name string);
45+
INSERT INTO items (name) VALUES ("foo");
46+
INSERT INTO items (name) VALUES ("bar");
47+
EOSQL
48+
49+
class MyTranslator < DelegateClass(SQLite3::Statement)
50+
def step
51+
row = super
52+
return if done?
53+
54+
row.map.with_index do |item, i|
55+
case types[i]
56+
when "integer" # turn all integers to floats
57+
item.to_f
58+
when "string" # add "hello" to all strings
59+
item + "hello"
60+
end
61+
end
62+
end
63+
end
64+
65+
db.prepare("SELECT * FROM items") do |stmt|
66+
stmt = MyTranslator.new(stmt)
67+
while row = stmt.step
68+
p row
69+
end
70+
end
71+
```
72+
73+
- Removed `types` and `fields` readers on row objects.
74+
Deprecated code looks like this:
75+
76+
```ruby
77+
row = @db.execute("select * from foo")
78+
assert_equal ["blob"], row.first.types
79+
```
80+
81+
If you would like to access the "types" associated with a returned query,
82+
use a prepared statement like this:
83+
84+
```ruby
85+
@db.prepare("select * from foo") do |v|
86+
assert_equal ["blob"], v.types
87+
end
88+
```
2789

2890
## 1.7.0 / 2023-12-27
2991

FAQ.md

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -289,49 +289,6 @@ by column name, even though they are still arrays!
289289
end
290290
```
291291

292-
## I'd like the values from a query to be the correct types, instead of String.
293-
294-
You can turn on "type translation" by setting `Database#type_translation` to
295-
true:
296-
297-
298-
```ruby
299-
db.type_translation = true
300-
db.execute( "select * from table" ) do |row|
301-
p row
302-
end
303-
```
304-
305-
306-
By doing this, each return value for each row will be translated to its
307-
correct type, based on its declared column type.
308-
309-
310-
You can even declare your own translation routines, if (for example) you are
311-
using an SQL type that is not handled by default:
312-
313-
314-
```ruby
315-
# assume "objects" table has the following schema:
316-
# create table objects (
317-
# name varchar2(20),
318-
# thing object
319-
# )
320-
321-
db.type_translation = true
322-
db.translator.add_translator( "object" ) do |type, value|
323-
db.decode( value )
324-
end
325-
326-
h = { :one=>:two, "three"=>"four", 5=>6 }
327-
dump = db.encode( h )
328-
329-
db.execute( "insert into objects values ( ?, ? )", "bob", dump )
330-
331-
obj = db.get_first_value( "select thing from objects where name='bob'" )
332-
p obj == h
333-
```
334-
335292
## How do I insert binary data into the database?
336293

337294
Use blobs. Blobs are new features of SQLite3. You have to use bind

Gemfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@ source "https://rubygems.org"
22

33
gemspec
44

5-
gem("minitest", "5.20.0")
6-
gem("rake-compiler", "1.2.5")
7-
gem("rake-compiler-dock", "1.4.0")
8-
gem("rdoc", "6.6.2")
5+
group :development do
6+
gem "minitest", "5.20.0"
97

10-
gem("ruby_memcheck", "2.3.0") if Gem::Platform.local.os == "linux"
8+
gem "rake-compiler", "1.2.5"
9+
gem "rake-compiler-dock", "1.4.0"
10+
11+
gem "ruby_memcheck", "2.3.0" if Gem::Platform.local.os == "linux"
12+
13+
gem "rdoc", "6.6.2"
14+
15+
gem "rubocop", require: false
16+
gem "standardrb", require: false
17+
gem "rubocop-minitest", require: false
18+
19+
# FIXME: Remove after minitest removes dependency
20+
gem "mutex_m"
21+
end

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
#
66
require "bundler"
77
SQLITE3_SPEC = Bundler.load_gemspec("sqlite3.gemspec")
8+
9+
task default: [:rubocop, :compile, :test]

0 commit comments

Comments
 (0)