Ejemplo n.º 1
0
        public string ToStr()
        {
            switch (Type)
            {
            case DbColumnType.Unknow:
                return("UNKNOW");

            case DbColumnType.Char:
                return("CHAR(" + MaxTextLength.ToString() + ")");

            case DbColumnType.VarChar:
                return("VARCHAR(" + MaxTextLength.ToString() + ")");

            case DbColumnType.Text:
            case DbColumnType.Byte:
            case DbColumnType.SmallInt:
            case DbColumnType.Integer:
            case DbColumnType.BigInt:
            case DbColumnType.Real:
            case DbColumnType.Double:
            case DbColumnType.Money:
            case DbColumnType.Blob:
            case DbColumnType.Date:
            case DbColumnType.DateTime:
            case DbColumnType.Time:
            case DbColumnType.Boolean:
            case DbColumnType.Geometry:
            case DbColumnType.Geography:
                return(Type.ToString().ToUpper());

            case DbColumnType.Numeric:
                string s = "NUMERIC";
                if (Precision > 0)
                {
                    s += "(" + Precision.ToString();
                    if (Scale > 0)
                    {
                        s += ", " + Scale.ToString();
                    }
                    s += ")";
                }
                return(s);

            case DbColumnType.DateTimeWithTimeZone:
                return("DATETIME WITH TIME ZONE");

            case DbColumnType.TimeWithTimeZome:
                return("TIME WITH TIME ZONE");

            default:
                throw new Exception("Unknow data type");
            }
        }
Ejemplo n.º 2
0
        public string ToSql(ExpressionSqlBuilder builder)
        {
            switch (Type)
            {
            case DbColumnType.Unknow:
                return("UNKNOW");

            case DbColumnType.Char:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("NCHAR(" + MaxTextLength.ToString() + ")");
                }
                else
                {
                    return("CHAR(" + MaxTextLength.ToString() + ")");
                }

            case DbColumnType.VarChar:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("NVARCHAR(" + MaxTextLength.ToString() + ")");
                }
                else
                {
                    return("VARCHAR(" + MaxTextLength.ToString() + ")");
                }

            case DbColumnType.Text:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("NVARCHAR(MAX)");
                }
                else
                {
                    return("text");
                }

            case DbColumnType.Byte:
            case DbColumnType.SmallInt:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("smallint");
                }
                else
                {
                    return("int8");
                }

            case DbColumnType.Integer:
                return("int");

            case DbColumnType.BigInt:
                return("bigint");

            case DbColumnType.Real:
                return("real");

            case DbColumnType.Double:
                if (builder.DbType == DriverType.PostgreSQL)
                {
                    return("double precision");
                }
                return("float");

            case DbColumnType.Money:
                return("money");

            case DbColumnType.Blob:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("varbinary(max)");
                }
                else
                {
                    return("bytea");
                }

            case DbColumnType.Date:
                return("date");

            case DbColumnType.DateTime:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("datetime");
                }
                else
                {
                    return("timestamp without time zone");
                }

            case DbColumnType.Time:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("time");
                }
                else
                {
                    return("time without time zone");
                }

            case DbColumnType.Boolean:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("bit");
                }
                else
                {
                    return("boolean");
                }

            case DbColumnType.Geometry:
                return("geometry");

            case DbColumnType.Geography:
                return("geometry");

            case DbColumnType.Numeric:
                string s = "numeric";
                if (Precision > 0)
                {
                    s += "(" + Precision.ToString();
                    if (Scale > 0)
                    {
                        s += ", " + Scale.ToString();
                    }
                    s += ")";
                }
                return(s);

            case DbColumnType.DateTimeWithTimeZone:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("DATETIME");
                }
                else
                {
                    return("timestamp with time zone");
                }

            case DbColumnType.TimeWithTimeZome:
                if (builder.DbType == DriverType.SqlServer)
                {
                    return("time");
                }
                else
                {
                    return("time with time zone");
                }

            default:
                throw new Exception("Unknow data type");
            }
        }