aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/PGSQL/PGSQLRegionData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/PGSQL/PGSQLRegionData.cs')
-rw-r--r--OpenSim/Data/PGSQL/PGSQLRegionData.cs82
1 files changed, 61 insertions, 21 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLRegionData.cs b/OpenSim/Data/PGSQL/PGSQLRegionData.cs
index b3076f0..1272e37 100644
--- a/OpenSim/Data/PGSQL/PGSQLRegionData.cs
+++ b/OpenSim/Data/PGSQL/PGSQLRegionData.cs
@@ -26,16 +26,14 @@
26 */ 26 */
27 27
28using System; 28using System;
29using System.Collections;
29using System.Collections.Generic; 30using System.Collections.Generic;
30using System.Data; 31using System.Data;
31using System.Drawing;
32using System.IO;
33using System.Reflection; 32using System.Reflection;
34using log4net; 33using log4net;
35using OpenMetaverse; 34using OpenMetaverse;
36using OpenSim.Framework; 35using OpenSim.Framework;
37using OpenSim.Region.Framework.Interfaces; 36using OpenSim.Data;
38using OpenSim.Region.Framework.Scenes;
39using RegionFlags = OpenSim.Framework.RegionFlags; 37using RegionFlags = OpenSim.Framework.RegionFlags;
40using Npgsql; 38using Npgsql;
41 39
@@ -59,7 +57,7 @@ namespace OpenSim.Data.PGSQL
59 get { return GetType().Assembly; } 57 get { return GetType().Assembly; }
60 } 58 }
61 59
62 public PGSQLRegionData(string connectionString, string realm) 60 public PGSQLRegionData(string connectionString, string realm)
63 { 61 {
64 m_Realm = realm; 62 m_Realm = realm;
65 m_ConnectionString = connectionString; 63 m_ConnectionString = connectionString;
@@ -79,7 +77,7 @@ namespace OpenSim.Data.PGSQL
79 m_FieldTypes = new Dictionary<string, string>(); 77 m_FieldTypes = new Dictionary<string, string>();
80 78
81 string query = string.Format(@"select column_name,data_type 79 string query = string.Format(@"select column_name,data_type
82 from INFORMATION_SCHEMA.COLUMNS 80 from INFORMATION_SCHEMA.COLUMNS
83 where table_name = lower('{0}'); 81 where table_name = lower('{0}');
84 82
85 ", m_Realm); 83 ", m_Realm);
@@ -109,7 +107,7 @@ namespace OpenSim.Data.PGSQL
109 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) 107 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
110 { 108 {
111 cmd.Parameters.Add(m_database.CreateParameter("regionName", regionName)); 109 cmd.Parameters.Add(m_database.CreateParameter("regionName", regionName));
112 if (scopeID != UUID.Zero) 110 if (scopeID != UUID.Zero)
113 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); 111 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID));
114 conn.Open(); 112 conn.Open();
115 return RunCommand(cmd); 113 return RunCommand(cmd);
@@ -118,24 +116,46 @@ namespace OpenSim.Data.PGSQL
118 116
119 public RegionData Get(int posX, int posY, UUID scopeID) 117 public RegionData Get(int posX, int posY, UUID scopeID)
120 { 118 {
121 string sql = "select * from "+m_Realm+" where \"locX\" = :posX and \"locY\" = :posY"; 119 // extend database search for maximum region size area
120 string sql = "select * from "+m_Realm+" where \"locX\" between :startX and :endX and \"locY\" between :startY and :endY";
122 if (scopeID != UUID.Zero) 121 if (scopeID != UUID.Zero)
123 sql += " and \"ScopeID\" = :scopeID"; 122 sql += " and \"ScopeID\" = :scopeID";
124 123
124 int startX = posX - (int)Constants.MaximumRegionSize;
125 int startY = posY - (int)Constants.MaximumRegionSize;
126 int endX = posX;
127 int endY = posY;
128
129 List<RegionData> ret;
125 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) 130 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString))
126 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) 131 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
127 { 132 {
128 cmd.Parameters.Add(m_database.CreateParameter("posX", posX)); 133 cmd.Parameters.Add(m_database.CreateParameter("startX", startX));
129 cmd.Parameters.Add(m_database.CreateParameter("posY", posY)); 134 cmd.Parameters.Add(m_database.CreateParameter("startY", startY));
130 if (scopeID != UUID.Zero) 135 cmd.Parameters.Add(m_database.CreateParameter("endX", endX));
136 cmd.Parameters.Add(m_database.CreateParameter("endY", endY));
137 if (scopeID != UUID.Zero)
131 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); 138 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID));
132 conn.Open(); 139 conn.Open();
133 List<RegionData> ret = RunCommand(cmd); 140 ret = RunCommand(cmd);
134 if (ret.Count == 0) 141 }
135 return null;
136 142
137 return ret[0]; 143 if (ret.Count == 0)
144 return null;
145
146 // Find the first that contains pos
147 RegionData rg = null;
148 foreach (RegionData r in ret)
149 {
150 if (posX >= r.posX && posX < r.posX + r.sizeX
151 && posY >= r.posY && posY < r.posY + r.sizeY)
152 {
153 rg = r;
154 break;
155 }
138 } 156 }
157
158 return rg;
139 } 159 }
140 160
141 public RegionData Get(UUID regionID, UUID scopeID) 161 public RegionData Get(UUID regionID, UUID scopeID)
@@ -147,7 +167,7 @@ namespace OpenSim.Data.PGSQL
147 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) 167 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
148 { 168 {
149 cmd.Parameters.Add(m_database.CreateParameter("regionID", regionID)); 169 cmd.Parameters.Add(m_database.CreateParameter("regionID", regionID));
150 if (scopeID != UUID.Zero) 170 if (scopeID != UUID.Zero)
151 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); 171 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID));
152 conn.Open(); 172 conn.Open();
153 List<RegionData> ret = RunCommand(cmd); 173 List<RegionData> ret = RunCommand(cmd);
@@ -160,21 +180,41 @@ namespace OpenSim.Data.PGSQL
160 180
161 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID) 181 public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID)
162 { 182 {
183 // extend database search for maximum region size area
163 string sql = "select * from "+m_Realm+" where \"locX\" between :startX and :endX and \"locY\" between :startY and :endY"; 184 string sql = "select * from "+m_Realm+" where \"locX\" between :startX and :endX and \"locY\" between :startY and :endY";
164 if (scopeID != UUID.Zero) 185 if (scopeID != UUID.Zero)
165 sql += " and \"ScopeID\" = :scopeID"; 186 sql += " and \"ScopeID\" = :scopeID";
166 187
188 int qstartX = startX - (int)Constants.MaximumRegionSize;
189 int qstartY = startY - (int)Constants.MaximumRegionSize;
190
191 List<RegionData> dbret;
167 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) 192 using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString))
168 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) 193 using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
169 { 194 {
170 cmd.Parameters.Add(m_database.CreateParameter("startX", startX)); 195 cmd.Parameters.Add(m_database.CreateParameter("startX", qstartX));
171 cmd.Parameters.Add(m_database.CreateParameter("startY", startY)); 196 cmd.Parameters.Add(m_database.CreateParameter("startY", qstartY));
172 cmd.Parameters.Add(m_database.CreateParameter("endX", endX)); 197 cmd.Parameters.Add(m_database.CreateParameter("endX", endX));
173 cmd.Parameters.Add(m_database.CreateParameter("endY", endY)); 198 cmd.Parameters.Add(m_database.CreateParameter("endY", endY));
174 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); 199 if (scopeID != UUID.Zero)
200 cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID));
175 conn.Open(); 201 conn.Open();
176 return RunCommand(cmd); 202
203 dbret = RunCommand(cmd);
177 } 204 }
205
206 List<RegionData> ret = new List<RegionData>();
207
208 if(dbret.Count == 0)
209 return ret;
210
211 foreach (RegionData r in dbret)
212 {
213 if (r.posX + r.sizeX > startX && r.posX <= endX
214 && r.posY + r.sizeY > startY && r.posY <= endY)
215 ret.Add(r);
216 }
217 return ret;
178 } 218 }
179 219
180 public List<RegionData> RunCommand(NpgsqlCommand cmd) 220 public List<RegionData> RunCommand(NpgsqlCommand cmd)
@@ -258,7 +298,7 @@ namespace OpenSim.Data.PGSQL
258 { 298 {
259 299
260 string update = "update " + m_Realm + " set \"locX\"=:posX, \"locY\"=:posY, \"sizeX\"=:sizeX, \"sizeY\"=:sizeY "; 300 string update = "update " + m_Realm + " set \"locX\"=:posX, \"locY\"=:posY, \"sizeX\"=:sizeX, \"sizeY\"=:sizeY ";
261 301
262 foreach (string field in fields) 302 foreach (string field in fields)
263 { 303 {
264 304