...

Source file src/github.com/DATA-DOG/go-sqlmock/rows_go18.go

Documentation: github.com/DATA-DOG/go-sqlmock

     1  // +build go1.8
     2  
     3  package sqlmock
     4  
     5  import (
     6  	"database/sql/driver"
     7  	"io"
     8  	"reflect"
     9  )
    10  
    11  // Implement the "RowsNextResultSet" interface
    12  func (rs *rowSets) HasNextResultSet() bool {
    13  	return rs.pos+1 < len(rs.sets)
    14  }
    15  
    16  // Implement the "RowsNextResultSet" interface
    17  func (rs *rowSets) NextResultSet() error {
    18  	if !rs.HasNextResultSet() {
    19  		return io.EOF
    20  	}
    21  
    22  	rs.pos++
    23  	return nil
    24  }
    25  
    26  // type for rows with columns definition created with sqlmock.NewRowsWithColumnDefinition
    27  type rowSetsWithDefinition struct {
    28  	*rowSets
    29  }
    30  
    31  // Implement the "RowsColumnTypeDatabaseTypeName" interface
    32  func (rs *rowSetsWithDefinition) ColumnTypeDatabaseTypeName(index int) string {
    33  	return rs.getDefinition(index).DbType()
    34  }
    35  
    36  // Implement the "RowsColumnTypeLength" interface
    37  func (rs *rowSetsWithDefinition) ColumnTypeLength(index int) (length int64, ok bool) {
    38  	return rs.getDefinition(index).Length()
    39  }
    40  
    41  // Implement the "RowsColumnTypeNullable" interface
    42  func (rs *rowSetsWithDefinition) ColumnTypeNullable(index int) (nullable, ok bool) {
    43  	return rs.getDefinition(index).IsNullable()
    44  }
    45  
    46  // Implement the "RowsColumnTypePrecisionScale" interface
    47  func (rs *rowSetsWithDefinition) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) {
    48  	return rs.getDefinition(index).PrecisionScale()
    49  }
    50  
    51  // ColumnTypeScanType is defined from driver.RowsColumnTypeScanType
    52  func (rs *rowSetsWithDefinition) ColumnTypeScanType(index int) reflect.Type {
    53  	return rs.getDefinition(index).ScanType()
    54  }
    55  
    56  // return column definition from current set metadata
    57  func (rs *rowSetsWithDefinition) getDefinition(index int) *Column {
    58  	return rs.sets[rs.pos].def[index]
    59  }
    60  
    61  // NewRowsWithColumnDefinition return rows with columns metadata
    62  func NewRowsWithColumnDefinition(columns ...*Column) *Rows {
    63  	cols := make([]string, len(columns))
    64  	for i, column := range columns {
    65  		cols[i] = column.Name()
    66  	}
    67  
    68  	return &Rows{
    69  		cols:      cols,
    70  		def:       columns,
    71  		nextErr:   make(map[int]error),
    72  		converter: driver.DefaultParameterConverter,
    73  	}
    74  }
    75  

View as plain text