diff options
author | onefang | 2019-05-19 21:24:15 +1000 |
---|---|---|
committer | onefang | 2019-05-19 21:24:15 +1000 |
commit | 5e4d6cab00cb29cd088ab7b62ab13aff103b64cb (patch) | |
tree | a9fbc62df9eb2d1d9ba2698d8552eae71eca20d8 /OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs | |
parent | Add a build script. (diff) | |
download | opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.zip opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.gz opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.bz2 opensim-SC_OLD-5e4d6cab00cb29cd088ab7b62ab13aff103b64cb.tar.xz |
Dump OpenSim 0.9.0.1 into it's own branch.
Diffstat (limited to 'OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs')
-rw-r--r-- | OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs index 826c6fc..5b24720 100644 --- a/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs +++ b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs | |||
@@ -64,7 +64,7 @@ namespace OpenSim.Data.PGSQL | |||
64 | : base(connectionString) | 64 | : base(connectionString) |
65 | { | 65 | { |
66 | m_Realm = realm; | 66 | m_Realm = realm; |
67 | 67 | ||
68 | m_ConnectionString = connectionString; | 68 | m_ConnectionString = connectionString; |
69 | 69 | ||
70 | if (storeName != String.Empty) | 70 | if (storeName != String.Empty) |
@@ -104,7 +104,7 @@ namespace OpenSim.Data.PGSQL | |||
104 | m_FieldTypes = new Dictionary<string, string>(); | 104 | m_FieldTypes = new Dictionary<string, string>(); |
105 | 105 | ||
106 | string query = string.Format(@"select column_name,data_type | 106 | string query = string.Format(@"select column_name,data_type |
107 | from INFORMATION_SCHEMA.COLUMNS | 107 | from INFORMATION_SCHEMA.COLUMNS |
108 | where table_name = lower('{0}'); | 108 | where table_name = lower('{0}'); |
109 | 109 | ||
110 | ", m_Realm); | 110 | ", m_Realm); |
@@ -145,27 +145,22 @@ namespace OpenSim.Data.PGSQL | |||
145 | private List<string> GetConstraints() | 145 | private List<string> GetConstraints() |
146 | { | 146 | { |
147 | List<string> constraints = new List<string>(); | 147 | List<string> constraints = new List<string>(); |
148 | string query = string.Format(@"SELECT kcu.column_name | 148 | string query = string.Format(@"select |
149 | FROM information_schema.table_constraints tc | 149 | a.attname as column_name |
150 | LEFT JOIN information_schema.key_column_usage kcu | 150 | from |
151 | ON tc.constraint_catalog = kcu.constraint_catalog | 151 | pg_class t, |
152 | AND tc.constraint_schema = kcu.constraint_schema | 152 | pg_class i, |
153 | AND tc.constraint_name = kcu.constraint_name | 153 | pg_index ix, |
154 | 154 | pg_attribute a | |
155 | LEFT JOIN information_schema.referential_constraints rc | 155 | where |
156 | ON tc.constraint_catalog = rc.constraint_catalog | 156 | t.oid = ix.indrelid |
157 | AND tc.constraint_schema = rc.constraint_schema | 157 | and i.oid = ix.indexrelid |
158 | AND tc.constraint_name = rc.constraint_name | 158 | and a.attrelid = t.oid |
159 | 159 | and a.attnum = ANY(ix.indkey) | |
160 | LEFT JOIN information_schema.constraint_column_usage ccu | 160 | and t.relkind = 'r' |
161 | ON rc.unique_constraint_catalog = ccu.constraint_catalog | 161 | and ix.indisunique = true |
162 | AND rc.unique_constraint_schema = ccu.constraint_schema | 162 | and t.relname = lower('{0}') |
163 | AND rc.unique_constraint_name = ccu.constraint_name | 163 | ;", m_Realm); |
164 | |||
165 | where tc.table_name = lower('{0}') | ||
166 | and lower(tc.constraint_type) in ('primary key') | ||
167 | and kcu.column_name is not null | ||
168 | ;", m_Realm); | ||
169 | 164 | ||
170 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | 165 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) |
171 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn)) | 166 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn)) |
@@ -237,7 +232,7 @@ namespace OpenSim.Data.PGSQL | |||
237 | if (reader == null) | 232 | if (reader == null) |
238 | return new T[0]; | 233 | return new T[0]; |
239 | 234 | ||
240 | CheckColumnNames(reader); | 235 | CheckColumnNames(reader); |
241 | 236 | ||
242 | while (reader.Read()) | 237 | while (reader.Read()) |
243 | { | 238 | { |
@@ -344,7 +339,7 @@ namespace OpenSim.Data.PGSQL | |||
344 | names.Add(fi.Name); | 339 | names.Add(fi.Name); |
345 | values.Add(":" + fi.Name); | 340 | values.Add(":" + fi.Name); |
346 | // Temporarily return more information about what field is unexpectedly null for | 341 | // Temporarily return more information about what field is unexpectedly null for |
347 | // http://opensimulator.org/mantis/view.php?id=5403. This might be due to a bug in the | 342 | // http://opensimulator.org/mantis/view.php?id=5403. This might be due to a bug in the |
348 | // InventoryTransferModule or we may be required to substitute a DBNull here. | 343 | // InventoryTransferModule or we may be required to substitute a DBNull here. |
349 | if (fi.GetValue(row) == null) | 344 | if (fi.GetValue(row) == null) |
350 | throw new NullReferenceException( | 345 | throw new NullReferenceException( |
@@ -400,11 +395,11 @@ namespace OpenSim.Data.PGSQL | |||
400 | } | 395 | } |
401 | string where = String.Join(" AND ", terms.ToArray()); | 396 | string where = String.Join(" AND ", terms.ToArray()); |
402 | query.AppendFormat(" WHERE {0} ", where); | 397 | query.AppendFormat(" WHERE {0} ", where); |
403 | 398 | ||
404 | } | 399 | } |
405 | cmd.Connection = conn; | 400 | cmd.Connection = conn; |
406 | cmd.CommandText = query.ToString(); | 401 | cmd.CommandText = query.ToString(); |
407 | 402 | ||
408 | conn.Open(); | 403 | conn.Open(); |
409 | if (cmd.ExecuteNonQuery() > 0) | 404 | if (cmd.ExecuteNonQuery() > 0) |
410 | { | 405 | { |
@@ -421,7 +416,7 @@ namespace OpenSim.Data.PGSQL | |||
421 | query.Append("\") values (" + String.Join(",", values.ToArray()) + ")"); | 416 | query.Append("\") values (" + String.Join(",", values.ToArray()) + ")"); |
422 | cmd.Connection = conn; | 417 | cmd.Connection = conn; |
423 | cmd.CommandText = query.ToString(); | 418 | cmd.CommandText = query.ToString(); |
424 | 419 | ||
425 | // m_log.WarnFormat("[PGSQLGenericTable]: Inserting into {0} sql {1}", m_Realm, cmd.CommandText); | 420 | // m_log.WarnFormat("[PGSQLGenericTable]: Inserting into {0} sql {1}", m_Realm, cmd.CommandText); |
426 | 421 | ||
427 | if (conn.State != ConnectionState.Open) | 422 | if (conn.State != ConnectionState.Open) |