Example #1
0
File: driver.go Project: rsc/sqlite
func (s *stmt) Exec(args []driver.Value) (driver.Result, error) {
	if s.closed {
		panic("database/sql/driver: misuse of sqlite driver: Exec after Close")
	}
	if s.rows {
		panic("database/sql/driver: misuse of sqlite driver: Exec with active Rows")
	}

	err := s.start(args)
	if err != nil {
		return nil, err
	}

	rv := C.sqlite3_step(s.stmt)
	if errno(rv) != stepDone {
		if rv == 0 {
			rv = 21 // errMisuse
		}
		return nil, s.c.error(rv)
	}

	id := int64(C.sqlite3_last_insert_rowid(s.c.db))
	rows := int64(C.sqlite3_changes(s.c.db))
	return &result{id, rows}, nil
}
Example #2
0
func (stmt Stmt) Exec(args []driver.Value) (driver.Result, error) {
	if err := stmt.bind(args); err != nil {
		return nil, err
	}

	r := C.sqlite3_step(stmt.stmt)
	db := C.sqlite3_db_handle(stmt.stmt)

	if r != C.SQLITE_DONE && r != C.SQLITE_ROW {
		return nil, dbError(db)
	}

	var result Result
	result.rowsAffected = int64(C.sqlite3_changes(db))
	result.lastInsertId = int64(C.sqlite3_last_insert_rowid(db))
	return &result, nil
}
Example #3
0
// LastInsertRowid returns the rowid of the most recent successful INSERT into the database.
// If a separate thread performs a new INSERT on the same database connection while the LastInsertRowid() function is running and thus changes the last insert rowid, then the value returned by LastInsertRowid() is unpredictable and might not equal either the old or the new last insert rowid.
// (See http://sqlite.org/c3ref/last_insert_rowid.html)
func (c *Conn) LastInsertRowid() int64 {
	return int64(C.sqlite3_last_insert_rowid(c.db))
}
Example #4
0
func (self *sqlConnection) sqlLastInsertRowId() int64 {
	return int64(C.sqlite3_last_insert_rowid(self.handle))
}
Example #5
0
func (r *SQLiteResult) LastInsertId() (int64, error) {
	var rr int64
	rr = int64(C.sqlite3_last_insert_rowid(r.s.c.db))
	return rr, nil
}
Example #6
0
func (h *Handle) LastInsertRowID() int64 {
	return int64(C.sqlite3_last_insert_rowid(h.cptr))
}
Example #7
0
func (r *SQLiteResult) LastInsertId() (int64, error) {
	return int64(C.sqlite3_last_insert_rowid(r.s.c.db)), nil
}
Example #8
0
func (db *Database) LastInsertRowID() int64 {
	return int64(C.sqlite3_last_insert_rowid(db.handle))
}
Example #9
0
// LastInsertId returns the ROWID of the most recent successful INSERT
// statement.
// [http://www.sqlite.org/c3ref/last_insert_rowid.html]
func (c *Conn) LastInsertId() int64 {
	if c.db == nil {
		return 0
	}
	return int64(C.sqlite3_last_insert_rowid(c.db))
}