Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions token.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func parseFeatureExtAck(r *tdsBuffer) map[byte]interface{} {
}

// http://msdn.microsoft.com/en-us/library/dd357363.aspx
func parseColMetadata72(r *tdsBuffer) (columns []columnStruct) {
func parseColMetadata72(sess *tdsSession, r *tdsBuffer) (columns []columnStruct) {
count := r.uint16()
if count == 0xffff {
// no metadata is sent
Expand All @@ -593,12 +593,12 @@ func parseColMetadata72(r *tdsBuffer) (columns []columnStruct) {
column.Flags = r.uint16()

// parsing TYPE_INFO structure
column.ti = readTypeInfo(r)
column.ti = readTypeInfo(sess, r)
column.ColName = r.BVarChar()
}
return columns
}
func parseColMetadata71(r *tdsBuffer) (columns []columnStruct) {
func parseColMetadata71(sess *tdsSession, r *tdsBuffer) (columns []columnStruct) {
count := r.uint16()
if count == 0xffff {
// no metadata is sent
Expand All @@ -611,7 +611,7 @@ func parseColMetadata71(r *tdsBuffer) (columns []columnStruct) {
column.Flags = r.uint16()

// parsing TYPE_INFO structure
column.ti = readTypeInfo(r)
column.ti = readTypeInfo(sess, r)
column.ColName = r.BVarChar()
}
return columns
Expand Down Expand Up @@ -691,7 +691,7 @@ func parseInfo71(r *tdsBuffer) (res Error) {
}

// https://msdn.microsoft.com/en-us/library/dd303881.aspx
func parseReturnValue(r *tdsBuffer) (nv namedValue) {
func parseReturnValue(sess *tdsSession, r *tdsBuffer) (nv namedValue) {
/*
ParamOrdinal
ParamName
Expand All @@ -707,7 +707,7 @@ func parseReturnValue(r *tdsBuffer) (nv namedValue) {
r.byte()
r.uint32() // UserType (uint16 prior to 7.2)
r.uint16()
ti := readTypeInfo(r)
ti := readTypeInfo(sess, r)
nv.Value = ti.Reader(&ti, r)
return
}
Expand Down Expand Up @@ -846,9 +846,9 @@ func processSingleResponse(ctx context.Context, sess *tdsSession, ch chan tokenS
}
case tokenColMetadata:
if sess.loginAck.TDSVersion <= verTDS71rev1 {
columns = parseColMetadata71(sess.buf)
columns = parseColMetadata71(sess, sess.buf)
} else {
columns = parseColMetadata72(sess.buf)
columns = parseColMetadata72(sess, sess.buf)
}
ch <- columns
colsReceived = true
Expand Down Expand Up @@ -900,7 +900,7 @@ func processSingleResponse(ctx context.Context, sess *tdsSession, ch chan tokenS
_ = sqlexp.ReturnMessageEnqueue(ctx, outs.msgq, sqlexp.MsgNotice{Message: info})
}
case tokenReturnValue:
nv := parseReturnValue(sess.buf)
nv := parseReturnValue(sess, sess.buf)
if len(nv.Name) > 0 {
name := nv.Name[1:] // Remove the leading "@".
if ov, has := outs.params[name]; has {
Expand Down
28 changes: 18 additions & 10 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type xmlInfo struct {
XmlSchemaCollection string
}

func readTypeInfo(r *tdsBuffer) (res typeInfo) {
func readTypeInfo(sess *tdsSession, r *tdsBuffer) (res typeInfo) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the code-style. I did not want to copy the whole readTypeInfo func for v7.1 compatibility as the version-info is needed in readVarLen

res.TypeId = r.byte()
switch res.TypeId {
case typeNull, typeInt1, typeBit, typeInt2, typeInt4, typeDateTim4,
Expand All @@ -140,7 +140,7 @@ func readTypeInfo(r *tdsBuffer) (res typeInfo) {
res.Reader = readFixedType
res.Buffer = make([]byte, res.Size)
default: // all others are VARLENTYPE
readVarLen(&res, r)
readVarLen(sess, &res, r)
}
return
}
Expand Down Expand Up @@ -719,7 +719,7 @@ func writePLPType(w io.Writer, ti typeInfo, buf []byte) (err error) {
}
}

func readVarLen(ti *typeInfo, r *tdsBuffer) {
func readVarLen(sess *tdsSession, ti *typeInfo, r *tdsBuffer) {
switch ti.TypeId {
case typeDateN:
ti.Size = 3
Expand Down Expand Up @@ -798,17 +798,25 @@ func readVarLen(ti *typeInfo, r *tdsBuffer) {
switch ti.TypeId {
case typeText, typeNText:
ti.Collation = readCollation(r)
// ignore tablenames
numparts := int(r.byte())
for i := 0; i < numparts; i++ {
// only present in TDS > 7.2
if sess.loginAck.TDSVersion >= verTDS72 {
// ignore tablenames
numparts := int(r.byte())
for i := 0; i < numparts; i++ {
r.UsVarChar()
}
} else {
r.UsVarChar()
}
ti.Reader = readLongLenType
case typeImage:
// ignore tablenames
numparts := int(r.byte())
for i := 0; i < numparts; i++ {
r.UsVarChar()
// only present in TDS >= 7.2
if sess.loginAck.TDSVersion >= verTDS72 {
// ignore tablenames
numparts := int(r.byte())
for i := 0; i < numparts; i++ {
r.UsVarChar()
}
}
ti.Reader = readLongLenType
case typeVariant:
Expand Down