Use arg for regex queries (#311)

This commit is contained in:
WithoutPants
2020-01-07 05:02:25 +11:00
committed by Leopere
parent bab7c8f250
commit 488cd5575d
2 changed files with 6 additions and 3 deletions

View File

@@ -21,7 +21,7 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
) )
const testName = "Foo Bar" const testName = "Foo's Bar"
const testExtension = ".mp4" const testExtension = ".mp4"
var testSeparators = []string{ var testSeparators = []string{

View File

@@ -293,7 +293,9 @@ func getMultiCriterionClause(table string, joinTable string, joinTableField stri
func (qb *SceneQueryBuilder) QueryAllByPathRegex(regex string) ([]*Scene, error) { func (qb *SceneQueryBuilder) QueryAllByPathRegex(regex string) ([]*Scene, error) {
var args []interface{} var args []interface{}
body := selectDistinctIDs("scenes") + " WHERE scenes.path regexp '(?i)" + regex + "'" body := selectDistinctIDs("scenes") + " WHERE scenes.path regexp ?"
args = append(args, "(?i)"+regex)
idsResult, err := runIdsQuery(body, args) idsResult, err := runIdsQuery(body, args)
@@ -326,7 +328,8 @@ func (qb *SceneQueryBuilder) QueryByPathRegex(findFilter *FindFilterType) ([]*Sc
body := selectDistinctIDs("scenes") body := selectDistinctIDs("scenes")
if q := findFilter.Q; q != nil && *q != "" { if q := findFilter.Q; q != nil && *q != "" {
whereClauses = append(whereClauses, "scenes.path regexp '(?i)"+*q+"'") whereClauses = append(whereClauses, "scenes.path regexp ?")
args = append(args, "(?i)"+*q)
} }
sortAndPagination := qb.getSceneSort(findFilter) + getPagination(findFilter) sortAndPagination := qb.getSceneSort(findFilter) + getPagination(findFilter)