diff --git a/dataset.go b/dataset.go new file mode 100644 index 0000000..26460d7 --- /dev/null +++ b/dataset.go @@ -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 +}