fix: make array variables work again

This commit is contained in:
Vikram Rangnekar
2020-05-24 17:43:54 -04:00
parent 31afdac3af
commit ccab367351
6 changed files with 63 additions and 51 deletions

View File

@ -239,8 +239,6 @@ func (al *List) save(item Item) error {
qd := &schema.QueryDocument{}
if err := qd.Parse(item.Query); err != nil {
fmt.Println("##", item.Query)
return err
}
@ -248,8 +246,6 @@ func (al *List) save(item Item) error {
query := buf.String()
buf.Reset()
// fmt.Println(">", query)
item.Name = QueryName(query)
item.key = strings.ToLower(item.Name)

View File

@ -1027,9 +1027,9 @@ func (c *compilerContext) renderOp(ex *qcode.Exp, ti *DBTableInfo) error {
case qcode.OpLesserThan:
io.WriteString(c.w, `<`)
case qcode.OpIn:
io.WriteString(c.w, `IN`)
io.WriteString(c.w, `= ANY`)
case qcode.OpNotIn:
io.WriteString(c.w, `NOT IN`)
io.WriteString(c.w, `!= ANY`)
case qcode.OpLike:
io.WriteString(c.w, `LIKE`)
case qcode.OpNotLike:
@ -1175,6 +1175,16 @@ func (c *compilerContext) renderVal(ex *qcode.Exp, vars map[string]string, col *
io.WriteString(c.w, `)`)
case ok:
squoted(c.w, val)
case ex.Op == qcode.OpIn || ex.Op == qcode.OpNotIn:
io.WriteString(c.w, ` (string_to_array('{{`)
io.WriteString(c.w, ex.Val)
io.WriteString(c.w, `}}', ',')`)
io.WriteString(c.w, ` :: `)
io.WriteString(c.w, col.Type)
io.WriteString(c.w, `[])`)
return
default:
io.WriteString(c.w, ` '{{`)
io.WriteString(c.w, ex.Val)

View File

@ -344,17 +344,17 @@ func (com *Compiler) compileQuery(qc *QCode, op *Operation, role string) error {
case QTInsert:
if trv.insert.block {
return fmt.Errorf("insert blocked: %s", field.Name)
return fmt.Errorf("%s, insert blocked: %s", role, field.Name)
}
case QTUpdate:
if trv.update.block {
return fmt.Errorf("update blocked: %s", field.Name)
return fmt.Errorf("%s, update blocked: %s", role, field.Name)
}
case QTDelete:
if trv.delete.block {
return fmt.Errorf("delete blocked: %s", field.Name)
return fmt.Errorf("%s, delete blocked: %s", role, field.Name)
}
}
@ -1030,10 +1030,15 @@ func setListVal(ex *Exp, node *Node) {
case NodeFloat:
ex.ListType = ValFloat
}
} else {
ex.Val = node.Val
return
}
for i := range node.Children {
ex.ListVal = append(ex.ListVal, node.Children[i].Val)
}
}
func setWhereColName(ex *Exp, node *Node) {