From e217b3634014337ccbbaad2133f3d8a2b13c1d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Carlos=20Nieto?= Date: Wed, 15 Feb 2017 18:01:19 +0000 Subject: [PATCH] Make sure arguments end up in their place --- lib/sqlbuilder/builder_test.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/sqlbuilder/builder_test.go b/lib/sqlbuilder/builder_test.go index 62ee9617..52e4648c 100644 --- a/lib/sqlbuilder/builder_test.go +++ b/lib/sqlbuilder/builder_test.go @@ -66,10 +66,19 @@ func TestSelect(t *testing.T) { b.Select().Distinct(db.Raw(`ON ? col1`, []interface{}{db.Raw(`SELECT foo FROM bar`), db.Raw(`SELECT baz from qux`)})).Columns("col2", "col3").Distinct("col4", "col5").From("artist").String(), ) - assert.Equal( - `SELECT DISTINCT ON ((SELECT foo FROM bar, SELECT baz from qux)) col1, "col2", "col3", "col4", "col5" FROM "artist"`, - b.Select().Distinct(db.Raw(`ON (?) col1`, []db.RawValue{db.Raw(`SELECT foo FROM bar`), db.Raw(`SELECT baz from qux`)})).Columns("col2", "col3").Distinct("col4", "col5").From("artist").String(), - ) + { + q := b.Select().Distinct(db.Raw(`ON (?) col1`, []db.RawValue{db.Raw(`SELECT foo FROM bar WHERE id = ?`, 1), db.Raw(`SELECT baz from qux WHERE id = 2`)})).Columns("col2", "col3").Distinct("col4", "col5").From("artist"). + Where("id", 3) + assert.Equal( + `SELECT DISTINCT ON ((SELECT foo FROM bar WHERE id = $1, SELECT baz from qux WHERE id = 2)) col1, "col2", "col3", "col4", "col5" FROM "artist" WHERE ("id" = $2)`, + q.String(), + ) + + assert.Equal( + []interface{}{1, 3}, + q.Arguments(), + ) + } { rawCase := db.Raw("CASE WHEN id IN ? THEN 0 ELSE 1 END", []int{1000, 2000})