示例#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));
     }
 }
示例#2
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");
     }
 }
示例#3
0
 public bool DataTypeIsBinary()
 {
     return(DataTypeConstants.DataTypeIsBinary(Type));
 }