Beispiel #1
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            switch (SqlDbType)
            {
            case NpgsqlDbType.Char:
                if (Size == STRING_SIZE)
                {
                    return("Char(" + STRING_SIZE + ")");
                }
                return(string.Format("Char({0})", Size));

            case NpgsqlDbType.Varchar:
                if (Size == STRING_SIZE)
                {
                    return("VarChar(" + STRING_SIZE + ")");
                }
                return(string.Format("VarChar({0})", Size));

            case NpgsqlDbType.Numeric:
                return(string.Format("Decimal({0},{1})", Precision, Scale));
                //case NpgsqlDbType.Bytea:
                //    return "BYTEA";
                //case NpgsqlDbType.Bigint:
                //    return "INT8";
                //case NpgsqlDbType.Integer:
                //    return "INT4";
                //case NpgsqlDbType.Text:
                //    return "Text";
            }
            return(base.ToQueryString(formatFlags));
        }
Beispiel #2
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            switch (SqlDbType)
            {
            case DB2Type.VarChar:
            case DB2Type.LongVarChar:
                if (Size == STRING_SIZE)
                {
                    return("VarChar(" + STRING_SIZE + ")");
                }
                return(string.Format("VarChar({0})", Size));

            case DB2Type.Decimal:
                return(string.Format("Decimal({0},{1})", Precision, Scale));

            case DB2Type.Numeric:
                if (Scale == 0)
                {
                    return(string.Format("Numeric({0})", Precision));
                }

                return(string.Format("Numeric({0},{1})", Precision, Scale));

            case DB2Type.BigInt:
                return("BigInt");

            case DB2Type.Binary:
                return("Blob");

            case DB2Type.Char:
                return(string.Format("Char({0})", Size));
            }
            return(base.ToQueryString(formatFlags));
        }
Beispiel #3
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            switch (this.SqlDbType)
            {
            case DbType.Int32:
            case DbType.Int16:
                return("INT");

            case DbType.Boolean:
                return("BIT");

            case DbType.Byte:
            case DbType.SByte:
                return("TINYINT");

            case DbType.Int64:
                return("BIGINT");

            case DbType.Single:
                return("FLOAT");

            case DbType.Double:
                return("DOUBLE");
            }
            return(base.ToQueryString(formatFlags));
        }
Beispiel #4
0
 public virtual string ToQueryString(QueryFormatOptions formatFlags)
 {
     if (RuntimeOnlyType != null)
     {
         return(RuntimeOnlyType.ToString());
     }
     return(SqlDbType.ToString());
 }
Beispiel #5
0
            protected override SqlExpression TranslateConverter(SqlUnary uo)
            {
                sb.Append("CAST(");
                QueryFormatOptions none = QueryFormatOptions.None;

                if (uo.Operand.SqlType.CanSuppressSizeForConversionToString)
                {
                    none = QueryFormatOptions.SuppressSize;
                }
                Visit(uo.Operand);
                sb.Append(" AS ");
                var sqlType = (MySqlDataType)uo.SqlType;

                switch (sqlType.Category)
                {
                case DBTypeCategory.Binary:
                    sb.Append("BINARY");
                    break;

                case DBTypeCategory.Numeric:
                    switch (sqlType.SqlDbType)
                    {
                    case MySqlDbType.Decimal:
                    case MySqlDbType.Double:
                    case MySqlDbType.Float:
                        sb.Append("DECIMAL");
                        break;

                    default:
                        if (sqlType.SqlDbType.ToString()[0] == 'U')
                        {
                            sb.Append("UNSIGNED");
                        }
                        else
                        {
                            sb.Append("SIGNED");
                        }
                        break;
                    }
                    break;

                case DBTypeCategory.Text:
                    sb.Append("CHAR");
                    break;

                case DBTypeCategory.DateTime:
                    sb.Append("DATETIME");
                    break;
                }
                sb.Append(")");
                return(uo);
            }
Beispiel #6
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            switch (SqlDbType)
            {
            case DbType.Boolean:
                return("Bit");

            case DbType.Binary:
                return("Binary");

            case DbType.DateTime:
                return("DateTime");

            case DbType.Double:
                return("Float");

            case DbType.Guid:
                return("UniqueIdentifier");

            case DbType.Int16:
                return("SmallInt");

            case DbType.Int32:
                return("Integer");

            case DbType.Int64:
                return("BitInt");

            case DbType.SByte:
                return("SmallInt");

            case DbType.Single:
                return("Real");

            case DbType.String:
                return(string.Format("VarChar({0})", Size));

            case DbType.StringFixedLength:
                return(string.Format("Char({0})", Size));

            case DbType.UInt16:
                return(string.Format("Int"));

            case DbType.UInt32:
                return(string.Format("BitInt"));

            case DbType.Decimal:
                return(string.Format("Decimal({0},{1})", Precision, Scale));
            }
            return(base.ToQueryString(formatFlags));
        }
Beispiel #7
0
            protected override SqlExpression TranslateConverter(SqlUnary uo)
            {
                sb.Append("CAST(");
                QueryFormatOptions none = QueryFormatOptions.None;

                if (uo.Operand.SqlType.CanSuppressSizeForConversionToString)
                {
                    none = QueryFormatOptions.SuppressSize;
                }
                Visit(uo.Operand);
                sb.Append(" AS ");
                sb.Append(uo.SqlType.ToQueryString(none));
                sb.Append(")");
                return(uo);
            }
Beispiel #8
0
        string IProviderType.ToQueryString(QueryFormatOptions formatOptions)
        {
            if (RuntimeOnlyType != null)
            {
                return(RuntimeOnlyType.ToString());
            }
            var builder = new StringBuilder();

            switch (SqlDbType)
            {
            case MySqlDbType.Int32:
                builder.Append("SIGNED");
                break;

            default:
                builder.Append(SqlDbType.ToString());
                break;
            }
            return(builder.ToString());
        }
Beispiel #9
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            switch (SqlDbType)
            {
            case OleDbType.VarChar:
            case OleDbType.LongVarChar:
                if (Size == STRING_SIZE)
                {
                    return("Text");
                }
                return(string.Format("VarChar({0})", Size));

            case OleDbType.Decimal:
            case OleDbType.Numeric:
                return(string.Format("Decimal({0},{1})", Precision, Scale));

            case OleDbType.BigInt:
                return("Long");
            }
            return(base.ToQueryString(formatFlags));
        }
Beispiel #10
0
            protected override SqlExpression TranslateConverter(SqlUnary uo)
            {
                //兼容类型,无需转换
                switch (((SqlDataType <DB2Type>)uo.SqlType).Category)
                {
                case DBTypeCategory.Text:
                    if (uo.Operand.ClrType == typeof(char) || uo.Operand.ClrType == typeof(string))
                    {
                        Visit(uo.Operand);
                        return(uo);
                    }
                    break;

                case DBTypeCategory.Numeric:
                    //if (uo.Operand.ClrType == typeof(int) || uo.Operand.ClrType == typeof(Int16) ||
                    //   uo.Operand.ClrType == typeof(long) || uo.Operand.ClrType == typeof(byte))
                    if (uo.Operand.ClrType.IsValueType)
                    {
                        Visit(uo.Operand);
                        return(uo);
                    }
                    break;
                }


                sb.Append("CAST(");
                QueryFormatOptions none = QueryFormatOptions.None;

                if (uo.Operand.SqlType.CanSuppressSizeForConversionToString)
                {
                    none = QueryFormatOptions.SuppressSize;
                }
                Visit(uo.Operand);
                sb.Append(" AS ");
                sb.Append(uo.SqlType.ToQueryString(none));
                sb.Append(")");
                return(uo);
            }
 /// <summary>
 /// Convert this type into a string that can be used in a query.
 /// </summary>
 internal abstract string ToQueryString(QueryFormatOptions formatOptions);
Beispiel #12
0
        internal override string ToQueryString(QueryFormatOptions formatFlags)
        {
            if (this.RuntimeOnlyType != null)
            {
                return(this.RuntimeOnlyType.ToString());
            }
            StringBuilder sb = new StringBuilder();

            switch (sqlDbType)
            {
            case SqlDbType.BigInt:
            case SqlDbType.Bit:
            case SqlDbType.Date:
            case SqlDbType.Time:
            case SqlDbType.DateTime:
            case SqlDbType.DateTime2:
            case SqlDbType.DateTimeOffset:
            case SqlDbType.Int:
            case SqlDbType.Money:
            case SqlDbType.SmallDateTime:
            case SqlDbType.SmallInt:
            case SqlDbType.SmallMoney:
            case SqlDbType.Timestamp:
            case SqlDbType.TinyInt:
            case SqlDbType.UniqueIdentifier:
            case SqlDbType.Xml:
            case SqlDbType.Image:
            case SqlDbType.NText:
            case SqlDbType.Text:
            case SqlDbType.Udt:
                sb.Append(sqlDbType.ToString());
                break;

            case SqlDbType.Variant:
                sb.Append("sql_variant");
                break;

            case SqlDbType.Binary:
            case SqlDbType.Char:
            case SqlDbType.NChar:
                sb.Append(sqlDbType);
                if ((formatFlags & QueryFormatOptions.SuppressSize) == 0)
                {
                    sb.Append("(");
                    sb.Append(size);
                    sb.Append(")");
                }
                break;

            case SqlDbType.NVarChar:
            case SqlDbType.VarBinary:
            case SqlDbType.VarChar:
                sb.Append(sqlDbType);
                if ((size.HasValue && size != 0) && (formatFlags & QueryFormatOptions.SuppressSize) == 0)
                {
                    sb.Append("(");
                    if (size == ProviderConstants.LargeTypeSizeIndicator)
                    {
                        sb.Append("MAX");
                    }
                    else
                    {
                        sb.Append(size);
                    }
                    sb.Append(")");
                }
                break;

            case SqlDbType.Decimal:
            case SqlDbType.Float:
            case SqlDbType.Real:
                sb.Append(sqlDbType);
                if (precision != 0)
                {
                    sb.Append("(");
                    sb.Append(precision);
                    if (scale != 0)
                    {
                        sb.Append(",");
                        sb.Append(scale);
                    }
                    sb.Append(")");
                }
                break;
            }
            return(sb.ToString());
        }
 /// <summary>
 /// Convert this type into a string that can be used in a query.
 /// </summary>
 internal abstract string ToQueryString(QueryFormatOptions formatOptions);
Beispiel #14
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            if (RuntimeOnlyType != null)
            {
                return(RuntimeOnlyType.ToString());
            }
            var builder = new StringBuilder();

            string typeName;
            var    size    = Size;
            var    unicode = false;

            switch (SqlDbType)
            {
            case MySqlDbType.Date:
            case MySqlDbType.DateTime:
            case MySqlDbType.Time:
                typeName = SqlDbType.ToString();
                size     = 0;
                break;

            case MySqlDbType.Bit:
                typeName = "BIT";
                break;

            case MySqlDbType.Byte:
                typeName = "TINYINT";
                break;

            case MySqlDbType.Double:
                typeName = "DOUBLE";
                break;

            case MySqlDbType.UByte:
                typeName = "TINYINT";
                break;

            case MySqlDbType.Int16:
                typeName = "SMALLINT";
                break;

            case MySqlDbType.Int24:
                typeName = "MEDIUMINT";
                break;

            case MySqlDbType.UInt24:
                typeName = "MEDIUMINT";
                break;

            case MySqlDbType.Int32:
                typeName = "INT";
                break;

            case MySqlDbType.UInt32:
                typeName = "INT";
                break;

            case MySqlDbType.Int64:
                typeName = "BIGINT";
                break;

            case MySqlDbType.UInt64:
                typeName = "BIGINT";
                break;

            case MySqlDbType.Float:
                typeName = "FLOAT";
                break;

            case MySqlDbType.VarChar:
                typeName = "VARCHAR";
                break;

            default:
                typeName = SqlDbType.ToString();
                break;
                //throw SqlClient.Error.InvalidProviderType(SqlDbType);
            }
            builder.Append(typeName);
            if (size > 0 && formatFlags != QueryFormatOptions.SuppressSize)
            {
                builder.Append("(");
                builder.Append(Size);
                builder.Append(")");
            }
            if (Unsigned)
            {
                builder.Append("UNSIGNED");
            }
            return(builder.ToString());
        }
Beispiel #15
0
 public abstract string ToQueryString(QueryFormatOptions formatOptions);
Beispiel #16
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            if (this.runtimeOnlyType != null)
            {
                return(this.runtimeOnlyType.ToString());
            }
            var builder = new StringBuilder();

            switch (this.sqlDbType)
            {
            case MySqlDbType.Byte:
            case MySqlDbType.Int16:
            case MySqlDbType.Int24:
            case MySqlDbType.Int32:
            case MySqlDbType.Int64:
            case MySqlDbType.Timestamp:
            case MySqlDbType.Date:
            case MySqlDbType.Time:
            case MySqlDbType.DateTime:
            case MySqlDbType.Year:
            case MySqlDbType.Enum:
            case MySqlDbType.Set:

            case MySqlDbType.TinyBlob:
            case MySqlDbType.MediumBlob:
            case MySqlDbType.LongBlob:
            case MySqlDbType.Blob:

            case MySqlDbType.UByte:
            case MySqlDbType.UInt16:
            case MySqlDbType.UInt24:
            case MySqlDbType.UInt32:
            case MySqlDbType.UInt64:

            case MySqlDbType.TinyText:
            case MySqlDbType.MediumText:
            case MySqlDbType.LongText:
                builder.Append(sqlDbType.ToString());
                break;

            case MySqlDbType.Float:
            case MySqlDbType.Double:
                builder.Append(sqlDbType);
                if (this.precision != 0)
                {
                    builder.Append("(");
                    builder.Append(this.precision);
                    if (this.scale != 0)
                    {
                        builder.Append(",");
                        builder.Append(this.scale);
                    }
                    builder.Append(")");
                }
                break;

            case MySqlDbType.VarString:
            case MySqlDbType.Binary:
            case MySqlDbType.VarBinary:
            case MySqlDbType.Text:
                builder.Append(this.sqlDbType);
                if (!this.size.HasValue || ((this.size == 0) ||
                                            ((formatFlags & QueryFormatOptions.SuppressSize) != QueryFormatOptions.None)))
                {
                    break;
                }
                builder.Append("(");
                if (this.size != -1)
                {
                    builder.Append(this.size);
                    break;
                }
                builder.Append("MAX");
                break;
            }
            return(builder.ToString());

            #region MyRegion
            //    switch (this.sqlDbType)
            //    {
            //        case SqlDbType.BigInt:
            //        case SqlDbType.Bit:
            //        case SqlDbType.DateTime:
            //        case SqlDbType.Image:
            //        case SqlDbType.Int:
            //        case SqlDbType.Money:
            //        case SqlDbType.NText:
            //        case SqlDbType.UniqueIdentifier:
            //        case SqlDbType.SmallDateTime:
            //        case SqlDbType.SmallInt:
            //        case SqlDbType.SmallMoney:
            //        case SqlDbType.Text:
            //        case SqlDbType.Timestamp:
            //        case SqlDbType.TinyInt:
            //        case SqlDbType.Xml:
            //        case SqlDbType.Udt:
            //            builder.Append(this.sqlDbType.ToString());
            //            goto Label_021D;

            //        case SqlDbType.Binary:
            //        case SqlDbType.Char:
            //        case SqlDbType.NChar:
            //            builder.Append(this.sqlDbType);
            //            if ((formatFlags & QueryFormatOptions.SuppressSize) == QueryFormatOptions.None)
            //            {
            //                builder.Append("(");
            //                builder.Append(this.size);
            //                builder.Append(")");
            //            }
            //            goto Label_021D;

            //        case SqlDbType.Decimal:
            //        case SqlDbType.Float:
            //        case SqlDbType.Real:
            //            builder.Append(this.sqlDbType);
            //            if (this.precision != 0)
            //            {
            //                builder.Append("(");
            //                builder.Append(this.precision);
            //                if (this.scale != 0)
            //                {
            //                    builder.Append(",");
            //                    builder.Append(this.scale);
            //                }
            //                builder.Append(")");
            //            }
            //            goto Label_021D;

            //        case SqlDbType.NVarChar:
            //        case SqlDbType.VarBinary:
            //        case SqlDbType.VarChar:
            //            builder.Append(this.sqlDbType);
            //            if (!this.size.HasValue || ((this.size == 0) || ((formatFlags & QueryFormatOptions.SuppressSize) != QueryFormatOptions.None)))
            //            {
            //                goto Label_021D;
            //            }
            //            builder.Append("(");
            //            if (this.size != -1)
            //            {
            //                builder.Append(this.size);
            //                break;
            //            }
            //            builder.Append("MAX");
            //            break;

            //        case SqlDbType.Variant:
            //            builder.Append("sql_variant");
            //            goto Label_021D;

            //        default:
            //            goto Label_021D;
            //    }
            //    builder.Append(")");
            //Label_021D:
            //    return builder.ToString();
            #endregion
        }
Beispiel #17
0
        public override string ToQueryString(QueryFormatOptions formatFlags)
        {
            if (RuntimeOnlyType != null)
            {
                return(RuntimeOnlyType.ToString());
            }
            var builder = new StringBuilder();

            switch (SqlDbType)
            {
            case FbDbType.VarChar:    //System.Data.SqlDbType.NVarChar:
                builder.Append("VarChar");
                builder.Append("(");
                builder.Append(Size);
                builder.Append(")");
                return(builder.ToString());

            case FbDbType.Guid:
                builder.Append("CHAR(38)");
                return(builder.ToString());

            case FbDbType.Binary:
                builder.Append("BLOB");
                builder.Append("(");
                builder.Append(Size);
                builder.Append(")");
                return(builder.ToString());

            case FbDbType.TimeStamp:
                builder.Append(FbDbType.TimeStamp);
                return(builder.ToString());

            //case System.Data.SqlDbType.DateTimeOffset:
            //    builder.Append(FbDbType.Time);
            //    return builder.ToString();

            case FbDbType.Double:    //System.Data.SqlDbType.Real:
                builder.Append("Double Precision");
                return(builder.ToString());

            case FbDbType.Decimal:    //System.Data.SqlDbType.Decimal:
                builder.Append(FbDbType.Decimal);
                //if (Precision != 0 && Scale != 0)
                //{
                //const int MaxPrecision = 18;
                builder.Append("(");
                //builder.Append(Precision > MaxPrecision ? 18 : Precision);
                builder.Append(Precision);
                //if (Scale != 0)
                //{
                builder.Append(",");
                builder.Append(Scale);
                //}
                builder.Append(")");
                //}
                return(builder.ToString());

            case FbDbType.Char:    //System.Data.SqlDbType.NChar:
                builder.Append("Char");
                builder.Append("(");
                builder.Append(Size);
                builder.Append(")");
                //builder.Append(" CHARACTER SET UNICODE_FSS");
                return(builder.ToString());

            case FbDbType.Text:    //System.Data.SqlDbType.NText:
                builder.Append("BLOB SUB_TYPE TEXT SEGMENT SIZE 4000");
                //builder.Append("VarChar(4000)");
                return(builder.ToString());

                #region MyRegion
                //case FbDbType.SmallInt://System.Data.SqlDbType.TinyInt:
                //    builder.Append(FbDbType.SmallInt);
                //    return builder.ToString();
                //case System.Data.SqlDbType.BigInt:
                //case System.Data.SqlDbType.Bit:
                //case System.Data.SqlDbType.Image:
                //case System.Data.SqlDbType.Int:
                //case System.Data.SqlDbType.Money:
                //case System.Data.SqlDbType.SmallDateTime:
                //case System.Data.SqlDbType.SmallInt:
                //case System.Data.SqlDbType.SmallMoney:
                //case System.Data.SqlDbType.Text:
                //case System.Data.SqlDbType.Timestamp:
                //case System.Data.SqlDbType.Xml:
                //case System.Data.SqlDbType.Udt:
                #endregion
            default:
                builder.Append(SqlDbType.ToString());
                return(builder.ToString());

                #region MyRegion
                //case FbDbType.Binary://System.Data.SqlDbType.Binary:
                //case System.Data.SqlDbType.Char:
                //    //case System.Data.SqlDbType.NChar:
                //    builder.Append(this.sqlDbType);
                //    if ((formatFlags & QueryFormatOptions.SuppressSize) == QueryFormatOptions.None)
                //    {
                //        builder.Append("(");
                //        builder.Append(this.size);
                //        builder.Append(")");
                //    }
                //    return builder.ToString();


                //case System.Data.SqlDbType.Float:
                //    builder.Append(this.sqlDbType);
                //    if (this.precision != 0)
                //    {
                //        builder.Append("(");
                //        builder.Append(this.precision);
                //        if (this.scale != 0)
                //        {
                //            builder.Append(",");
                //            builder.Append(this.scale);
                //        }
                //        builder.Append(")");
                //    }
                //    return builder.ToString();

                //case System.Data.SqlDbType.VarChar:
                //    builder.Append(this.sqlDbType);
                //    if (!size.HasValue || ((size == 0) || ((formatFlags & QueryFormatOptions.SuppressSize) != QueryFormatOptions.None)))
                //    {
                //        return builder.ToString();
                //    }
                //    builder.Append("(");
                //    if (this.size != -1)
                //        builder.Append(this.size);
                //    else
                //        builder.Append("MAX");

                //    builder.Append(")");
                //    return builder.ToString();

                //case System.Data.SqlDbType.Variant:
                //    builder.Append("sql_variant");
                //    return builder.ToString();

                //default:
                //    return builder.ToString();
                #endregion
            }
        }
Beispiel #18
0
		internal override string ToQueryString(QueryFormatOptions formatFlags)
		{
			if(this.RuntimeOnlyType != null)
			{
				return this.RuntimeOnlyType.ToString();
			}
			StringBuilder sb = new StringBuilder();

			switch(sqlDbType)
			{
				case SqlDbType.BigInt:
				case SqlDbType.Bit:
				case SqlDbType.Date:
				case SqlDbType.Time:
				case SqlDbType.DateTime:
				case SqlDbType.DateTime2:
				case SqlDbType.DateTimeOffset:
				case SqlDbType.Int:
				case SqlDbType.Money:
				case SqlDbType.SmallDateTime:
				case SqlDbType.SmallInt:
				case SqlDbType.SmallMoney:
				case SqlDbType.Timestamp:
				case SqlDbType.TinyInt:
				case SqlDbType.UniqueIdentifier:
				case SqlDbType.Xml:
				case SqlDbType.Image:
				case SqlDbType.NText:
				case SqlDbType.Text:
				case SqlDbType.Udt:
					sb.Append(sqlDbType.ToString());
					break;
				case SqlDbType.Variant:
					sb.Append("sql_variant");
					break;
				case SqlDbType.Binary:
				case SqlDbType.Char:
				case SqlDbType.NChar:
					sb.Append(sqlDbType);
					if((formatFlags & QueryFormatOptions.SuppressSize) == 0)
					{
						sb.Append("(");
						sb.Append(size);
						sb.Append(")");
					}
					break;
				case SqlDbType.NVarChar:
				case SqlDbType.VarBinary:
				case SqlDbType.VarChar:
					sb.Append(sqlDbType);
					if((size.HasValue && size != 0) && (formatFlags & QueryFormatOptions.SuppressSize) == 0)
					{
						sb.Append("(");
						if(size == ProviderConstants.LargeTypeSizeIndicator)
						{
							sb.Append("MAX");
						}
						else
						{
							sb.Append(size);
						}
						sb.Append(")");
					}
					break;
				case SqlDbType.Decimal:
				case SqlDbType.Float:
				case SqlDbType.Real:
					sb.Append(sqlDbType);
					if(precision != 0)
					{
						sb.Append("(");
						sb.Append(precision);
						if(scale != 0)
						{
							sb.Append(",");
							sb.Append(scale);
						}
						sb.Append(")");
					}
					break;
			}
			return sb.ToString();
		}