PageRenderTime 15ms CodeModel.GetById 1ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/ConnectionOracle.go

http://go-db-oracle.googlecode.com/
Go | 63 lines | 33 code | 13 blank | 17 comment | 4 complexity | a73c95f4d5e216bab8f537c4080d3f9e MD5 | raw file
 1// Copyright 2011 Antonio Diaz Gil. All rights reserved.
 2
 3package dboracle
 4
 5
 6
 7/*
 8#cgo CFLAGS: -I/opt/oracle/include
 9#cgo LDFLAGS: -lclntsh -L/opt/oracle/lib32
10
11#include <oci.h>
12//#include <oratypes.h>
13#include <stdlib.h>
14#include <string.h>
15
16extern void AuxOCIErrorGet( OCIError *hError);
17extern OraText *Get_OraText( char* str);
18
19*/
20import "C"
21
22
23import (
24//    "os"
25    "fmt"
26    "unsafe"
27)
28 
29
30type ConnectionOracle struct {
31	driver *DriverOracle
32	
33	hServer *C.OCIServer
34    hSession *C.OCISession
35	//hError *C.OCIError
36}
37
38func (c *ConnectionOracle) NewStatement( sql string) (s *StatementOracle, err int) {
39
40	s = new(StatementOracle)
41    pStatement := unsafe.Pointer(&s.hStatement)
42    res := C.OCIHandleAlloc( unsafe.Pointer(c.driver.hEnv), (*unsafe.Pointer)(pStatement), C.OCI_HTYPE_STMT, 0, nil);
43    if (C.OCI_SUCCESS != res /*&& C.OCI_STILL_EXECUTING != res*/) {
44 		fmt.Printf( "Result hSession=%v\n", res)
45     	C.AuxOCIErrorGet( c.driver.hError);
46     	return nil, -1
47    }
48
49    cSql := C.CString( sql)
50    defer C.free( unsafe.Pointer(cSql))
51    var osql *C.OraText = C.Get_OraText( cSql)
52//fmt.Printf( "%v:%v\n", C.strlen(sql), C.GoString(sql))
53    res = C.OCIStmtPrepare(s.hStatement, c.driver.hError, osql, C.ub4(C.strlen(cSql)), C.OCI_NTV_SYNTAX, C.OCI_DEFAULT);
54    if (C.OCI_SUCCESS != res /*&& C.OCI_STILL_EXECUTING != res*/) {
55 		fmt.Printf( "Resultado OCIStmtPrepare=%v\n", res)
56     	C.AuxOCIErrorGet( c.driver.hError);
57     	return nil, -2
58    }
59    s.fetchDone = false
60    s.con = c
61    return s, 0
62}
63