From 7211b7212b6379501cf9beecac814c21223beda3 Mon Sep 17 00:00:00 2001 From: mattn Date: Mon, 14 Nov 2011 22:10:13 +0900 Subject: [PATCH] last inserted row ID, affected rows. --- sqlite3.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index 58f93f6..25b646f 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -193,6 +193,18 @@ func (s *SQLiteStmt) Query(args []interface{}) (driver.Rows, error) { return &SQLiteRows{s, int(C.sqlite3_column_count(s.s)), nil}, nil } +type SQLiteResult struct { + s *SQLiteStmt +} + +func (r *SQLiteResult) LastInsertId() (int64, error) { + return int64(C.sqlite3_last_insert_rowid(r.s.s)), nil +} + +func (r *SQLiteResult) RowsAffected() (int64, error) { + return int64(C.sqlite3_changes(r.s.s)), nil +} + func (s *SQLiteStmt) Exec(args []interface{}) (driver.Result, error) { if err := s.bind(args); err != nil { return nil, err @@ -201,7 +213,7 @@ func (s *SQLiteStmt) Exec(args []interface{}) (driver.Result, error) { if rv != C.SQLITE_ROW && rv != C.SQLITE_OK && rv != C.SQLITE_DONE { return nil, errors.New(C.GoString(C.sqlite3_errmsg(s.c.db))) } - return driver.DDLSuccess, nil + return &SQLiteResult {s}, nil } type SQLiteRows struct {