3
0

Make paging cursor expr. builders work with MSSQL

This commit is contained in:
Tomaž Jerman
2022-12-08 13:44:02 +01:00
committed by Jože Fortun
parent a5e5e15296
commit 771c87548a
2 changed files with 35 additions and 14 deletions

View File

@@ -345,11 +345,26 @@ func (cur *PagingCursor) ToAST(identLookup func(i string) (string, error), castF
false: "gt",
}
isValueNull = func(i int, neg bool) expr.TypedValue {
if (reflect2.IsNil(vv[i]) && !neg) || (!reflect2.IsNil(vv[i]) && neg) {
return expr.Must(expr.NewBoolean(true))
// Modifying this function to use expressions instead of constant boolean
// values because MSSQL doesn't have those.
//
// @todo rethink and redo the whole/all of the filtering logic surrounding paging
// cursors to make them consistent/reusable
isValueNull = func(i int, neg bool) *ql.ASTNode {
out := &ql.ASTNode{
Ref: "eq",
Args: ql.ASTNodeSet{{
Value: ql.MakeValueOf("Integer", 1),
}},
}
return expr.Must(expr.NewBoolean(false))
if (reflect2.IsNil(vv[i]) && !neg) || (!reflect2.IsNil(vv[i]) && neg) {
// Makes the expr. true
out.Args = append(out.Args, &ql.ASTNode{Value: ql.MakeValueOf("Integer", 1)})
}
// Makes the expr false
out.Args = append(out.Args, &ql.ASTNode{Value: ql.MakeValueOf("Integer", 0)})
return out
}
)
@@ -412,9 +427,7 @@ func (cur *PagingCursor) ToAST(identLookup func(i string) (string, error), castF
},
},
},
&ql.ASTNode{
Value: ql.WrapValue(isValueNull(i, false)),
},
isValueNull(i, false),
},
},
},
@@ -465,9 +478,7 @@ func (cur *PagingCursor) ToAST(identLookup func(i string) (string, error), castF
},
},
},
&ql.ASTNode{
Value: ql.WrapValue(isValueNull(i, false)),
},
isValueNull(i, false),
},
},

View File

@@ -151,12 +151,17 @@ func (c *cursorCondition) sql() (cnd string, err error) {
return false
}
// Modifying this function to use expressions instead of constant boolean
// values because MSSQL doesn't have those.
//
// @todo rethink and redo the whole/all of the filtering logic surrounding paging
// cursors to make them consistent/reusable
isNull = func(i int, neg bool) string {
if (nilCheck(vv[i]) && !neg) || (!nilCheck(vv[i]) && neg) {
return "TRUE"
return "1=1"
}
return "FALSE"
return "1=0"
}
)
@@ -259,12 +264,17 @@ func CursorExpression(
return false
}
// Modifying this function to use expressions instead of constant boolean
// values because MSSQL doesn't have those.
//
// @todo rethink and redo the whole/all of the filtering logic surrounding paging
// cursors to make them consistent/reusable
isValueNull = func(i int, neg bool) exp.Expression {
if (nilCheck(vv[i]) && !neg) || (!nilCheck(vv[i]) && neg) {
return exp.NewLiteralExpression("TRUE")
return exp.NewLiteralExpression("1=1")
}
return exp.NewLiteralExpression("FALSE")
return exp.NewLiteralExpression("1=0")
}
curCond exp.ExpressionList