diff --git a/dataset.go b/dataset.go index 1065da6..a1b4394 100644 --- a/dataset.go +++ b/dataset.go @@ -5,7 +5,7 @@ import ( "q5" ) -type DataSet struct { +type OldDataSet struct { rows *sql.Rows columns []string values []interface{} @@ -14,20 +14,20 @@ type DataSet struct { } //已读取函数(调用Next成功的次数) -func (this *DataSet) NumOfReaded() int64 { +func (this *OldDataSet) NumOfReaded() int64 { return this.numOfReaded } -func (this *DataSet) close() { +func (this *OldDataSet) close() { if this.rows != nil { this.rows.Close() } this.closed = true } -func (this *DataSet) Next() bool { +func (this *OldDataSet) Next() bool { if this.closed { - panic("DataSet is closed") + panic("OldDataSet is closed") } ret := this.rows.Next() if !ret { @@ -42,12 +42,12 @@ func (this *DataSet) Next() bool { } err := this.rows.Scan(this.values...) if err != nil { - panic("DataSet Next error:" + err.Error()) + panic("OldDataSet Next error:" + err.Error()) } return ret } -func (this *DataSet) GetColumns() []string { +func (this *OldDataSet) GetColumns() []string { if len(this.columns) <= 0 { columns, err := this.rows.Columns() if err == nil { @@ -60,7 +60,7 @@ func (this *DataSet) GetColumns() []string { /* 安全版:nil值视为"" */ -func (this *DataSet) GetValues() *[]string { +func (this *OldDataSet) GetValues() *[]string { values := []string{} for _, val := range this.values { raw_val := val.(*sql.NullString) @@ -76,7 +76,7 @@ func (this *DataSet) GetValues() *[]string { /* 安全版:nil值视为"" */ -func (this *DataSet) GetByName(name string) string { +func (this *OldDataSet) GetByName(name string) string { val := this.GetRawValueByName(name) if val == nil { return "" @@ -88,7 +88,7 @@ func (this *DataSet) GetByName(name string) string { /* 安全版:nil值视为"" */ -func (this *DataSet) GetByIndex(index int32) string { +func (this *OldDataSet) GetByIndex(index int32) string { val := this.GetRawValueByIndex(index) if val == nil { return "" @@ -100,7 +100,7 @@ func (this *DataSet) GetByIndex(index int32) string { /* !!!原始版: 调用方应处理值为nil的情况 */ -func (this *DataSet) GetRawValues() *[]string { +func (this *OldDataSet) GetRawValues() *[]string { values := []*string{} for _, val := range this.values { raw_val := val.(*sql.NullString) @@ -116,7 +116,7 @@ func (this *DataSet) GetRawValues() *[]string { /* !!!原始版: 调用方应处理值为nil的情况 */ -func (this *DataSet) GetRawValueByName(name string) *string { +func (this *OldDataSet) GetRawValueByName(name string) *string { this.GetColumns() for i := 0; i < len(this.columns); i++ { if this.columns[i] == name { @@ -129,7 +129,7 @@ func (this *DataSet) GetRawValueByName(name string) *string { /* !!!原始版: 调用方应处理值为nil的情况 */ -func (this *DataSet) GetRawValueByIndex(index int32) *string { +func (this *OldDataSet) GetRawValueByIndex(index int32) *string { this.GetColumns() sql_val := this.values[index].(*sql.NullString) if sql_val.Valid { @@ -139,8 +139,8 @@ func (this *DataSet) GetRawValueByIndex(index int32) *string { } } -func NewDataSet(rows *sql.Rows) *DataSet { - dataSet := new(DataSet) +func NewDataSet(rows *sql.Rows) *OldDataSet { + dataSet := new(OldDataSet) dataSet.rows = rows return dataSet } diff --git a/types.go b/types.go index cd8d196..531a1e9 100644 --- a/types.go +++ b/types.go @@ -34,6 +34,7 @@ type StreamPagination struct { Remaining int32 } +type DataSet = OldDataSet; type HandlerFunc func(*Context) type GinHandlerFunc func(*gin.Context)