Merge pull request #204 from edznux-dd/nil-pointer-deref

[bugfix] Nil pointer deref
This commit is contained in:
Huan Du
2025-07-06 18:55:09 +08:00
committed by GitHub
2 changed files with 9 additions and 1 deletions
+5
View File
@@ -417,3 +417,8 @@ func ExampleSelectBuilder_LateralAs() {
// Output:
// SELECT salesperson.name, max_sale.amount, max_sale.customer_name FROM salesperson, LATERAL (SELECT amount, customer_name FROM all_sales WHERE all_sales.salesperson_id = salesperson.id ORDER BY amount DESC LIMIT ?) AS max_sale
}
func TestNilPointerWhere(t *testing.T) {
NewSelectBuilder().SQL("$0").Build()
NewSelectBuilder().SQL("$0").BuildWithFlavor(DefaultFlavor)
}
+4 -1
View File
@@ -60,7 +60,7 @@ var _ Builder = new(whereClauseProxy)
// BuildWithFlavor builds a WHERE clause with the specified flavor and initial arguments.
func (wc *WhereClause) BuildWithFlavor(flavor Flavor, initialArg ...interface{}) (sql string, args []interface{}) {
if len(wc.clauses) == 0 {
if wc == nil || len(wc.clauses) == 0 {
return "", nil
}
@@ -128,6 +128,9 @@ func (wc *WhereClause) AddWhereExpr(args *Args, andExpr ...string) *WhereClause
// AddWhereClause adds all clauses in the whereClause to the wc.
func (wc *WhereClause) AddWhereClause(whereClause *WhereClause) *WhereClause {
if wc == nil {
return nil
}
if whereClause == nil {
return wc
}