From ae129046e7bed05d67f52bb3605f90cfd948444c Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 1 Mar 2024 16:37:38 -0500 Subject: [PATCH] remove deprecated method signatures callers must use an Array to pass bind parameters to execute, execute_batch, and query --- CHANGELOG.md | 9 +++++--- lib/sqlite3/database.rb | 45 ------------------------------------- test/test_deprecated.rb | 49 ----------------------------------------- 3 files changed, 6 insertions(+), 97 deletions(-) delete mode 100644 test/test_deprecated.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 02456e78..11d99bf5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,9 +38,8 @@ This release drops support for Ruby 2.7. [#453] @flavorjones ### Removed -- Remove methods `SQLite3::Database::FunctionProxy#count` and `#set_error`. [#164, #509, #510] @alexcwatt @flavorjones -- Remove class `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones -- Remove class `SQLite3::Translator` and all related type translation methods. +- Removed class `SQLite3::VersionProxy` which has been deprecated since v1.3.2. [#453] @flavorjones +- Removed class `SQLite3::Translator` and all related type translation methods. If you need to do type translation on values returned from the statement object, please wrap it with a delegate object. Here is an example of using a delegate class to implement type translation: @@ -98,6 +97,10 @@ assert_equal ["blob"], row.first.types end ``` +- Removed methods `SQLite3::Database::FunctionProxy#count` and `#set_error`. [#164, #509, #510] @alexcwatt @flavorjones +- Removed support for non-Array bind parameters to methods `Database#execute`, `#execute_batch`, and `#query`. + + ## 1.7.2 / 2024-01-30 ### Dependencies diff --git a/lib/sqlite3/database.rb b/lib/sqlite3/database.rb index 0db72547..6a70a51a 100644 --- a/lib/sqlite3/database.rb +++ b/lib/sqlite3/database.rb @@ -195,18 +195,6 @@ def filename db_name = "main" # See also #execute2, #query, and #execute_batch for additional ways of # executing statements. def execute sql, bind_vars = [], *args, &block - if bind_vars.nil? || !args.empty? - bind_vars = if args.empty? - [] - else - [bind_vars] + args - end - - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `SQLite3::Database#execute` with nil or multiple bind params without using an array. Please switch to passing bind parameters as an array. Support for bind parameters as *args will be removed in 2.0.0. - EOWARN - end - prepare(sql) do |stmt| stmt.bind_params(bind_vars) stmt = build_result_set stmt @@ -257,27 +245,6 @@ def execute2(sql, *bind_vars) # See also #execute_batch2 for additional ways of # executing statements. def execute_batch(sql, bind_vars = [], *args) - # FIXME: remove this stuff later - unless [Array, Hash].include?(bind_vars.class) - bind_vars = [bind_vars] - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `SQLite3::Database#execute_batch` with bind parameters that are not a list of a hash. Please switch to passing bind parameters as an array or hash. Support for this behavior will be removed in version 2.0.0. - EOWARN - end - - # FIXME: remove this stuff later - if bind_vars.nil? || !args.empty? - bind_vars = if args.empty? - [] - else - [nil] + args - end - - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `SQLite3::Database#execute_batch` with nil or multiple bind params without using an array. Please switch to passing bind parameters as an array. Support for this behavior will be removed in version 2.0.0. - EOWARN - end - sql = sql.strip until sql.empty? prepare(sql) do |stmt| @@ -332,18 +299,6 @@ def execute_batch2(sql, &block) # with a block, +close+ will be invoked implicitly when the block # terminates. def query(sql, bind_vars = [], *args) - if bind_vars.nil? || !args.empty? - bind_vars = if args.empty? - [] - else - [bind_vars] + args - end - - warn(<<~EOWARN) if $VERBOSE - #{caller(1..1).first} is calling `SQLite3::Database#query` with nil or multiple bind params without using an array. Please switch to passing bind parameters as an array. Support for this will be removed in version 2.0.0. - EOWARN - end - result = prepare(sql).execute(bind_vars) if block_given? begin diff --git a/test/test_deprecated.rb b/test/test_deprecated.rb deleted file mode 100644 index e16601db..00000000 --- a/test/test_deprecated.rb +++ /dev/null @@ -1,49 +0,0 @@ -require "helper" - -module SQLite3 - class TestDeprecated < SQLite3::TestCase - def setup - super - @warn_before = $-w - $-w = false - @db = SQLite3::Database.new(":memory:") - @db.execute "CREATE TABLE test_table (name text, age int)" - end - - def teardown - super - $-w = @warn_before - @db.close - end - - def test_query_with_many_bind_params_not_nil - rs = @db.query("select ?, ?", 1, 2) - assert_equal [[1, 2]], rs.to_a - rs.close - end - - def test_execute_with_many_bind_params_not_nil - assert_equal [[1, 2]], @db.execute("select ?, ?", 1, 2).to_a - end - - def test_query_with_many_bind_params - rs = @db.query("select ?, ?", nil, 1) - assert_equal [[nil, 1]], rs.to_a - rs.close - end - - def test_query_with_nil_bind_params - rs = @db.query("select 'foo'", nil) - assert_equal [["foo"]], rs.to_a - rs.close - end - - def test_execute_with_many_bind_params - assert_equal [[nil, 1]], @db.execute("select ?, ?", nil, 1) - end - - def test_execute_with_nil_bind_params - assert_equal [["foo"]], @db.execute("select 'foo'", nil) - end - end -end