public override IExtents GetExtents()
        {
            using (IDbConnection conn = DbUtility.CreateConnection(ConnectionString))
                using (IDbCommand cmd = DbUtility.CreateCommand())
                {
                    conn.Open();
                    cmd.Connection = conn;

                    cmd.CommandText = String.Format(
                        "SELECT " +
                        "min({0}.ST_MINX(tbl.\"{3}\")) AS xmin, min({0}.ST_MINY(tbl.\"{3}\")) AS ymin, " +
                        "max({0}.ST_MAXX(tbl.\"{3}\")) AS xmax, max({0}.ST_MAXY(tbl.\"{3}\")) AS ymax " +
                        "FROM \"{1}\".\"{2}\" AS tbl;",
                        DB2SpatialExtenderProviderStatic.DefaultSpatialSchema,
                        TableSchema,
                        Table,
                        GeometryColumn);
                    cmd.CommandType = CommandType.Text;

                    using (DB2DataReader r = (DB2DataReader)cmd.ExecuteReader(CommandBehavior.CloseConnection))
                    {
                        while (r.Read())
                        {
                            if (r.IsDBNull(0) || r.IsDBNull(1) || r.IsDBNull(2) || r.IsDBNull(3))
                            {
                                return(GeometryFactory.CreateExtents());
                            }

                            double xmin = r.GetDouble(0);
                            double ymin = r.GetDouble(1);
                            double xmax = r.GetDouble(2);
                            double ymax = r.GetDouble(3);

                            IExtents ext = GeometryFactory.CreateExtents2D(
                                r.GetDouble(0), r.GetDouble(1),
                                r.GetDouble(2), r.GetDouble(3));
                            return(ext);
                        }
                    }
                    return(GeometryFactory.CreateExtents());
                }
        }
示例#2
0
        public string Read(string jsonQuery)
        {
            string selectSQL    = this._sqlParser.ReadSqlParser(jsonQuery);
            string objName      = this._sqlParser.ObjName;
            bool   isReadToList = this._sqlParser.IsReadToList;

            string jsonDataSet = string.Empty;

            if (!string.IsNullOrEmpty(selectSQL))
            {
                DB2Command dbCmd = new DB2Command(selectSQL, this._connection);
                this.OpenConnection();
                DB2DataReader dbReader = dbCmd.ExecuteReader();
                while (dbReader.Read())
                {
                    // add LIST seperator jsonDataSet
                    if (isReadToList && !string.IsNullOrEmpty(jsonDataSet))
                    {
                        jsonDataSet += ",";
                    }

                    int fieldCount = dbReader.FieldCount;

                    // open json row
                    jsonDataSet += "{";
                    for (int fieldIndex = 0; fieldIndex < fieldCount; fieldIndex++)
                    {
                        // GET NAME
                        string fieldName   = dbReader.GetName(fieldIndex);
                        string JOIN_PREFIX = "JOIN_";

                        bool isJoinField = false;
                        if (fieldName.ToUpper().StartsWith("JOIN_"))
                        {
                            isJoinField = true;
                            fieldName   = fieldName.Substring(fieldName.IndexOf(JOIN_PREFIX) + JOIN_PREFIX.Length);
                        }
                        fieldName = $"\"{fieldName}\"";

                        // GET VALUE
                        string fieldValue = dbReader.IsDBNull(fieldIndex) ? "\"\"" : dbReader.GetString(fieldIndex);
                        if (!isJoinField)
                        {
                            fieldValue = $"\"{fieldValue}\"";
                        }

                        jsonDataSet += $"{fieldName}:{fieldValue}";
                        if (fieldIndex < fieldCount - 1)
                        {
                            jsonDataSet += ",";
                        }
                    }
                    // close json row
                    jsonDataSet += "}";
                }

                //close
                dbReader.Close();
                dbReader.Dispose();
                this.CloseConnection();
            }
            return(StringHelper.Simpler(string.IsNullOrEmpty(jsonDataSet) ? null : ("{" + $"\"{objName}\"" + ":" + ((isReadToList) ? "[" + jsonDataSet + "]" : jsonDataSet) + "}"), Pattern.PATTERN_SPECIAL_CHARS));
        }
示例#3
0
 public override bool IsDBNull(int ordinal)
 {
     return(source.IsDBNull(ordinal));
 }