Repository: apache/shardingsphere
Issue: Lost the BinaryResultSetRowPacket when there's null value

For English only, other languages we will close it directly.

Please answer these questions before submitting your issue. Thanks!

### Which version of Sharding-Sphere do you using?
3.0.0.M3

### Which project do you using? Sharding-JDBC or Sharding-Proxy?
Sharding-Proxy

### Expected behavior
Return the BinaryResultSetRowPacket when there's null value.

### Actual behavior
Lost the BinaryResultSetRowPacket when there's null value.

### Reason analyze
Sharding-Proxy burst Exception when write binary protocol null value, althouth have already filled the nullBitmap correctly.

### Steps to reproduce the behavior, such as: SQL to execute, sharding rule configuration, when exception occur etc
Use preparedStatement select a row which contains null value column.

### For bug report, please *MUST* provide the reproduce example codes (such as a github link).
Official example.

Changed files:
sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryResultSetRowPacketTest.java
sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryProtocolValue.java

diff --git a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryProtocolValue.java b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryProtocolValue.java
index 6579c517db2..c29bad6ef09 100644
--- a/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryProtocolValue.java
+++ b/sharding-proxy/src/main/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryProtocolValue.java
@@ -91,6 +91,9 @@ public final class BinaryProtocolValue {
      * @param binaryData binary data to be written
      */
     public void write(final Object binaryData) {
+        if (null == binaryData) {
+            return;
+        }
         switch (columnType) {
             case MYSQL_TYPE_STRING:
             case MYSQL_TYPE_VARCHAR:
@@ -108,11 +111,7 @@ public final class BinaryProtocolValue {
                 payload.writeStringLenenc(binaryData.toString());
                 break;
             case MYSQL_TYPE_LONGLONG:
-                if (binaryData instanceof BigDecimal) {
-                    payload.writeInt8(((BigDecimal) binaryData).longValue());
-                } else {
-                    payload.writeInt8((Long) binaryData);
-                }
+                writeInt8(binaryData);
                 break;
             case MYSQL_TYPE_LONG:
             case MYSQL_TYPE_INT24:
@@ -143,4 +142,12 @@ public final class BinaryProtocolValue {
                 throw new IllegalArgumentException(String.format("Cannot find MySQL type '%s' in column type when write binary protocol value", columnType));
         }
     }
+    
+    private void writeInt8(final Object binaryData) {
+        if (binaryData instanceof BigDecimal) {
+            payload.writeInt8(((BigDecimal) binaryData).longValue());
+        } else {
+            payload.writeInt8((Long) binaryData);
+        }
+    }
 }
diff --git a/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryResultSetRowPacketTest.java b/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryResultSetRowPacketTest.java
index 3b38ad5a6eb..af4f039c9c8 100644
--- a/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryResultSetRowPacketTest.java
+++ b/sharding-proxy/src/test/java/io/shardingsphere/proxy/transport/mysql/packet/command/query/binary/execute/BinaryResultSetRowPacketTest.java
@@ -39,13 +39,13 @@ public final class BinaryResultSetRowPacketTest {
     private MySQLPacketPayload payload;
     
     @Test
-    @Ignore
     public void assertWrite() {
         BinaryResultSetRowPacket actual = new BinaryResultSetRowPacket(1, 2, Arrays.<Object>asList("value", null), Arrays.asList(ColumnType.MYSQL_TYPE_STRING, ColumnType.MYSQL_TYPE_STRING));
         assertThat(actual.getSequenceId(), is(1));
         assertThat(actual.getData(), is(Arrays.<Object>asList("value", null)));
         actual.write(payload);
-        verify(payload, times(2)).writeInt1(0x00);
+        verify(payload).writeInt1(0x00);
+        verify(payload).writeInt1(0x08);
         verify(payload).writeStringLenenc("value");
     }
 }