1
This commit is contained in:
parent
36bf9bbc4c
commit
1ab3d3cc9a
51
dataset.go
Normal file
51
dataset.go
Normal file
@ -0,0 +1,51 @@
|
||||
package f5
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type DataSet struct {
|
||||
rows *sql.Rows
|
||||
columns []string
|
||||
values []interface{}
|
||||
}
|
||||
|
||||
func (this *DataSet) Next() bool {
|
||||
this.GetColumns()
|
||||
this.values = []interface{}{}
|
||||
for i := 0 ; i < len(this.columns); i++ {
|
||||
str := ""
|
||||
this.values = append(this.values, &str)
|
||||
}
|
||||
this.rows.Scan(this.values...)
|
||||
return this.rows.Next()
|
||||
}
|
||||
|
||||
func (this *DataSet) GetColumns() []string {
|
||||
if len(this.columns) <= 0 {
|
||||
columns, err := this.rows.Columns()
|
||||
if err == nil {
|
||||
this.columns = columns
|
||||
}
|
||||
}
|
||||
return this.columns
|
||||
}
|
||||
|
||||
func (this *DataSet) GetByName(name string) *string {
|
||||
for i := 0; i < len(this.columns); i++ {
|
||||
if this.columns[i] == name {
|
||||
return this.GetByIndex(int32(i))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *DataSet) GetByIndex(index int32) *string {
|
||||
return this.values[index].(*string);
|
||||
}
|
||||
|
||||
func NewDataSet(rows *sql.Rows) *DataSet {
|
||||
dataSet := new(DataSet)
|
||||
dataSet.rows = rows
|
||||
return dataSet
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user