Пример #1
0
// Execute a query with 1 or more parameters.
func (c *libpqConn) execParams(cmd string, args []driver.Value) (driver.Result, error) {
	// convert args into C array-of-strings
	cargs, err := buildCArgs(args)
	if err != nil {
		return nil, err
	}
	defer returnCharArrayToPool(len(args), cargs)

	ccmd := C.CString(cmd)
	defer C.free(unsafe.Pointer(ccmd))

	// execute
	cres := C.PQexecParams(c.db, ccmd, C.int(len(args)), nil, cargs, nil, nil, 0)
	defer C.PQclear(cres)
	if err = resultError(cres); err != nil {
		return nil, err
	}

	// get modified rows
	nrows, err := getNumRows(cres)
	if err != nil {
		return nil, err
	}

	return libpqResult(nrows), nil
}
Пример #2
0
func (c *driverConn) exec(stmt string, args []driver.Value) (cres *C.PGresult) {
	stmtstr := C.CString(stmt)
	defer C.free(unsafe.Pointer(stmtstr))
	if len(args) == 0 {
		cres = C.PQexec(c.db, stmtstr)
	} else {
		cargs := buildCArgs(args)
		defer C.freeCharArray(cargs, C.int(len(args)))
		cres = C.PQexecParams(c.db, stmtstr, C.int(len(args)), nil, cargs, nil, nil, 0)
	}
	return cres
}
Пример #3
0
func (c *Conn) exec(stmt string, params ...interface{}) (cres *C.PGresult) {
	stmtstr := C.CString(stmt)
	defer C.free(unsafe.Pointer(stmtstr))
	if len(params) == 0 {
		cres = C.PQexec(c.db, stmtstr)
	} else {
		cparams := buildCArgs(params...)
		defer C.freeCharArray(cparams, C.int(len(params)))
		cres = C.PQexecParams(c.db, stmtstr, C.int(len(params)), nil, cparams, nil, nil, 0)
	}
	return cres
}