示例#1
0
文件: oci8.go 项目: AsamQi/go-oci8
func (c *OCI8Conn) Prepare(query string) (driver.Stmt, error) {
	pquery := C.CString(query)
	defer C.free(unsafe.Pointer(pquery))
	var s, bp, defp unsafe.Pointer

	if rv := C.WrapOCIHandleAlloc(
		c.env,
		C.OCI_HTYPE_STMT,
		(C.size_t)(unsafe.Sizeof(bp)*2)); rv.rv != C.OCI_SUCCESS {
		return nil, ociGetError(c.err)
	} else {
		s = rv.ptr
		bp = rv.extra
		defp = unsafe.Pointer(uintptr(rv.extra) + unsafe.Sizeof(unsafe.Pointer(nil)))
	}

	if rv := C.OCIStmtPrepare(
		(*C.OCIStmt)(s),
		(*C.OCIError)(c.err),
		(*C.OraText)(unsafe.Pointer(pquery)),
		C.ub4(C.strlen(pquery)),
		C.ub4(C.OCI_NTV_SYNTAX),
		C.ub4(C.OCI_DEFAULT)); rv != C.OCI_SUCCESS {
		return nil, ociGetError(c.err)
	}

	ss := &OCI8Stmt{c: c, s: s, bp: (**C.OCIBind)(bp), defp: (**C.OCIDefine)(defp)}
	runtime.SetFinalizer(ss, (*OCI8Stmt).Close)
	return ss, nil
}
示例#2
0
func (c *ConnectionOracle) NewStatement(sql string) (s *StatementOracle, err int) {

	s = new(StatementOracle)
	pStatement := unsafe.Pointer(&s.hStatement)
	res := C.OCIHandleAlloc(unsafe.Pointer(c.driver.hEnv), (*unsafe.Pointer)(pStatement), C.OCI_HTYPE_STMT, 0, nil)
	if C.OCI_SUCCESS != res /*&& C.OCI_STILL_EXECUTING != res*/ {
		fmt.Printf("Result hSession=%v\n", res)
		C.AuxOCIErrorGet(c.driver.hError)
		return nil, -1
	}

	cSql := C.CString(sql)
	defer C.free(unsafe.Pointer(cSql))
	var osql *C.OraText = C.Get_OraText(cSql)
	//fmt.Printf( "%v:%v\n", C.strlen(sql), C.GoString(sql))
	res = C.OCIStmtPrepare(s.hStatement, c.driver.hError, osql, C.ub4(C.strlen(cSql)), C.OCI_NTV_SYNTAX, C.OCI_DEFAULT)
	if C.OCI_SUCCESS != res /*&& C.OCI_STILL_EXECUTING != res*/ {
		fmt.Printf("Resultado OCIStmtPrepare=%v\n", res)
		C.AuxOCIErrorGet(c.driver.hError)
		return nil, -2
	}
	s.fetchDone = false
	s.con = c
	return s, 0
}
示例#3
0
文件: oci8.go 项目: supiyun/go-oci8
func (c *OCI8Conn) Prepare(query string) (driver.Stmt, error) {
	pquery := C.CString(query)
	defer C.free(unsafe.Pointer(pquery))
	var s unsafe.Pointer

	rv := C.OCIHandleAlloc(
		c.env,
		&s,
		C.OCI_HTYPE_STMT,
		0,
		nil)
	if rv == C.OCI_ERROR {
		return nil, ociGetError(c.err)
	}

	rv = C.OCIStmtPrepare(
		(*C.OCIStmt)(s),
		(*C.OCIError)(c.err),
		(*C.OraText)(unsafe.Pointer(pquery)),
		C.ub4(C.strlen(pquery)),
		C.ub4(C.OCI_NTV_SYNTAX),
		C.ub4(OCI_MODE))
	if rv == C.OCI_ERROR {
		return nil, ociGetError(c.err)
	}

	return &OCI8Stmt{c: c, s: s}, nil
}
示例#4
0
文件: oci8.go 项目: kwargs/go-oci8
func (conn *OCI8Conn) Prepare(query string) (driver.Stmt, error) {
	pquery := C.CString(query)
	defer C.free(unsafe.Pointer(pquery))
	var s unsafe.Pointer

	rv := C.OCIHandleAlloc(
		conn.env,
		&s,
		C.OCI_HTYPE_STMT,
		0,
		nil)

	if err := conn.check(rv, "OCI8Conn.Prepare() allocate statement handle"); err != nil {
		return nil, err
	}

	rv = C.OCIStmtPrepare(
		(*C.OCIStmt)(s),
		(*C.OCIError)(conn.err),
		(*C.OraText)(unsafe.Pointer(pquery)),
		C.ub4(C.strlen(pquery)),
		C.ub4(C.OCI_NTV_SYNTAX),
		C.ub4(C.OCI_DEFAULT))

	if err := conn.check(rv, "OCI8Conn.Prepare() prepare statement"); err != nil {
		return nil, err
	}

	return &OCI8Stmt{c: conn, s: s}, nil
}
示例#5
0
文件: conn.go 项目: jeffycf/goci-1
func (conn *connection) Prepare(query string) (driver.Stmt, error) {
	pquery := C.CString(query)
	defer C.free(unsafe.Pointer(pquery))
	var stmt unsafe.Pointer

	if C.OCIHandleAlloc(conn.env, &stmt, C.OCI_HTYPE_STMT, 0, nil) != C.OCI_SUCCESS {
		return nil, ociGetError(conn.err)
	}
	result := C.OCIStmtPrepare((*C.OCIStmt)(stmt), (*C.OCIError)(conn.err),
		(*C.OraText)(unsafe.Pointer(pquery)), C.ub4(C.strlen(pquery)),
		C.ub4(C.OCI_NTV_SYNTAX), C.ub4(C.OCI_DEFAULT))
	if result != C.OCI_SUCCESS {
		return nil, ociGetError(conn.err)
	}
	return &statement{handle: stmt, conn: conn}, nil
}