// 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 }
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 }
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 }