@@ -16,7 +16,7 @@ import (
1616// Ping database connection
1717func (conn * OCI8Conn ) Ping (ctx context.Context ) error {
1818 done := make (chan struct {})
19- go conn .ociBreak (ctx , done )
19+ go conn .ociBreakDone (ctx , done )
2020 result := C .OCIPing (conn .svc , conn .errHandle , C .OCI_DEFAULT )
2121 close (done )
2222 if result == C .OCI_SUCCESS || result == C .OCI_SUCCESS_WITH_INFO {
@@ -96,24 +96,23 @@ func (conn *OCI8Conn) PrepareContext(ctx context.Context, query string) (driver.
9696 defer C .free (unsafe .Pointer (queryP ))
9797
9898 // statement handle
99- stmt , _ , err := conn . ociHandleAlloc ( C . OCI_HTYPE_STMT , 0 )
100- if err != nil {
101- return nil , fmt . Errorf ( "allocate statement handle error: %v" , err )
102- }
103-
104- if rv := C . OCIStmtPrepare (
105- ( * C . OCIStmt )( * stmt ),
106- conn . errHandle ,
107- queryP ,
108- C .ub4 (len ( query )),
109- C .ub4 (C .OCI_NTV_SYNTAX ),
110- C .ub4 (C .OCI_DEFAULT ),
99+ var stmtTemp * C. OCIStmt
100+ stmt := & stmtTemp
101+ if rv := C . OCIStmtPrepare2 (
102+ conn . svc , // service context handle
103+ stmt , // pointer to the statement handle returned
104+ conn . errHandle , // error handle
105+ queryP , // statement text
106+ C . ub4 ( len ( query )), // statement text length
107+ nil , // key to be used for searching the statement in the statement cache
108+ C .ub4 (0 ), // length of the key
109+ C .ub4 (C .OCI_NTV_SYNTAX ), // syntax - OCI_NTV_SYNTAX: syntax depends upon the version of the server
110+ C .ub4 (C .OCI_DEFAULT ), // mode
111111 ); rv != C .OCI_SUCCESS {
112- C .OCIHandleFree (* stmt , C .OCI_HTYPE_STMT )
113112 return nil , conn .getError (rv )
114113 }
115114
116- return & OCI8Stmt {conn : conn , stmt : ( * C . OCIStmt )( * stmt ) }, nil
115+ return & OCI8Stmt {conn : conn , stmt : * stmt }, nil
117116}
118117
119118// Begin starts a transaction
@@ -567,23 +566,28 @@ func appendSmallInt(slice []byte, num int) []byte {
567566 return append (slice , byte ('0' + num / 10 ), byte ('0' + (num % 10 )))
568567}
569568
570- // ociBreak calls OCIBreak if ctx.Done is finished before done chan is closed
571- func (conn * OCI8Conn ) ociBreak (ctx context.Context , done chan struct {}) {
569+ // ociBreakDone calls OCIBreak if ctx.Done is finished before done chan is closed
570+ func (conn * OCI8Conn ) ociBreakDone (ctx context.Context , done chan struct {}) {
572571 select {
573572 case <- done :
574573 case <- ctx .Done ():
575574 // select again to avoid race condition if both are done
576575 select {
577576 case <- done :
578577 default :
579- result := C .OCIBreak (
580- unsafe .Pointer (conn .svc ), // The service context handle or the server context handle.
581- conn .errHandle , // An error handle
582- )
583- err := conn .getError (result )
584- if err != nil {
585- conn .logger .Print ("OCIBreak error: " , err )
586- }
578+ conn .ociBreak ()
587579 }
588580 }
589581}
582+
583+ // ociBreak calls OCIBreak
584+ func (conn * OCI8Conn ) ociBreak () {
585+ result := C .OCIBreak (
586+ unsafe .Pointer (conn .svc ), // service or server context handle
587+ conn .errHandle , // error handle
588+ )
589+ err := conn .getError (result )
590+ if err != nil {
591+ conn .logger .Print ("OCIBreak error: " , err )
592+ }
593+ }
0 commit comments