11package csvdata
22
33import (
4+ "database/sql"
45 "strconv"
56 "strings"
67
@@ -87,6 +88,18 @@ func (r *Rows) ColumnString(s string) (string, error) {
8788 return r .GetString (i )
8889}
8990
91+ //ColumnNullString method returns ql.NullString data in current row.
92+ func (r * Rows ) ColumnNullString (s string ) (sql.NullString , error ) {
93+ str , err := r .ColumnString (s )
94+ if err != nil {
95+ if errs .Is (err , ErrNullPointer ) {
96+ err = nil
97+ }
98+ return sql.NullString {Valid : false }, errs .Wrap (err )
99+ }
100+ return sql.NullString {String : str , Valid : len (str ) > 0 }, nil
101+ }
102+
90103//GetString method returns string data in current row.
91104func (r Rows ) Get (i int ) string {
92105 s , _ := r .GetString (i )
@@ -124,6 +137,18 @@ func (r *Rows) ColumnBool(s string) (bool, error) {
124137 return r .GetBool (i )
125138}
126139
140+ //ColumnNullBool method returns sql.NullBool data in current row.
141+ func (r * Rows ) ColumnNullBool (s string ) (sql.NullBool , error ) {
142+ res , err := r .ColumnBool (s )
143+ if err != nil {
144+ if errs .Is (err , ErrNullPointer ) {
145+ err = nil
146+ }
147+ return sql.NullBool {Valid : false }, errs .Wrap (err )
148+ }
149+ return sql.NullBool {Bool : res , Valid : true }, nil
150+ }
151+
127152//GetFloat method returns type float64 data in current row.
128153func (r * Rows ) GetFloat64 (i int ) (float64 , error ) {
129154 s , err := r .GetString (i )
@@ -149,6 +174,18 @@ func (r *Rows) ColumnFloat64(s string) (float64, error) {
149174 return r .GetFloat64 (i )
150175}
151176
177+ //ColumnNullFloat64 method returns sql.NullFloat64 data in current row.
178+ func (r * Rows ) ColumnNullFloat64 (s string ) (sql.NullFloat64 , error ) {
179+ res , err := r .ColumnFloat64 (s )
180+ if err != nil {
181+ if errs .Is (err , ErrNullPointer ) {
182+ err = nil
183+ }
184+ return sql.NullFloat64 {Valid : false }, errs .Wrap (err )
185+ }
186+ return sql.NullFloat64 {Float64 : res , Valid : true }, nil
187+ }
188+
152189//GetInt method returns type int64 data in current row.
153190func (r * Rows ) GetInt64 (i int , base int ) (int64 , error ) {
154191 s , err := r .GetString (i )
@@ -174,6 +211,45 @@ func (r *Rows) ColumnInt64(s string, base int) (int64, error) {
174211 return r .GetInt64 (i , base )
175212}
176213
214+ //ColumnNullByte method returns sql.NullByte data in current row.
215+ func (r * Rows ) ColumnNullByte (s string , base int ) (sql.NullByte , error ) {
216+ res , err := r .ColumnNullInt64 (s , base )
217+ if err != nil {
218+ return sql.NullByte {Valid : false }, errs .Wrap (err )
219+ }
220+ return sql.NullByte {Byte : byte (res .Int64 ), Valid : true }, nil
221+ }
222+
223+ //ColumnNullInt16 method returns sql.NullFloat64 data in current row.
224+ func (r * Rows ) ColumnNullInt16 (s string , base int ) (sql.NullInt16 , error ) {
225+ res , err := r .ColumnNullInt64 (s , base )
226+ if err != nil {
227+ return sql.NullInt16 {Valid : false }, errs .Wrap (err )
228+ }
229+ return sql.NullInt16 {Int16 : int16 (res .Int64 ), Valid : true }, nil
230+ }
231+
232+ //ColumnNullInt32 method returns sql.NullInt32 data in current row.
233+ func (r * Rows ) ColumnNullInt32 (s string , base int ) (sql.NullInt32 , error ) {
234+ res , err := r .ColumnNullInt64 (s , base )
235+ if err != nil {
236+ return sql.NullInt32 {Valid : false }, errs .Wrap (err )
237+ }
238+ return sql.NullInt32 {Int32 : int32 (res .Int64 ), Valid : true }, nil
239+ }
240+
241+ //ColumnNullInt64 method returns sql.NullInt64 data in current row.
242+ func (r * Rows ) ColumnNullInt64 (s string , base int ) (sql.NullInt64 , error ) {
243+ res , err := r .ColumnInt64 (s , base )
244+ if err != nil {
245+ if errs .Is (err , ErrNullPointer ) {
246+ err = nil
247+ }
248+ return sql.NullInt64 {Valid : false }, errs .Wrap (err )
249+ }
250+ return sql.NullInt64 {Int64 : res , Valid : true }, nil
251+ }
252+
177253//Close method is closing RowsReader instance.
178254func (r * Rows ) Close () error {
179255 return r .reader .Close ()
0 commit comments