Skip to content

Commit

Permalink
Implements the functions Length and DecimalSize of sql.ColumnType
Browse files Browse the repository at this point in the history
  • Loading branch information
sanmarco committed Mar 21, 2023
1 parent dd97fc9 commit 4beef52
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions v2/data_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@ import (
"database/sql/driver"
"errors"
"fmt"
"github.com/sijms/go-ora/v2/network"
"github.com/sijms/go-ora/v2/trace"
"io"
"reflect"
"strconv"
"strings"
"time"

"github.com/sijms/go-ora/v2/network"
"github.com/sijms/go-ora/v2/trace"
)

// Compile time Sentinels for implemented Interfaces.
var _ = driver.Rows((*DataSet)(nil))
var _ = driver.RowsColumnTypeDatabaseTypeName((*DataSet)(nil))
var _ = driver.RowsColumnTypeLength((*DataSet)(nil))
var _ = driver.RowsColumnTypeNullable((*DataSet)(nil))
var _ = driver.RowsColumnTypePrecisionScale((*DataSet)(nil))

// var _ = driver.RowsColumnTypePrecisionScale((*DataSet)(nil))
// var _ = driver.RowsColumnTypeScanType((*DataSet)(nil))
// var _ = driver.RowsNextResultSet((*DataSet)(nil))

Expand Down Expand Up @@ -498,21 +499,24 @@ func (dataSet DataSet) ColumnTypeDatabaseTypeName(index int) string {
}

// ColumnTypeLength return length of column type
func (dataSet DataSet) ColumnTypeLength(index int) (length int64, ok bool) {
length = int64(len(dataSet.Cols[index].BValue))
ok = true
return
//switch dataSet.Cols[index].DataType {
//case NCHAR, CHAR:
// return int64(dataSet.Cols[index].MaxCharLen), true
//case NUMBER:
// return int64(dataSet.Cols[index].Precision), true
//}
//return int64(0), false

func (dataSet DataSet) ColumnTypeLength(index int) (int64, bool) {
switch dataSet.Cols[index].DataType {
case NCHAR, CHAR:
return int64(dataSet.Cols[index].MaxCharLen), true
}
return int64(0), false
}

// ColumnTypeNullable return if column allow null or not
func (dataSet DataSet) ColumnTypeNullable(index int) (nullable, ok bool) {
return dataSet.Cols[index].AllowNull, true
}

// ColumnTypePrecisionScale return the precision and scale for numeric types
func (dataSet DataSet) ColumnTypePrecisionScale(index int) (int64, int64, bool) {
switch dataSet.Cols[index].DataType {
case NUMBER:
return int64(dataSet.Cols[index].Precision), int64(dataSet.Cols[index].Scale), true
}
return int64(0), int64(0), false
}

0 comments on commit 4beef52

Please sign in to comment.