Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't cache the database encoding #485

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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