@@ -39,13 +39,16 @@ const (
3939 sqliteOptionForeignKeys = "&_foreign_keys=1"
4040 // Make sure that transactions happen exclusively.
4141 sqliteOptionTXLock = "&_txlock=exclusive"
42+ // Enforce case sensitivity for LIKE
43+ sqliteOptionCaseSensitiveLike = "&_cslike=TRUE"
4244
4345 // Assembled sqlite options used when opening the database.
4446 sqliteOptions = "db.sql?" +
4547 sqliteOptionLocation +
4648 sqliteOptionSynchronous +
4749 sqliteOptionForeignKeys +
48- sqliteOptionTXLock
50+ sqliteOptionTXLock +
51+ sqliteOptionCaseSensitiveLike
4952)
5053
5154// NewSqliteState creates a new SQLite-backed state database.
@@ -2210,7 +2213,9 @@ func (s *SQLiteState) LookupVolume(name string) (*Volume, error) {
22102213 return nil , define .ErrDBClosed
22112214 }
22122215
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 )
22142219 if err != nil {
22152220 return nil , fmt .Errorf ("querying database for volume %s: %w" , name , err )
22162221 }
0 commit comments