Exemplo n.º 1
0
func (s *driverStmt) exec(params []driver.Value) *C.PGresult {
	stmtName := C.CString(s.name)
	defer C.free(unsafe.Pointer(stmtName))
	cparams := buildCArgs(params)
	defer C.freeCharArray(cparams, C.int(len(params)))
	return C.PQexecPrepared(s.db, stmtName, C.int(len(params)), cparams, nil, nil, 0)
}
Exemplo n.º 2
0
func (s *Statement) exec(params ...interface{}) *C.PGresult {
	stmtName := C.CString(s.name)
	defer C.free(unsafe.Pointer(stmtName))
	cparams := buildCArgs(params...)
	defer C.freeCharArray(cparams, C.int(len(params)))
	return C.PQexecPrepared(s.db, stmtName, C.int(len(params)), cparams, nil, nil, 0)
}
Exemplo n.º 3
0
func (s *libpqStmt) exec(args []driver.Value) (*C.PGresult, error) {
	// if we have no arguments, use plain exec instead of more complicated PQexecPrepared
	if len(args) == 0 {
		if s.cquery == nil {
			s.cquery = C.CString(s.query)
		}
		cres := C.PQexec(s.c.db, s.cquery)
		if err := resultError(cres); err != nil {
			C.PQclear(cres)
			return nil, err
		}
		return cres, nil
	}

	// convert args into C array-of-strings
	cargs, err := buildCArgs(args)
	if err != nil {
		return nil, err
	}
	defer returnCharArrayToPool(len(args), cargs)

	// execute
	cres := C.PQexecPrepared(s.c.db, s.name, C.int(len(args)), cargs, nil, nil, 0)
	if err = resultError(cres); err != nil {
		C.PQclear(cres)
		return nil, err
	}
	return cres, nil
}
Exemplo n.º 4
0
func (s *libpqStmt) exec(args []driver.Value) (*C.PGresult, error) {
	// convert args into C array-of-strings
	cargs, err := buildCArgs(args)
	if err != nil {
		return nil, err
	}
	defer returnCharArrayToPool(len(args), cargs)

	// execute
	cres := C.PQexecPrepared(s.c.db, s.name, C.int(len(args)), cargs, nil, nil, 0)
	if err = resultError(cres); err != nil {
		C.PQclear(cres)
		return nil, err
	}
	return cres, nil
}
Exemplo n.º 5
0
Arquivo: pq.go Projeto: dvarrazzo/pger
func exec_prepared(stmt PgStmt, values []driver.Value) (*C.PGresult, error) {
	conn := stmt.conn
	params, err := AdaptValues(values, conn)
	if err != nil {
		return nil, err
	}

	name := C.CString(stmt.name)
	defer C.free(unsafe.Pointer(name))

	cparams := charpp(params)
	defer charppFree(cparams, len(params))

	// TODO: binary params
	// TODO: binary results
	res := C.PQexecPrepared(conn.conn, name, C.int(len(params)),
		cparams, nil, nil, C.int(0))
	if err := errorFromPGresult(res); err != nil {
		pqclear(res)
		return nil, err
	}

	return res, nil
}