Example #1
0
func getNumRows(cres *C.PGresult) (int64, error) {
	rowstr := C.GoString(C.PQcmdTuples(cres))
	if rowstr == "" {
		return 0, nil
	}

	return strconv.ParseInt(rowstr, 10, 64)
}
Example #2
0
func (s *driverStmt) Exec(args []driver.Value) (res driver.Result, err error) {
	cres := s.exec(args)
	if err = resultError(cres); err != nil {
		C.PQclear(cres)
		return
	}
	defer C.PQclear(cres)
	rowsAffected, err := strconv.ParseInt(C.GoString(C.PQcmdTuples(cres)), 10, 64)
	if err != nil {
		return
	}
	return driver.RowsAffected(rowsAffected), nil
}
Example #3
0
File: pq.go Project: dvarrazzo/pger
func exec(stmt PgStmt, values []driver.Value) (*PgResult, error) {
	res, err := exec_prepared(stmt, values)
	if err != nil {
		return &PgResult{}, err
	}
	defer pqclear(res)

	tuples := C.GoString(C.PQcmdTuples(res))
	lastoid := uint(C.PQoidValue(res))

	rv := PgResult{tuples: tuples, lastoid: lastoid}
	return &rv, nil
}
Example #4
0
func (c *driverConn) Exec(query string, args []driver.Value) (res driver.Result, err error) {
	cres := c.exec(query, args)
	if err = resultError(cres); err != nil {
		C.PQclear(cres)
		return
	}
	defer C.PQclear(cres)
	ns := C.GoString(C.PQcmdTuples(cres))
	if ns == "" {
		return driver.ResultNoRows, nil
	}
	rowsAffected, err := strconv.ParseInt(ns, 10, 64)
	if err != nil {
		return
	}
	return driver.RowsAffected(rowsAffected), nil
}