Skip to content

Commit

Permalink
Merge pull request #485 from sparklemotion/no-encoding-cache
Browse files Browse the repository at this point in the history
Don't cache the database encoding
  • Loading branch information
tenderlove committed Jan 24, 2024
2 parents ca7a142 + d15f6c3 commit f5f6859
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/sqlite3/database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def initialize file, options = {}, zvfs = nil

@tracefunc = nil
@authorizer = nil
@encoding = nil
@busy_handler = nil
@collations = {}
@functions = {}
Expand All @@ -138,9 +137,7 @@ def initialize file, options = {}, zvfs = nil
#
# Fetch the encoding set on this database
def encoding
@encoding ||= prepare("PRAGMA encoding") { |stmt|
Encoding.find(stmt.first.first)
}
prepare("PRAGMA encoding") { |stmt| Encoding.find(stmt.first.first) }
end

# Installs (or removes) a block that will be invoked for every access
Expand Down
8 changes: 8 additions & 0 deletions test/test_encoding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ def teardown
@db.close
end

def test_change_encoding
db = SQLite3::Database.new(":memory:")
assert_equal Encoding.find("UTF-8"), db.encoding

db.execute "PRAGMA encoding='UTF-16le'"
assert_equal Encoding.find("UTF-16le"), db.encoding
end

def test_encoding_when_results_are_hash
db = SQLite3::Database.new(":memory:", results_as_hash: true)
assert_equal Encoding.find("UTF-8"), db.encoding
Expand Down

0 comments on commit f5f6859

Please sign in to comment.