Example #1
0
        public DataTable getDataFields(bool reloadFromDatabase)
        {
            log.enterFunc("getDataFields");

            // reloadFromDatabase - true to refresh the cache from the database.
            if (m_fields == null || reloadFromDatabase)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("1");
                }
                // Query the view for its fields and store them in the array.
                // Paolo: gid is not always in the PostGIS layer: let's use limit 1 instead than gid=-1
                string sql = DbHelper.createSelectSql(schemaAndView, "*", null, null, "limit 1");
                if (log.IsDebugEnabled)
                {
                    log.Debug(sql);
                }
                using (AutoDataReader dr = connection.doQuery(sql))
                {
                    log.Debug(dr == null ? "null" : "not null");
                    log.Debug("2");
                    m_fields = dr.GetSchemaTable();
                }
            }

            log.leaveFunc();

            return(m_fields);
        }
Example #2
0
        internal AutoDataReader doQuery(string sql)
        {
            log.enterFunc("doQuery");

            IDbConnection con;
            IDbCommand    cmd;

            createCommand(sql, out con, out cmd);
            AutoDataReader retVal = null;

            using (cmd)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Executing reader ...");
                    log.Debug(cmd.CommandText);
                }
                IDataReader dr = cmd.ExecuteReader();
                retVal = new AutoDataReader(con, dr);
                if (log.IsDebugEnabled)
                {
                    log.Debug("Reader executed.");
                }
            }

            log.leaveFunc();

            return(retVal);
        }
Example #3
0
        // Gets the different layer attributes stored by PostGis.
        private void loadLayer(bool loadFromOid)
        {
            log.enterFunc("loadLayer");

            // Create a query that selects layer attributes from the geometry columns
            // table and selects the spatial reference from the spatial reference table.
            // The join must be constructed such that a record is gotten whether this
            // layer has a spatial reference or not (hence the left join).
            string where;
            if (loadFromOid)
            {
                where = "g.oid=" + oid.ToString();
            }
            else
            {
                where = PostGisConstants.schemaField + "=" + DbHelper.quote(schema) +
                        " and " + PostGisConstants.tableField + "=" + DbHelper.quote(view);
            }

            string sql = DbHelper.createSelectSql(PostGisConstants.geometryColumnsTable + " as g",
                                                  "g.*,g.oid,s." + PostGisConstants.spatialReferenceSrField,
                                                  "left join " + PostGisConstants.spatialReferenceTable + " as s on g." +
                                                  PostGisConstants.spatialReferenceIdField + "=s." +
                                                  PostGisConstants.spatialReferenceIdField, where, null);

            AutoDataReader dr = connection.doQuery(sql);

            if (dr.Read())
            {
                m_geomFld        = DbHelper.getValueAsString(dr[PostGisConstants.geometryColumnLookupField]);
                m_geomType       = DbHelper.getValueAsString(dr[PostGisConstants.geometryTypeField]);
                m_spatialRefText = DbHelper.getValueAsString(dr[PostGisConstants.spatialReferenceSrField]);
                m_srid           = (int)dr[PostGisConstants.spatialReferenceIdField];

                m_spatialReference = GeomHelper.setEsriSpatiaReferenceFromSrid(m_srid);
                if (m_spatialReference.FactoryCode == 0 && m_srid != -1)
                {
                    //PostGis srid is not implemented as an Esri Factory Code
                    System.Windows.Forms.MessageBox.Show("PostGis srid is not implemented as an Esri Factory Code: this PostGis table can not be reprojected in ArcMap.");
                }

                if (loadFromOid)
                {
                    m_schema = DbHelper.getValueAsString(dr[PostGisConstants.schemaField]);
                    m_view   = DbHelper.getValueAsString(dr[PostGisConstants.tableField]);
                }
                else
                {
                    m_oid = (int)((Int64)dr["oid"]);
                }
            }
            else
            {
                // Todo - throw exception.
            }
            //Initialize spatial reference
            log.leaveFunc();
        }
Example #4
0
        // Paolo (Returns the record for the given Id with corrected geometry)
        public IDataRecord getRecord(string fields, string where)
        {
            string         sql = DbHelper.createSelectSql(schemaAndView, fields, where);
            AutoDataReader dr  = connection.doQuery(sql);

            if (!dr.Read())
            {
                dr = null;
            }
            return(dr);
        }
Example #5
0
        // Returns the record for the given Id.
        public IDataRecord getRecord(int id)
        {
            string         sql = DbHelper.createSelectSql(schemaAndView, "*", "gid=" + id.ToString());
            AutoDataReader dr  = connection.doQuery(sql);

            if (!dr.Read())
            {
                dr = null;
            }
            return(dr);
        }
Example #6
0
        internal AutoDataReader doQuery(string sql)
        {
            log.enterFunc("doQuery");

            IDbConnection con;
            IDbCommand cmd;
            createCommand(sql, out con, out cmd);
            AutoDataReader retVal = null;
            using (cmd)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("Executing reader ...");
                    log.Debug(cmd.CommandText);
                }
                IDataReader dr = cmd.ExecuteReader();
                retVal = new AutoDataReader(con, dr);
                if (log.IsDebugEnabled) log.Debug("Reader executed.");
            }

            log.leaveFunc();

            return retVal;
        }
		/// <summary>
		/// Create a SelectionSet from a dataReader
		/// </summary>
		/// <param name="postGisFeatureClass"></param>
		/// <param name="dataReader"></param>
        public PostGisSelectionSet(PostGisFeatureClass postGisFeatureClass, AutoDataReader dataReader)
        {
			System.Diagnostics.Debug.WriteLine("NOT-Empty PostGisSelectionSet...");
			m_featClass = postGisFeatureClass;
			//oids.Add(1);
            m_dr = dataReader;
            if (dataReader != null)
            {
				while (dataReader.Read())
				{
					oids.Add((object)dataReader[PostGisConstants.idField]);
				}
				dataReader.Close();
            }
        }