Beispiel #1
0
 private static string GetInsertRepresentationOfSqlValue(SqlDataReader resultReader, int field)
 {
     if (!resultReader.IsDBNull(field))
     {
         if (resultReader.GetDataTypeName(field) == DataTypeConstants.DATETIME || resultReader.GetDataTypeName(field) == DataTypeConstants.DATE)
         {
             return($"CAST(N'{GetStringRepresentationOfSqlValue(resultReader, field, false)}' AS {resultReader.GetDataTypeName(field)})");
         }
         else if (DataTypeConstants.DataTypeIsBinary(resultReader.GetDataTypeName(field)))
         {
             return($"CONVERT({resultReader.GetDataTypeName(field)}, '{GetStringRepresentationOfSqlValue(resultReader, field, false)}', 1)");
         }
         else if (!DataTypeConstants.DataTypeIsUnicodeCharPrefix(resultReader.GetDataTypeName(field)))
         {
             return("'" + GetStringRepresentationOfSqlValue(resultReader, field, false).Replace("'", "''") + "'");
         }
         else
         {
             return("N'" + GetStringRepresentationOfSqlValue(resultReader, field, false).Replace("'", "''") + "'");
         }
     }
     else
     {
         return(GetStringRepresentationOfSqlValue(resultReader, field, false));
     }
 }
Beispiel #2
0
 public TableColumn(string name, string defaultValue, bool canBeNull, string type, int length, bool isUserType, bool isForeignKey)
 {
     Name         = name;
     DefaultValue = defaultValue;
     CanBeNull    = canBeNull;
     Type         = type;
     MaxLength    = -1;
     if (DataTypeIsChar() || DataTypeIsBinary())
     {
         MaxLength = DataTypeConstants.MAX_LENGTH_IN_BYTES;
         if (DataTypeConstants.DataTypeIsUnicodeChar(type)) // Need 2 bytes per char
         {
             IsUnicode  = true;
             length    /= 2;
             MaxLength /= 2;
         }
         if (length <= 0)
         {
             TypeWithLength = $"{type}(MAX)";
         }
         else
         {
             TypeWithLength = $"{type}({length})";
         }
     }
     else
     {
         TypeWithLength = type;
     }
     Length       = length;
     IsUserType   = isUserType;
     IsForeignKey = isForeignKey;
 }
Beispiel #3
0
 private static string GetStringRepresentationOfSqlValue(SqlDataReader resultReader, int field, bool nullAsHyphen)
 {
     if (!resultReader.IsDBNull(field))
     {
         if (resultReader.GetDataTypeName(field) == DataTypeConstants.DATETIME)
         {
             return(resultReader.GetDateTime(field).ToString("yyyy-MM-ddTHH:mm:ss.fff"));
         }
         else if (resultReader.GetDataTypeName(field) == DataTypeConstants.DATE)
         {
             return(resultReader.GetDateTime(field).ToString("yyyy-MM-dd"));
         }
         else if (DataTypeConstants.DataTypeIsBinary(resultReader.GetDataTypeName(field)))
         {
             byte[] bytes = (byte[])resultReader.GetValue(field);
             return($"0x{BitConverter.ToString(bytes).Replace("-", string.Empty)}");
         }
         else if (DataTypeConstants.DataTypeIsFloatingPoint(resultReader.GetDataTypeName(field)))
         {
             return(resultReader.GetValue(field).ToString().Replace(",", ".")); // conversion to floatinf point (fixes Czech environment)
         }
         else if (!DataTypeConstants.DataTypeIsUnicodeCharPrefix(resultReader.GetDataTypeName(field)))
         {
             return(resultReader.GetValue(field).ToString());
         }
         else
         {
             return(resultReader.GetValue(field).ToString());
         }
     }
     else if (nullAsHyphen)
     {
         return("-");
     }
     else
     {
         return("NULL");
     }
 }
Beispiel #4
0
 public bool DataTypeIsInteger()
 {
     return(DataTypeConstants.DataTypeIsInteger(Type));
 }
Beispiel #5
0
 public bool DataTypeIsBinary()
 {
     return(DataTypeConstants.DataTypeIsBinary(Type));
 }
Beispiel #6
0
 public bool DataTypeIsChar()
 {
     return(DataTypeConstants.DataTypeIsChar(Type));
 }