private static SqlDbType ConvertSqlTypeEnum(SqlDataType sqlDataType) { SqlDbType sqlDbType; switch (sqlDataType) { case SqlDataType.UserDefinedType: sqlDbType = System.Data.SqlDbType.Udt; break; case SqlDataType.None: case SqlDataType.NVarCharMax: case SqlDataType.UserDefinedDataType: case SqlDataType.VarBinaryMax: case SqlDataType.VarCharMax: case SqlDataType.SysName: //case SqlDataType.Numeric: case SqlDataType.UserDefinedTableType: case SqlDataType.HierarchyId: case SqlDataType.Geometry: case SqlDataType.Geography: throw new NotSupportedException("Unable to convert to SqlDbType:" + sqlDataType); case SqlDataType.Numeric: sqlDbType = SqlDbType.Decimal; break; default: sqlDbType = (SqlDbType)Enum.Parse(typeof(SqlDbType), sqlDataType.ToString()); break; } return sqlDbType; }
public TSqlDataType Build(SqlDataType value) { return new TSqlDataType() { SqlDataType = value, }; }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.Int32 : case DataType.UInt16 : case DataType.Int16 : if (createDbType) goto default; StringBuilder.Append("Signed"); break; case DataType.SByte : case DataType.Byte : if (createDbType) goto default; StringBuilder.Append("Unsigned"); break; case DataType.Money : StringBuilder.Append("Decimal(19,4)"); break; case DataType.SmallMoney : StringBuilder.Append("Decimal(10,4)"); break; case DataType.DateTime2 : case DataType.SmallDateTime : StringBuilder.Append("DateTime"); break; case DataType.Boolean : StringBuilder.Append("Boolean"); break; case DataType.Double : case DataType.Single : base.BuildDataType(SqlDataType.Decimal); break; case DataType.VarChar : case DataType.NVarChar : StringBuilder.Append("Char"); if (type.Length > 0) StringBuilder.Append('(').Append(type.Length).Append(')'); break; default : base.BuildDataType(type); break; } }
public static DataType ConvertToDotNetType(SqlDataType dbDataType) { string name = "string"; switch (dbDataType) { case SqlDataType.XML: case SqlDataType.VARCHAR: case SqlDataType.NVARCHAR: case SqlDataType.CHAR: case SqlDataType.NCHAR: case SqlDataType.NTEXT: case SqlDataType.TEXT: name = "string"; break; case SqlDataType.BIGINT: name = "long"; break; case SqlDataType.TIMESTAMP: case SqlDataType.BINARY: case SqlDataType.IMAGE: case SqlDataType.VARBINARY: name = "byte[]"; break; case SqlDataType.MONEY: case SqlDataType.BIT: name = "bool"; break; case SqlDataType.DATETIME: name = "DateTime"; break; case SqlDataType.REAL: case SqlDataType.DECIMAL: name = "decimal"; break; case SqlDataType.FLOAT: name = "single"; break; case SqlDataType.SMALLMONEY: case SqlDataType.INT: name = "int"; break; case SqlDataType.SMALLDATETIME: break; case SqlDataType.SMALLINT: name = "short"; break; case SqlDataType.SQL_VARIANT: break; case SqlDataType.TINYINT: name = "byte"; break; case SqlDataType.UNIQUEIDENTIFIER: name = "GUID"; break; default: throw new ArgumentOutOfRangeException("dbDataType"); } return new DataType { Name = name }; }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.DateTime2 : StringBuilder.Append("DateTime"); break; default : base.BuildDataType(type); break; } }
protected override void BuildDataType(StringBuilder sb, SqlDataType type) { switch (type.SqlDbType) { case SqlDbType.DateTimeOffset : case SqlDbType.DateTime2 : case SqlDbType.Time : case SqlDbType.Date : sb.Append("DateTime"); break; default : base.BuildDataType(sb, type); break; } }
public static Function Cast(Expression exp, SqlDataType type) { if (exp == null) { throw new ArgumentNullException("exp"); } if (type == null) { throw new ArgumentNullException("type"); } return new CastFunction(exp, type); }
public CastFunction(Expression exp, SqlDataType type) { if (exp == null) { throw new ArgumentNullException("exp"); } if (type == null) { throw new ArgumentNullException("type"); } this.Expression = exp; this.Type = type; }
public static Function Convert(SqlDataType type, Expression exp, uint? style = null) { if (type == null) { throw new ArgumentNullException("type"); } if (exp == null) { throw new ArgumentNullException("exp"); } return new ConvertFunction(type, exp, style); }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.DateTime : StringBuilder.Append("datetime year to second"); break; case DataType.DateTime2 : StringBuilder.Append("datetime year to fraction"); break; case DataType.SByte : case DataType.Byte : StringBuilder.Append("SmallInt"); break; case DataType.SmallMoney : StringBuilder.Append("Decimal(10,4)"); break; default : base.BuildDataType(type); break; } }
public ConvertFunction(SqlDataType type, Expression exp, uint? style) { if (type == null) { throw new ArgumentNullException("type"); } if (exp == null) { throw new ArgumentNullException("exp"); } this.Type = type; this.Value = exp; this.Style = style; }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.Char : base.BuildDataType(new SqlDataType(DataType.NChar, type.Length)); break; case DataType.VarChar : base.BuildDataType(new SqlDataType(DataType.NVarChar, type.Length)); break; case DataType.SmallMoney : StringBuilder.Append("Decimal(10,4)"); break; case DataType.DateTime2 : case DataType.Time : case DataType.Date : case DataType.SmallDateTime : StringBuilder.Append("DateTime"); break; default : base.BuildDataType(type); break; } }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.Int32 : case DataType.UInt16 : StringBuilder.Append("Integer"); return; case DataType.Double: StringBuilder.Append("Double"); return; case DataType.DateTime2 : case DataType.DateTime : case DataType.Time: StringBuilder.Append("Timestamp"); return; case DataType.SmallDateTime : StringBuilder.Append("SecondDate"); return; case DataType.Boolean : StringBuilder.Append("TinyInt"); return; case DataType.Image: StringBuilder.Append("Blob"); return; case DataType.Xml: StringBuilder.Append("Clob"); return; case DataType.Guid: StringBuilder.Append("Char (36)"); return; case DataType.NVarChar: case DataType.VarChar: case DataType.VarBinary: if (type.Length == int.MaxValue || type.Length < 0) { StringBuilder .Append(type.DataType) .Append("(Max)"); return; } break; } base.BuildDataType(type, createDbType); }
static void ConvertCharToSql(StringBuilder stringBuilder, SqlDataType sqlDataType, char value) { string start; switch (sqlDataType.DataType) { case DataType.Char : case DataType.VarChar : case DataType.Text : start = "'"; break; default : start = "N'"; break; } DataTools.ConvertCharToSql(stringBuilder, start, AppendConversion, value); }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.Int32 : case DataType.UInt16 : StringBuilder.Append("Integer"); break; case DataType.Double: StringBuilder.Append("Double"); break; case DataType.Money : StringBuilder.Append("Decimal(19,4)"); break; case DataType.SmallMoney : StringBuilder.Append("Decimal(10,4)"); break; case DataType.DateTime2 : case DataType.DateTime : case DataType.Time: StringBuilder.Append("Timestamp"); break; case DataType.SmallDateTime : StringBuilder.Append("SecondDate"); break; case DataType.Boolean : StringBuilder.Append("TinyInt"); break; case DataType.Image: StringBuilder.Append("Blob"); break; case DataType.Xml: StringBuilder.Append("Clob"); break; case DataType.Guid: StringBuilder.Append("Char (36)"); break; default: base.BuildDataType(type, createDbType); break; } }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.Decimal : base.BuildDataType(type.Precision > 18 ? new SqlDataType(type.DataType, type.Type, null, 18, type.Scale) : type); break; case DataType.SByte : case DataType.Byte : StringBuilder.Append("SmallInt"); break; case DataType.Money : StringBuilder.Append("Decimal(18,4)"); break; case DataType.SmallMoney : StringBuilder.Append("Decimal(10,4)"); break; case DataType.DateTime2 : case DataType.SmallDateTime : case DataType.DateTime : StringBuilder.Append("TimeStamp"); break; case DataType.NVarChar : StringBuilder.Append("VarChar"); if (type.Length > 0) StringBuilder.Append('(').Append(type.Length).Append(')'); StringBuilder.Append(" CHARACTER SET UNICODE_FSS"); break; default : base.BuildDataType(type); break; } }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.DateTimeOffset : case DataType.DateTime2 : case DataType.Time : case DataType.Date : StringBuilder.Append("DateTime"); return; case DataType.Xml : StringBuilder.Append("NText"); return; case DataType.NVarChar : if (type.Length == int.MaxValue || type.Length < 0) { StringBuilder .Append(type.DataType) .Append("(4000)"); return; } break; case DataType.VarChar : case DataType.VarBinary : if (type.Length == int.MaxValue || type.Length < 0) { StringBuilder .Append(type.DataType) .Append("(8000)"); return; } break; } base.BuildDataType(type, createDbType); }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.SByte : case DataType.Byte : StringBuilder.Append("SmallInt"); break; case DataType.Money : StringBuilder.Append("Decimal(19,4)"); break; case DataType.SmallMoney : StringBuilder.Append("Decimal(10,4)"); break; case DataType.DateTime2 : case DataType.SmallDateTime : case DataType.DateTime : StringBuilder.Append("TimeStamp"); break; case DataType.Boolean : StringBuilder.Append("Boolean"); break; case DataType.NVarChar : StringBuilder.Append("VarChar"); if (type.Length > 0) StringBuilder.Append('(').Append(type.Length).Append(')'); break; case DataType.Undefined : if (type.Type == typeof(string)) goto case DataType.NVarChar; break; default : base.BuildDataType(type); break; } }
public override ISqlExpression GetExpression(MemberInfo member, params ISqlExpression[] args) { var arr = new ISqlExpression[args.Length]; for (var i = 0; i <= args.Length; i++) { var arg = args[i]; if (arg.SystemType == typeof(string)) { arr[i] = arg; } else { var len = arg.SystemType == null || arg.SystemType == typeof(object) ? 100 : SqlDataType.GetMaxDisplaySize(SqlDataType.GetDataType(arg.SystemType).Type.DataType); arr[i] = new SqlFunction(typeof(string), "Convert", new SqlDataType(DataType.VarChar, len), arg); } } if (arr.Length == 1) { return(arr[0]); } var expr = new SqlBinaryExpression(typeof(string), arr[0], "+", arr[1]); var num2 = arr.Length - 1; for (var i = 2; i <= num2; i++) { expr = new SqlBinaryExpression(typeof(string), expr, "+", arr[i]); } return(expr); }
public void GetHashCode_ReturnsCorrectHashCode(SqlDataType dataType, SqlDataType other, bool expected) { Assert.Equal(expected, dataType.GetHashCode().Equals(other?.GetHashCode() ?? 0)); }
protected override void BuildDataType(StringBuilder sb, SqlDataType type) { switch (type.SqlDbType) { case SqlDbType.Char : base.BuildDataType(sb, new SqlDataType(SqlDbType.NChar, type.Length)); break; case SqlDbType.VarChar : base.BuildDataType(sb, new SqlDataType(SqlDbType.NVarChar, type.Length)); break; case SqlDbType.SmallMoney : sb.Append("Decimal(10,4)"); break; #if !MONO case SqlDbType.DateTime2 : #endif case SqlDbType.Time : case SqlDbType.Date : case SqlDbType.SmallDateTime : sb.Append("DateTime"); break; default : base.BuildDataType(sb, type); break; } }
protected override void BuildDataType(SqlDataType type, bool createDbType) { if (type.Type != null) { switch (type.DataType) { case DataType.Udt: var udtType = type.Type.ToNullableUnderlying(); if (udtType == _baseProvider.NpgsqlPointType) { StringBuilder.Append("point"); } else if (udtType == _baseProvider.NpgsqlLineType) { StringBuilder.Append("line"); } else if (udtType == _baseProvider.NpgsqlBoxType) { StringBuilder.Append("box"); } else if (udtType == _baseProvider.NpgsqlLSegType) { StringBuilder.Append("lseg"); } else if (udtType == _baseProvider.NpgsqlCircleType) { StringBuilder.Append("circle"); } else if (udtType == _baseProvider.NpgsqlPolygonType) { StringBuilder.Append("polygon"); } else if (udtType == _baseProvider.NpgsqlPathType) { StringBuilder.Append("path"); } else if (udtType == _baseProvider.NpgsqlIntervalType) { StringBuilder.Append("interval"); } else if (udtType == _baseProvider.NpgsqlDateType) { StringBuilder.Append("date"); } else if (udtType == _baseProvider.NpgsqlDateTimeType) { StringBuilder.Append("timestamp"); } else if (udtType == typeof(PhysicalAddress) && !_baseProvider.HasMacAddr8) { StringBuilder.Append("macaddr"); } else { break; } return; } } base.BuildDataType(type, createDbType); }
protected override void BuildDataType(StringBuilder sb, SqlDataType type) { switch (type.SqlDbType) { case SqlDbType.Int : case SqlDbType.SmallInt : sb.Append("Signed"); break; case SqlDbType.TinyInt : sb.Append("Unsigned"); break; case SqlDbType.Money : sb.Append("Decimal(19,4)"); break; case SqlDbType.SmallMoney : sb.Append("Decimal(10,4)"); break; #if !MONO case SqlDbType.DateTime2 : #endif case SqlDbType.SmallDateTime : sb.Append("DateTime"); break; case SqlDbType.Bit : sb.Append("Boolean"); break; case SqlDbType.Float : case SqlDbType.Real : base.BuildDataType(sb, SqlDataType.Decimal); break; case SqlDbType.VarChar : case SqlDbType.NVarChar : sb.Append("Char"); if (type.Length > 0) sb.Append('(').Append(type.Length).Append(')'); break; default: base.BuildDataType(sb, type); break; } }
public virtual async Task Data_StoreWideDecimal() { // test the full decimal storage capabilities of the engine using the max decimal value await Data_TestStoreDataType(SqlDataType.Decimal(38), decimal.MaxValue); }
/// <summary> /// This method adds a CSharpParam to the container /// and adds to user parameter dictionary as well. /// </summary> public unsafe void AddParam( ushort paramNumber, string paramName, SqlDataType dataType, ulong paramSize, short decimalDigits, void *paramValue, int strLenOrNullMap, short inputOutputType) { Logging.Trace("CSharpParamContainer::AddParam"); if (paramName == null) { throw new ArgumentException("Invalid input parameter name supplied"); } else if (paramNumber >= TotalParams || paramNumber < 0) { throw new ArgumentException("Invalid input parameter id supplied: " + paramNumber.ToString()); } _params[paramNumber] = new CSharpParam { DataType = dataType, DecimalDigits = decimalDigits, Name = paramName, InputOutputType = inputOutputType, Number = paramNumber, Size = paramSize, StrLenOrNullMap = strLenOrNullMap }; if (strLenOrNullMap == SQL_NULL_DATA) { return; } switch (dataType) { case SqlDataType.DotNetInteger: _params[paramNumber].Value = *(int *)paramValue; break; case SqlDataType.DotNetUInteger: _params[paramNumber].Value = *(uint *)paramValue; break; case SqlDataType.DotNetBigInt: _params[paramNumber].Value = *(long *)paramValue; break; case SqlDataType.DotNetUBigInt: _params[paramNumber].Value = *(ulong *)paramValue; break; case SqlDataType.DotNetTinyInt: _params[paramNumber].Value = *(sbyte *)paramValue; break; case SqlDataType.DotNetUTinyInt: _params[paramNumber].Value = *(byte *)paramValue; break; case SqlDataType.DotNetSmallInt: _params[paramNumber].Value = *(short *)paramValue; break; case SqlDataType.DotNetUSmallInt: _params[paramNumber].Value = *(ushort *)paramValue; break; case SqlDataType.DotNetDouble: _params[paramNumber].Value = *(double *)paramValue; break; case SqlDataType.DotNetFloat: _params[paramNumber].Value = *(double *)paramValue; break; case SqlDataType.DotNetReal: _params[paramNumber].Value = *(float *)paramValue; break; case SqlDataType.DotNetBit: _params[paramNumber].Value = *(bool *)paramValue; break; case SqlDataType.DotNetChar: _params[paramNumber].Value = Interop.UTF8PtrToStr((char *)paramValue, (ulong)strLenOrNullMap); break; default: throw new NotImplementedException("Parameter type for " + dataType.ToString() + " has not been implemented yet"); } UserParams[paramName] = _params[paramNumber].Value; }
protected override void BuildDataType(StringBuilder sb, SqlDataType type) { switch (type.SqlDbType) { case SqlDbType.BigInt : sb.Append("Number(19)"); break; case SqlDbType.TinyInt : sb.Append("Number(3)"); break; case SqlDbType.Money : sb.Append("Number(19,4)"); break; case SqlDbType.SmallMoney : sb.Append("Number(10,4)"); break; case SqlDbType.NVarChar : sb.Append("VarChar2"); if (type.Length > 0) sb.Append('(').Append(type.Length).Append(')'); break; default : base.BuildDataType(sb, type); break; } }
public virtual async Task Data_StoreFloat() { await Data_TestStoreDataType(SqlDataType.Float(), float.MaxValue); }
public override void SetTable(ISqlBuilder sqlBuilder, MappingSchema mappingSchema, SqlTable table, MemberInfo member, IEnumerable <Expression> arguments, IEnumerable <ISqlExpression> sqlArgs) { var arg = sqlArgs.ElementAt(1); var ed = mappingSchema.GetEntityDescriptor(table.ObjectType !); if (arg is SqlParameter p) { var exp = arguments.ElementAt(1).Unwrap(); // TODO: ValueConverter contract nullability violations if (exp is ConstantExpression constExpr) { if (constExpr.Value is Func <string> ) { p.ValueConverter = l => ((Func <string>)l !)(); } else { p.ValueConverter = GetXmlConverter(mappingSchema, table) !; } } else if (exp is LambdaExpression) { p.ValueConverter = l => ((Func <string>)l !)(); } } var columns = ed.Columns .Select((c, i) => string.Format("{0} {1} path 'c{2}'", sqlBuilder.ConvertInline(c.ColumnName, ConvertType.NameToQueryField), string.IsNullOrEmpty(c.DbType) ? GetDataTypeText( new SqlDataType( c.DataType == DataType.Undefined ? SqlDataType.GetDataType(c.MemberType).Type.DataType : c.DataType, c.MemberType, c.Length, c.Precision, c.Scale, c.DbType)) : c.DbType, i)) .Aggregate((s1, s2) => s1 + ", " + s2); table.SqlTableType = SqlTableType.Expression; table.Name = $"XmlTable(\'/t/r\' PASSING XmlType({{2}}) COLUMNS {columns}) {{1}}"; table.TableArguments = new[] { arg }; }
//------------------------------------------------------------------- public static Type GetDataType(SqlDataType type) { Type dataType = null; switch (type) { case SqlDataType.BigInt: dataType = typeof(long); break; case SqlDataType.Binary: dataType = typeof(byte[]); break; case SqlDataType.Bit: dataType = typeof(bool); break; case SqlDataType.Char: dataType = typeof(string); break; case SqlDataType.Date: dataType = typeof(DateTime); break; case SqlDataType.DateTime: dataType = typeof(DateTime); break; case SqlDataType.DateTime2: dataType = typeof(DateTime); break; case SqlDataType.DateTimeOffset: dataType = typeof(DateTimeOffset); break; case SqlDataType.Decimal: dataType = typeof(decimal); break; case SqlDataType.Float: dataType = typeof(double); break; case SqlDataType.Image: dataType = typeof(byte[]); break; case SqlDataType.Int: dataType = typeof(int); break; case SqlDataType.Money: dataType = typeof(decimal); break; case SqlDataType.NChar: dataType = typeof(string); break; case SqlDataType.NText: dataType = typeof(string); break; case SqlDataType.NVarChar: dataType = typeof(string); break; case SqlDataType.Real: dataType = typeof(Single); break; case SqlDataType.SmallDateTime: dataType = typeof(DateTime); break; case SqlDataType.SmallInt: dataType = typeof(short); break; case SqlDataType.SmallMoney: dataType = typeof(decimal); break; case SqlDataType.Text: dataType = typeof(string); break; case SqlDataType.Time: dataType = typeof(TimeSpan); break; case SqlDataType.Timestamp: dataType = typeof(byte[]); break; case SqlDataType.TinyInt: dataType = typeof(byte); break; case SqlDataType.UniqueIdentifier: dataType = typeof(Guid); break; case SqlDataType.VarBinary: dataType = typeof(byte[]); break; case SqlDataType.VarChar: dataType = typeof(string); break; case SqlDataType.Variant: dataType = typeof(object); break; case SqlDataType.Xml: dataType = typeof(XmlDocument); break; case SqlDataType.Geography: dataType = typeof(object); break; case SqlDataType.Geometry: dataType = typeof(object); break; case SqlDataType.HierarchyId: dataType = typeof(object); break; case SqlDataType.None: dataType = null; break; case SqlDataType.Numeric: dataType = typeof(decimal); break; case SqlDataType.NVarCharMax: dataType = typeof(string); break; case SqlDataType.SysName: dataType = typeof(object); break; case SqlDataType.UserDefinedTableType: dataType = typeof(object); break; case SqlDataType.UserDefinedType: dataType = typeof(object); break; case SqlDataType.VarBinaryMax: dataType = typeof(byte[]); break; case SqlDataType.VarCharMax: dataType = typeof(string); break; default: dataType = null; break; } return(dataType); }
//------------------------------------------------------------------- public static SqlDbType GetSqlDbType(SqlDataType type) { SqlDbType dataType = SqlDbType.NVarChar; switch (type) { case SqlDataType.BigInt: dataType = SqlDbType.BigInt; break; case SqlDataType.Binary: dataType = SqlDbType.Binary; break; case SqlDataType.Bit: dataType = SqlDbType.Bit; break; case SqlDataType.Char: dataType = SqlDbType.Char; break; case SqlDataType.Date: dataType = SqlDbType.Date; break; case SqlDataType.DateTime: dataType = SqlDbType.DateTime; break; case SqlDataType.DateTime2: dataType = SqlDbType.DateTime2; break; case SqlDataType.DateTimeOffset: dataType = SqlDbType.DateTimeOffset; break; case SqlDataType.Decimal: dataType = SqlDbType.Decimal; break; case SqlDataType.Float: dataType = SqlDbType.Float; break; case SqlDataType.Image: dataType = SqlDbType.Image; break; case SqlDataType.Int: dataType = SqlDbType.Int; break; case SqlDataType.Money: dataType = SqlDbType.Money; break; case SqlDataType.NChar: dataType = SqlDbType.NChar; break; case SqlDataType.NText: dataType = SqlDbType.NText; break; case SqlDataType.NVarChar: dataType = SqlDbType.NVarChar; break; case SqlDataType.Real: dataType = SqlDbType.Real; break; case SqlDataType.SmallDateTime: dataType = SqlDbType.SmallDateTime; break; case SqlDataType.SmallInt: dataType = SqlDbType.SmallInt; break; case SqlDataType.SmallMoney: dataType = SqlDbType.SmallMoney; break; case SqlDataType.Text: dataType = SqlDbType.Text; break; case SqlDataType.Time: dataType = SqlDbType.Time; break; case SqlDataType.Timestamp: dataType = SqlDbType.Timestamp; break; case SqlDataType.TinyInt: dataType = SqlDbType.TinyInt; break; case SqlDataType.UniqueIdentifier: dataType = SqlDbType.UniqueIdentifier; break; case SqlDataType.VarBinary: dataType = SqlDbType.VarBinary; break; case SqlDataType.VarChar: dataType = SqlDbType.VarChar; break; case SqlDataType.Variant: dataType = SqlDbType.Variant; break; case SqlDataType.Xml: dataType = SqlDbType.Xml; break; //case SqlDataType.Geography: // dataType = SqlDbType.Geography; // break; //case SqlDataType.Geometry: // dataType = SqlDbType.Geometry; // break; //case SqlDataType.HierarchyId: // dataType = SqlDbType.HierarchyId; // break; //case SqlDataType.None: // dataType = SqlDbType.None; // break; //case SqlDataType.Numeric: // dataType = SqlDbType.Numeric; // break; case SqlDataType.NVarCharMax: dataType = SqlDbType.NVarChar; break; //case SqlDataType.SysName: // dataType = SqlDbType.SysName; // break; case SqlDataType.UserDefinedTableType: dataType = SqlDbType.Udt; break; case SqlDataType.UserDefinedType: dataType = SqlDbType.Udt; break; case SqlDataType.VarBinaryMax: dataType = SqlDbType.VarBinary; break; case SqlDataType.VarCharMax: dataType = SqlDbType.VarChar; break; //default: // dataType = null; // break; } return(dataType); }
//------------------------------------------------------------ public static string GetDataTypeString(SqlDataType type) { string dataType = ""; switch (type) { case SqlDataType.BigInt: dataType = "Int64"; break; case SqlDataType.Binary: dataType = "Byte[]"; break; case SqlDataType.Bit: dataType = "Boolean"; break; case SqlDataType.Char: dataType = "String"; break; case SqlDataType.Date: dataType = "DateTime"; break; case SqlDataType.DateTime: dataType = "DateTime"; break; case SqlDataType.DateTime2: dataType = "DateTime"; break; case SqlDataType.DateTimeOffset: dataType = "DateTimeOffset"; break; case SqlDataType.Decimal: dataType = "Decimal"; break; case SqlDataType.Float: dataType = "Double"; break; case SqlDataType.Image: dataType = "Byte[]"; break; case SqlDataType.Int: dataType = "Int32"; break; case SqlDataType.Money: dataType = "Decimal"; break; case SqlDataType.NChar: dataType = "String"; break; case SqlDataType.NText: dataType = "String"; break; case SqlDataType.NVarChar: dataType = "String"; break; case SqlDataType.Real: dataType = "Single"; break; case SqlDataType.SmallDateTime: dataType = "DateTime"; break; case SqlDataType.SmallInt: dataType = "Int16"; break; case SqlDataType.SmallMoney: dataType = "Decimal"; break; case SqlDataType.Text: dataType = "String"; break; case SqlDataType.Time: dataType = "TimeSpan"; break; case SqlDataType.Timestamp: dataType = "Byte[]"; break; case SqlDataType.TinyInt: dataType = "Byte"; break; case SqlDataType.UserDefinedDataType: dataType = "Object"; break; case SqlDataType.UniqueIdentifier: dataType = "Guid"; break; case SqlDataType.VarBinary: dataType = "Byte[]"; break; case SqlDataType.VarChar: dataType = "String"; break; case SqlDataType.Variant: dataType = "Object"; break; case SqlDataType.Xml: dataType = "XmlDocument"; break; case SqlDataType.Geography: dataType = "Object"; break; case SqlDataType.Geometry: dataType = "Object"; break; case SqlDataType.HierarchyId: dataType = "Object"; break; case SqlDataType.None: dataType = ""; break; case SqlDataType.Numeric: dataType = "Decimal"; break; case SqlDataType.NVarCharMax: dataType = "String"; break; case SqlDataType.SysName: dataType = "Object"; break; case SqlDataType.UserDefinedTableType: dataType = "Object"; break; case SqlDataType.UserDefinedType: dataType = "Object"; break; case SqlDataType.VarBinaryMax: dataType = "Byte[]"; break; case SqlDataType.VarCharMax: dataType = "String"; break; default: dataType = ""; break; } return(dataType); }
protected override void AddSourceValue( ValueToSqlConverter valueConverter, ColumnDescriptor column, SqlDataType columnType, object value, bool isFirstRow, bool isLastRow) { // strange thing, that real type needs explicit typing only on some combinations of columns and values // from other side, for Sybase it is not surprising if (column.DataType == DataType.Single || (column.DataType == DataType.Undefined && column.MemberType.ToNullableUnderlying() == typeof(float))) { Command.Append("CAST("); base.AddSourceValue(valueConverter, column, columnType, value, isFirstRow, isLastRow); Command.Append(" AS REAL)"); } else if (column.DataType == DataType.DateTime || column.DataType == DataType.DateTime2) { Command.Append("CAST("); base.AddSourceValue(valueConverter, column, columnType, value, isFirstRow, isLastRow); Command.Append(" AS DATETIME)"); } else if (column.DataType == DataType.Date) { Command.Append("CAST("); base.AddSourceValue(valueConverter, column, columnType, value, isFirstRow, isLastRow); Command.Append(" AS DATE)"); } else if (column.DataType == DataType.Time) { Command.Append("CAST("); base.AddSourceValue(valueConverter, column, columnType, value, isFirstRow, isLastRow); Command.Append(" AS TIME)"); } else if (isFirstRow && value == null) { string type; if (column.DbType != null) { type = column.DbType; } else { var dataType = column.DataType != DataType.Undefined ? column.DataType : DataContext.MappingSchema.GetDataType(column.MemberType).DataType; switch (dataType) { case DataType.Double: type = "FLOAT"; break; case DataType.Single: type = "REAL"; break; case DataType.SByte: type = "TINYINT"; break; case DataType.UInt16: type = "INT"; break; case DataType.UInt32: type = "BIGINT"; break; case DataType.UInt64: type = "DECIMAL"; break; case DataType.Byte: type = "TINYINT"; break; case DataType.Int16: type = "SMALLINT"; break; case DataType.Int32: type = "INT"; break; case DataType.Int64: type = "BIGINT"; break; case DataType.Boolean: type = "BIT"; break; default: type = null; break; } } if (type != null) { Command .Append("CAST(NULL AS ") .Append(type) ; if (column.Length > 0) { Command .Append('(') .Append(column.Length) .Append(')') ; } if (column.Precision > 0) { Command .Append('(') .Append(column.Precision) .Append(',') .Append(column.Scale) .Append(')') ; } Command .Append(")") ; } else { base.AddSourceValue(valueConverter, column, columnType, value, isFirstRow, isLastRow); } } else { base.AddSourceValue(valueConverter, column, columnType, value, isFirstRow, isLastRow); } }
public static IEnumerable <object[]> EqualsData(bool exactTypeOnly) { var dataType = new SqlDataType("FOOBAR"); if (!exactTypeOnly) { yield return(new object[] { dataType, "FOOBAR", false }); } yield return(new object[] { dataType, (SqlDataType)null, false }); yield return(new object[] { dataType, new SqlDataType("NONE"), false }); yield return(new object[] { dataType, new SqlDataType("FOOBAR"), true }); yield return(new object[] { dataType, dataType, true }); yield return(new object[] { SqlDataType.Int(), SqlDataType.Int(), true }); yield return(new object[] { SqlDataType.Int(), SqlDataType.BigInt(), false }); yield return(new object[] { SqlDataType.VarChar(5), SqlDataType.VarChar(10), false }); yield return(new object[] { SqlDataType.VarChar(5), SqlDataType.Char(10), false }); yield return(new object[] { SqlDataType.VarChar(5), SqlDataType.VarChar(5), true }); yield return(new object[] { SqlDataType.VarChar(5), SqlDataType.Float(5), false }); yield return(new object[] { SqlDataType.VarChar(5), SqlDataType.Float(6), false }); yield return(new object[] { SqlDataType.VarChar(5), null, false }); yield return(new object[] { SqlDataType.Float(), SqlDataType.Float(10), false }); yield return(new object[] { SqlDataType.Float(), new SqlPrecisionDataType("DOUBLE"), false }); yield return(new object[] { SqlDataType.Float(), SqlDataType.Float(), true }); yield return(new object[] { SqlDataType.Float(5), SqlDataType.Float(10), false }); yield return(new object[] { SqlDataType.Float(5), SqlDataType.Float(5), true }); yield return(new object[] { SqlDataType.Float(5), SqlDataType.VarChar(42), false }); yield return(new object[] { SqlDataType.Float(5), null, false }); yield return(new object[] { SqlDataType.Decimal(), SqlDataType.Decimal(10, 3), false }); yield return(new object[] { SqlDataType.Decimal(), SqlDataType.Float(10), false }); yield return(new object[] { SqlDataType.Decimal(), SqlDataType.Decimal(), true }); yield return(new object[] { SqlDataType.Decimal(5, 3), SqlDataType.Decimal(10, 3), false }); yield return(new object[] { SqlDataType.Decimal(5, 3), SqlDataType.Decimal(5, 3), true }); yield return(new object[] { SqlDataType.Decimal(5, 3), SqlDataType.VarChar(42), false }); yield return(new object[] { SqlDataType.Decimal(5, 3), SqlDataType.Decimal(5, 4), false }); yield return(new object[] { SqlDataType.Decimal(5, 3), null, false }); var self = (SqlDataType)SqlDataType.VarChar(5); yield return(new object[] { self, self, true }); self = SqlDataType.Float(5); yield return(new object[] { self, self, true }); self = SqlDataType.Decimal(10, 3); yield return(new object[] { self, self, true }); }
public string Generate() { Padding = PaddingForMethodDeclaration; WriteLine("/// <summary>"); WriteLine("///" + PaddingForComment + "<para> {0} </para>", ForcedComment); if (Comment != null) { foreach (var commentLine in from line in Comment.Split(Environment.NewLine.ToCharArray()) where !string.IsNullOrWhiteSpace(line) select line) { WriteLine("///" + PaddingForComment + "<para> " + commentLine + " </para>"); } } if (Parameters.Any()) { foreach (var p in Parameters) { var column = p.FindColum(Columns); var propertyName = p.GetPropertyName(Columns); if (propertyName == null) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} = {0}</param>", column.ColumnName.AsMethodParameter(), column.ColumnName); } else if (propertyName == Names.NotEqual) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} != {0} </param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.BiggerThan) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} > {0}</param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.BiggerThanOrEquals) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} >= {0}</param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.LessThan) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} < {0}</param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.LessThanOrEquals) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} <= {0}</param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.StartsWith) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} LIKE {0} + '%'</param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.EndsWith) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} LIKE '%' + {0}</param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.Contains) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE {1} LIKE '%' + {0} + '%'</param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else if (propertyName == Names.IsNull) { WriteLine("///" + PaddingForComment + "<param name=\"{0}\">WHERE(( {0} = true AND {1} IS NULL ) OR ( {0} = false AND {1} IS NOT NULL )) </param>", column.ColumnName.AsMethodParameter() + propertyName, column.ColumnName); } else { throw new Exception(propertyName); } } } WriteLine("/// </summary>"); WritePadding(); var methodAccess = "public "; if (CustomSelect.MemberAccessibility == MemberAccessibility.Private) { methodAccess = ""; } if (CustomSelect.MemberAccessibility == MemberAccessibility.Internal) { methodAccess = "internal "; } Write(methodAccess); Write("GenericResponse<{1}> {0}(", NameOfCsMethod, GenericResponseMethodReturnType); if (Parameters.Any()) { var last = Parameters.Last(); foreach (var p in Parameters) { var column = p.FindColum(Columns); var propertyName = p.GetPropertyName(Columns); var propertyNameIsNull = propertyName == Names.IsNull; var parameterName = column.ColumnName.AsMethodParameter() + propertyName; var parameterType = column.DotNetType; if (p.CanBeNull) { parameterType = SqlDataType.GetDotNetNullableType(parameterType); } if (propertyNameIsNull) { parameterType = "bool"; } Write("{0} {1}", parameterType, parameterName); if (p != last) { Write(","); } } } Write(")"); WriteLine(); WriteLine("{"); Padding++; WriteLine("var returnObject = CreateResponse<{0}>();", GenericResponseMethodReturnType); WriteLine(); WriteLine("var command = DBLayer.GetDBCommand(Databases.{0}, \"{1}\");", Context.Naming.DatabaseEnumName, Context.Naming.SchemaName + "." + NameOfSqlProcedure); WriteLine(); if (Parameters.Any()) { WriteLine("#region Parameters"); foreach (var p in Parameters) { var column = p.FindColum(Columns); var propertyName = p.GetPropertyName(Columns); var parameterName = column.ColumnName.AsMethodParameter() + propertyName; var sqlDatabaseTypeName = column.SqlDatabaseTypeName; if (p.GetPropertyName(Columns) == Names.IsNull) { sqlDatabaseTypeName = "TinyInt"; parameterName = "(" + parameterName + " ? 1 : 0)"; } WriteLine("DBLayer.AddInParameter(command, \"{0}\", SqlDbType.{1}, {2});", column.ColumnName + propertyName, sqlDatabaseTypeName, parameterName); } WriteLine("#endregion"); WriteLine(); } WriteLine("var sp = DBLayer.{0}(command);", ExecutionMethod); WriteLine("if (!sp.Success)"); WriteLine("{"); Padding++; WriteLine("return returnObject.Add(sp);"); Padding--; WriteLine("}"); ProcessReturnValues(); WriteLine("return returnObject;"); Padding--; WriteLine("}"); return(GeneratedString); }
public virtual async Task Data_StoreDoublePrecisionFloat() { await Data_TestStoreDataType(SqlDataType.Float(SqlDataType.DOUBLE_MAX_PRECISION), double.MaxValue); }
protected override void BuildTypedExpression(SqlDataType dataType, ISqlExpression value) { BuildExpression(value); StringBuilder.Append("::"); BuildDataType(dataType, false); }
public virtual async Task Data_StoreGuid() { await Data_TestStoreDataType(SqlDataType.Guid(), Guid.NewGuid()); }
protected ISqlExpression[] ConvertArgs(MemberInfo member, ISqlExpression[] args) { if (member is MethodInfo) { var method = (MethodInfo)member; if (method.DeclaringType.IsGenericTypeEx()) { args = args.Concat(method.DeclaringType.GetGenericArgumentsEx().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray(); } if (method.IsGenericMethod) { args = args.Concat(method.GetGenericArguments().Select(t => (ISqlExpression)SqlDataType.GetDataType(t))).ToArray(); } } if (ArgIndices != null) { var idxs = new ISqlExpression[ArgIndices.Length]; for (var i = 0; i < ArgIndices.Length; i++) { idxs[i] = args[ArgIndices[i]]; } return(idxs); } return(args); }
private void WriteTypeHint(ColumnDescriptor column, SqlDataType columnType) { Command.Append("::"); BuildColumnType(column, columnType); }
public void GetHashCode_ReturnsHashCodeOfNameProperty(string name) { var dataType = new SqlDataType(name); Assert.Equal(name.GetHashCode(), dataType.GetHashCode()); }
public static SqlExpression Constant(SqlDataType dataType, object val) { SqlExpression expression = new SqlExpression(); expression.val = new SqlConstant(dataType, val); expression.type = SqlExpressionType.Constant; return expression; }
static void ConvertDateTimeOffsetToSql(StringBuilder stringBuilder, SqlDataType sqlDataType, DateTimeOffset value) { var format = "'{0:yyyy-MM-dd HH:mm:ss.fffffff zzz}'"; switch (sqlDataType.Precision ?? sqlDataType.Scale) { case 0 : format = "'{0:yyyy-MM-dd HH:mm:ss zzz}'"; break; case 1 : format = "'{0:yyyy-MM-dd HH:mm:ss.f zzz}'"; break; case 2 : format = "'{0:yyyy-MM-dd HH:mm:ss.ff zzz}'"; break; case 3 : format = "'{0:yyyy-MM-dd HH:mm:ss.fff zzz}'"; break; case 4 : format = "'{0:yyyy-MM-dd HH:mm:ss.ffff zzz}'"; break; case 5 : format = "'{0:yyyy-MM-dd HH:mm:ss.fffff zzz}'"; break; case 6 : format = "'{0:yyyy-MM-dd HH:mm:ss.ffffff zzz}'"; break; case 7 : format = "'{0:yyyy-MM-dd HH:mm:ss.fffffff zzz}'"; break; } stringBuilder.AppendFormat(format, value); }
//private bool CreateStatisticTable(StatisticInfo[] infos, int statisticTypeIndex, object[] statistic) //{ // string[] StatisticTypeNames = new string[] { StringDef.Level, StringDef.RoleClass, StringDef.Sex, StringDef.Map }; // TableHeaderRow headerRow = new TableHeaderRow(); // TableHeaderCell headerCell = new TableHeaderCell(); // headerCell.Text = StatisticTypeNames[statisticTypeIndex]; // headerRow.Cells.Add(headerCell); // headerCell = new TableHeaderCell(); // headerCell.Text = StringDef.Count; // headerRow.Cells.Add(headerCell); // TableStatistic.Rows.Add(headerRow); // for (int i = 0; i < infos.Length; i++) // { // StatisticInfo info = infos[i]; // TableRow row = new TableRow(); // TableCell cell = new TableCell(); // for (int j = 0; j < statistic.Length; j++) // { // if (statistic[j].Id == info.Type) // { // cell.Text = statistic[j].Name; // row.Cells.Add(cell); // break; // } // } // cell = new TableCell(); // cell.Text = info.Count.ToString(); // row.Cells.Add(cell); // TableStatistic.Rows.Add(row); // } // return true; //} protected void ZedGraphWebStatistic_RenderGraph(ZedGraph.Web.ZedGraphWeb webObject, Graphics g, MasterPane masterPane) { if (_server != null) { GraphPane graphPane = masterPane[0]; string[] StatisticTypeNames = new string[] { StringDef.Level, StringDef.RoleClass, StringDef.Sex, StringDef.Map }; string staticType = StatisticTypes[_statisticType]; string staticTypeName = StatisticTypeNames[_statisticType]; SqlCommand cmd = new SqlCommand("SELECT " + staticType + ",COUNT(*) FROM rolesfirst " + _whereStatement + " GROUP BY " + staticType); if (!_server.IsConnected) { //LabelMessage.Visible = true; //LabelMessage.Text = StringDef.NoConnectionAlert; return; } SqlResult result = WebUtil.QueryGameServerDb(CurrentUser.Id,_server, cmd); if (result != null && result.Success) { //整理数据 SqlDataType[] dataTypes = new SqlDataType[] { SqlDataType.Int32, SqlDataType.Int32 }; result.SetFieldType(dataTypes); object[] statistic = null; switch (_statisticType) { case 0: { statistic = new object[FS2GameDataManager.MaxLevel]; for (int level = 1; level <= FS2GameDataManager.MaxLevel; level++) { statistic[level - 1] = level; } } break; case 1: { statistic = new object[FS2GameDataManager.RoleClasses.Length]; for (int i = 0; i < FS2GameDataManager.RoleClasses.Length; i++) { statistic[i] = FS2GameDataManager.RoleClasses[i]; } } break; case 2: { statistic = new object[FS2GameDataManager.RoleSexes.Length]; for (int i = 0; i < FS2GameDataManager.RoleSexes.Length; i++) { statistic[i] = FS2GameDataManager.RoleSexes[i]; } } break; case 3: statistic = new object[] { 0, 1, 2, 3, 4 }; break; } StatisticInfo[] infos = new StatisticInfo[statistic.Length]; for (int i = 0; i < infos.Length; i++) { infos[i] = new StatisticInfo(int.Parse(statistic[i].ToString()), 0); } object[] record = null; while ((record = result.ReadRecord()) != null) { int type = (int)record[0]; int count = (int)record[1]; for (int i = 0; i < infos.Length; i++) { if (infos[i].Type == type) { infos[i].Count = count; } } } ////构造数据表格 //bool success = CreateStatisticTable(infos, _statisticType, statistic); //if (success) //{ // TableStatistic.Visible = true; //} graphPane.Title.Text = staticTypeName; graphPane.Fill = new Fill(WebConfig.GraphPaneBgColor); graphPane.Legend.IsVisible = false; string[] textLabels = new string[statistic.Length]; for (int i = 0; i < statistic.Length; i++) { textLabels[i] = statistic[i].ToString(); } graphPane.XAxis.Title.Text = staticTypeName; graphPane.XAxis.MajorGrid.Color = WebConfig.GraphXAxisGridColor; if (_statisticType > 0) { graphPane.XAxis.MajorTic.IsBetweenLabels = true; graphPane.XAxis.Type = AxisType.Text; graphPane.XAxis.Scale.TextLabels = textLabels; } graphPane.YAxis.Title.Text = StringDef.Count; graphPane.YAxis.Scale.Min = 0; graphPane.YAxis.MajorGrid.IsVisible = true; graphPane.YAxis.MajorGrid.DashOff = 0; graphPane.YAxis.MajorGrid.Color = Color.Gray; graphPane.YAxis.MinorGrid.IsVisible = true; graphPane.YAxis.MinorGrid.Color = Color.LightGray; graphPane.YAxis.MinorGrid.DashOff = 0; if (_chartType == ChartType.Bar) { graphPane.BarSettings.Type = BarType.Stack; double[] counts = new double[infos.Length]; double[] types = new double[infos.Length]; for (int i = 0; i < infos.Length; i++) { StatisticInfo info = infos[i] as StatisticInfo; counts[i] = info.Count; types[i] = info.Type; //添加数值标签 string lab = info.Count.ToString(); TextObj text = new TextObj(lab, i + 1, (float)(info.Count)); ; text.Location.CoordinateFrame = CoordType.AxisXYScale; text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; if (_statisticType == 0) { text.Location.AlignH = AlignH.Left; text.Location.AlignV = AlignV.Center; text.FontSpec.Angle = 90f; } else { text.Location.AlignH = AlignH.Center; text.Location.AlignV = AlignV.Bottom; } graphPane.GraphObjList.Add(text); } //绘制柱子 BarItem barItem = graphPane.AddBar(StringDef.Count, types, counts, WebConfig.GraphColors[0]); barItem.Bar.Fill = new Fill(WebConfig.GraphColors[0]); } else if (_chartType == ChartType.Line) { double[] counts = new double[infos.Length]; double[] types = new double[infos.Length]; for (int i = 0; i < infos.Length; i++) { StatisticInfo info = infos[i] as StatisticInfo; counts[i] = info.Count; types[i] = info.Type; //添加数值标签 string lab = info.Count.ToString(); TextObj text = new TextObj(lab, i + 1, (float)(info.Count)); ; text.Location.CoordinateFrame = CoordType.AxisXYScale; text.FontSpec.Border.IsVisible = false; text.FontSpec.Fill.IsVisible = false; if (_statisticType == 0) { text.Location.AlignH = AlignH.Left; text.Location.AlignV = AlignV.Center; text.FontSpec.Angle = 90f; } else { text.Location.AlignH = AlignH.Center; text.Location.AlignV = AlignV.Bottom; } graphPane.GraphObjList.Add(text); } //绘制线条 LineItem lineItem = graphPane.AddCurve("xxx", types, counts, WebConfig.GraphColors[1], SymbolType.None); } graphPane.AxisChange(g); } } }
public void ExpressionType_ReturnsDataType() { var constant = SqlDataType.Int(); Assert.Equal(SqlExpressionType.DataType, constant.ExpressionType); }
static void ConvertTimeSpanToSql(StringBuilder stringBuilder, SqlDataType sqlDataType, TimeSpan value) { if (sqlDataType.DataType == DataType.Int64) { stringBuilder.Append(value.Ticks); } else { var format = value.Days > 0 ? value.Milliseconds > 0 ? "d\\.hh\\:mm\\:ss\\.fff" : "d\\.hh\\:mm\\:ss" : value.Milliseconds > 0 ? "hh\\:mm\\:ss\\.fff" : "hh\\:mm\\:ss"; stringBuilder .Append('\'') .Append(value.ToString(format)) .Append('\'') ; } }
protected override void BuildDataTypeFromDataType(SqlDataType type, bool forCreateTable) { switch (type.Type.DataType) { case DataType.Date: case DataType.DateTime: StringBuilder.Append("date"); break; case DataType.DateTime2: if (type.Type.Precision == 6 || type.Type.Precision == null) { StringBuilder.Append("timestamp"); } else { StringBuilder.Append($"timestamp({type.Type.Precision})"); } break; case DataType.DateTimeOffset: if (type.Type.Precision == 6 || type.Type.Precision == null) { StringBuilder.Append("timestamp with time zone"); } else { StringBuilder.Append($"timestamp({type.Type.Precision}) with time zone"); } break; case DataType.UInt32: case DataType.Int64: StringBuilder.Append("Number(19)"); break; case DataType.SByte: case DataType.Byte: StringBuilder.Append("Number(3)"); break; case DataType.Money: StringBuilder.Append("Number(19, 4)"); break; case DataType.SmallMoney: StringBuilder.Append("Number(10, 4)"); break; case DataType.VarChar: if (type.Type.Length == null || type.Type.Length > 4000 || type.Type.Length < 1) { StringBuilder.Append("VarChar(4000)"); } else { StringBuilder.Append($"VarChar({type.Type.Length})"); } break; case DataType.NVarChar: if (type.Type.Length == null || type.Type.Length > 4000 || type.Type.Length < 1) { StringBuilder.Append("VarChar2(4000)"); } else { StringBuilder.Append($"VarChar2({type.Type.Length})"); } break; case DataType.Boolean: StringBuilder.Append("Char(1)"); break; case DataType.NText: StringBuilder.Append("NClob"); break; case DataType.Text: StringBuilder.Append("Clob"); break; case DataType.Guid: StringBuilder.Append("Raw(16)"); break; case DataType.Binary: case DataType.VarBinary: if (type.Type.Length == null || type.Type.Length == 0) { StringBuilder.Append("BLOB"); } else { StringBuilder.Append("Raw(").Append(type.Type.Length).Append(")"); } break; default: base.BuildDataTypeFromDataType(type, forCreateTable); break; } }
static void ConvertGuidToSql(StringBuilder stringBuilder, SqlDataType dt, Guid value) { // keep in sync with provider's SetParameter method switch (dt.Type.DataType, dt.Type.DbType) {
protected override void BuildDataTypeFromDataType(SqlDataType type, bool forCreateTable) { switch (type.Type.DataType) { case DataType.SByte: case DataType.Byte: StringBuilder.Append("SmallInt"); break; case DataType.Money: StringBuilder.Append("money"); break; case DataType.SmallMoney: StringBuilder.Append("Decimal(10, 4)"); break; case DataType.DateTime2: case DataType.SmallDateTime: case DataType.DateTime: StringBuilder.Append("TimeStamp"); break; case DataType.DateTimeOffset: StringBuilder.Append("TimeStampTZ"); break; case DataType.Boolean: StringBuilder.Append("Boolean"); break; case DataType.Text: StringBuilder.Append("text"); break; case DataType.NVarChar: StringBuilder.Append("VarChar"); if (type.Type.Length > 0) { StringBuilder.Append('(').Append(type.Type.Length.Value.ToString(NumberFormatInfo.InvariantInfo)).Append(')'); } break; case DataType.Json: StringBuilder.Append("json"); break; case DataType.BinaryJson: StringBuilder.Append("jsonb"); break; case DataType.Guid: StringBuilder.Append("uuid"); break; case DataType.VarBinary: StringBuilder.Append("bytea"); break; case DataType.BitArray: if (type.Type.Length == 1) { StringBuilder.Append("bit"); } if (type.Type.Length > 1) { StringBuilder.Append("bit(").Append(type.Type.Length.Value.ToString(NumberFormatInfo.InvariantInfo)).Append(')'); } else { StringBuilder.Append("bit varying"); } break; case DataType.NChar: StringBuilder.Append("character"); if (type.Type.Length > 1) // this is correct condition { StringBuilder.Append('(').Append(type.Type.Length.Value.ToString(NumberFormatInfo.InvariantInfo)).Append(')'); } break; case DataType.Interval: StringBuilder.Append("interval"); break; case DataType.Udt: var udtType = type.Type.SystemType.ToNullableUnderlying(); if (_provider != null && udtType == _provider.Adapter.NpgsqlPointType) { StringBuilder.Append("point"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlLineType) { StringBuilder.Append("line"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlBoxType) { StringBuilder.Append("box"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlLSegType) { StringBuilder.Append("lseg"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlCircleType) { StringBuilder.Append("circle"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlPolygonType) { StringBuilder.Append("polygon"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlPathType) { StringBuilder.Append("path"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlDateType) { StringBuilder.Append("date"); } else if (_provider != null && udtType == _provider.Adapter.NpgsqlDateTimeType) { StringBuilder.Append("timestamp"); } else if (udtType == typeof(PhysicalAddress) && _provider != null && !_provider.HasMacAddr8) { StringBuilder.Append("macaddr"); } else if (udtType == typeof(IPAddress)) { StringBuilder.Append("inet"); } else { base.BuildDataTypeFromDataType(type, forCreateTable); } break; default: base.BuildDataTypeFromDataType(type, forCreateTable); break; } }
protected override void BuildDataType(SqlDataType type, bool createDbType = false) { switch (type.DataType) { case DataType.UInt32 : case DataType.Int64 : StringBuilder.Append("Number(19)"); break; case DataType.SByte : case DataType.Byte : StringBuilder.Append("Number(3)"); break; case DataType.Money : StringBuilder.Append("Number(19,4)"); break; case DataType.SmallMoney : StringBuilder.Append("Number(10,4)"); break; case DataType.NVarChar : StringBuilder.Append("VarChar2"); if (type.Length > 0) StringBuilder.Append('(').Append(type.Length).Append(')'); break; default : base.BuildDataType(type); break; } }
public void Cast_WithNullValue_ConvertsToNullConstant() { var cast = SqlExpression.Cast(null, SqlDataType.BigInt()); Assert.Same(SqlConstant.Null, cast.Value); }
protected override void BuildDataType(StringBuilder sb, SqlDataType type) { switch (type.SqlDbType) { case SqlDbType.Decimal : base.BuildDataType(sb, type.Precision > 18 ? new SqlDataType(type.SqlDbType, type.Type, 18, type.Scale) : type); break; case SqlDbType.TinyInt : sb.Append("SmallInt"); break; case SqlDbType.Money : sb.Append("Decimal(18,4)"); break; case SqlDbType.SmallMoney : sb.Append("Decimal(10,4)"); break; #if !MONO case SqlDbType.DateTime2 : #endif case SqlDbType.SmallDateTime : case SqlDbType.DateTime : sb.Append("TimeStamp"); break; case SqlDbType.NVarChar : sb.Append("VarChar"); if (type.Length > 0) sb.Append('(').Append(type.Length).Append(')'); break; default : base.BuildDataType(sb, type); break; } }
public virtual async Task Data_StoreDate() { // for DateTime values to be equal they need to have the same DateTimeKind // database providers should return a DateTime value with a DateTimeKind of Unspecified. await Data_TestStoreDataType(SqlDataType.Date(), new DateTime(2018, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); }
public bool TryConvert(StringBuilder stringBuilder, SqlDataType dataType, object value) { return(TryConvertImpl(stringBuilder, dataType, value, true)); }
public void Equals_WithSqlDataType_ReturnsCorrectly(SqlDataType dataType, SqlDataType other, bool expected) { Assert.Equal(expected, dataType.Equals(other)); }
protected override void BuildDataType(StringBuilder sb, SqlDataType type) { switch (type.SqlDbType) { #if !MONO case SqlDbType.DateTime2 : sb.Append("DateTime"); break; #endif default : base.BuildDataType(sb, type); break; } }
bool TryConvertImpl(StringBuilder stringBuilder, SqlDataType dataType, object value, bool tryBase) { if (value == null || value is INullable && ((INullable)value).IsNull ) { stringBuilder.Append("NULL"); return(true); } var type = value.GetType(); ConverterType converter = null; if (_converters.Count > 0 && !type.IsEnumEx()) { switch (type.GetTypeCodeEx()) { #if NETSTANDARD1_6 case (TypeCode)2: stringBuilder.Append("NULL"); return(true); #else case TypeCode.DBNull: stringBuilder.Append("NULL"); return(true); #endif case TypeCode.Boolean: converter = _booleanConverter; break; case TypeCode.Char: converter = _charConverter; break; case TypeCode.SByte: converter = _sByteConverter; break; case TypeCode.Byte: converter = _byteConverter; break; case TypeCode.Int16: converter = _int16Converter; break; case TypeCode.UInt16: converter = _uInt16Converter; break; case TypeCode.Int32: converter = _int32Converter; break; case TypeCode.UInt32: converter = _uInt32Converter; break; case TypeCode.Int64: converter = _int64Converter; break; case TypeCode.UInt64: converter = _uInt64Converter; break; case TypeCode.Single: converter = _singleConverter; break; case TypeCode.Double: converter = _doubleConverter; break; case TypeCode.Decimal: converter = _decimalConverter; break; case TypeCode.DateTime: converter = _dateTimeConverter; break; case TypeCode.String: converter = _stringConverter; break; default: _converters.TryGetValue(type, out converter); break; } } if (converter != null) { converter(stringBuilder, dataType, value); return(true); } if (tryBase && BaseConverters.Length > 0) { foreach (var valueConverter in BaseConverters) { if (valueConverter.TryConvertImpl(stringBuilder, dataType, value, false)) { return(true); } } } /* * var ar = new AttributeReader(); * var udtAttr = ar.GetAttributes<Microsoft.SqlServer.Server.SqlUserDefinedTypeAttribute>(type); * * if (udtAttr.Length > 0 && udtAttr[0].Format == Microsoft.SqlServer.Server.Format.UserDefined) * { * SetConverter(type, (sb,dt,v) => BuildString(sb, v.ToString())); * return TryConvertImpl(stringBuilder, dataType, value, tryBase); * } */ return(false); }
public Parameter(string name, SqlDataType type) { Name = name; Type = type; }
public void SetDataType(Type type, SqlDataType dataType) { Schemas[0].SetDataType(type, dataType); }
protected override void BuildDataType(StringBuilder sb, SqlDataType type) { switch (type.SqlDbType) { case SqlDbType.TinyInt : sb.Append("SmallInt"); break; case SqlDbType.SmallMoney : sb.Append("Decimal(10,4)"); break; default : base.BuildDataType(sb, type); break; } }
public Column(string name, SqlDataType dataType, bool isNullable) { Name = name; DataType = dataType; IsNullable = isNullable; }