Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

Commit faa27f6

Browse files
authored
Merge pull request #825 from maniak89/null_int32
Support sql.NullInt32 for write
2 parents 7c33d07 + c8f4cd0 commit faa27f6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

write.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ func (r *Row) WriteSlice(e interface{}, cols int) int {
5959
if cell.SetString(``); t.Valid {
6060
cell.SetValue(t.Int64)
6161
}
62+
case sql.NullInt32:
63+
cell := r.AddCell()
64+
if cell.SetString(``); t.Valid {
65+
cell.SetValue(t.Int32)
66+
}
6267
case sql.NullFloat64:
6368
cell := r.AddCell()
6469
if cell.SetString(``); t.Valid {
@@ -136,6 +141,11 @@ func (r *Row) WriteStruct(e interface{}, cols int) int {
136141
if cell.SetString(``); t.Valid {
137142
cell.SetValue(t.Int64)
138143
}
144+
case sql.NullInt32:
145+
cell := r.AddCell()
146+
if cell.SetString(``); t.Valid {
147+
cell.SetValue(t.Int32)
148+
}
139149
case sql.NullFloat64:
140150
cell := r.AddCell()
141151
if cell.SetString(``); t.Valid {

write_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestWrite(t *testing.T) {
4242
Raiting sql.NullFloat64
4343
NullLastName sql.NullString
4444
NullHasPhd sql.NullBool
45-
NullGithubStars sql.NullInt64
45+
NullGithubStars sql.NullInt32
4646
NullRaiting sql.NullFloat64
4747
}
4848
testStruct := e{
@@ -59,7 +59,7 @@ func TestWrite(t *testing.T) {
5959
sql.NullFloat64{Float64: 0.123, Valid: true},
6060
sql.NullString{String: `What ever`, Valid: false},
6161
sql.NullBool{Bool: true, Valid: false},
62-
sql.NullInt64{Int64: 100, Valid: false},
62+
sql.NullInt32{Int32: 100, Valid: false},
6363
sql.NullFloat64{Float64: 0.123, Valid: false},
6464
}
6565
cnt := row.WriteStruct(&testStruct, -1)

0 commit comments

Comments
 (0)