Add FROM clause support for UPDATE statements
This commit is contained in:
parent
97c34fbb54
commit
72e8d7d584
11 changed files with 211 additions and 18 deletions
|
|
@ -70,3 +70,9 @@ func skipForMariaDB(t *testing.T) {
|
|||
t.SkipNow()
|
||||
}
|
||||
}
|
||||
|
||||
func beginTx(t *testing.T) *sql.Tx {
|
||||
tx, err := db.Begin()
|
||||
require.NoError(t, err)
|
||||
return tx
|
||||
}
|
||||
|
|
|
|||
|
|
@ -261,15 +261,22 @@ func TestUpdateExecContext(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestUpdateWithJoin(t *testing.T) {
|
||||
query := table.Staff.
|
||||
INNER_JOIN(table.Address, table.Address.AddressID.EQ(table.Staff.AddressID)).
|
||||
tx := beginTx(t)
|
||||
defer tx.Rollback()
|
||||
|
||||
statement := table.Staff.INNER_JOIN(table.Address, table.Address.AddressID.EQ(table.Staff.AddressID)).
|
||||
UPDATE(table.Staff.LastName).
|
||||
SET(String("New name")).
|
||||
SET(String("New staff name")).
|
||||
WHERE(table.Staff.StaffID.EQ(Int(1)))
|
||||
|
||||
//fmt.Println(query.DebugSql())
|
||||
testutils.AssertStatementSql(t, statement, `
|
||||
UPDATE dvds.staff
|
||||
INNER JOIN dvds.address ON (address.address_id = staff.address_id)
|
||||
SET last_name = ?
|
||||
WHERE staff.staff_id = ?;
|
||||
`, "New staff name", int64(1))
|
||||
|
||||
_, err := query.Exec(db)
|
||||
_, err := statement.Exec(tx)
|
||||
require.NoError(t, err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue