MS SQL

From time to time I run the DbUnit test suite against an MsSQL instance. At first glance DbUnit work great with it but I'm not using MsSQL for any real life project. The test suite does not use any fancy MsSQL data types; so support for some of them still lack at this time. —ManuelLaflamme

MsSqlDataTypeFactory provides MsSQL data types support.

We use DBUnit with MSSQL for a complex (300+ tables) project. Works just fine. We use JNetDirect's JDBC driver which intelligently recognizes that an nvarchar is a VARCHAR, etc., so we have never needed custom types. A while back we also had it working with Bea's JDBC driver. —Yishai Hornbacher

I've had some luck dealing with nvarchar by updating the createDataType method in MsSqlDataTypeFactory:

public DataType createDataType(int sqltype, String sqltypename) throws DataTypeException
    {
          if ("nvarchar".equals(sqltype)) { 
              return DataType.VARCHAR;
          }

        return super.createDataType(sqltype, sqltypename);
    }

—Todd McGrath


I'm using DbUnit with a large real life project and I ran into two missing data types. One was the nvarchar that Todd spotted (though how he compared "nvarchar" to an int, I don't know ;) ) and the other was the primary key type we use in most of our tables: uniqueidentifier. Here's the factory code I used:

public class MsSqlDataTypeFactory extends DefaultDataTypeFactory
{
    public static int NVARCHAR = -9;
    public static int UNIQUEIDENTIFIER = -11;

    public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException
    {
        if (sqlType == NVARCHAR)
        {
            return DataType.VARCHAR;
        }

        if (sqlType == UNIQUEIDENTIFIER)
        {
            return DataType.VARCHAR;
        }

        return super.createDataType(sqlType, sqlTypeName);
    }
}

— Paul Hicks

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License