Exemplo n.º 1
0
Arquivo: driver.go Projeto: 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
}
Exemplo n.º 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
}
Exemplo n.º 3
0
// Changes returns the number of database rows that were changed or inserted or deleted by the most recently completed SQL statement on the database connection.
// If a separate thread makes changes on the same database connection while Changes() is running then the value returned is unpredictable and not meaningful.
// (See http://sqlite.org/c3ref/changes.html)
func (c *Conn) Changes() int {
	return int(C.sqlite3_changes(c.db))
}
Exemplo n.º 4
0
func (self *sqlConnection) sqlChanges() int {
	return int(C.sqlite3_changes(self.handle))
}
Exemplo n.º 5
0
func (r *SQLiteResult) RowsAffected() (int64, error) {
	return int64(C.sqlite3_changes(r.s.c.db)), nil
}
Exemplo n.º 6
0
func (h *Handle) Changes() int {
	return int(C.sqlite3_changes(h.cptr))
}
Exemplo n.º 7
0
func (db *Database) Changes() int {
	return int(C.sqlite3_changes(db.handle))
}
Exemplo n.º 8
0
// RowsAffected returns the number of rows that were changed, inserted, or
// deleted by the most recent statement. Auxiliary changes caused by triggers or
// foreign key actions are not counted.
// [http://www.sqlite.org/c3ref/changes.html]
func (c *Conn) RowsAffected() int {
	if c.db == nil {
		return 0
	}
	return int(C.sqlite3_changes(c.db))
}