protected virtual bool AddColDefinition(StringBuilder sb, string col, ClassMapping mapping,
string separator, ICollection<string> extraStatements)
{
Type colType = GetDataType(col, mapping);
sb.Append(separator).Append(col);
bool nullable = true;
string colTypeStr;
if (colType.Equals(typeof(string)))
{
colTypeStr = GetStringType();
}
else if (colType.Equals(typeof(int)))
{
nullable = false;
colTypeStr = GetIntType();
}
else if (colType.Equals(typeof(long)))
{
nullable = false;
colTypeStr = GetLongType();
}
else if (colType.Equals(typeof(double)))
{
nullable = false;
colTypeStr = GetDoubleType();
}
else if (colType.Equals(typeof(DateTime)))
{
nullable = false;
colTypeStr = GetDateTimeType();
}
else if (colType.IsEnum)
{
nullable = false;
colTypeStr = GetIntType();
}
else if (colType.Equals(typeof(bool)))
{
nullable = false;
colTypeStr = GetBooleanType();
}
else if (colType.Equals(typeof(short)))
{
nullable = false;
colTypeStr = GetShortType();
}
else if (colType.Equals(typeof(byte)))
{
nullable = false;
colTypeStr = GetByteType();
}
else if (colType.Equals(typeof(char)))
{
nullable = false;
colTypeStr = GetCharType();
}
else if (colType.Equals(typeof(float)))
{
nullable = false;
colTypeStr = GetFloatType();
}
else if (colType.Equals(typeof(DateTime?)))
{
colTypeStr = GetDateTimeType();
}
else if (colType.Equals(typeof(int?)))
{
colTypeStr = GetIntType();
}
else if (colType.Equals(typeof(long?)))
{
colTypeStr = GetLongType();
}
else if (colType.Equals(typeof(double?)))
{
colTypeStr = GetDoubleType();
}
else if (colType.Equals(typeof(float?)))
{
colTypeStr = GetFloatType();
}
else if (colType.Equals(typeof(bool?)))
{
colTypeStr = GetBooleanType();
}
else if (colType.Equals(typeof(byte[])))
{
colTypeStr = GetByteArrayType();
}
// Nullables are generics, so nullable enums are more work to check for.
else if (colType.IsGenericType &&
colType.GetGenericTypeDefinition().Equals(typeof(Nullable<>)))
{
// Note that we're only handling nullables, which have 1 generic param
// which is why the [0] is correct.
Type genericType = colType.GetGenericArguments()[0];
if (genericType.IsEnum)
{
colTypeStr = GetIntType();
}
else
{
throw new NotImplementedException("Unable to map generic type " + colType +
"." + genericType + " to a database type.");
}
}
else if (colType.Equals(typeof(AsciiString)))
{
colTypeStr = GetAsciiStringType();
}
else
{
throw new NotImplementedException("Unable to map type " + colType +
" to a database type.");
}
switch (GetGeneratorType(col, mapping))
{
case GeneratorType.AUTO:
// Override whatever it was mapped as and make it an auto number.
colTypeStr = GetAutoType(colType);
break;
case GeneratorType.SEQUENCE:
CreateSequence(mapping.IdSequencesByDataCol[col]);
break;
}
sb.Append(" ").Append(colTypeStr);
if (!nullable)
{
sb.Append(" NOT NULL");
}
return true;
}