예제 #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)
}
예제 #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
}
예제 #3
0
파일: pq.go 프로젝트: 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
}
예제 #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
}