// ---------------------------------------------------------------------------
type Field string
const (
- Author, Language, Series, Title Field = "aut", "lan", "ser", "tit"
+ Author, Language, List, Series, Title Field = "aut", "lan", "lst", "ser", "tit"
)
func (f Field) String() string {
func queryIds(criteria []SearchTerm) []int {
query := "SELECT b.id FROM Books b" +
" INNER JOIN Authors a ON a.id=b.author" +
- " LEFT OUTER JOIN Series s ON s.id=b.series"
+ " LEFT OUTER JOIN Series s ON s.id=b.series" +
+ " LEFT OUTER JOIN Lists_Books lb ON b.id=lb.book" +
+ " LEFT OUTER JOIN Lists l ON l.id=lb.list"
- args := make([]interface{}, len(criteria))
+ args := make([]interface{}, 0)
- for i, criterion := range criteria {
+ i := 0
+
+ for _, criterion := range criteria {
if 0 == i {
query += " WHERE "
} else {
query += " AND "
}
- text := criterion.Text
-
switch criterion.Attribute {
case Author:
query += " UPPER(a.grouping) LIKE UPPER($" + strconv.Itoa(i + 1) + ")"
- text = strings.Replace(text, " ", "", -1) // Remove spaces
+ args = append(args, strings.Replace(criterion.Text, " ", "", -1))
case Language:
query += " UPPER(b.language) LIKE UPPER($" + strconv.Itoa(i + 1) + ")"
+ args = append(args, criterion.Text)
+ case List:
+ codes := strings.Split(criterion.Text, ",")
+ query += " UPPER(l.code) IN ("
+
+ for j, code := range codes {
+ if j > 0 {
+ query += ","
+ }
+ query += "UPPER($" + strconv.Itoa(i + j + 1) + ")"
+ args = append(args, code)
+ }
+ query += ")"
+ i += len(codes) - 1
case Series:
query += " UPPER(s.descr) LIKE UPPER($" + strconv.Itoa(i + 1) + ")"
+ args = append(args, criterion.Text)
case Title:
query += " UPPER(b.title) LIKE UPPER($" + strconv.Itoa(i + 1) + ")"
+ args = append(args, criterion.Text)
default:
report("Error: unrecognized search field in queryIds(): " + criterion.Attribute.String(), nil)
return nil
}
- args[i] = text
+
+ i++
}
query += " ORDER BY a.grouping,s.descr,b.volume,b.title,b.path"