From c621a9b7018f1d3219ac32180f68150d1906d32d Mon Sep 17 00:00:00 2001 From: "Brian J. Cardiff" Date: Thu, 18 Apr 2019 15:58:02 -0300 Subject: [PATCH] Upgrade to Crystal 0.28.0 (#38) --- spec/driver_spec.cr | 11 +++++++++++ spec/pool_spec.cr | 7 ++++++- spec/spec_helper.cr | 10 ++++++---- src/sqlite3/connection.cr | 14 +++++++++----- 4 files changed, 32 insertions(+), 10 deletions(-) diff --git a/spec/driver_spec.cr b/spec/driver_spec.cr index fae5ba1..fe1d963 100644 --- a/spec/driver_spec.cr +++ b/spec/driver_spec.cr @@ -18,6 +18,17 @@ describe Driver do assert_filename("sqlite3:/path/to/file.db", "/path/to/file.db") assert_filename("sqlite3:///path/to/file.db", "/path/to/file.db") + + {% if compare_versions(Crystal::VERSION, "0.28.0") >= 0 %} + # Before 0.28.0 the filename had the query string in this case + # but it didn't bother when deleting the file in pool_spec.cr. + # After 0.28.0 the behavior is changed, but can't be fixed prior that + # due to the use of URI#opaque. + assert_filename("sqlite3:./file.db?max_pool_size=5", "./file.db") + {% end %} + assert_filename("sqlite3:/path/to/file.db?max_pool_size=5", "/path/to/file.db") + assert_filename("sqlite3://./file.db?max_pool_size=5", "./file.db") + assert_filename("sqlite3:///path/to/file.db?max_pool_size=5", "/path/to/file.db") end it "should use database option as file to open" do diff --git a/spec/pool_spec.cr b/spec/pool_spec.cr index 81a95c6..edd3f2f 100644 --- a/spec/pool_spec.cr +++ b/spec/pool_spec.cr @@ -21,7 +21,12 @@ describe DB::Pool do fibers.times { channel.receive } # all numbers were inserted - s = fibers * max_n * (max_n + 1) / 2 + s : Int32 + {% if compare_versions(Crystal::VERSION, "0.28.0") >= 0 %} + s = fibers * max_n * (max_n + 1) // 2 + {% else %} + s = fibers * max_n * (max_n + 1) / 2 + {% end %} db.scalar("select sum(n) from numbers").should eq(s) # numbers were not inserted one fiber at a time diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 9f55c83..d83e845 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -19,11 +19,13 @@ ensure File.delete(DB_FILENAME) end -def with_db(name, &block : DB::Database ->) - File.delete(name) rescue nil - DB.open "sqlite3:#{name}", &block +def with_db(config, &block : DB::Database ->) + uri = "sqlite3:#{config}" + filename = SQLite3::Connection.filename(URI.parse(uri)) + File.delete(filename) rescue nil + DB.open uri, &block ensure - File.delete(name) + File.delete(filename) if filename end def with_mem_db(&block : DB::Database ->) diff --git a/src/sqlite3/connection.cr b/src/sqlite3/connection.cr index d405654..3b5c917 100644 --- a/src/sqlite3/connection.cr +++ b/src/sqlite3/connection.cr @@ -9,11 +9,15 @@ class SQLite3::Connection < DB::Connection end def self.filename(uri : URI) - URI.unescape (if path = uri.path - (uri.host || "") + path - else - uri.opaque.not_nil! - end) + {% if compare_versions(Crystal::VERSION, "0.28.0") >= 0 %} + URI.unescape((uri.host || "") + uri.path) + {% else %} + URI.unescape (if path = uri.path + (uri.host || "") + path + else + uri.opaque.not_nil! + end) + {% end %} end def build_prepared_statement(query)