Skip to content

Commit a772a2d

Browse files
committed
1 parent 60cb4d4 commit a772a2d

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

clickhouse_nullable_test.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func Test_Nullable(t *testing.T) {
3333
dml = `
3434
INSERT INTO clickhouse_test_nullable (
3535
int8,
36-
int16,
36+
int16,
3737
int32,
3838
int64,
39-
uint8,
40-
uint16,
39+
uint8,
40+
uint16,
4141
uint32,
4242
uint64,
4343
float32,
@@ -49,8 +49,8 @@ func Test_Nullable(t *testing.T) {
4949
enum8,
5050
enum16
5151
) VALUES (
52-
?,
53-
?,
52+
?,
53+
?,
5454
?,
5555
?,
5656
?,
@@ -68,13 +68,13 @@ func Test_Nullable(t *testing.T) {
6868
)
6969
`
7070
query = `
71-
SELECT
72-
int8,
73-
int16,
71+
SELECT
72+
int8,
73+
int16,
7474
int32,
7575
int64,
76-
uint8,
77-
uint16,
76+
uint8,
77+
uint16,
7878
uint32,
7979
uint64,
8080
float32,
@@ -273,13 +273,13 @@ func Test_Nullable(t *testing.T) {
273273
&Enum8,
274274
&Enum16,
275275
); assert.NoError(t, err) {
276-
if assert.Nil(t, Int8) {
277-
if assert.NotNil(t, Int16) {
276+
if assert.NotNil(t, Int8) {
277+
if assert.Equal(t, int8(0), *Int8) && assert.NotNil(t, Int16) {
278278
assert.Equal(t, int16(16), *Int16)
279279
}
280280
}
281-
if assert.Nil(t, Int32) {
282-
if assert.NotNil(t, Int64) {
281+
if assert.NotNil(t, Int32) {
282+
if assert.Equal(t, int32(0), *Int32) && assert.NotNil(t, Int64) {
283283
assert.Equal(t, int64(64), *Int64)
284284
}
285285
}

lib/column/nullable.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (null *Nullable) ReadNull(decoder *binary.Decoder, rows int) (_ []interface
5151
return values, nil
5252
}
5353
func (null *Nullable) WriteNull(nulls, encoder *binary.Encoder, v interface{}) error {
54-
if v == nil || reflect.ValueOf(v).IsNil() {
54+
if value := reflect.ValueOf(v); v == nil || (value.Kind() == reflect.Ptr && value.IsNil()) {
5555
if _, err := nulls.Write([]byte{1}); err != nil {
5656
return err
5757
}

0 commit comments

Comments
 (0)