1
This commit is contained in:
parent
bf49efd5a0
commit
154c533e70
30
dataset.go
30
dataset.go
@ -5,7 +5,7 @@ import (
|
|||||||
"q5"
|
"q5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataSet struct {
|
type OldDataSet struct {
|
||||||
rows *sql.Rows
|
rows *sql.Rows
|
||||||
columns []string
|
columns []string
|
||||||
values []interface{}
|
values []interface{}
|
||||||
@ -14,20 +14,20 @@ type DataSet struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//已读取函数(调用Next成功的次数)
|
//已读取函数(调用Next成功的次数)
|
||||||
func (this *DataSet) NumOfReaded() int64 {
|
func (this *OldDataSet) NumOfReaded() int64 {
|
||||||
return this.numOfReaded
|
return this.numOfReaded
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DataSet) close() {
|
func (this *OldDataSet) close() {
|
||||||
if this.rows != nil {
|
if this.rows != nil {
|
||||||
this.rows.Close()
|
this.rows.Close()
|
||||||
}
|
}
|
||||||
this.closed = true
|
this.closed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DataSet) Next() bool {
|
func (this *OldDataSet) Next() bool {
|
||||||
if this.closed {
|
if this.closed {
|
||||||
panic("DataSet is closed")
|
panic("OldDataSet is closed")
|
||||||
}
|
}
|
||||||
ret := this.rows.Next()
|
ret := this.rows.Next()
|
||||||
if !ret {
|
if !ret {
|
||||||
@ -42,12 +42,12 @@ func (this *DataSet) Next() bool {
|
|||||||
}
|
}
|
||||||
err := this.rows.Scan(this.values...)
|
err := this.rows.Scan(this.values...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic("DataSet Next error:" + err.Error())
|
panic("OldDataSet Next error:" + err.Error())
|
||||||
}
|
}
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DataSet) GetColumns() []string {
|
func (this *OldDataSet) GetColumns() []string {
|
||||||
if len(this.columns) <= 0 {
|
if len(this.columns) <= 0 {
|
||||||
columns, err := this.rows.Columns()
|
columns, err := this.rows.Columns()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -60,7 +60,7 @@ func (this *DataSet) GetColumns() []string {
|
|||||||
/*
|
/*
|
||||||
安全版:nil值视为""
|
安全版:nil值视为""
|
||||||
*/
|
*/
|
||||||
func (this *DataSet) GetValues() *[]string {
|
func (this *OldDataSet) GetValues() *[]string {
|
||||||
values := []string{}
|
values := []string{}
|
||||||
for _, val := range this.values {
|
for _, val := range this.values {
|
||||||
raw_val := val.(*sql.NullString)
|
raw_val := val.(*sql.NullString)
|
||||||
@ -76,7 +76,7 @@ func (this *DataSet) GetValues() *[]string {
|
|||||||
/*
|
/*
|
||||||
安全版:nil值视为""
|
安全版:nil值视为""
|
||||||
*/
|
*/
|
||||||
func (this *DataSet) GetByName(name string) string {
|
func (this *OldDataSet) GetByName(name string) string {
|
||||||
val := this.GetRawValueByName(name)
|
val := this.GetRawValueByName(name)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return ""
|
return ""
|
||||||
@ -88,7 +88,7 @@ func (this *DataSet) GetByName(name string) string {
|
|||||||
/*
|
/*
|
||||||
安全版:nil值视为""
|
安全版:nil值视为""
|
||||||
*/
|
*/
|
||||||
func (this *DataSet) GetByIndex(index int32) string {
|
func (this *OldDataSet) GetByIndex(index int32) string {
|
||||||
val := this.GetRawValueByIndex(index)
|
val := this.GetRawValueByIndex(index)
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return ""
|
return ""
|
||||||
@ -100,7 +100,7 @@ func (this *DataSet) GetByIndex(index int32) string {
|
|||||||
/*
|
/*
|
||||||
!!!原始版: 调用方应处理值为nil的情况
|
!!!原始版: 调用方应处理值为nil的情况
|
||||||
*/
|
*/
|
||||||
func (this *DataSet) GetRawValues() *[]string {
|
func (this *OldDataSet) GetRawValues() *[]string {
|
||||||
values := []*string{}
|
values := []*string{}
|
||||||
for _, val := range this.values {
|
for _, val := range this.values {
|
||||||
raw_val := val.(*sql.NullString)
|
raw_val := val.(*sql.NullString)
|
||||||
@ -116,7 +116,7 @@ func (this *DataSet) GetRawValues() *[]string {
|
|||||||
/*
|
/*
|
||||||
!!!原始版: 调用方应处理值为nil的情况
|
!!!原始版: 调用方应处理值为nil的情况
|
||||||
*/
|
*/
|
||||||
func (this *DataSet) GetRawValueByName(name string) *string {
|
func (this *OldDataSet) GetRawValueByName(name string) *string {
|
||||||
this.GetColumns()
|
this.GetColumns()
|
||||||
for i := 0; i < len(this.columns); i++ {
|
for i := 0; i < len(this.columns); i++ {
|
||||||
if this.columns[i] == name {
|
if this.columns[i] == name {
|
||||||
@ -129,7 +129,7 @@ func (this *DataSet) GetRawValueByName(name string) *string {
|
|||||||
/*
|
/*
|
||||||
!!!原始版: 调用方应处理值为nil的情况
|
!!!原始版: 调用方应处理值为nil的情况
|
||||||
*/
|
*/
|
||||||
func (this *DataSet) GetRawValueByIndex(index int32) *string {
|
func (this *OldDataSet) GetRawValueByIndex(index int32) *string {
|
||||||
this.GetColumns()
|
this.GetColumns()
|
||||||
sql_val := this.values[index].(*sql.NullString)
|
sql_val := this.values[index].(*sql.NullString)
|
||||||
if sql_val.Valid {
|
if sql_val.Valid {
|
||||||
@ -139,8 +139,8 @@ func (this *DataSet) GetRawValueByIndex(index int32) *string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDataSet(rows *sql.Rows) *DataSet {
|
func NewDataSet(rows *sql.Rows) *OldDataSet {
|
||||||
dataSet := new(DataSet)
|
dataSet := new(OldDataSet)
|
||||||
dataSet.rows = rows
|
dataSet.rows = rows
|
||||||
return dataSet
|
return dataSet
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user