internal SysFn GetSys() { if (_style == 0) { return(new SysFn((buildContext, buildArgs) => { return Text.GenerateSql(30) .Append(Text.Convert) .EncloseLeft() .Append(_def.Build()) .AppendComma() .Append(_argument.Build(buildContext, buildArgs)) .EncloseRight() .ToString(); }, chainException)); } else { return(new SysFn((buildContext, buildArgs) => { return Text.GenerateSql(30) .Append(Text.Convert) .EncloseLeft() .Append(_def.Build()) .AppendComma() .Append(_argument.Build(buildContext, buildArgs)) .AppendComma() .Append(_style) .EncloseRight() .ToString(); }, chainException)); } }
/// <summary> /// <para>CAST AS built-in function.</para> /// <para>Converts an expression of one data type to another.</para> /// </summary> /// <param name="column">A column expression.</param> /// <param name="dataType">The target data type definition.</param> public static SysFn Cast(Column column, DataType dataType) { column = column ?? Designer.Null; return(new SysFn((buildContext, buildArgs) => { if (dataType == null) { throw new QueryTalkException("Cast", QueryTalkExceptionType.ArgumentNull, "dataTypeDef = null", Wall.Text.Method.SysConvert); } var sql = String.Format( "CAST({0} AS {1})", column.Build(buildContext, buildArgs), dataType.Build()); buildContext.TryTakeException(column.Exception, "Sys.Cast"); return sql; })); }
/// <summary> /// <para>CAST AS built-in function.</para> /// <para>Converts an expression of one data type to another.</para> /// </summary> /// <param name="argument">A scalar expression.</param> /// <param name="dataTypeDef">A data type definition.</param> public static SysFn Cast(IScalar argument, DataType dataTypeDef) { argument = argument ?? Designer.Null; return(new SysFn((buildContext, buildArgs) => { if (dataTypeDef == null) { throw new QueryTalkException("Cast", QueryTalkExceptionType.ArgumentNull, "dataTypeDef = null", Wall.Text.Method.SysConvert); } var sql = String.Format( "CAST({0} AS {1})", ((Chainer)argument).Build(buildContext, buildArgs), dataTypeDef.Build()); buildContext.TryTakeException(((Chainer)argument).Exception, "Sys.Cast"); return sql; })); }
internal Value(object value, Parameterization p, DataType dataType = null) : base(value) { if (value == null) { SetAsNull(); return; } Original = value; var clrType = value.GetType(); if (Mapping.CheckClrCompliance(clrType, out _clrType, out chainException) != Mapping.ClrTypeMatch.ClrMatch) { TryThrow(); } DebugValue = value; if (_clrType == typeof(DBNull) || _clrType == typeof(System.Object)) { SetAsNull(); return; } _hashCode = GetCrossTypeHashCode(_clrType, value.GetHashCode()); Build = (buildContext, buildArgs) => { string sql = null; if (p != Parameterization.None) { sql = value.Parameterize(buildContext, dataType, p); } if (sql == null) { if (dataType != null) { sql = String.Format("{0}({1} AS {2})", Text.Cast, Mapping.Build(value, dataType), dataType.Build()); } else { sql = Mapping.BuildUnchecked(value, out chainException); } } return(sql); }; }