nakagami / firebirdsql

Firebird RDBMS sql driver for Go (golang)
MIT License
229 stars 60 forks source link

RETURNING clause in INSERT statements #1

Closed ghost closed 10 years ago

ghost commented 10 years ago

It seems that Statement.Exec returns an empty Result instance with the LastInsertId and RowsAffected set explicitly to 0. Is there any chance to make this work with the RETURNING statement? E.g.:

res, err := db.Exec("INSERT INTO foo(a, b) VALUES(?, ?) RETURNING id", a, b)
...
_ = res.LastInsertId()
nakagami commented 10 years ago

Sorry LastInsertID() always return -1 (modified from return 0) beause Firebird can't return rowid

RowAffected() now return correct value (fixed)

ghost commented 10 years ago

Thanks. Firebird not returning the last insert id, is that a problem with protocol itself? Because this seems like it could potentially be a pretty big issue.

nakagami commented 10 years ago

OTH "insert .. returning ... "statement can get optional row value like select

https://github.com/nakagami/firebirdsql/blob/master/driver_test.go#L126

Regards

ghost commented 10 years ago

Aah. excellent. Thanks!