コード例 #1
0
        public PostGisProvider(IGeometryFactory geometryFactory, string connectionString,
                               string tableSchema, string tableName, string oidColumn, string geometryColumn,
                               ICoordinateTransformationFactory coordinateTransformationFactory)
            : base(
                new PostGisDbUtility(), geometryFactory, connectionString, tableSchema,
                tableName,
                oidColumn,
                geometryColumn,
                coordinateTransformationFactory)
        {
            using (NpgsqlConnection cn = (NpgsqlConnection)DbUtility.CreateConnection(connectionString))
            {
                try
                {
                    cn.Open();

                    if (!PostGisProviderStatic.Has_X_Privilege(cn, "table", "\"public\".\"geometry_columns\"", "SELECT"))
                    {
                        throw new PostGisException(
                                  "Insufficient rights to access table \"public\".\"geometry_columns\"!");
                    }

                    if (
                        !PostGisProviderStatic.Has_X_Privilege(cn, "table",
                                                               string.Format("\"{0}\".\"{1}\"", tableSchema, tableName),
                                                               "SELECT"))
                    {
                        throw new PostGisException(string.Format(
                                                       "Insufficient rights to access table \"{0}\".\"{1}\"!",
                                                       tableSchema, tableName));
                    }

                    NpgsqlCommand cmd = (NpgsqlCommand)DbUtility.CreateCommand();
                    cmd.Connection  = cn;
                    cmd.CommandText =
                        @"SELECT x.""type""
    FROM ""public"".""geometry_columns"" AS x
    WHERE (x.""f_table_schema""=:p0 AND x.""f_table_name""=:p1 AND x.""f_geometry_column""=:p2);";
                    cmd.Parameters.Add(DbUtility.CreateParameter("p0", tableSchema, ParameterDirection.Input));
                    cmd.Parameters.Add(DbUtility.CreateParameter("p1", tableName, ParameterDirection.Input));
                    cmd.Parameters.Add(DbUtility.CreateParameter("p2", geometryColumn, ParameterDirection.Input));

                    NpgsqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                    if (dr.HasRows)
                    {
                        dr.Read();
                        //valid geometry type
                        _validGeometryType = parseGeometryType(dr.GetString(0));
                    }
                    else
                    {
                        _validGeometryType = OgcGeometryType.Geometry;
                    }
                }
                catch (Exception)
                {
                    _validGeometryType = OgcGeometryType.Unknown;
                }
            }
        }
コード例 #2
0
        private static String getGeometryColumnName(string connectionString, String schemaName, String tableName)
        {
            String columnName = PostGisProviderStatic.DefaultGeometryColumnName;

            using (NpgsqlConnection cn = new NpgsqlConnection(connectionString))
            {
                try
                {
                    cn.Open();

                    if (!PostGisProviderStatic.Has_X_Privilege(cn, "table", "\"public\".\"geometry_columns\"", "SELECT"))
                    {
                        return(null);
                    }

                    NpgsqlCommand cmd = new NpgsqlCommand();
                    cmd.Connection  = cn;
                    cmd.CommandText =
                        @"SELECT x.""f_geometry_column""
FROM ""public"".""geometry_columns"" AS x 
WHERE (x.""f_table_schema""=:p0 AND x.""f_table_name""=:p1)
LIMIT 1;";
                    cmd.Parameters.Add(new NpgsqlParameter("p0", schemaName));
                    cmd.Parameters.Add(new NpgsqlParameter("p1", tableName));

                    columnName = (String)cmd.ExecuteScalar();
                }
                catch
                {
                    columnName = "";
                }
            }

            return(columnName);
        }