예제 #1
0
        public override ISpecificType GenericTypeToSpecific(DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            switch (type.Code)
            {
            case DbTypeCode.Int:
                return(GetPostgreSqlTypeInt((DbTypeInt)type));

            case DbTypeCode.String:
                return(GetPostgreSqlTypeString((DbTypeString)type));

            case DbTypeCode.Logical:
                return(new PostgreSqlTypeBoolean());

            case DbTypeCode.Datetime:
                return(GetPostgreSqlTypeDatetime((DbTypeDatetime)type));

            case DbTypeCode.Numeric:
            {
                PostgreSqlTypeNumeric res = new PostgreSqlTypeNumeric();
                res.Precision = ((DbTypeNumeric)type).Precision;
                res.Scale     = ((DbTypeNumeric)type).Scale;
                return(res);
            }

            case DbTypeCode.Blob:
                return(new PostgreSqlTypeBytea());

            case DbTypeCode.Xml:
                return(new PostgreSqlTypeText());

            case DbTypeCode.Text:
                return(GetPostgreSqlTypeText((DbTypeText)type));

            case DbTypeCode.Array:
                return(GetPostgreSqlTypeArray((DbTypeArray)type, profile, progress));

            case DbTypeCode.Float:
                return(GetPostgreSqlTypeFloat((DbTypeFloat)type));

            case DbTypeCode.Generic:
                return(new PostgreSqlTypeGeneric {
                    Sql = ((DbTypeGeneric)type).Sql
                });
            }
            throw new Exception("DAE-00346 unknown type");
        }
예제 #2
0
        private PostgreSqlTypeBase MakeSpecificPostgreSqlType(string dt, int len, int prec, int scale, string coldef)
        {
            if (dt.StartsWith("_"))
            {
                var res = MakeSpecificPostgreSqlType(dt.Substring(1), len, prec, scale, coldef);
                res.IsArray = true;
                return(res);
            }
            switch (dt)
            {
            case "bigint":
            case "int8":
                if (coldef != null && coldef.StartsWith("nextval("))
                {
                    return(new PostgreSqlTypeBigSerial());
                }
                return(new PostgreSqlTypeBigInt());

            case "bigserial":
            case "serial8":
                return(new PostgreSqlTypeBigSerial());

            case "bit":
            {
                PostgreSqlTypeBit res = new PostgreSqlTypeBit();
                res.Length = len;
                return(res);
            }

            case "varbit":
            case "bit varying":
            {
                PostgreSqlTypeVarBit res = new PostgreSqlTypeVarBit();
                res.Length = len;
                return(res);
            }

            case "boolean":
            case "bool":
                return(new PostgreSqlTypeBoolean());

            case "box":
                return(new PostgreSqlTypeBox());

            case "bytea":
                return(new PostgreSqlTypeBytea());

            case "character varying":
            case "varchar":
            {
                PostgreSqlTypeVarChar res = new PostgreSqlTypeVarChar();
                res.Length = len;
                return(res);
            }

            case "character":
            case "char":
            {
                PostgreSqlTypeChar res = new PostgreSqlTypeChar();
                res.Length = len;
                return(res);
            }

            case "cidr":
                return(new PostgreSqlTypeCidr());

            case "circle":
                return(new PostgreSqlTypeCircle());

            case "date":
                return(new PostgreSqlTypeDate());

            case "double precision":
            case "float8":
                return(new PostgreSqlTypeDouble());

            case "inet":
                return(new PostgreSqlTypeInet());

            case "integer":
            case "int":
            case "int4":
                if (coldef != null && coldef.StartsWith("nextval("))
                {
                    return(new PostgreSqlTypeSerial());
                }
                return(new PostgreSqlTypeInteger());

            case "line":
                return(new PostgreSqlTypeLine());

            case "lseg":
                return(new PostgreSqlTypeLineSeg());

            case "macaddr":
                return(new PostgreSqlTypeMacAddr());

            case "money":
                return(new PostgreSqlTypeMoney());

            case "numeric":
            case "decimal":
            {
                PostgreSqlTypeNumeric res = new PostgreSqlTypeNumeric();
                res.Precision = prec;
                res.Scale     = scale;
                return(res);
            }

            case "path":
                return(new PostgreSqlTypePath());

            case "point":
                return(new PostgreSqlTypePoint());

            case "polygon":
                return(new PostgreSqlTypePolygon());

            case "real":
            case "float4":
                return(new PostgreSqlTypeReal());

            case "smallint":
            case "int2":
                return(new PostgreSqlTypeSmallInt());

            case "serial":
            case "serial4":
                return(new PostgreSqlTypeSerial());

            case "text":
                return(new PostgreSqlTypeText());

            case "time":
                return(new PostgreSqlTypeTime());

            case "timetz":
                return(new PostgreSqlTypeTimeTz());

            case "timestamp":
                return(new PostgreSqlTypeTimestamp());

            case "timestamptz":
                return(new PostgreSqlTypeTimestampTz());

            case "bpchar":
            {
                PostgreSqlTypeBpChar res = new PostgreSqlTypeBpChar();
                res.Length = len;
                return(res);
            }

            case "oid":
                return(new PostgreSqlTypeOid());

            case "box2d":
                return(new PostGISTypeBox2D());

            case "box3d":
                return(new PostGISTypeBox3D());

            case "box3d_extent":
                return(new PostGISTypeBox3D_Extent());

            case "geometry":
                return(new PostGISTypeGeometry());

            case "geometry_dump":
                return(new PostGISTypeGeometry_Dump());

            case "geography":
                return(new PostGISTypeGeography());
            }
            return(new PostgreSqlTypeGeneric {
                Sql = dt
            });
            //throw new Exception(String.Format("Unknown Postgre SQL type:{0}", dt));
        }