Skip to content

Commit

Permalink
read error data outside session
Browse files Browse the repository at this point in the history
  • Loading branch information
sijms committed Dec 6, 2022
1 parent 70e8832 commit 9ef801f
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 66 deletions.
70 changes: 44 additions & 26 deletions v2/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,25 +502,25 @@ func (stmt *defaultStmt) read(dataSet *DataSet) error {
return err
}
switch msg {
case 4:
stmt.connection.session.Summary, err = network.NewSummary(session)
if err != nil {
return err
}
stmt.connection.connOption.Tracer.Printf("Summary: RetCode:%d, Error Message:%q", stmt.connection.session.Summary.RetCode, string(stmt.connection.session.Summary.ErrorMessage))

stmt.cursorID = stmt.connection.session.Summary.CursorID
stmt.disableCompression = stmt.connection.session.Summary.Flags&0x20 != 0
if stmt.connection.session.HasError() {
if stmt.connection.session.Summary.RetCode == 1403 {
stmt._hasMoreRows = false
stmt.connection.session.Summary = nil
} else {
return stmt.connection.session.GetError()
}

}
loop = false
//case 4:
// stmt.connection.session.Summary, err = network.NewSummary(session)
// if err != nil {
// return err
// }
// stmt.connection.connOption.Tracer.Printf("Summary: RetCode:%d, Error Message:%q", stmt.connection.session.Summary.RetCode, string(stmt.connection.session.Summary.ErrorMessage))
//
// stmt.cursorID = stmt.connection.session.Summary.CursorID
// stmt.disableCompression = stmt.connection.session.Summary.Flags&0x20 != 0
// if stmt.connection.session.HasError() {
// if stmt.connection.session.Summary.RetCode == 1403 {
// stmt._hasMoreRows = false
// stmt.connection.session.Summary = nil
// } else {
// return stmt.connection.session.GetError()
// }
//
// }
// loop = false
case 6:
//_, err = session.GetByte()
err = dataSet.load(session)
Expand Down Expand Up @@ -778,17 +778,35 @@ func (stmt *defaultStmt) read(dataSet *DataSet) error {
}
}
dataSet.setBitVector(bitVector)
case 23:
opCode, err := session.GetByte()
//case 23:
// opCode, err := session.GetByte()
// if err != nil {
// return err
// }
// err = stmt.connection.getServerNetworkInformation(opCode)
// if err != nil {
// return err
// }
default:
err = stmt.connection.readResponse(msg)
if err != nil {
return err
}
err = stmt.connection.getServerNetworkInformation(opCode)
if err != nil {
return err
if msg == 4 {
stmt.cursorID = stmt.connection.session.Summary.CursorID
stmt.disableCompression = stmt.connection.session.Summary.Flags&0x20 != 0
if stmt.connection.session.HasError() {
if stmt.connection.session.Summary.RetCode == 1403 {
stmt._hasMoreRows = false
stmt.connection.session.Summary = nil
} else {
return stmt.connection.session.GetError()
}

}
loop = false
}
default:
return errors.New(fmt.Sprintf("TTC error: received code %d during stmt reading", msg))
//return errors.New(fmt.Sprintf("TTC error: received code %d during stmt reading", msg))
}
}
if stmt.connection.connOption.Tracer.IsOn() {
Expand Down
108 changes: 108 additions & 0 deletions v2/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"database/sql/driver"
"encoding/binary"
"errors"
"fmt"
"strconv"
Expand Down Expand Up @@ -1156,3 +1157,110 @@ func (conn *Connection) PrepareContext(ctx context.Context, query string) (drive
defer conn.session.EndContext()
return NewStmt(query, conn), nil
}

func (conn *Connection) readResponse(msgCode uint8) error {
session := conn.session
tracer := conn.connOption.Tracer
var err error
switch msgCode {
case 4:
conn.session.Summary, err = network.NewSummary(session)
if err != nil {
return err
}
tracer.Printf("Summary: RetCode:%d, Error Message:%q", session.Summary.RetCode, string(session.Summary.ErrorMessage))
case 8:
size, err := session.GetInt(2, true, true)
if err != nil {
return err
}
for x := 0; x < 2; x++ {
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
}
for x := 2; x < size; x++ {
_, err = session.GetInt(4, true, true)
if err != nil {
return err
}
}
_, err = session.GetInt(2, true, true)
if err != nil {
return err
}
size, err = session.GetInt(2, true, true)
for x := 0; x < size; x++ {
_, val, num, err := session.GetKeyVal()
if err != nil {
return err
}
//fmt.Println(key, val, num)
if num == 163 {
session.TimeZone = val
//fmt.Println("session time zone", session.TimeZone)
}
}
if session.TTCVersion >= 4 {
// get queryID
size, err = session.GetInt(4, true, true)
if err != nil {
return err
}
if size > 0 {
bty, err := session.GetBytes(size)
if err != nil {
return err
}
if len(bty) >= 8 {
queryID := binary.LittleEndian.Uint64(bty[size-8:])
fmt.Println("query ID: ", queryID)
}
}
}
if session.TTCVersion >= 7 {
length, err := session.GetInt(4, true, true)
if err != nil {
return err
}
for i := 0; i < length; i++ {
_, err = session.GetInt(8, true, true)
if err != nil {
return err
}
}
}
case 9:
if session.HasEOSCapability {
temp, err := session.GetInt(4, true, true)
if err != nil {
return err
}
if session.Summary != nil {
session.Summary.EndOfCallStatus = temp
}
}
case 15:
warning, err := network.NewWarningObject(session)
if err != nil {
return err
}
if warning != nil {
fmt.Println(warning)
}
case 23:
opCode, err := session.GetByte()
if err != nil {
return err
}
err = conn.getServerNetworkInformation(opCode)
if err != nil {
return err
}
default:
return errors.New(fmt.Sprintf("TTC error: received code %d during response reading", msgCode))
}
return nil
// cancel loop if = 4 or 9
}
95 changes: 55 additions & 40 deletions v2/lob.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package go_ora
import (
"bytes"
"errors"
"fmt"
"github.com/sijms/go-ora/v2/network"
)

type Clob struct {
Expand Down Expand Up @@ -407,19 +405,19 @@ func (lob *Lob) read() error {
return err
}
switch msg {
case 4:
session.Summary, err = network.NewSummary(session)
if err != nil {
return err
}
if session.HasError() {
if session.Summary.RetCode == 1403 {
session.Summary = nil
} else {
return session.GetError()
}
}
loop = false
//case 4:
// session.Summary, err = network.NewSummary(session)
// if err != nil {
// return err
// }
// if session.HasError() {
// if session.Summary.RetCode == 1403 {
// session.Summary = nil
// } else {
// return session.GetError()
// }
// }
// loop = false

case 8:
// read rpa message
Expand Down Expand Up @@ -470,42 +468,59 @@ func (lob *Lob) read() error {
lob.isNull = true
}
}
case 9:
if session.HasEOSCapability {
temp, err := session.GetInt(4, true, true)
if err != nil {
return err
}
if session.Summary != nil {
session.Summary.EndOfCallStatus = temp
}
}
loop = false
//case 9:
// if session.HasEOSCapability {
// temp, err := session.GetInt(4, true, true)
// if err != nil {
// return err
// }
// if session.Summary != nil {
// session.Summary.EndOfCallStatus = temp
// }
// }
// loop = false
case 14:
// get the data
err = lob.readData()
if err != nil {
return err
}
case 15:
warning, err := network.NewWarningObject(session)
//case 15:
// warning, err := network.NewWarningObject(session)
// if err != nil {
// return err
// }
// if warning != nil {
// fmt.Println(warning)
// }
//case 23:
// opCode, err := session.GetByte()
// if err != nil {
// return err
// }
// err = lob.connection.getServerNetworkInformation(opCode)
// if err != nil {
// return err
// }
default:
err = lob.connection.readResponse(msg)
if err != nil {
return err
}
if warning != nil {
fmt.Println(warning)
}
case 23:
opCode, err := session.GetByte()
if err != nil {
return err
if msg == 4 {
if session.HasError() {
if session.Summary.RetCode == 1403 {
session.Summary = nil
} else {
return session.GetError()
}
}
loop = false
}
err = lob.connection.getServerNetworkInformation(opCode)
if err != nil {
return err
if msg == 9 {
loop = false
}
default:
return errors.New(fmt.Sprintf("TTC error: received code %d during LOB reading", msg))
//return errors.New(fmt.Sprintf("TTC error: received code %d during LOB reading", msg))
}
}
return nil
Expand Down

0 comments on commit 9ef801f

Please sign in to comment.