Esempio n. 1
0
        /// <summary>
        /// 根据数据类型生成相应的列。
        /// </summary>
        /// <param name="dbType">数据类型。</param>
        /// <param name="length">数据长度。</param>
        /// <param name="precision">数值的精度。</param>
        /// <param name="scale">数值的小数位。</param>
        /// <returns></returns>
        public string Column(DbType dbType, int?length, int?precision, int?scale = new int?())
        {
            switch (dbType)
            {
            case DbType.AnsiString:
            case DbType.AnsiStringFixedLength:
            case DbType.String:
            case DbType.StringFixedLength:
                return("TEXT");

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

            case DbType.Boolean:
            case DbType.Decimal:
            case DbType.Double:
            case DbType.Single:
            case DbType.VarNumeric:
                return("NUMERIC");

            case DbType.Int16:
            case DbType.Int32:
            case DbType.Int64:
            case DbType.Byte:
            case DbType.UInt16:
            case DbType.UInt32:
            case DbType.UInt64:
            case DbType.SByte:
                return("INTEGER");

            case DbType.Date:
                return("DATE");

            case DbType.DateTime:
            case DbType.DateTime2:
            case DbType.DateTimeOffset:
                return("DATETIME");

            case DbType.Time:
                return("TIME");

            case DbType.Guid:
                return("UNIQUEIDENTIFIER");
            }

            return(ExceptionHelper.ThrowSyntaxCreteException(dbType));
        }
Esempio n. 2
0
        /// <summary>
        /// 根据数据类型生成相应的列。
        /// </summary>
        /// <param name="dbType">数据类型。</param>
        /// <param name="length">数据长度。</param>
        /// <param name="precision">数值的精度。</param>
        /// <param name="scale">数值的小数位。</param>
        /// <returns></returns>
        public string Column(DbType dbType, int?length, int?precision, int?scale = new int?())
        {
            switch (dbType)
            {
            case DbType.String:
            case DbType.AnsiString:
                if (length == null || length <= 255)
                {
                    return(string.Format("VARCHAR({0})", length ?? 255));
                }
                if (length > 255 && length <= 65535)
                {
                    return("TEXT");
                }
                //length > 65535 && length <= 16777215
                return("MEDIUMTEXT");

            case DbType.StringFixedLength:
            case DbType.AnsiStringFixedLength:
                if (length == null || length <= 255)
                {
                    return(string.Format("CHAR({0})", length ?? 255));
                }
                if (length > 255 && length <= 65535)
                {
                    return("TEXT");
                }
                //length > 65535 && length <= 16777215
                return("MEDIUMTEXT");

            case DbType.Guid:
                return("VARCHAR(40)");

            case DbType.Binary:
                if (length == null || length <= 127)
                {
                    return("LONGBLOB");
                }
                if (length > 127 && length <= 65535)
                {
                    return("BLOB");
                }
                //length > 65535 && length <= 16777215
                return("MEDIUMBLOB");

            case DbType.Decimal:
                if (precision == null && scale == null)
                {
                    return("DECIMAL(19, 5)");
                }
                if (precision == null)
                {
                    return(string.Format("DECIMAL(19, {0})", scale));
                }
                if (scale == null)
                {
                    return(string.Format("DECIMAL({0}, 5)", precision));
                }
                return(string.Format("DECIMAL({0}, {1})", precision, scale));

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

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

            case DbType.Boolean:
                return("TINYINT(1)");

            case DbType.Byte:
                return("TINY INT");

            case DbType.Currency:
                return("MONEY");

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

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

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

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

            case DbType.UInt16:
                return("SMALLINT");

            case DbType.UInt32:
                return("MEDIUMINT");

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

            case DbType.Date:
                return("DATE");

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

            case DbType.Time:
                return("TIME");
            }
            return(ExceptionHelper.ThrowSyntaxCreteException(dbType));
        }
Esempio n. 3
0
        /// <summary>
        /// 根据数据类型生成相应的列。
        /// </summary>
        /// <param name="dbType">数据类型。</param>
        /// <param name="length">数据长度。</param>
        /// <param name="precision">数值的精度。</param>
        /// <param name="scale">数值的小数位。</param>
        /// <returns></returns>
        public string Column(DbType dbType, int?length, int?precision, int?scale = new int?())
        {
            switch (dbType)
            {
            case DbType.AnsiString:
                if (length == null)
                {
                    return("VARCHAR2(255)");
                }
                if (length > 8000)
                {
                    return("CLOB");
                }
                return(string.Format("VARCHAR2({0})", length));

            case DbType.AnsiStringFixedLength:
                return(length == null ? "NCHAR(255)" : string.Format("NCHAR({0})", length));

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

            case DbType.Boolean:
                return("NUMBER(1,0)");

            case DbType.Byte:
                return("NUMBER(3,0)");

            case DbType.Currency:
                return("NUMBER(20,0)");

            case DbType.Date:
            case DbType.DateTime:
            case DbType.DateTime2:
                return("DATE");

            case DbType.DateTimeOffset:
                return("TIMESTAMP(4)");

            case DbType.Decimal:
                if (precision == null && scale == null)
                {
                    return("NUMBER(19, 5)");
                }
                if (precision == null)
                {
                    return(string.Format("NUMBER(19, {0})", scale));
                }
                if (scale == null)
                {
                    return(string.Format("NUMBER({0}, 5)", precision));
                }
                return(string.Format("NUMBER({0}, {1})", precision, scale));

            case DbType.Double:
                return("DOUBLE PRECISION");

            case DbType.Guid:
                return("CHAR(38)");

            case DbType.Int16:
                return("NUMBER(5,0)");

            case DbType.Int32:
                return("NUMBER(10,0)");

            case DbType.Int64:
                return("NUMBER(20,0)");

            case DbType.SByte:
                return("NUMBER(5,0)");

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

            case DbType.String:
                if (length == null)
                {
                    return("NVARCHAR2(255)");
                }
                if (length > 4000)
                {
                    return("NCLOB");
                }
                return(string.Format("NVARCHAR2({0})", length));

            case DbType.StringFixedLength:
                if (length == null)
                {
                    return("NCHAR(255)");
                }
                return(string.Format("NCHAR({0})", length));

            case DbType.Time:
                return("TIMESTAMP(4)");

            case DbType.UInt16:
                return("NUMBER(5,0)");

            case DbType.UInt32:
                return("NUMBER(10,0)");

            case DbType.UInt64:
                return("NUMBER(20,0)");

            case DbType.VarNumeric:
                break;

            case DbType.Xml:
                break;
            }
            return(ExceptionHelper.ThrowSyntaxCreteException(dbType));
        }
Esempio n. 4
0
        /// <summary>
        /// 根据数据类型生成相应的列。
        /// </summary>
        /// <param name="dbType">数据类型。</param>
        /// <param name="length">数据长度。</param>
        /// <param name="precision">数值的精度。</param>
        /// <param name="scale">数值的小数位。</param>
        /// <returns></returns>
        public string Column(DbType dbType, int?length, int?precision, int?scale = new int?())
        {
            switch (dbType)
            {
            case DbType.AnsiString:
                if (length == null)
                {
                    return("VARCHAR(255)");
                }
                if (length > 8000)
                {
                    return("NTEXT");
                }
                return(string.Format("VARCHAR({0})", length));

            case DbType.AnsiStringFixedLength:
                return(length == null ? "CHAR(255)" : string.Format("CHAR({0})", length));

            case DbType.Binary:
                if (length == null)
                {
                    return("VARBINARY(8000)");
                }
                if (length > 8000)
                {
                    return("IMAGE");
                }
                return(string.Format("VARBINARY({0})", length));

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

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

            case DbType.Currency:
                return("MONEY");

            case DbType.Date:
                return("DATETIME");

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

            case DbType.DateTime2:
                ExceptionHelper.ThrowSyntaxCreteException(dbType);
                break;

            case DbType.DateTimeOffset:
                ExceptionHelper.ThrowSyntaxCreteException(dbType);
                break;

            case DbType.Decimal:
                if (precision == null && scale == null)
                {
                    return("DECIMAL(19, 5)");
                }
                if (precision == null)
                {
                    return(string.Format("DECIMAL(19, {0})", scale));
                }
                if (scale == null)
                {
                    return(string.Format("DECIMAL({0}, 5)", precision));
                }
                return(string.Format("DECIMAL({0}, {1})", precision, scale));

            case DbType.Double:
                return("DOUBLE PRECISION");

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

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

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

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

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

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

            case DbType.String:
                if (length == null)
                {
                    return("VARCHAR(255)");
                }
                if (length > 8000)
                {
                    return("NTEXT");
                }
                return(string.Format("VARCHAR({0})", length));

            case DbType.StringFixedLength:
                if (length == null)
                {
                    return("NCHAR(255)");
                }
                return(string.Format("NCHAR({0})", length));

            case DbType.Time:
                return("DATETIME");

            case DbType.UInt16:
            case DbType.UInt32:
            case DbType.UInt64:
            case DbType.VarNumeric:
            case DbType.Xml:
                break;
            }
            throw new SyntaxParseException("Create" + dbType);
        }
Esempio n. 5
0
        /// <summary>
        /// 根据数据类型生成相应的列。
        /// </summary>
        /// <param name="dbType">数据类型。</param>
        /// <param name="length">数据长度。</param>
        /// <param name="precision">数值的精度。</param>
        /// <param name="scale">数值的小数位。</param>
        /// <returns></returns>
        public virtual string Column(System.Data.DbType dbType, int?length = null, int?precision = null, int?scale = null)
        {
            switch (dbType)
            {
            case DbType.String:
            case DbType.AnsiString:
                if (length == null || length <= 255)
                {
                    return($"VARCHAR({length ?? 255})");
                }
                throw new ArgumentOutOfRangeException();

            case DbType.StringFixedLength:
            case DbType.AnsiStringFixedLength:
                if (length == null || length <= 255)
                {
                    return($"CHAR({length ?? 255})");
                }
                throw new ArgumentOutOfRangeException();

            case DbType.Guid:
                return("VARCHAR(40)");

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

            case DbType.Decimal:
                if (precision == null && scale == null)
                {
                    return("DECIMAL(19, 5)");
                }
                if (precision == null)
                {
                    return($"DECIMAL(19, {scale})");
                }
                if (scale == null)
                {
                    return($"DECIMAL({precision}, 5)");
                }
                return($"DECIMAL({precision}, {scale})");

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

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

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

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

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

            case DbType.Date:
                return("DATE");

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

            case DbType.Time:
                return("TIME");
            }
            return(ExceptionHelper.ThrowSyntaxCreteException(dbType));
        }