@@ -39,13 +39,16 @@ const (
39
39
sqliteOptionForeignKeys = "&_foreign_keys=1"
40
40
// Make sure that transactions happen exclusively.
41
41
sqliteOptionTXLock = "&_txlock=exclusive"
42
+ // Enforce case sensitivity for LIKE
43
+ sqliteOptionCaseSensitiveLike = "&_cslike=TRUE"
42
44
43
45
// Assembled sqlite options used when opening the database.
44
46
sqliteOptions = "db.sql?" +
45
47
sqliteOptionLocation +
46
48
sqliteOptionSynchronous +
47
49
sqliteOptionForeignKeys +
48
- sqliteOptionTXLock
50
+ sqliteOptionTXLock +
51
+ sqliteOptionCaseSensitiveLike
49
52
)
50
53
51
54
// NewSqliteState creates a new SQLite-backed state database.
@@ -2210,7 +2213,9 @@ func (s *SQLiteState) LookupVolume(name string) (*Volume, error) {
2210
2213
return nil , define .ErrDBClosed
2211
2214
}
2212
2215
2213
- rows , err := s .conn .Query ("SELECT Name, JSON FROM VolumeConfig WHERE Name LIKE ? ORDER BY LENGTH(Name) ASC;" , name + "%" )
2216
+ escaper := strings .NewReplacer ("\\ " , "\\ \\ " , "_" , "\\ _" , "%" , "\\ %" )
2217
+ queryString := escaper .Replace (name ) + "%"
2218
+ rows , err := s .conn .Query ("SELECT Name, JSON FROM VolumeConfig WHERE Name LIKE ? ESCAPE '\\ ' ORDER BY LENGTH(Name) ASC;" , queryString )
2214
2219
if err != nil {
2215
2220
return nil , fmt .Errorf ("querying database for volume %s: %w" , name , err )
2216
2221
}
0 commit comments