Skip to content

Commit 87a0cdf

Browse files
authored
Deprecate @sr_str macro by Base.@raw_str and suggest users to switch. (#318)
* Deprecate @sr_str macro by Base.@raw_str and suggest users to switch. * Remove more @sr_str in docs.
1 parent 09b3a18 commit 87a0cdf

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

docs/src/index.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ julia> DBInterface.execute(db, "SELECT * FROM MediaType WHERE Name REGEXP '-d'")
116116

117117
This can be avoided in two ways.
118118
You can either escape each backslash yourself
119-
or you can use the sr"..." string literal that SQLite.jl exports.
119+
or you can use the raw"..." string literal.
120120
The previous query can then successfully be run like so:
121121

122122
```julia
@@ -128,18 +128,14 @@ julia> DBInterface.execute(db, "SELECT * FROM MediaType WHERE Name REGEXP '-\\d'
128128
|-----|---------------|-------------------------------|
129129
| 1 | 3 | "Protected MPEG-4 video file" |
130130

131-
julia> # using sr"..."
132131

133-
julia> DBInterface.execute(db, sr"SELECT * FROM MediaType WHERE Name REGEXP '-\d'") |> DataFrame
132+
julia> DBInterface.execute(db, raw"SELECT * FROM MediaType WHERE Name REGEXP '-\d'") |> DataFrame
134133
1x2 ResultSet
135134
| Row | "MediaTypeId" | "Name" |
136135
|-----|---------------|-------------------------------|
137136
| 1 | 3 | "Protected MPEG-4 video file" |
138137
```
139138

140-
The `sr"..."` currently escapes all special characters in a string
141-
but it may be changed in the future to escape only characters which are part of a regex.
142-
143139

144140
### Custom Scalar Functions
145141

src/UDF.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ regexp(r::AbstractString, s::AbstractString) = occursin(Regex(r), s)
306306
307307
This string literal is used to escape all special characters in the string,
308308
useful for using regex in a query.
309+
310+
This literal is deprecated and users should switch to `Base.@raw_str` instead.
309311
"""
310312
macro sr_str(s)
311313
s

test/runtests.jl

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ end
391391
r =
392392
DBInterface.execute(
393393
db,
394-
SQLite.@sr_str(
394+
@raw_str(
395395
"SELECT LastName FROM Employee WHERE BirthDate REGEXP '^\\d{4}-08'"
396396
)
397397
) |> columntable
@@ -907,7 +907,9 @@ function Base.iterate(::UnknownSchemaTable, st = 1)
907907
end
908908

909909
@testset "SQLite Open Flags" begin
910-
@test_throws SQLiteException("unable to open database file") SQLite.DB("file:test.db?mode=ro")
910+
@test_throws SQLiteException("unable to open database file") SQLite.DB(
911+
"file:test.db?mode=ro",
912+
)
911913

912914
db = SQLite.DB("file:test.db?mode=rwc")
913915
@test db isa SQLite.DB
@@ -953,36 +955,26 @@ end
953955
UnknownSchemaTable(),
954956
db,
955957
"tmp",
956-
on_conflict = "ROLLBACK"
958+
on_conflict = "ROLLBACK",
957959
)
958960
tbl = DBInterface.execute(db, "select * from tmp") |> columntable
959961
@test tbl == (a = [], b = [], c = [])
960962
@test_throws SQLite.SQLiteException SQLite.load!(
961963
UnknownSchemaTable(),
962964
db,
963965
"tmp",
964-
on_conflict = "ABORT"
966+
on_conflict = "ABORT",
965967
)
966968
@test_throws SQLite.SQLiteException SQLite.load!(
967969
UnknownSchemaTable(),
968970
db,
969971
"tmp",
970-
on_conflict = "FAIL"
971-
)
972-
SQLite.load!(
973-
UnknownSchemaTable(),
974-
db,
975-
"tmp",
976-
on_conflict = "IGNORE"
972+
on_conflict = "FAIL",
977973
)
974+
SQLite.load!(UnknownSchemaTable(), db, "tmp"; on_conflict = "IGNORE")
978975
tbl = DBInterface.execute(db, "select * from tmp") |> columntable
979976
@test tbl == (a = [1], b = [3], c = [4])
980-
SQLite.load!(
981-
UnknownSchemaTable(),
982-
db,
983-
"tmp",
984-
on_conflict = "REPLACE"
985-
)
977+
SQLite.load!(UnknownSchemaTable(), db, "tmp"; on_conflict = "REPLACE")
986978
tbl = DBInterface.execute(db, "select * from tmp") |> columntable
987979
@test tbl == (a = [1], b = [5], c = [6])
988980

0 commit comments

Comments
 (0)