MySQL bool expressions.

This commit is contained in:
go-jet 2019-07-30 11:18:12 +02:00
parent bffa102849
commit d0533f73fb
37 changed files with 720 additions and 436 deletions

View file

@ -174,29 +174,75 @@ func TestStringOperators(t *testing.T) {
func TestBoolOperators(t *testing.T) {
query := AllTypes.SELECT(
AllTypes.Boolean.EQ(AllTypes.BooleanPtr),
AllTypes.Boolean.EQ(Bool(true)),
AllTypes.Boolean.NOT_EQ(AllTypes.BooleanPtr),
AllTypes.Boolean.NOT_EQ(Bool(false)),
AllTypes.Boolean.IS_DISTINCT_FROM(AllTypes.BooleanPtr),
AllTypes.Boolean.IS_DISTINCT_FROM(Bool(true)),
AllTypes.Boolean.IS_NOT_DISTINCT_FROM(AllTypes.BooleanPtr),
AllTypes.Boolean.IS_NOT_DISTINCT_FROM(Bool(true)),
AllTypes.Boolean.IS_TRUE(),
AllTypes.Boolean.IS_NOT_TRUE(),
AllTypes.Boolean.IS_NOT_FALSE(),
AllTypes.Boolean.IS_UNKNOWN(),
AllTypes.Boolean.IS_NOT_UNKNOWN(),
AllTypes.Boolean.EQ(AllTypes.BooleanPtr).AS("EQ1"),
AllTypes.Boolean.EQ(Bool(true)).AS("EQ2"),
AllTypes.Boolean.NOT_EQ(AllTypes.BooleanPtr).AS("NEq1"),
AllTypes.Boolean.NOT_EQ(Bool(false)).AS("NEq2"),
AllTypes.Boolean.IS_DISTINCT_FROM(AllTypes.BooleanPtr).AS("distinct1"),
AllTypes.Boolean.IS_DISTINCT_FROM(Bool(true)).AS("distinct2"),
AllTypes.Boolean.IS_NOT_DISTINCT_FROM(AllTypes.BooleanPtr).AS("not_distinct_1"),
AllTypes.Boolean.IS_NOT_DISTINCT_FROM(Bool(true)).AS("NOTDISTINCT2"),
AllTypes.Boolean.IS_TRUE().AS("ISTRUE"),
AllTypes.Boolean.IS_NOT_TRUE().AS("isnottrue"),
AllTypes.Boolean.IS_FALSE().AS("is_False"),
AllTypes.Boolean.IS_NOT_FALSE().AS("is not false"),
AllTypes.Boolean.IS_UNKNOWN().AS("is unknown"),
AllTypes.Boolean.IS_NOT_UNKNOWN().AS("is_not_unknown"),
AllTypes.Boolean.AND(AllTypes.Boolean).EQ(AllTypes.Boolean.AND(AllTypes.Boolean)),
AllTypes.Boolean.OR(AllTypes.Boolean).EQ(AllTypes.Boolean.AND(AllTypes.Boolean)),
)
AllTypes.Boolean.AND(AllTypes.Boolean).EQ(AllTypes.Boolean.AND(AllTypes.Boolean)).AS("complex1"),
AllTypes.Boolean.OR(AllTypes.Boolean).EQ(AllTypes.Boolean.AND(AllTypes.Boolean)).AS("complex2"),
).LIMIT(2)
//fmt.Println(query.DebugSql())
//fmt.Println(query.Sql())
err := query.Query(db, &struct{}{})
testutils.AssertStatementSql(t, query, `
SELECT (all_types.boolean = all_types.boolean_ptr) AS "EQ1",
(all_types.boolean = $1) AS "EQ2",
(all_types.boolean != all_types.boolean_ptr) AS "NEq1",
(all_types.boolean != $2) AS "NEq2",
(all_types.boolean IS DISTINCT FROM all_types.boolean_ptr) AS "distinct1",
(all_types.boolean IS DISTINCT FROM $3) AS "distinct2",
(all_types.boolean IS NOT DISTINCT FROM all_types.boolean_ptr) AS "not_distinct_1",
(all_types.boolean IS NOT DISTINCT FROM $4) AS "NOTDISTINCT2",
all_types.boolean IS TRUE AS "ISTRUE",
all_types.boolean IS NOT TRUE AS "isnottrue",
all_types.boolean IS FALSE AS "is_False",
all_types.boolean IS NOT FALSE AS "is not false",
all_types.boolean IS UNKNOWN AS "is unknown",
all_types.boolean IS NOT UNKNOWN AS "is_not_unknown",
((all_types.boolean AND all_types.boolean) = (all_types.boolean AND all_types.boolean)) AS "complex1",
((all_types.boolean OR all_types.boolean) = (all_types.boolean AND all_types.boolean)) AS "complex2"
FROM test_sample.all_types
LIMIT $5;
`, true, false, true, true, int64(2))
var dest []struct {
Eq1 *bool
Eq2 *bool
NEq1 *bool
NEq2 *bool
Distinct1 *bool
Distinct2 *bool
NotDistinct1 *bool
NotDistinct2 *bool
IsTrue *bool
IsNotTrue *bool
IsFalse *bool
IsNotFalse *bool
IsUnknown *bool
IsNotUnknown *bool
Complex1 *bool
Complex2 *bool
}
err := query.Query(db, &dest)
assert.NilError(t, err)
testutils.JsonPrint(dest)
testutils.AssertJSONFile(t, "./testdata/common_db_results/bool_operators.json", dest)
}
func TestFloatOperators(t *testing.T) {
@ -507,7 +553,7 @@ SELECT "subQuery"."all_types.boolean" AS "all_types.boolean",
"subQuery"."aliasedColumn" AS "aliasedColumn"
FROM`
testutils.AssertStatementSql(t, stmt1, expectedSQL+expected.sql+";\n", expected.args...)
testutils.AssertDebugStatementSql(t, stmt1, expectedSQL+expected.sql+";\n", expected.args...)
dest1 := []model.AllTypes{}
err := stmt1.Query(db, &dest1)
@ -530,7 +576,7 @@ FROM`
//fmt.Println(stmt2.DebugSql())
testutils.AssertStatementSql(t, stmt2, expectedSQL+expected.sql+";\n", expected.args...)
testutils.AssertDebugStatementSql(t, stmt2, expectedSQL+expected.sql+";\n", expected.args...)
dest2 := []model.AllTypes{}
err = stmt2.Query(db, &dest2)

View file

@ -16,7 +16,7 @@ func TestSelect(t *testing.T) {
SELECT(Album.AllColumns).
ORDER_BY(Album.AlbumId.ASC())
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT "Album"."AlbumId" AS "Album.AlbumId",
"Album"."Title" AS "Album.Title",
"Album"."ArtistId" AS "Album.ArtistId"
@ -126,7 +126,7 @@ func TestSelfJoin(t *testing.T) {
).
ORDER_BY(Employee.EmployeeId)
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT "Employee"."EmployeeId" AS "Employee.EmployeeId",
"Employee"."FirstName" AS "Employee.FirstName",
"Employee"."LastName" AS "Employee.LastName",
@ -210,7 +210,7 @@ func TestUnionForQuotedNames(t *testing.T) {
ORDER_BY(Album.AlbumId)
//fmt.Println(stmt.DebugSql())
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
(
(
SELECT "Album"."AlbumId" AS "Album.AlbumId",
@ -294,7 +294,7 @@ func TestSubQueriesForQuotedNames(t *testing.T) {
SELECT(first10Artist.AllColumns(), first10Albums.AllColumns()).
ORDER_BY(artistID)
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT "first10Artist"."Artist.ArtistId" AS "Artist.ArtistId",
"first10Artist"."Artist.Name" AS "Artist.Name",
"first10Albums"."Album.AlbumId" AS "Album.AlbumId",

View file

@ -22,7 +22,7 @@ WHERE link.name IN ('Gmail', 'Outlook');
DELETE().
WHERE(Link.Name.IN(String("Gmail"), String("Outlook")))
testutils.AssertStatementSql(t, deleteStmt, expectedSQL, "Gmail", "Outlook")
testutils.AssertDebugStatementSql(t, deleteStmt, expectedSQL, "Gmail", "Outlook")
assertExec(t, deleteStmt, 2)
}
@ -42,7 +42,7 @@ RETURNING link.id AS "link.id",
WHERE(Link.Name.IN(String("Gmail"), String("Outlook"))).
RETURNING(Link.AllColumns)
testutils.AssertStatementSql(t, deleteStmt, expectedSQL, "Gmail", "Outlook")
testutils.AssertDebugStatementSql(t, deleteStmt, expectedSQL, "Gmail", "Outlook")
dest := []model.Link{}

View file

@ -8,6 +8,9 @@
DROP TABLE IF EXISTS `all_types`;
CREATE TABLE `all_types` (
`boolean` BOOLEAN NOT NULL,
`boolean_ptr` BOOLEAN,
`tiny_int` TINYINT NOT NULL,
`utiny_int` TINYINT unsigned NOT NULL,
@ -107,8 +110,8 @@ CREATE TABLE `all_types` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
INSERT INTO `all_types` VALUES
(-3,3,-14,14,-150,150,-1600,1600,-17000,17000,-3,3,-14,14,-150,150,-1600,1600,-17000,17000,1.11,1.11,2.22,2.22,3.33,3.33,4.44,4.44,_binary '\0',_binary '\0','2008-07-04','2008-07-04','2011-12-18 13:17:17','2011-12-18 13:17:17','2007-12-31 23:00:01','2007-12-31 23:00:01',2004,2004,'char','char','varchar','varchar',_binary 'binary\0\0\0\0\0\0\0\0\0\0\0\0\0\0',_binary 'binary\0\0\0\0\0\0\0\0\0\0\0\0\0\0',_binary 'varbinary',_binary 'varbinary',_binary 'blob',_binary 'blob','text','text','value1','value1','s1','s2','{\"key1\": \"value1\", \"key2\": \"value2\"}','{\"key1\": \"value1\", \"key2\": \"value2\"}'),
(-3,3,-14,14,-150,150,-1600,1600,-17000,17000,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1.11,NULL,2.22,NULL,3.33,NULL,4.44,NULL,_binary '\0',NULL,'2008-07-04',NULL,'2011-12-18 13:17:17',NULL,'2007-12-31 23:00:01',NULL,2004,NULL,'char',NULL,'varchar',NULL,_binary 'binary\0\0\0\0\0\0\0\0\0\0\0\0\0\0',NULL,_binary 'varbinary',NULL,_binary 'blob',NULL,'text',NULL,'value1',NULL,'s1',NULL,'{\"key1\": \"value1\", \"key2\": \"value2\"}',NULL);
(false, true, -3,3,-14,14,-150,150,-1600,1600,-17000,17000,-3,3,-14,14,-150,150,-1600,1600,-17000,17000,1.11,1.11,2.22,2.22,3.33,3.33,4.44,4.44,_binary '\0',_binary '\0','2008-07-04','2008-07-04','2011-12-18 13:17:17','2011-12-18 13:17:17','2007-12-31 23:00:01','2007-12-31 23:00:01',2004,2004,'char','char','varchar','varchar',_binary 'binary\0\0\0\0\0\0\0\0\0\0\0\0\0\0',_binary 'binary\0\0\0\0\0\0\0\0\0\0\0\0\0\0',_binary 'varbinary',_binary 'varbinary',_binary 'blob',_binary 'blob','text','text','value1','value1','s1','s2','{\"key1\": \"value1\", \"key2\": \"value2\"}','{\"key1\": \"value1\", \"key2\": \"value2\"}'),
(false, NULL, -3,3,-14,14,-150,150,-1600,1600,-17000,17000,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,1.11,NULL,2.22,NULL,3.33,NULL,4.44,NULL,_binary '\0',NULL,'2008-07-04',NULL,'2011-12-18 13:17:17',NULL,'2007-12-31 23:00:01',NULL,2004,NULL,'char',NULL,'varchar',NULL,_binary 'binary\0\0\0\0\0\0\0\0\0\0\0\0\0\0',NULL,_binary 'varbinary',NULL,_binary 'blob',NULL,'text',NULL,'value1',NULL,'s1',NULL,'{\"key1\": \"value1\", \"key2\": \"value2\"}',NULL);

View file

@ -7,6 +7,7 @@ import (
"github.com/go-jet/jet/generator/mysql"
"github.com/go-jet/jet/generator/postgres"
"github.com/go-jet/jet/tests/dbconfig"
_ "github.com/go-sql-driver/mysql"
_ "github.com/lib/pq"
"io/ioutil"
"os"

View file

@ -31,7 +31,7 @@ RETURNING link.id AS "link.id",
VALUES(102, "http://www.yahoo.com", "Yahoo", nil).
RETURNING(Link.AllColumns)
testutils.AssertStatementSql(t, insertQuery, expectedSQL,
testutils.AssertDebugStatementSql(t, insertQuery, expectedSQL,
100, "http://www.postgresqltutorial.com", "PostgreSQL Tutorial",
101, "http://www.google.com", "Google",
102, "http://www.yahoo.com", "Yahoo", nil)
@ -85,7 +85,7 @@ INSERT INTO test_sample.link VALUES
stmt := Link.INSERT().
VALUES(100, "http://www.postgresqltutorial.com", "PostgreSQL Tutorial", DEFAULT)
testutils.AssertStatementSql(t, stmt, expectedSQL,
testutils.AssertDebugStatementSql(t, stmt, expectedSQL,
100, "http://www.postgresqltutorial.com", "PostgreSQL Tutorial")
assertExec(t, stmt, 1)
@ -107,7 +107,7 @@ INSERT INTO test_sample.link (url, name) VALUES
INSERT(Link.URL, Link.Name).
MODEL(linkData)
testutils.AssertStatementSql(t, query, expectedSQL, "http://www.duckduckgo.com", "Duck Duck go")
testutils.AssertDebugStatementSql(t, query, expectedSQL, "http://www.duckduckgo.com", "Duck Duck go")
assertExec(t, query, 1)
}
@ -129,7 +129,7 @@ INSERT INTO test_sample.link VALUES
INSERT().
MODEL(linkData)
testutils.AssertStatementSql(t, query, expectedSQL, int32(1000), "http://www.duckduckgo.com", "Duck Duck go", nil)
testutils.AssertDebugStatementSql(t, query, expectedSQL, int32(1000), "http://www.duckduckgo.com", "Duck Duck go", nil)
assertExec(t, query, 1)
}
@ -161,7 +161,7 @@ INSERT INTO test_sample.link (url, name) VALUES
INSERT(Link.URL, Link.Name).
MODELS([]model.Link{tutorial, google, yahoo})
testutils.AssertStatementSql(t, stmt, expectedSQL,
testutils.AssertDebugStatementSql(t, stmt, expectedSQL,
"http://www.postgresqltutorial.com", "PostgreSQL Tutorial",
"http://www.google.com", "Google",
"http://www.yahoo.com", "Yahoo")
@ -194,7 +194,7 @@ INSERT INTO test_sample.link (url, name, description) VALUES
MODEL(google).
MODELS([]model.Link{google, yahoo})
testutils.AssertStatementSql(t, stmt, expectedSQL,
testutils.AssertDebugStatementSql(t, stmt, expectedSQL,
"http://www.postgresqltutorial.com", "PostgreSQL Tutorial",
"http://www.google.com", "Google", nil,
"http://www.google.com", "Google", nil,
@ -231,7 +231,7 @@ RETURNING link.id AS "link.id",
).
RETURNING(Link.AllColumns)
testutils.AssertStatementSql(t, query, expectedSQL, int64(0))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(0))
dest := []model.Link{}

View file

@ -29,7 +29,7 @@ LOCK TABLE dvds.address IN`
for _, lockMode := range testData {
query := Address.LOCK().IN(lockMode)
testutils.AssertStatementSql(t, query, expectedSQL+" "+string(lockMode)+" MODE;\n")
testutils.AssertDebugStatementSql(t, query, expectedSQL+" "+string(lockMode)+" MODE;\n")
tx, _ := db.Begin()
@ -45,7 +45,7 @@ LOCK TABLE dvds.address IN`
for _, lockMode := range testData {
query := Address.LOCK().IN(lockMode).NOWAIT()
testutils.AssertStatementSql(t, query, expectedSQL+" "+string(lockMode)+" MODE NOWAIT;\n")
testutils.AssertDebugStatementSql(t, query, expectedSQL+" "+string(lockMode)+" MODE NOWAIT;\n")
tx, _ := db.Begin()

View file

@ -2,11 +2,9 @@ package mysql
import (
"database/sql"
"fmt"
"github.com/go-jet/jet/tests/dbconfig"
//_ "github.com/go-sql-driver/mysql"
_ "github.com/ziutek/mymysql/godrv"
_ "github.com/go-sql-driver/mysql"
"github.com/pkg/profile"
"os"
@ -18,10 +16,8 @@ var db *sql.DB
func TestMain(m *testing.M) {
defer profile.Start().Stop()
fmt.Println(dbconfig.MySQLConnectionString)
var err error
db, err = sql.Open("mysql", "jet:jet@tcp(localhost:3306)/")
db, err = sql.Open("mysql", dbconfig.MySQLConnectionString)
if err != nil {
panic("Failed to connect to test db" + err.Error())
}

View file

@ -1,14 +1,11 @@
package mysql
import (
"github.com/davecgh/go-spew/spew"
"github.com/go-jet/jet/internal/testutils"
. "github.com/go-jet/jet/mysql"
"gotest.tools/assert"
"reflect"
"github.com/go-jet/jet/tests/.gentestdata/sakila/model"
. "github.com/go-jet/jet/tests/.gentestdata/sakila/table"
"gotest.tools/assert"
"testing"
)
@ -20,9 +17,8 @@ SELECT DISTINCT actor.actor_id AS "actor.actor_id",
actor.last_name AS "actor.last_name",
actor.last_update AS "actor.last_update"
FROM sakila.actor
WHERE actor.actor_id = 1;
WHERE actor.actor_id = ?;
`
spew.Dump(reflect.TypeOf(db.Driver()).String())
query := Actor.
SELECT(Actor.AllColumns).

View file

@ -4,6 +4,9 @@ import (
"github.com/go-jet/jet/internal/testutils"
"github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/model"
. "github.com/go-jet/jet/tests/.gentestdata/mysql/test_sample/table"
. "github.com/go-jet/jet/mysql"
"gotest.tools/assert"
"testing"
)
@ -23,9 +26,83 @@ func TestAllTypes(t *testing.T) {
testutils.AssertJSON(t, dest, allTypesJson)
}
func TestBoolOperators(t *testing.T) {
query := AllTypes.SELECT(
AllTypes.Boolean.EQ(AllTypes.BooleanPtr).AS("EQ1"),
AllTypes.Boolean.EQ(Bool(true)).AS("EQ2"),
AllTypes.Boolean.NOT_EQ(AllTypes.BooleanPtr).AS("NEq1"),
AllTypes.Boolean.NOT_EQ(Bool(false)).AS("NEq2"),
AllTypes.Boolean.IS_DISTINCT_FROM(AllTypes.BooleanPtr).AS("distinct1"),
AllTypes.Boolean.IS_DISTINCT_FROM(Bool(true)).AS("distinct2"),
AllTypes.Boolean.IS_NOT_DISTINCT_FROM(AllTypes.BooleanPtr).AS("not_distinct_1"),
AllTypes.Boolean.IS_NOT_DISTINCT_FROM(Bool(true)).AS("NOTDISTINCT2"),
AllTypes.Boolean.IS_TRUE().AS("ISTRUE"),
AllTypes.Boolean.IS_NOT_TRUE().AS("isnottrue"),
AllTypes.Boolean.IS_FALSE().AS("is_False"),
AllTypes.Boolean.IS_NOT_FALSE().AS("is not false"),
AllTypes.Boolean.IS_UNKNOWN().AS("is unknown"),
AllTypes.Boolean.IS_NOT_UNKNOWN().AS("is_not_unknown"),
AllTypes.Boolean.AND(AllTypes.Boolean).EQ(AllTypes.Boolean.AND(AllTypes.Boolean)).AS("complex1"),
AllTypes.Boolean.OR(AllTypes.Boolean).EQ(AllTypes.Boolean.AND(AllTypes.Boolean)).AS("complex2"),
)
//fmt.Println(query.Sql())
testutils.AssertStatementSql(t, query, `
SELECT (all_types.boolean = all_types.boolean_ptr) AS "EQ1",
(all_types.boolean = ?) AS "EQ2",
(all_types.boolean != all_types.boolean_ptr) AS "NEq1",
(all_types.boolean != ?) AS "NEq2",
(NOT all_types.boolean <=> all_types.boolean_ptr) AS "distinct1",
(NOT all_types.boolean <=> ?) AS "distinct2",
(all_types.boolean <=> all_types.boolean_ptr) AS "not_distinct_1",
(all_types.boolean <=> ?) AS "NOTDISTINCT2",
all_types.boolean IS TRUE AS "ISTRUE",
all_types.boolean IS NOT TRUE AS "isnottrue",
all_types.boolean IS FALSE AS "is_False",
all_types.boolean IS NOT FALSE AS "is not false",
all_types.boolean IS UNKNOWN AS "is unknown",
all_types.boolean IS NOT UNKNOWN AS "is_not_unknown",
((all_types.boolean AND all_types.boolean) = (all_types.boolean AND all_types.boolean)) AS "complex1",
((all_types.boolean OR all_types.boolean) = (all_types.boolean AND all_types.boolean)) AS "complex2"
FROM test_sample.all_types;
`, true, false, true, true)
var dest []struct {
Eq1 *bool
Eq2 *bool
NEq1 *bool
NEq2 *bool
Distinct1 *bool
Distinct2 *bool
NotDistinct1 *bool
NotDistinct2 *bool
IsTrue *bool
IsNotTrue *bool
IsFalse *bool
IsNotFalse *bool
IsUnknown *bool
IsNotUnknown *bool
Complex1 *bool
Complex2 *bool
}
err := query.Query(db, &dest)
assert.NilError(t, err)
testutils.JsonPrint(dest)
testutils.AssertJSONFile(t, "./testdata/common_db_results/bool_operators.json", dest)
}
var allTypesJson = `
[
{
"Boolean": false,
"BooleanPtr": true,
"TinyInt": -3,
"UtinyInt": 3,
"SmallInt": -14,
@ -84,6 +161,8 @@ var allTypesJson = `
"JSONPtr": "{\"key1\": \"value1\", \"key2\": \"value2\"}"
},
{
"Boolean": false,
"BooleanPtr": null,
"TinyInt": -3,
"UtinyInt": 3,
"SmallInt": -14,

View file

@ -15,7 +15,7 @@ func TestUUIDType(t *testing.T) {
SELECT(AllTypes.UUID, AllTypes.UUIDPtr).
WHERE(AllTypes.UUID.EQ(String("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11")))
testutils.AssertStatementSql(t, query, `
testutils.AssertDebugStatementSql(t, query, `
SELECT all_types.uuid AS "all_types.uuid",
all_types.uuid_ptr AS "all_types.uuid_ptr"
FROM test_sample.all_types
@ -34,7 +34,7 @@ func TestEnumType(t *testing.T) {
query := Person.
SELECT(Person.AllColumns)
testutils.AssertStatementSql(t, query, `
testutils.AssertDebugStatementSql(t, query, `
SELECT person.person_id AS "person.person_id",
person.first_name AS "person.first_name",
person.last_name AS "person.last_name",
@ -98,7 +98,7 @@ ORDER BY employee.employee_id;
).
ORDER_BY(Employee.EmployeeID)
testutils.AssertStatementSql(t, query, expectedSQL)
testutils.AssertDebugStatementSql(t, query, expectedSQL)
type Manager model.Employee
@ -134,7 +134,7 @@ ORDER BY employee.employee_id;
func TestWierdNamesTable(t *testing.T) {
stmt := WeirdNamesTable.SELECT(WeirdNamesTable.AllColumns)
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT "WEIRD NAMES TABLE".weird_column_name1 AS "WEIRD NAMES TABLE.weird_column_name1",
"WEIRD NAMES TABLE"."Weird_Column_Name2" AS "WEIRD NAMES TABLE.Weird_Column_Name2",
"WEIRD NAMES TABLE"."wEiRd_cOluMn_nAmE3" AS "WEIRD NAMES TABLE.wEiRd_cOluMn_nAmE3",

View file

@ -25,7 +25,7 @@ WHERE actor.actor_id = 1;
DISTINCT().
WHERE(Actor.ActorID.EQ(Int(1)))
testutils.AssertStatementSql(t, query, expectedSQL, int64(1))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(1))
actor := model.Actor{}
err := query.Query(db, &actor)
@ -75,7 +75,7 @@ LIMIT 30;
ORDER_BY(Payment.PaymentID.ASC()).
LIMIT(30)
testutils.AssertStatementSql(t, query, expectedSQL, int64(30))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(30))
dest := []model.Payment{}
@ -104,7 +104,7 @@ ORDER BY customer.customer_id ASC;
query := Customer.SELECT(Customer.AllColumns).ORDER_BY(Customer.CustomerID.ASC())
testutils.AssertStatementSql(t, query, expectedSQL)
testutils.AssertDebugStatementSql(t, query, expectedSQL)
err := query.Query(db, &customers)
assert.NilError(t, err)
@ -157,7 +157,7 @@ LIMIT 12;
).
LIMIT(12)
testutils.AssertStatementSql(t, query, expectedSQL, int64(1), int64(1), int64(10), int64(1), int64(2), int64(1), int64(12))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(1), int64(1), int64(10), int64(1), int64(2), int64(1), int64(12))
}
func TestJoinQueryStruct(t *testing.T) {
@ -225,7 +225,7 @@ LIMIT 1000;
ORDER_BY(Film.FilmID.ASC()).
LIMIT(1000)
testutils.AssertStatementSql(t, query, expectedSQL, int64(1000))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(1000))
var languageActorFilm []struct {
model.Language
@ -291,7 +291,7 @@ LIMIT 15;
WHERE(Film.Rating.EQ(enum.MpaaRating.Nc17)).
LIMIT(15)
testutils.AssertStatementSql(t, query, expectedSQL, int64(15))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(15))
err := query.Query(db, &filmsPerLanguage)
@ -326,7 +326,7 @@ func TestExecution1(t *testing.T) {
WHERE(City.City.EQ(String("London")).OR(City.City.EQ(String("York")))).
ORDER_BY(City.CityID, Address.AddressID, Customer.CustomerID)
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT city.city_id AS "city.city_id",
city.city AS "city.city",
address.address_id AS "address.address_id",
@ -400,7 +400,7 @@ func TestExecution2(t *testing.T) {
WHERE(City.City.EQ(String("London")).OR(City.City.EQ(String("York")))).
ORDER_BY(City.CityID, Address.AddressID, Customer.CustomerID)
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT city.city_id AS "my_city.id",
city.city AS "myCity.Name",
address.address_id AS "My_Address.id",
@ -458,7 +458,7 @@ func TestExecution3(t *testing.T) {
WHERE(City.City.EQ(String("London")).OR(City.City.EQ(String("York")))).
ORDER_BY(City.CityID, Address.AddressID, Customer.CustomerID)
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT city.city_id AS "city_id",
city.city AS "city_name",
customer.customer_id AS "customer_id",
@ -515,7 +515,7 @@ func TestExecution4(t *testing.T) {
WHERE(City.City.EQ(String("London")).OR(City.City.EQ(String("York")))).
ORDER_BY(City.CityID, Address.AddressID, Customer.CustomerID)
testutils.AssertStatementSql(t, stmt, `
testutils.AssertDebugStatementSql(t, stmt, `
SELECT city.city_id AS "city.city_id",
city.city AS "city.city",
customer.customer_id AS "customer.customer_id",
@ -686,7 +686,7 @@ ORDER BY customer.customer_id ASC;
SELECT(Customer.AllColumns, Address.AllColumns).
ORDER_BY(Customer.CustomerID.ASC())
testutils.AssertStatementSql(t, query, expectedSQL)
testutils.AssertDebugStatementSql(t, query, expectedSQL)
allCustomersAndAddress := []struct {
Address *model.Address
@ -739,7 +739,7 @@ LIMIT 1000;
ORDER_BY(Customer.CustomerID.ASC()).
LIMIT(1000)
testutils.AssertStatementSql(t, query, expectedSQL, int64(1000))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(1000))
var customerAddresCrosJoined []struct {
model.Customer
@ -794,7 +794,7 @@ ORDER BY f1.film_id ASC;
SELECT(f1.AllColumns, f2.AllColumns).
ORDER_BY(f1.FilmID.ASC())
testutils.AssertStatementSql(t, query, expectedSQL)
testutils.AssertDebugStatementSql(t, query, expectedSQL)
type F1 model.Film
type F2 model.Film
@ -836,7 +836,7 @@ LIMIT 1000;
ORDER_BY(f1.Length.ASC(), f1.Title.ASC(), f2.Title.ASC()).
LIMIT(1000)
testutils.AssertStatementSql(t, query, expectedSQL, int64(1000))
testutils.AssertDebugStatementSql(t, query, expectedSQL, int64(1000))
type thesameLengthFilms struct {
Title1 string
@ -898,7 +898,7 @@ FROM dvds.actor
rRatingFilms.AllColumns(),
)
testutils.AssertStatementSql(t, query, expectedQuery)
testutils.AssertDebugStatementSql(t, query, expectedQuery)
dest := []model.Actor{}
@ -916,7 +916,7 @@ FROM dvds.film;
MAXf(Film.RentalRate).AS("max_film_rate"),
)
testutils.AssertStatementSql(t, query, expectedQuery)
testutils.AssertDebugStatementSql(t, query, expectedQuery)
ret := struct {
MaxFilmRate float64
@ -961,7 +961,7 @@ ORDER BY film.film_id ASC;
WHERE(Film.RentalRate.EQ(maxFilmRentalRate)).
ORDER_BY(Film.FilmID.ASC())
testutils.AssertStatementSql(t, query, expectedSQL)
testutils.AssertDebugStatementSql(t, query, expectedSQL)
maxRentalRateFilms := []model.Film{}
err := query.Query(db, &maxRentalRateFilms)
@ -1019,7 +1019,7 @@ ORDER BY SUM(payment.amount) ASC;
SUMf(Payment.Amount).GT(Float(100)),
)
testutils.AssertStatementSql(t, customersPaymentQuery, expectedSQL, float64(100))
testutils.AssertDebugStatementSql(t, customersPaymentQuery, expectedSQL, float64(100))
type CustomerPaymentSum struct {
CustomerID int16
@ -1089,7 +1089,7 @@ ORDER BY customer_payment_sum."amount_sum" ASC;
).
ORDER_BY(amountSum.ASC())
testutils.AssertStatementSql(t, query, expectedSQL)
testutils.AssertDebugStatementSql(t, query, expectedSQL)
type CustomerWithAmounts struct {
Customer *model.Customer
@ -1174,7 +1174,7 @@ ORDER BY payment.payment_date ASC;
WHERE(Payment.PaymentDate.LT(Timestamp(2007, 02, 14, 22, 16, 01, 0))).
ORDER_BY(Payment.PaymentDate.ASC())
testutils.AssertStatementSql(t, query, expectedSQL, "2007-02-14 22:16:01.000")
testutils.AssertDebugStatementSql(t, query, expectedSQL, "2007-02-14 22:16:01.000")
payments := []model.Payment{}
@ -1228,7 +1228,7 @@ OFFSET 20;
LIMIT(10).
OFFSET(20)
testutils.AssertStatementSql(t, query, expectedQuery, float64(100), float64(200), int64(10), int64(20))
testutils.AssertDebugStatementSql(t, query, expectedQuery, float64(100), float64(200), int64(10), int64(20))
dest := []model.Payment{}
@ -1302,7 +1302,7 @@ LIMIT 20;
ORDER_BY(Payment.PaymentID.ASC()).
LIMIT(20)
testutils.AssertStatementSql(t, query, expectedQuery, int64(1), "ONE", int64(2), "TWO", int64(3), "THREE", "OTHER", int64(20))
testutils.AssertDebugStatementSql(t, query, expectedQuery, int64(1), "ONE", int64(2), "TWO", int64(3), "THREE", "OTHER", int64(20))
dest := []struct {
StaffIDNum string
@ -1338,7 +1338,7 @@ FOR`
for lockType, lockTypeStr := range getRowLockTestData() {
query.FOR(lockType)
testutils.AssertStatementSql(t, query, expectedSQL+" "+lockTypeStr+";\n", int64(3))
testutils.AssertDebugStatementSql(t, query, expectedSQL+" "+lockTypeStr+";\n", int64(3))
tx, _ := db.Begin()
@ -1354,7 +1354,7 @@ FOR`
for lockType, lockTypeStr := range getRowLockTestData() {
query.FOR(lockType.NOWAIT())
testutils.AssertStatementSql(t, query, expectedSQL+" "+lockTypeStr+" NOWAIT;\n", int64(3))
testutils.AssertDebugStatementSql(t, query, expectedSQL+" "+lockTypeStr+" NOWAIT;\n", int64(3))
tx, _ := db.Begin()
@ -1370,7 +1370,7 @@ FOR`
for lockType, lockTypeStr := range getRowLockTestData() {
query.FOR(lockType.SKIP_LOCKED())
testutils.AssertStatementSql(t, query, expectedSQL+" "+lockTypeStr+" SKIP LOCKED;\n", int64(3))
testutils.AssertDebugStatementSql(t, query, expectedSQL+" "+lockTypeStr+" SKIP LOCKED;\n", int64(3))
tx, _ := db.Begin()
@ -1441,7 +1441,7 @@ ORDER BY actor.actor_id ASC, film.film_id ASC;
Film.FilmID.ASC(),
)
testutils.AssertStatementSql(t, stmt, expectedSQL, "English", "Action", int64(180))
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, "English", "Action", int64(180))
var dest []struct {
model.Actor

View file

@ -0,0 +1,38 @@
[
{
"Eq1": false,
"Eq2": false,
"NEq1": true,
"NEq2": false,
"Distinct1": true,
"Distinct2": true,
"NotDistinct1": false,
"NotDistinct2": false,
"IsTrue": false,
"IsNotTrue": true,
"IsFalse": true,
"IsNotFalse": false,
"IsUnknown": false,
"IsNotUnknown": true,
"Complex1": true,
"Complex2": true
},
{
"Eq1": null,
"Eq2": false,
"NEq1": null,
"NEq2": false,
"Distinct1": true,
"Distinct2": true,
"NotDistinct1": false,
"NotDistinct2": false,
"IsTrue": false,
"IsNotTrue": true,
"IsFalse": true,
"IsNotFalse": false,
"IsUnknown": false,
"IsNotUnknown": true,
"Complex1": true,
"Complex2": true
}
]

View file

@ -24,7 +24,7 @@ UPDATE test_sample.link
SET (name, url) = ('Bong', 'http://bong.com')
WHERE link.name = 'Bing';
`
testutils.AssertStatementSql(t, query, expectedSQL, "Bong", "http://bong.com", "Bing")
testutils.AssertDebugStatementSql(t, query, expectedSQL, "Bong", "http://bong.com", "Bing")
assertExec(t, query, 1)
@ -69,7 +69,7 @@ SET (name, url) = ((
WHERE link.name = 'Bing';
`
testutils.AssertStatementSql(t, query, expectedSQL, "Bong", "Bing", "Bing")
testutils.AssertDebugStatementSql(t, query, expectedSQL, "Bong", "Bing", "Bing")
assertExec(t, query, 1)
}
@ -93,7 +93,7 @@ RETURNING link.id AS "link.id",
WHERE(Link.Name.EQ(String("Ask"))).
RETURNING(Link.AllColumns)
testutils.AssertStatementSql(t, stmt, expectedSQL, "DuckDuckGo", "http://www.duckduckgo.com", "Ask")
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, "DuckDuckGo", "http://www.duckduckgo.com", "Ask")
links := []model.Link{}
@ -127,7 +127,7 @@ SET (id, url, name, description) = (
)
WHERE link.id = 0;
`
testutils.AssertStatementSql(t, stmt, expectedSQL, int64(0), int64(0))
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, int64(0), int64(0))
assertExec(t, stmt, 1)
}
@ -152,7 +152,7 @@ SET (id, url, name, description) = (
)
WHERE link.id = 0;
`
testutils.AssertStatementSql(t, stmt, expectedSQL, int64(0), int64(0))
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, int64(0), int64(0))
assertExecErr(t, stmt, "pq: number of columns does not match number of values")
}
@ -176,7 +176,7 @@ UPDATE test_sample.link
SET (id, url, name, description) = (201, 'http://www.duckduckgo.com', 'DuckDuckGo', NULL)
WHERE link.id = 201;
`
testutils.AssertStatementSql(t, stmt, expectedSQL, int32(201), "http://www.duckduckgo.com", "DuckDuckGo", nil, int64(201))
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, int32(201), "http://www.duckduckgo.com", "DuckDuckGo", nil, int64(201))
assertExec(t, stmt, 1)
}
@ -203,7 +203,7 @@ UPDATE test_sample.link
SET (description, name, url) = (NULL, 'DuckDuckGo', 'http://www.duckduckgo.com')
WHERE link.id = 201;
`
testutils.AssertStatementSql(t, stmt, expectedSQL, nil, "DuckDuckGo", "http://www.duckduckgo.com", int64(201))
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, nil, "DuckDuckGo", "http://www.duckduckgo.com", int64(201))
assertExec(t, stmt, 1)
}
@ -239,7 +239,7 @@ UPDATE test_sample.link
SET (id, url, name, description, rel) = ('http://www.duckduckgo.com', 'DuckDuckGo', NULL, NULL)
WHERE link.id = 201;
`
testutils.AssertStatementSql(t, stmt, expectedSQL, "http://www.duckduckgo.com", "DuckDuckGo", nil, nil, int64(201))
testutils.AssertDebugStatementSql(t, stmt, expectedSQL, "http://www.duckduckgo.com", "DuckDuckGo", nil, nil, int64(201))
assertExecErr(t, stmt, "pq: number of columns does not match number of values")
}