Skip to content

Commit

Permalink
add help comment to function
Browse files Browse the repository at this point in the history
add implementation for refCursor
  • Loading branch information
sijms committed Oct 26, 2021
1 parent f1d607f commit 02caefb
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 204 deletions.
77 changes: 2 additions & 75 deletions v2/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type StmtInterface interface {
//write() error
//getExeOption() int
read(dataSet *DataSet) error
//Close() error
Close() error
//Exec(args []driver.Value) (driver.Result, error)
//Query(args []driver.Value) (driver.Rows, error)
}
Expand Down Expand Up @@ -283,7 +283,7 @@ func NewStmt(text string, conn *Connection) *Stmt {
return ret
}

// write it write stmt data to network stream
// write stmt data to network stream
func (stmt *Stmt) write(session *network.Session) error {
if !stmt.parse && !stmt.reSendParDef {
exeOf := 0
Expand Down Expand Up @@ -320,79 +320,6 @@ func (stmt *Stmt) write(session *network.Session) error {
stmt.define = false
stmt.reSendParDef = false
}
//if !stmt.reExec {
//exeOp := stmt.getExeOption()
//session.PutBytes(3, 0x5E, 0)
//session.PutUint(exeOp, 4, true, true)
//session.PutUint(stmt.cursorID, 2, true, true)
//if stmt.cursorID == 0 {
// session.PutBytes(1)
// //session.PutUint(1, 1, false, false)
//} else {
// session.PutBytes(0)
// //session.PutUint(0, 1, false, false)
//}
//session.PutUint(len(stmt.text), 4, true, true)
//session.PutBytes(1)
//session.PutUint(1, 1, false, false)
//session.PutUint(13, 2, true, true)
//session.PutBytes(0, 0)
//if exeOp&0x40 == 0 && exeOp&0x20 != 0 && exeOp&0x1 != 0 && stmt.stmtType == SELECT {
// session.PutBytes(0)
// //session.PutUint(0, 1, false, false)
// session.PutUint(stmt.noOfRowsToFetch, 4, true, true)
//} else {
// session.PutUint(0, 4, true, true)
// session.PutUint(0, 4, true, true)
//}
// longFetchSize == 0 marshal 1 else marshal longFetchSize
//session.PutUint(1, 4, true, true)
//if len(stmt.Pars) > 0 {
// session.PutBytes(1)
// //session.PutUint(1, 1, false, false)
// session.PutUint(len(stmt.Pars), 2, true, true)
//} else {
// session.PutBytes(0, 0)
// //session.PutUint(0, 1, false, false)
// //session.PutUint(0, 1, false, false)
//}
//session.PutBytes(0, 0, 0, 0, 0)
//if stmt.define {
// session.PutBytes(1)
// //session.PutUint(1, 1, false, false)
// session.PutUint(stmt.noOfDefCols, 2, true, true)
//} else {
// session.PutBytes(0, 0)
// //session.PutUint(0, 1, false, false)
// //session.PutUint(0, 1, false, false)
//}
//if session.TTCVersion >= 4 {
// session.PutBytes(0, 0, 1)
// //session.PutUint(0, 1, false, false) // dbChangeRegisterationId
// //session.PutUint(0, 1, false, false)
// //session.PutUint(1, 1, false, false)
//}
//if session.TTCVersion >= 5 {
// session.PutBytes(0, 0, 0, 0, 0)
// //session.PutUint(0, 1, false, false)
// //session.PutUint(0, 1, false, false)
// //session.PutUint(0, 1, false, false)
// //session.PutUint(0, 1, false, false)
// //session.PutUint(0, 1, false, false)
//}

//session.PutBytes([]byte(stmt.text)...)
//for x := 0; x < len(stmt.al8i4); x++ {
// session.PutUint(stmt.al8i4[x], 2, true, true)
//}
//for _, par := range stmt.Pars {
// _ = par.write(session)
//}
//stmt.reExec = true
//stmt.parse = false
//} else {
//
//}

if len(stmt.Pars) > 0 {
session.PutBytes(7)
Expand Down
2 changes: 1 addition & 1 deletion v2/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (conn *Connection) Open() error {
}

tracer.Print("TCP Negotiation")
conn.tcpNego, err = NewTCPNego(conn.session)
conn.tcpNego, err = newTCPNego(conn.session)
if err != nil {
return err
}
Expand Down
9 changes: 9 additions & 0 deletions v2/data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (dataSet *DataSet) Close() error {
return nil
}

// Next_ act like Next in sql package return false if no other rows in dataset
func (dataSet *DataSet) Next_() bool {
err := dataSet.Next(dataSet.currentRow)
if err != nil {
Expand All @@ -115,6 +116,7 @@ func (dataSet *DataSet) Next_() bool {
return true
}

// Scan act like scan in sql package return row values to dest variable pointers
func (dataSet *DataSet) Scan(dest ...interface{}) error {
if dataSet.lasterr != nil {
return dataSet.lasterr
Expand Down Expand Up @@ -180,9 +182,13 @@ func (dataSet *DataSet) Scan(dest ...interface{}) error {
}
return nil
}

// Err return last error
func (dataSet *DataSet) Err() error {
return dataSet.lasterr
}

// Next implement method need for sql.Rows interface
func (dataSet *DataSet) Next(dest []driver.Value) error {
hasMoreRows := dataSet.parent.hasMoreRows()
noOfRowsToFetch := len(dataSet.Rows) // dataSet.parent.noOfRowsToFetch()
Expand Down Expand Up @@ -262,10 +268,12 @@ func (dataSet DataSet) Trace(t trace.Tracer) {
}
}

// ColumnTypeDatabaseTypeName return Col DataType name
func (dataSet DataSet) ColumnTypeDatabaseTypeName(index int) string {
return dataSet.Cols[index].DataType.String()
}

// ColumnTypeLength return length of column type
func (dataSet DataSet) ColumnTypeLength(index int) (length int64, ok bool) {
switch dataSet.Cols[index].DataType {
case NCHAR, CHAR:
Expand All @@ -277,6 +285,7 @@ func (dataSet DataSet) ColumnTypeLength(index int) (length int64, ok bool) {

}

// ColumnTypeNullable return if column allow null or not
func (dataSet DataSet) ColumnTypeNullable(index int) (nullable, ok bool) {
return dataSet.Cols[index].AllowNull, true
}
2 changes: 2 additions & 0 deletions v2/db_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ type DBVersion struct {
isDb11gR10OrHigher bool
}

// GetDBVersion write a request to get database version the read
// database version from network session
func GetDBVersion(session *network.Session) (*DBVersion, error) {
session.ResetBuffer()
session.PutBytes(3, 0x3B, 0, 1)
Expand Down
12 changes: 12 additions & 0 deletions v2/lob.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,20 @@ type Lob struct {
data bytes.Buffer
}

// variableWidthChar if lob has variable width char or not
func (lob *Lob) variableWidthChar() bool {
if len(lob.sourceLocator) > 6 && lob.sourceLocator[6]&128 == 128 {
return true
}
return false
}

// littleEndianClob if CLOB is littleEndian or not
func (lob *Lob) littleEndianClob() bool {
return len(lob.sourceLocator) > 7 && lob.sourceLocator[7]&64 > 0
}

// getSize return lob size
func (lob *Lob) getSize(connection *Connection) (size int64, err error) {
session := connection.session
connection.connOption.Tracer.Print("Read Lob Size")
Expand All @@ -42,6 +47,8 @@ func (lob *Lob) getSize(connection *Connection) (size int64, err error) {
connection.connOption.Tracer.Print("Lob Size: ", size)
return
}

// getData return lob data
func (lob *Lob) getData(connection *Connection) (data []byte, err error) {
connection.connOption.Tracer.Print("Read Lob Data")
session := connection.session
Expand All @@ -57,6 +64,8 @@ func (lob *Lob) getData(connection *Connection) (data []byte, err error) {
data = lob.data.Bytes()
return
}

// write lob command to network session
func (lob *Lob) write(session *network.Session, operationID int) error {
session.ResetBuffer()
session.PutBytes(3, 0x60, 0)
Expand Down Expand Up @@ -140,6 +149,7 @@ func (lob *Lob) write(session *network.Session, operationID int) error {
return session.Write()
}

// read lob response from network session
func (lob *Lob) read(connection *Connection) error {
loop := true
session := connection.session
Expand Down Expand Up @@ -231,6 +241,8 @@ func (lob *Lob) read(connection *Connection) error {
}
return nil
}

// read lob data chunks from network session
func (lob *Lob) readData(session *network.Session) error {
num1 := 0 // data readed in the call of this function
var chunkSize int = 0
Expand Down
43 changes: 22 additions & 21 deletions v2/oracletype_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 3 additions & 85 deletions v2/parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ type ParameterInfo struct {
cusType *customType
}

// load get parameter information form network session
func (par *ParameterInfo) load(conn *Connection) error {
session := conn.session
par.getDataFromServer = true
Expand Down Expand Up @@ -275,12 +276,10 @@ func (par *ParameterInfo) load(conn *Connection) error {
_, err = session.GetInt(4, true, true)
return nil
}

// write parameter information to network session
func (par *ParameterInfo) write(session *network.Session) error {
session.PutBytes(uint8(par.DataType), par.Flag, par.Precision, par.Scale)
//session.PutUint(int(par.DataType), 1, false, false)
//session.PutUint(par.Flag, 1, false, false)
//session.PutUint(par.Precision, 1, false, false)
//session.PutUint(par.Scale, 1, false, false)
session.PutUint(par.MaxLen, 4, true, true)
session.PutInt(par.MaxNoOfArrayElements, 4, true, true)
if session.TTCVersion >= 10 {
Expand All @@ -305,84 +304,3 @@ func (par *ParameterInfo) write(session *network.Session) error {
}
return nil
}

//func NewIntegerParameter(name string, val int, direction ParameterDirection) *ParameterInfo {
// ret := ParameterInfo{
// Name: name,
// Direction: direction,
// flag: 3,
// ContFlag: 0,
// DataType: NUMBER,
// MaxCharLen: 22,
// MaxLen: 22,
// CharsetID: 871,
// CharsetForm: 1,
// BValue: converters.EncodeInt(val),
// }
// return &ret
//}
//func NewStringParameter(name string, val string, size int, direction ParameterDirection) *ParameterInfo {
// ret := ParameterInfo{
// Name: name,
// Direction: direction,
// flag: 3,
// ContFlag: 16,
// DataType: NCHAR,
// MaxCharLen: size,
// MaxLen: size,
// CharsetID: 871,
// CharsetForm: 1,
// BValue: []byte(val),
// }
// return &ret
//}

//func NewParamInfo(name string, parType ParameterType, size int, direction ParameterDirection) *ParameterInfo {
// ret := new(ParameterInfo)
// ret.Name = name
// ret.Direction = direction
// ret.flag = 3
// //ret.DataType = dataType
// switch parType {
// case String:
// ret.ContFlag = 16
// default:
// ret.ContFlag = 0
// }
// switch parType {
// case Number:
// ret.DataType = NUMBER
// ret.MaxLen = 22
// case String:
// ret.CharsetForm = 1
// ret.DataType = NCHAR
// ret.MaxCharLen = size
// ret.MaxLen = size
// }
// //ret.MaxCharLen = 0 // number of character to write
// //ret.MaxLen = ret.MaxCharLen * 1 // number of character * byte per character
// ret.CharsetID = 871
// return ret
// // if duplicateBind ret.flag = 128 else ret.flag = 3
// // if collection type is assocative array ret.Flat |= 64
//
// //num3 := 0
// //switch dataType {
// //case LONG:
// // fallthrough
// //case LongRaw:
// // fallthrough
// //case CHAR:
// // fallthrough
// //case RAW:
// // fallthrough
// //case NCHAR:
// // num3 = 1
// //default:
// // num3 = 0
// //}
// //if num3 != 0 {
// //
// //}
// //return ret
//}
Loading

0 comments on commit 02caefb

Please sign in to comment.