Beispiel #1
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));
        }
Beispiel #2
0
        private ISpecificType GetPostgreSqlTypeString(DbTypeString type)
        {
            string subtype = type.GetSpecificAttribute("pgsql", "subtype");

            switch (subtype)
            {
            case "box": return(new PostgreSqlTypeBox());

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

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

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

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

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

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

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

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

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

            case "bpchar": return(new PostgreSqlTypeBpChar {
                    Length = type.Length
                });
            }
            if (type.IsVarLength)
            {
                if (type.IsBinary)
                {
                    PostgreSqlTypeVarBit res = new PostgreSqlTypeVarBit();
                    res.Length = type.Length;
                    return(res);
                }
                else
                {
                    PostgreSqlTypeVarChar res = new PostgreSqlTypeVarChar();
                    res.Length = type.Length;
                    return(res);
                }
            }
            else
            {
                if (type.IsBinary)
                {
                    PostgreSqlTypeBit res = new PostgreSqlTypeBit();
                    res.Length = type.Length;
                    return(res);
                }
                else
                {
                    PostgreSqlTypeChar res = new PostgreSqlTypeChar();
                    res.Length = type.Length;
                    return(res);
                }
            }
        }