Exemplo n.º 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));
     }
 }
Exemplo n.º 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;
 }
Exemplo n.º 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");
     }
 }
Exemplo n.º 4
0
 public bool DataTypeIsInteger()
 {
     return(DataTypeConstants.DataTypeIsInteger(Type));
 }
Exemplo n.º 5
0
 public bool DataTypeIsBinary()
 {
     return(DataTypeConstants.DataTypeIsBinary(Type));
 }
Exemplo n.º 6
0
 public bool DataTypeIsChar()
 {
     return(DataTypeConstants.DataTypeIsChar(Type));
 }