Unverified Commit 11f89f7e authored by Henry's avatar Henry Committed by GitHub

Merge pull request #192 from cryptix/issue190

issue190: add test to show argument order issue
parents 8c32ff10 835399b2
......@@ -10,6 +10,7 @@ Boy van Duuren <[email protected]>
Dan Kortschak <[email protected]>
Donald Brower <[email protected]>
Geofrey Ernest <[email protected]>
Henry Bubert <[email protected]>
Jan Mercl <[email protected]>
Michael Eisendle <[email protected]>
OpenNota <[email protected]>
......
......@@ -3444,6 +3444,117 @@ func TestIssue142(t *testing.T) {
}
}
// Both of the UPDATEs _should_ work but the 2nd one results in a _type missmatch_ error at the time of writing.
// see https://github.com/cznic/ql/issues/190
func TestIssue190(t *testing.T) {
RegisterMemDriver()
db, err := sql.Open("ql-mem", "mem.test")
if err != nil {
t.Fatal(err)
}
// prepare db
tx, err := db.Begin()
if err != nil {
t.Fatal(err)
}
const createStmt = `CREATE TABLE issue190 (
Number float64,
Comment string
); `
_, err = tx.Exec(createStmt)
if err != nil {
t.Fatal(err)
}
const insertStmt = `INSERT INTO issue190 (Number,Comment) VALUES($1,$2);`
insStmt, err := tx.Prepare(insertStmt)
if err != nil {
t.Fatal(err)
}
defer insStmt.Close()
res, err := insStmt.Exec(0.1, "hello ql")
if err != nil {
t.Fatal(err)
}
pid, err := res.LastInsertId()
if err != nil {
t.Fatal(err)
}
err = tx.Commit()
if err != nil {
t.Fatal(err)
}
// run working
tx, err = db.Begin()
if err != nil {
t.Fatal(err)
}
const updateWorks = `
UPDATE issue190
SET
Number = $1,
Comment = $2
WHERE id() == $3;`
stmt, err := tx.Prepare(updateWorks)
if err != nil {
t.Fatal(err)
}
defer stmt.Close()
res, err = stmt.Exec(0.01, "hello QL", pid)
if err != nil {
t.Fatal(err)
}
cnt, err := res.RowsAffected()
if err != nil {
t.Fatal(err)
}
err = tx.Commit()
if err != nil {
t.Fatal(err)
}
if cnt != 1 {
t.Errorf("affected: %d\n", cnt)
}
// this updates leads to the following error
// invalid operation: 1 == 4.05 (mismatched types int64 and float64)
tx, err = db.Begin()
if err != nil {
t.Fatal(err)
}
const updateWithTypeMissmatch = `
UPDATE issue190
SET
Comment = $2,
Number = $3
WHERE id() == $1;`
stmt, err = tx.Prepare(updateWithTypeMissmatch)
if err != nil {
t.Fatal(err)
}
defer stmt.Close()
res, err = stmt.Exec(pid, "HELLO ql", 4.05)
if err != nil {
t.Fatal(err)
}
cnt, err = res.RowsAffected()
if err != nil {
t.Fatal(err)
}
err = tx.Commit()
if err != nil {
t.Fatal(err)
}
if cnt != 1 {
t.Errorf("affected: %d\n", cnt)
}
if err := db.Close(); err != nil {
t.Fatal(err)
}
}
func TestWhereExists(t *testing.T) {
RegisterMemDriver()
db, err := sql.Open("ql-mem", "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment