/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, DbType dbType) { switch (dbType) { case DbType.String: case DbType.AnsiString: case DbType.Guid: case DbType.StringFixedLength: case DbType.AnsiStringFixedLength: return(string.Format("STR({0})", sourceExp)); case DbType.Currency: case DbType.Decimal: case DbType.Double: case DbType.Single: case DbType.Boolean: case DbType.SByte: case DbType.Int16: case DbType.Int32: case DbType.Int64: case DbType.Byte: case DbType.UInt16: case DbType.UInt32: case DbType.UInt64: return(string.Format("VAL({0})", sourceExp)); case DbType.Date: case DbType.DateTime: case DbType.Time: return(string.Format("CDATE({0})", sourceExp)); } return(ExceptionHelper.ThrowSyntaxConvertException(dbType)); }
/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, DbType dbType) { switch (dbType) { case DbType.String: return string.Format("CAST({0} AS VARCHAR)", sourceExp); case DbType.Int16: case DbType.UInt16: return string.Format("CAST({0} AS SMALLINT)", sourceExp); case DbType.Int32: case DbType.UInt32: return string.Format("CAST({0} AS INT)", sourceExp); case DbType.Int64: case DbType.UInt64: return string.Format("CAST({0} AS BIGINT)", sourceExp); case DbType.Byte: case DbType.SByte: return string.Format("CAST({0} AS SMALLINT)", sourceExp); case DbType.Decimal: return string.Format("CAST({0} AS DECIMAL)", sourceExp); case DbType.Single: return string.Format("CAST({0} AS REAL)", sourceExp); case DbType.Double: return string.Format("CAST({0} AS FLOAT)", sourceExp); case DbType.DateTime: return string.Format("CAST({0} AS DATE)", sourceExp); case DbType.Boolean: return string.Format("CAST({0} AS BOOLEAN)", sourceExp); } return ExceptionHelper.ThrowSyntaxConvertException(dbType); }
/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, DbType dbType) { switch (dbType) { case DbType.String: case DbType.AnsiString: case DbType.Guid: case DbType.StringFixedLength: case DbType.AnsiStringFixedLength: return(string.Format("CAST({0} AS CHAR)", sourceExp)); case DbType.Binary: return(string.Format("CAST({0} AS BINARY)", sourceExp)); case DbType.Currency: case DbType.Decimal: case DbType.Double: case DbType.Single: return(string.Format("CAST({0} AS DECIMAL)", sourceExp)); case DbType.Boolean: case DbType.SByte: case DbType.Int16: case DbType.Int32: case DbType.Int64: return(string.Format("CAST({0} AS SIGNED)", sourceExp)); case DbType.Byte: case DbType.UInt16: case DbType.UInt32: case DbType.UInt64: return(string.Format("CAST({0} AS UNSIGNED)", sourceExp)); case DbType.Date: return(string.Format("CAST({0} AS DATE)", sourceExp)); case DbType.DateTime: return(string.Format("CAST({0} AS DATETIME)", sourceExp)); case DbType.Time: return(string.Format("CAST({0} AS TIME)", sourceExp)); } return(ExceptionHelper.ThrowSyntaxConvertException(dbType)); }
/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, System.Data.DbType dbType) { switch (dbType) { case DbType.String: case DbType.AnsiString: return($"CAST({sourceExp} AS VARCHAR)"); case DbType.StringFixedLength: case DbType.AnsiStringFixedLength: return($"CAST({sourceExp} AS CHAR)"); case DbType.Decimal: return($"CAST({sourceExp} AS DECIMAL)"); case DbType.Double: return($"CAST({sourceExp} AS DOUBLE)"); case DbType.Single: return($"CAST({sourceExp} AS FLOAT)"); case DbType.Boolean: return($"CAST({sourceExp} AS BOOLEAN)"); case DbType.Int16: return($"CAST({sourceExp} AS SMALLINT)"); case DbType.Int32: return($"CAST({sourceExp} AS INT)"); case DbType.Date: return($"CAST({sourceExp} AS DATE)"); case DbType.DateTime: return($"CAST({sourceExp} AS TIMESTAMP)"); case DbType.Time: return($"CAST({sourceExp} AS TIME)"); } return(ExceptionHelper.ThrowSyntaxConvertException(dbType)); }
/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, DbType dbType) { switch (dbType) { case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.String: case DbType.StringFixedLength: return(string.Format("CAST({0} AS TEXT)", sourceExp)); case DbType.Binary: return(string.Format("CAST({0} AS BLOB)", sourceExp)); case DbType.Boolean: case DbType.Decimal: case DbType.Double: case DbType.Single: return(string.Format("CAST({0} AS NUMERIC)", sourceExp)); case DbType.Int16: case DbType.Int32: case DbType.Int64: case DbType.Byte: return(string.Format("CAST({0} AS INTEGER)", sourceExp)); case DbType.Date: return(string.Format("DATE({0})", sourceExp)); case DbType.DateTime: return(string.Format("DATETIME({0})", sourceExp)); case DbType.Time: return(string.Format("TIME({0})", sourceExp)); case DbType.Guid: return(string.Format("CAST({0} AS UNIQUEIDENTIFIER)", sourceExp)); } return(ExceptionHelper.ThrowSyntaxConvertException(dbType)); }
/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, DbType dbType) { switch (dbType) { case DbType.AnsiString: return(string.Format("TO_CHAR({0})", sourceExp)); case DbType.AnsiStringFixedLength: return(string.Format("TO_CHAR({0})", sourceExp)); case DbType.Binary: return(string.Format("CAST({0} AS BLOB)", sourceExp)); case DbType.Boolean: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Byte: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Currency: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Date: return(string.Format("TO_DATE({0}, 'YYYY-MM-DD')", sourceExp)); case DbType.DateTime: return(string.Format("TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS')", sourceExp)); case DbType.DateTime2: return(string.Format("TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS')", sourceExp)); case DbType.DateTimeOffset: return(string.Format("TO_DATE({0}, 'YYYY-MM-DD HH24:MI:SS')", sourceExp)); case DbType.Decimal: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Double: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Guid: break; case DbType.Int16: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Int32: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Int64: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.SByte: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.Single: return(string.Format("CAST({0} AS FLOAT)", sourceExp)); case DbType.String: return(string.Format("TO_CHAR({0})", sourceExp)); case DbType.StringFixedLength: return(string.Format("TO_CHAR({0})", sourceExp)); case DbType.Time: return(string.Format("TO_DATE({0}, 'HH24:MI:SS')", sourceExp)); case DbType.UInt16: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.UInt32: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.UInt64: return(string.Format("CAST({0} AS NUMBER)", sourceExp)); case DbType.VarNumeric: break; case DbType.Xml: break; } return(ExceptionHelper.ThrowSyntaxConvertException(dbType)); }
/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, DbType dbType) { switch (dbType) { case DbType.AnsiString: case DbType.AnsiStringFixedLength: case DbType.String: case DbType.StringFixedLength: return(string.Format("CSTR({0})", sourceExp)); case DbType.Binary: return(string.Format("CVAR({0})", sourceExp)); case DbType.Boolean: return(string.Format("CBOOL({0})", sourceExp)); case DbType.Byte: return(string.Format("CBYTE({0})", sourceExp)); case DbType.Currency: return(string.Format("CCUR({0})", sourceExp)); case DbType.Date: case DbType.DateTime: return(string.Format("CDATE({0})", sourceExp)); case DbType.DateTime2: ExceptionHelper.ThrowSyntaxConvertException(dbType); break; case DbType.DateTimeOffset: ExceptionHelper.ThrowSyntaxConvertException(dbType); break; case DbType.Decimal: return(string.Format("CDEC({0})", sourceExp)); case DbType.Double: return(string.Format("CDBL({0})", sourceExp)); case DbType.Guid: return(string.Format("CSTR({0})", sourceExp)); case DbType.Int16: case DbType.Int32: case DbType.UInt16: case DbType.UInt32: return(string.Format("CINT({0})", sourceExp)); case DbType.Int64: case DbType.UInt64: return(string.Format("CLNG({0})", sourceExp)); case DbType.SByte: ExceptionHelper.ThrowSyntaxConvertException(dbType); break; case DbType.Single: return(string.Format("CSNG({0})", sourceExp)); case DbType.Time: case DbType.VarNumeric: case DbType.Xml: break; } throw new SyntaxParseException("ConvertTo" + dbType); }
/// <summary> /// 转换源表达式的数据类型。 /// </summary> /// <param name="sourceExp">要转换的源表达式。</param> /// <param name="dbType">要转换的类型。</param> /// <returns></returns> public virtual string Convert(object sourceExp, DbType dbType) { switch (dbType) { case DbType.AnsiString: return(string.Format("CAST({0} AS VARCHAR)", sourceExp)); case DbType.AnsiStringFixedLength: return(string.Format("CAST({0} AS CHAR)", sourceExp)); case DbType.Binary: return(string.Format("CAST({0} AS VARBINARY)", sourceExp)); case DbType.Boolean: return(string.Format("CAST({0} AS BIT)", sourceExp)); case DbType.Byte: return(string.Format("CAST({0} AS TINYINT)", sourceExp)); case DbType.Currency: return(string.Format("CAST({0} AS MONEY)", sourceExp)); case DbType.Date: return(string.Format("CAST({0} AS DATETIME)", sourceExp)); case DbType.DateTime: return(string.Format("CAST({0} AS DATETIME)", sourceExp)); case DbType.DateTime2: return(string.Format("CAST({0} AS DATETIME2)", sourceExp)); case DbType.DateTimeOffset: return(string.Format("CAST({0} AS DATETIMEOFFSET)", sourceExp)); case DbType.Decimal: return(string.Format("CAST({0} AS DECIMAL)", sourceExp)); case DbType.Double: return(string.Format("CAST({0} AS DOUBLE PRECISION)", sourceExp)); case DbType.Guid: return(string.Format("CAST({0} AS UNIQUEIDENTIFIER)", sourceExp)); case DbType.Int16: return(string.Format("CAST({0} AS SMALLINT)", sourceExp)); case DbType.Int32: return(string.Format("CAST({0} AS INT)", sourceExp)); case DbType.Int64: return(string.Format("CAST({0} AS BIGINT)", sourceExp)); case DbType.SByte: break; case DbType.Single: return(string.Format("CAST({0} AS REAL)", sourceExp)); case DbType.String: return(string.Format("CAST({0} AS NVARCHAR)", sourceExp)); case DbType.StringFixedLength: return(string.Format("CAST({0} AS NCHAR)", sourceExp)); case DbType.Time: break; case DbType.UInt16: break; case DbType.UInt32: break; case DbType.UInt64: break; case DbType.VarNumeric: break; case DbType.Xml: return(string.Format("CAST({0} AS XML)", sourceExp)); } return(ExceptionHelper.ThrowSyntaxConvertException(dbType)); }