diff --git a/CHANGELOG.md b/CHANGELOG.md index 6fa7495e..9e30304a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,22 @@ db.prepare("SELECT * FROM items") do |stmt| end ``` +- Removed `types` and `fields` readers on row objects. + Deprecated code looks like this: + +```ruby +row = @db.execute("select * from foo") +assert_equal ["blob"], row.first.types +``` + + If you would like to access the "types" associated with a returned query, + use a prepared statement like this: + +```ruby +@db.prepare("select * from foo") do |v| + assert_equal ["blob"], v.types +end +``` ## 1.7.0 / 2023-12-27 diff --git a/lib/sqlite3/database.rb b/lib/sqlite3/database.rb index b2719a9d..e8977896 100644 --- a/lib/sqlite3/database.rb +++ b/lib/sqlite3/database.rb @@ -676,7 +676,7 @@ def readonly? # but only retries up to the indicated number of +milliseconds+. # This is an alternative to #busy_timeout, which holds the GVL # while SQLite sleeps and retries. - def busy_handler_timeout=( milliseconds ) + def busy_handler_timeout=(milliseconds) timeout_seconds = milliseconds.fdiv(1000) busy_handler do |count| diff --git a/lib/sqlite3/resultset.rb b/lib/sqlite3/resultset.rb index bd9a1ceb..e8cbd62c 100644 --- a/lib/sqlite3/resultset.rb +++ b/lib/sqlite3/resultset.rb @@ -9,51 +9,6 @@ module SQLite3 class ResultSet include Enumerable - class ArrayWithTypesAndFields < Array # :nodoc: - attr_writer :types - attr_writer :fields - - def types - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `#{self.class}#types` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `types` method on the SQLite3::ResultSet object that created this object. - EOWARN - @types - end - - def fields - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `#{self.class}#fields` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `columns` method on the SQLite3::ResultSet object that created this object. - EOWARN - @fields - end - end - - # The class of which we return an object in case we want a Hash as - # result. - class HashWithTypesAndFields < Hash # :nodoc: - attr_writer :types - attr_writer :fields - - def types - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `#{self.class}#types` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `types` method on the SQLite3::ResultSet object that created this object. - EOWARN - @types - end - - def fields - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `#{self.class}#fields` which is deprecated and will be removed in sqlite3 version 2.0.0. Please call the `columns` method on the SQLite3::ResultSet object that created this object. - EOWARN - @fields - end - - def [] key - key = fields[key] if key.is_a? Numeric - super(key) - end - end - # Create a new ResultSet attached to the given database, using the # given sql text. def initialize db, stmt @@ -85,17 +40,7 @@ def eof? # For hashes, the column names are the keys of the hash, and the column # types are accessible via the +types+ property. def next - row = @stmt.step - return nil if @stmt.done? - - # FIXME: the `fields` and `types` methods are deprecated on this - # object for version 2.0, so we can safely remove this branch - # as well. - row = ArrayWithTypesAndFields.new(row) - - row.fields = @stmt.columns - row.types = @stmt.types - row + @stmt.step end # Required by the Enumerable mixin. Provides an internal iterator over the @@ -141,14 +86,7 @@ def next_hash row = @stmt.step return nil if @stmt.done? - # FIXME: this can be switched to a regular hash in 2.0 - row = HashWithTypesAndFields[*@stmt.columns.zip(row).flatten] - - # FIXME: these methods are deprecated for version 2.0, so we can remove - # this code in 2.0 - row.fields = @stmt.columns - row.types = @stmt.types - row + Hash[*@stmt.columns.zip(row).flatten] end end diff --git a/test/test_integration_pending.rb b/test/test_integration_pending.rb index 6a391f53..1a25910b 100644 --- a/test/test_integration_pending.rb +++ b/test/test_integration_pending.rb @@ -79,9 +79,9 @@ def test_busy_handler_timeout_releases_gvl work = [] Thread.new do - while true + loop do sleep 0.1 - work << '.' + work << "." end end sleep 1 @@ -91,25 +91,23 @@ def test_busy_handler_timeout_releases_gvl busy.lock t = Thread.new do - begin - db2 = SQLite3::Database.open( "test.db" ) - db2.transaction( :exclusive ) do - busy.lock - end - ensure - db2.close if db2 + db2 = SQLite3::Database.open("test.db") + db2.transaction(:exclusive) do + busy.lock end + ensure + db2&.close end sleep 1 - assert_raises( SQLite3::BusyException ) do - work << '|' + work << "|" + assert_raises(SQLite3::BusyException) do @db.execute "insert into foo (b) values ( 'from 2' )" end busy.unlock t.join - assert work.size - work.find_index('|') > 3 + assert_operator work.size - work.find_index("|"), :>, 3 end end diff --git a/test/test_statement.rb b/test/test_statement.rb index 7b55f0de..5d4d4377 100644 --- a/test/test_statement.rb +++ b/test/test_statement.rb @@ -136,12 +136,10 @@ def test_bind_blob stmt = SQLite3::Statement.new(@db, "insert into foo(text) values (?)") stmt.bind_param(1, SQLite3::Blob.new("hello")) stmt.execute - row = @db.execute("select * from foo") stmt.close - - assert_equal ["hello"], row.first - capture_io do # hush deprecation warning - assert_equal ["blob"], row.first.types + @db.prepare("select * from foo") do |v| + assert_equal ["hello"], v.first + assert_equal ["blob"], v.types end end