Repository: eclipse-vertx/vertx-sql-client
Issue: Table created with non-nullable column even without `NOT NULL` in column definition

When using the MS SQL Client for `CREATE TABLE` statements, the resulting columns are non-`nullable` even when `NOT NULL` is not specified on the column definition.

This does not happen when using the JDBC client on the same database.

```java
PreparedStatement create = conn.prepareStatement("create table Basic (id int, dessimal numeric(19,2), primary key (id))");
create.executeUpdate();
PreparedStatement insert = conn.prepareStatement("INSERT INTO Basic (id, dessimal) values (3, ?)");
insert.setBigDecimal(1, new BigDecimal("3.2"));
insert.executeUpdate();
```

The snippet above works fine but this one fails:

```java
connnection.preparedQuery("create table Basic2 (id int, dessimal numeric(19,2), primary key (id))")
  .execute(ctx.asyncAssertSuccess(create -> {
    connnection.preparedQuery("INSERT INTO Basic2 (id, dessimal) values (3, @p1)")
      .execute(Tuple.of(NullValue.BigDecimal), ctx.asyncAssertSuccess());
  }));
```

The error message is:

```
io.vertx.mssqlclient.MSSQLException: {number=515, state=2, severity=16, message='Cannot insert the value NULL into column 'dessimal', table 'master.dbo.Basic2'; column does not allow nulls. INSERT fails.', serverName='0ac9600ef0bb', lineNumber=1}
```

As a workaround, the column definition must explicitly allow `NULL` values:

```sql
create table Basic2 (id int, dessimal numeric(19,2) null, primary key (id))
```

Changed files:
vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java
vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/protocol/client/login/LoginPacket.java
vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java

diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java
index b862195d..1f24603b 100644
--- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java
+++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/codec/InitCommandCodec.java
@@ -86,9 +86,17 @@ class InitCommandCodec extends MSSQLCommandCodec<Connection, InitCommand> {
     packet.writeIntLE(0x00); // ClientProgVer
     packet.writeIntLE(0x00); // ClientPID
     packet.writeIntLE(0x00); // ConnectionID
-    packet.writeByte(LoginPacket.DEFAULT_OPTION_FLAGS1
-      | LoginPacket.OPTION_FLAGS1_DUMPLOAD_OFF); // OptionFlags1
-    packet.writeByte(LoginPacket.DEFAULT_OPTION_FLAGS2); // OptionFlags2
+    packet.writeByte(LoginPacket.DEFAULT_OPTION_FLAGS1 |
+      LoginPacket.OPTION_FLAGS1_ORDER_X86 |
+      LoginPacket.OPTION_FLAGS1_CHARSET_ASCII |
+      LoginPacket.OPTION_FLAGS1_FLOAT_IEEE_754 |
+      LoginPacket.OPTION_FLAGS1_USE_DB_OFF |
+      LoginPacket.OPTION_FLAGS1_INIT_DB_FATAL |
+      LoginPacket.OPTION_FLAGS1_SET_LANG_ON
+    ); // OptionFlags1
+    packet.writeByte(LoginPacket.DEFAULT_OPTION_FLAGS2 |
+      LoginPacket.OPTION_FLAGS2_ODBC_ON
+    ); // OptionFlags2
     packet.writeByte(LoginPacket.DEFAULT_TYPE_FLAGS); // TypeFlags
     packet.writeByte(LoginPacket.DEFAULT_OPTION_FLAGS3); // OptionFlags3
     packet.writeIntLE(0x00); // ClientTimeZone
diff --git a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/protocol/client/login/LoginPacket.java b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/protocol/client/login/LoginPacket.java
index b0eef9b3..3f7b5d6c 100644
--- a/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/protocol/client/login/LoginPacket.java
+++ b/vertx-mssql-client/src/main/java/io/vertx/mssqlclient/impl/protocol/client/login/LoginPacket.java
@@ -37,7 +37,7 @@ public final class LoginPacket {
   public static final byte OPTION_FLAGS1_ORDER_X68000 = 0x01;
   public static final byte OPTION_FLAGS1_CHARSET_ASCII = 0x00;
   public static final byte OPTION_FLAGS1_CHARSET_EBCDIC = 0x02;
-  public static final byte OPTION_FALGS1_FLOAT_IEEE_754 = 0x00;
+  public static final byte OPTION_FLAGS1_FLOAT_IEEE_754 = 0x00;
   public static final byte OPTION_FALGS1_FLOAT_VAX = 0x04;
   public static final byte OPTION_FALGS1_ND5000 = 0x08;
   public static final byte OPTION_FLAGS1_DUMPLOAD_ON = 0x00;
diff --git a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java
index 54ed353e..823bb348 100644
--- a/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java
+++ b/vertx-mssql-client/src/test/java/io/vertx/mssqlclient/MSSQLQueriesTest.java
@@ -17,6 +17,7 @@ import io.vertx.ext.unit.junit.Repeat;
 import io.vertx.ext.unit.junit.RepeatRule;
 import io.vertx.ext.unit.junit.VertxUnitRunner;
 import io.vertx.sqlclient.Tuple;
+import io.vertx.sqlclient.data.NullValue;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -74,4 +75,16 @@ public class MSSQLQueriesTest extends MSSQLTestBase {
         ctx.assertTrue(Math.abs(localDateTime.until(start, ChronoUnit.SECONDS)) < 1);
       }));
   }
+
+  @Test
+  public void testCreateTable(TestContext ctx) {
+    connnection.query("drop table if exists Basic")
+      .execute(ctx.asyncAssertSuccess(drop -> {
+        connnection.preparedQuery("create table Basic (id int, dessimal numeric(19,2), primary key (id))")
+          .execute(ctx.asyncAssertSuccess(create -> {
+            connnection.preparedQuery("INSERT INTO Basic (id, dessimal) values (3, @p1)")
+              .execute(Tuple.of(NullValue.BigDecimal), ctx.asyncAssertSuccess());
+          }));
+      }));
+  }
 }