File tree Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Expand file tree Collapse file tree 4 files changed +32
-10
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,17 @@ describe Driver do
18
18
19
19
assert_filename(" sqlite3:/path/to/file.db" , " /path/to/file.db" )
20
20
assert_filename(" sqlite3:///path/to/file.db" , " /path/to/file.db" )
21
+
22
+ {% if compare_versions(Crystal ::VERSION , " 0.28.0" ) >= 0 % }
23
+ # Before 0.28.0 the filename had the query string in this case
24
+ # but it didn't bother when deleting the file in pool_spec.cr.
25
+ # After 0.28.0 the behavior is changed, but can't be fixed prior that
26
+ # due to the use of URI#opaque.
27
+ assert_filename(" sqlite3:./file.db?max_pool_size=5" , " ./file.db" )
28
+ {% end % }
29
+ assert_filename(" sqlite3:/path/to/file.db?max_pool_size=5" , " /path/to/file.db" )
30
+ assert_filename(" sqlite3://./file.db?max_pool_size=5" , " ./file.db" )
31
+ assert_filename(" sqlite3:///path/to/file.db?max_pool_size=5" , " /path/to/file.db" )
21
32
end
22
33
23
34
it " should use database option as file to open" do
Original file line number Diff line number Diff line change @@ -21,7 +21,12 @@ describe DB::Pool do
21
21
fibers.times { channel.receive }
22
22
23
23
# all numbers were inserted
24
- s = fibers * max_n * (max_n + 1 ) / 2
24
+ s : Int32
25
+ {% if compare_versions(Crystal ::VERSION , " 0.28.0" ) >= 0 % }
26
+ s = fibers * max_n * (max_n + 1 ) // 2
27
+ {% else % }
28
+ s = fibers * max_n * (max_n + 1 ) / 2
29
+ {% end % }
25
30
db.scalar(" select sum(n) from numbers" ).should eq(s)
26
31
27
32
# numbers were not inserted one fiber at a time
Original file line number Diff line number Diff line change @@ -19,11 +19,13 @@ ensure
19
19
File .delete(DB_FILENAME )
20
20
end
21
21
22
- def with_db (name, & block : DB ::Database - > )
23
- File .delete(name) rescue nil
24
- DB .open " sqlite3:#{ name } " , & block
22
+ def with_db (config, & block : DB ::Database - > )
23
+ uri = " sqlite3:#{ config } "
24
+ filename = SQLite3 ::Connection .filename(URI .parse(uri))
25
+ File .delete(filename) rescue nil
26
+ DB .open uri, & block
25
27
ensure
26
- File .delete(name)
28
+ File .delete(filename) if filename
27
29
end
28
30
29
31
def with_mem_db (& block : DB ::Database - > )
Original file line number Diff line number Diff line change @@ -9,11 +9,15 @@ class SQLite3::Connection < DB::Connection
9
9
end
10
10
11
11
def self.filename (uri : URI )
12
- URI .unescape (if path = uri.path
13
- (uri.host || " " ) + path
14
- else
15
- uri.opaque.not_nil!
16
- end )
12
+ {% if compare_versions(Crystal ::VERSION , " 0.28.0" ) >= 0 % }
13
+ URI .unescape((uri.host || " " ) + uri.path)
14
+ {% else % }
15
+ URI .unescape (if path = uri.path
16
+ (uri.host || " " ) + path
17
+ else
18
+ uri.opaque.not_nil!
19
+ end )
20
+ {% end % }
17
21
end
18
22
19
23
def build_prepared_statement (query )
You can’t perform that action at this time.
0 commit comments