Skip to content

Commit 1839dbd

Browse files
committed
feat: allow URI filenames
See https://www.sqlite.org/uri.html
1 parent 9899f06 commit 1839dbd

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## next / unreleased
44

5+
### Added
6+
7+
- URI filenames are now allowed. This allows the injection of some behavior via recognized query parameters. See https://www.sqlite.org/uri.html for more information. #571 @flavorjones
8+
9+
510
### Improved
611

712
- SQL Syntax errors during `Database#prepare` will raise a verbose exception with a multiline message indicating with a "^" exactly where in the statement the error occurred. [#554] @fractaledmind @flavorjones

ext/sqlite3/extconf.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ def configure_packaged_libraries
6161
"-fPIC", # needed for linking the static library into a shared library
6262
"-O2", # see https://github.com/sparklemotion/sqlite3-ruby/issues/335 for some benchmarks
6363
"-fvisibility=hidden", # see https://github.com/rake-compiler/rake-compiler-dock/issues/87
64-
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1"
64+
"-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
65+
"-DSQLITE_USE_URI=1"
6566
]
6667
env["CFLAGS"] = [user_cflags, env["CFLAGS"], more_cflags].flatten.join(" ")
6768
recipe.configure_options += env.select { |k, v| ENV_ALLOWLIST.include?(k) }

test/test_database_uri.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require "helper"
2+
require "tempfile"
3+
require "pathname"
4+
5+
module SQLite3
6+
class TestDatabaseURI < SQLite3::TestCase
7+
def test_open_absolute_file_uri
8+
Tempfile.open "test.db" do |file|
9+
assert SQLite3::Database.new("file:#{file.path}")
10+
end
11+
end
12+
13+
def test_open_relative_file_uri
14+
Dir.mktmpdir do |dir|
15+
Dir.chdir dir do
16+
assert SQLite3::Database.new("file:test.db")
17+
assert_path_exists "test.db"
18+
end
19+
end
20+
end
21+
22+
def test_open_file_uri_readonly
23+
Tempfile.open "test.db" do |file|
24+
db = SQLite3::Database.new("file:#{file.path}?mode=ro")
25+
26+
assert_raise(SQLite3::ReadOnlyException) do
27+
db.execute("CREATE TABLE foos (id integer)")
28+
end
29+
end
30+
end
31+
end
32+
end

0 commit comments

Comments
 (0)