示例#1
0
func newResult(res *C.PGresult) *driverRows {
	ncols := int(C.PQnfields(res))
	nrows := int(C.PQntuples(res))
	result := &driverRows{res: res, nrows: nrows, currRow: -1, ncols: ncols, cols: nil}
	runtime.SetFinalizer(result, (*driverRows).Close)
	return result
}
示例#2
0
func newResult(res *C.PGresult) *Result {
	ncols := int(C.PQnfields(res))
	nrows := int(C.PQntuples(res))
	result := &Result{res: res, nrows: nrows, currRow: -1, ncols: ncols, cols: nil}
	runtime.SetFinalizer(result, (*Result).Clear)
	return result
}
示例#3
0
文件: pq.go 项目: dvarrazzo/pger
func columns(r *PgRows) []string {
	nfields := int(C.PQnfields(r.result))
	rv := make([]string, nfields)
	for i := 0; i < nfields; i++ {
		rv[i] = C.GoString(C.PQfname(r.result, C.int(i)))
	}
	return rv
}
示例#4
0
func (s *libpqStmt) Query(args []driver.Value) (driver.Rows, error) {
	// execute prepared statement
	cres, err := s.exec(args)
	if err != nil {
		return nil, err
	}

	// check to see if this was a "LISTEN"
	if C.GoString(C.PQcmdStatus(cres)) == "LISTEN" {
		C.PQclear(cres)
		return &libpqListenRows{s.c}, nil
	}

	return &libpqRows{
		s:       s,
		res:     cres,
		ncols:   int(C.PQnfields(cres)),
		nrows:   int(C.PQntuples(cres)),
		currRow: 0,
		cols:    nil,
	}, nil
}