Skip to content

Commit

Permalink
fix PreparedStatement#destroy calling in Connection#query method.
Browse files Browse the repository at this point in the history
  • Loading branch information
suketa committed Nov 27, 2024
1 parent dec79b2 commit a91f0c0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/connection_query_ng.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# example1.rb
require 'duckdb'

temp_file = "#{File.expand_path('.', __dir__)}/data.duckdb"
puts temp_file

db = DuckDB::Database.open(temp_file)
con = db.connect

con.query('CREATE TABLE test (id INTEGER)')
con.query('INSERT INTO test VALUES (?), (?)', 1, 2)

con.close
db.close

file_last_saved1 = File.mtime(temp_file) # DBクローズ直後にファイルの最終更新日時を取得
i = 0
while file_last_saved1 == File.mtime(temp_file) && i < 5000
sleep 0.0001
i += 1
end
file_last_saved2 = File.mtime(temp_file) # しばらくしてからファイルの最終更新日時を取得

# なぜか file_last_saved1 と file_last_saved2 が異なる
p file_last_saved1 # => 2024-11-27 13:18:42.213986983 +0900 (1)
p file_last_saved2 # => 2024-11-27 13:18:42.643766951 +0900 (2)
File.delete(temp_file)
15 changes: 15 additions & 0 deletions test/duckdb_test/connection_query_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

module DuckDBTest
class ConnectionQueryTest < Minitest::Test
def teardown
File.delete(@file) if File.exist?(@file)
end

def test_prepared_statement_destroy_in_query
outputs = `ruby -Ilib test/connection_query_ng.rb #{@file}`
@file, before, after = outputs.split("\n")
assert_equal(before, after)
end
end
end

0 comments on commit a91f0c0

Please sign in to comment.