Skip to content

Commit

Permalink
move calcBlr() to xsqlvar.go
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Aug 15, 2021
1 parent 72ac874 commit c19e7b9
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 107 deletions.
107 changes: 0 additions & 107 deletions utils.go
Expand Up @@ -237,110 +237,3 @@ func convertToBool(s string, defaultValue bool) bool {
}
return v
}

func calcBlr(xsqlda []xSQLVAR) []byte {
// Calculate BLR from XSQLVAR array.
ln := len(xsqlda) * 2
blr := make([]byte, (ln*4)+8)
blr[0] = 5
blr[1] = 2
blr[2] = 4
blr[3] = 0
blr[4] = byte(ln & 255)
blr[5] = byte(ln >> 8)
n := 6

for _, x := range xsqlda {
sqlscale := x.sqlscale
if sqlscale < 0 {
sqlscale += 256
}
switch x.sqltype {
case SQL_TYPE_VARYING:
blr[n] = 37
blr[n+1] = byte(x.sqllen & 255)
blr[n+2] = byte(x.sqllen >> 8)
n += 3
case SQL_TYPE_TEXT:
blr[n] = 14
blr[n+1] = byte(x.sqllen & 255)
blr[n+2] = byte(x.sqllen >> 8)
n += 3
case SQL_TYPE_LONG:
blr[n] = 8
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_SHORT:
blr[n] = 7
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_INT64:
blr[n] = 16
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_INT128:
blr[n] = 26
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_QUAD:
blr[n] = 9
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_DEC_FIXED: // OBSOLATED
blr[n] = 26
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_DOUBLE:
blr[n] = 27
n++
case SQL_TYPE_FLOAT:
blr[n] = 10
n++
case SQL_TYPE_D_FLOAT:
blr[n] = 11
n++
case SQL_TYPE_DATE:
blr[n] = 12
n++
case SQL_TYPE_TIME:
blr[n] = 13
n++
case SQL_TYPE_TIMESTAMP:
blr[n] = 35
n++
case SQL_TYPE_BLOB:
blr[n] = 9
blr[n+1] = 0
n += 2
case SQL_TYPE_ARRAY:
blr[n] = 9
blr[n+1] = 0
n += 2
case SQL_TYPE_BOOLEAN:
blr[n] = 23
n++
case SQL_TYPE_DEC64:
blr[n] = 24
n++
case SQL_TYPE_DEC128:
blr[n] = 25
n++
case SQL_TYPE_TIME_TZ:
blr[n] = 28
n++
case SQL_TYPE_TIMESTAMP_TZ:
blr[n] = 29
n++
}
// [blr_short, 0]
blr[n] = 7
blr[n+1] = 0
n += 2
}
// [blr_end, blr_eoc]
blr[n] = 255
blr[n+1] = 76
n += 2

return blr[:n]
}
107 changes: 107 additions & 0 deletions xsqlvar.go
Expand Up @@ -543,3 +543,110 @@ func (x *xSQLVAR) value(raw_value []byte, timezone string, charset string) (v in
}
return
}

func calcBlr(xsqlda []xSQLVAR) []byte {
// Calculate BLR from XSQLVAR array.
ln := len(xsqlda) * 2
blr := make([]byte, (ln*4)+8)
blr[0] = 5
blr[1] = 2
blr[2] = 4
blr[3] = 0
blr[4] = byte(ln & 255)
blr[5] = byte(ln >> 8)
n := 6

for _, x := range xsqlda {
sqlscale := x.sqlscale
if sqlscale < 0 {
sqlscale += 256
}
switch x.sqltype {
case SQL_TYPE_VARYING:
blr[n] = 37
blr[n+1] = byte(x.sqllen & 255)
blr[n+2] = byte(x.sqllen >> 8)
n += 3
case SQL_TYPE_TEXT:
blr[n] = 14
blr[n+1] = byte(x.sqllen & 255)
blr[n+2] = byte(x.sqllen >> 8)
n += 3
case SQL_TYPE_LONG:
blr[n] = 8
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_SHORT:
blr[n] = 7
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_INT64:
blr[n] = 16
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_INT128:
blr[n] = 26
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_QUAD:
blr[n] = 9
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_DEC_FIXED: // OBSOLATED
blr[n] = 26
blr[n+1] = byte(sqlscale)
n += 2
case SQL_TYPE_DOUBLE:
blr[n] = 27
n++
case SQL_TYPE_FLOAT:
blr[n] = 10
n++
case SQL_TYPE_D_FLOAT:
blr[n] = 11
n++
case SQL_TYPE_DATE:
blr[n] = 12
n++
case SQL_TYPE_TIME:
blr[n] = 13
n++
case SQL_TYPE_TIMESTAMP:
blr[n] = 35
n++
case SQL_TYPE_BLOB:
blr[n] = 9
blr[n+1] = 0
n += 2
case SQL_TYPE_ARRAY:
blr[n] = 9
blr[n+1] = 0
n += 2
case SQL_TYPE_BOOLEAN:
blr[n] = 23
n++
case SQL_TYPE_DEC64:
blr[n] = 24
n++
case SQL_TYPE_DEC128:
blr[n] = 25
n++
case SQL_TYPE_TIME_TZ:
blr[n] = 28
n++
case SQL_TYPE_TIMESTAMP_TZ:
blr[n] = 29
n++
}
// [blr_short, 0]
blr[n] = 7
blr[n+1] = 0
n += 2
}
// [blr_end, blr_eoc]
blr[n] = 255
blr[n+1] = 76
n += 2

return blr[:n]
}

0 comments on commit c19e7b9

Please sign in to comment.