f5/dataset.go
2023-08-13 18:02:14 +08:00

52 lines
941 B
Go

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
}