/// <summary> /// 获取 DatetTime 类型的 SQL 片断 /// </summary> protected override string GetSqlValueByDateTime(object value, object dbType, int?precision) { // 默认精度6 string format = "yyyy-MM-dd HH:mm:ss"; bool isTimestamp = false; if (DbTypeUtils.IsDateTime(dbType) || DbTypeUtils.IsDateTime2(dbType)) { format = "yyyy-MM-dd HH:mm:ss.ffffff"; isTimestamp = true; string pad = string.Empty; if (precision != null && precision.Value > 0) { pad = "f".PadLeft(precision.Value > 7 ? 7 : precision.Value, 'f'); } if (!string.IsNullOrEmpty(pad)) { format = string.Format("yyyy-MM-dd HH:mm:ss.{0}", pad); } } string result = this.EscapeQuote(((DateTime)value).ToString(format), false, false); result = isTimestamp ? string.Format("TO_TIMESTAMP({0},'yyyy-mm-dd hh24:mi:ss.ff')", result) : string.Format("TO_DATE({0},'yyyy-mm-dd hh24:mi:ss')", result); return(result); }
// 获取 DatetTime 类型的 SQL 片断(包括DateTime和TimeStamp) protected override string GetSqlValueByDateTime(object value, object dbType, int?precision) { // 默认精度为0 string format = "yyyy-MM-dd HH:mm:ss"; if (DbTypeUtils.IsDate(dbType)) { format = "yyyy-MM-dd"; } else if (DbTypeUtils.IsDateTime(dbType) || DbTypeUtils.IsDateTime2(dbType)) { string pad = string.Empty; if (precision != null && precision.Value > 0) { pad = "f".PadLeft(precision.Value > 6 ? 6 : precision.Value, 'f'); } if (!string.IsNullOrEmpty(pad)) { format = string.Format("yyyy-MM-dd HH:mm:ss.{0}", pad); } } string result = this.EscapeQuote(((DateTime)value).ToString(format), false, false); return(result); }
/// <summary> /// 是否日期+时间+精度类型 /// </summary> public static bool IsDateTime2(object dbType) { return(DbTypeUtils.IsDateTime(dbType)); }