Commit b0918982 authored by gwenn's avatar gwenn

It seems that driver.Result LastInsertId/RowsAffected cannot be lazily evaluated.

It does not seem to be specify but it fails at runtime.
parent aa2760c3
...@@ -44,6 +44,19 @@ type rowsImpl struct { ...@@ -44,6 +44,19 @@ type rowsImpl struct {
columnNames []string // cache columnNames []string // cache
} }
type result struct {
id int64
rows int64
}
func (r *result) LastInsertId() (int64, error) {
return r.id, nil
}
func (r *result) RowsAffected() (int64, error) {
return r.rows, nil
}
// NewDriver creates a new driver with specialized connection creation/configuration. // NewDriver creates a new driver with specialized connection creation/configuration.
// NewDriver(customOpen, nil) // no post-creation hook // NewDriver(customOpen, nil) // no post-creation hook
// NewDriver(nil, customConfigure) // default connection creation but specific configuration step // NewDriver(nil, customConfigure) // default connection creation but specific configuration step
...@@ -105,7 +118,7 @@ func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) { ...@@ -105,7 +118,7 @@ func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
if err := c.c.FastExec(query); err != nil { if err := c.c.FastExec(query); err != nil {
return nil, err return nil, err
} }
return c, nil return c.c.result(), nil
} }
// https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices // https://code.google.com/p/go-wiki/wiki/cgo#Turning_C_arrays_into_Go_slices
var iargs []interface{} var iargs []interface{}
...@@ -116,17 +129,7 @@ func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) { ...@@ -116,17 +129,7 @@ func (c *conn) Exec(query string, args []driver.Value) (driver.Result, error) {
if err := c.c.Exec(query, iargs...); err != nil { if err := c.c.Exec(query, iargs...); err != nil {
return nil, err return nil, err
} }
return c, nil // FIXME RowAffected/noRows return c.c.result(), nil
}
// TODO How to know that the last Stmt has done an INSERT? An authorizer?
func (c *conn) LastInsertId() (int64, error) {
return c.c.LastInsertRowid(), nil
}
// TODO How to know that the last Stmt has done a DELETE/INSERT/UPDATE? An authorizer?
func (c *conn) RowsAffected() (int64, error) {
return int64(c.c.Changes()), nil
} }
func (c *conn) Prepare(query string) (driver.Stmt, error) { func (c *conn) Prepare(query string) (driver.Stmt, error) {
...@@ -180,17 +183,7 @@ func (s *stmt) Exec(args []driver.Value) (driver.Result, error) { ...@@ -180,17 +183,7 @@ func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
if err := s.s.exec(); err != nil { if err := s.s.exec(); err != nil {
return nil, err return nil, err
} }
return s, nil // FIXME RowAffected/noRows return s.s.c.result(), nil
}
// TODO How to know that this Stmt has done an INSERT? An authorizer?
func (s *stmt) LastInsertId() (int64, error) {
return s.s.c.LastInsertRowid(), nil
}
// TODO How to know that this Stmt has done a DELETE/INSERT/UPDATE? An authorizer?
func (s *stmt) RowsAffected() (int64, error) {
return int64(s.s.c.Changes()), nil
} }
func (s *stmt) Query(args []driver.Value) (driver.Rows, error) { func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
...@@ -244,3 +237,11 @@ func (r *rowsImpl) Close() error { ...@@ -244,3 +237,11 @@ func (r *rowsImpl) Close() error {
} }
return r.s.s.Reset() return r.s.s.Reset()
} }
func (c *Conn) result() driver.Result {
// TODO How to know that the last Stmt has done an INSERT? An authorizer?
id := c.LastInsertRowid()
// TODO How to know that the last Stmt has done a DELETE/INSERT/UPDATE? An authorizer?
rows := int64(c.Changes())
return &result{id, rows} // FIXME RowAffected/noRows
}
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