Fix Mantis #7805, table handler needs to look for all unique constraints.

Signed-off-by: Kevin Cozens <kevin@ve3syb.ca>
LSLKeyTest
TomDataworks 2016-01-12 22:44:43 -05:00 committed by Kevin Cozens
parent 5ed0993845
commit e9b0f71575
1 changed files with 16 additions and 21 deletions

View File

@ -145,27 +145,22 @@ namespace OpenSim.Data.PGSQL
private List<string> GetConstraints() private List<string> GetConstraints()
{ {
List<string> constraints = new List<string>(); List<string> constraints = new List<string>();
string query = string.Format(@"SELECT kcu.column_name string query = string.Format(@"select
FROM information_schema.table_constraints tc a.attname as column_name
LEFT JOIN information_schema.key_column_usage kcu from
ON tc.constraint_catalog = kcu.constraint_catalog pg_class t,
AND tc.constraint_schema = kcu.constraint_schema pg_class i,
AND tc.constraint_name = kcu.constraint_name pg_index ix,
pg_attribute a
LEFT JOIN information_schema.referential_constraints rc where
ON tc.constraint_catalog = rc.constraint_catalog t.oid = ix.indrelid
AND tc.constraint_schema = rc.constraint_schema and i.oid = ix.indexrelid
AND tc.constraint_name = rc.constraint_name and a.attrelid = t.oid
and a.attnum = ANY(ix.indkey)
LEFT JOIN information_schema.constraint_column_usage ccu and t.relkind = 'r'
ON rc.unique_constraint_catalog = ccu.constraint_catalog and ix.indisunique = true
AND rc.unique_constraint_schema = ccu.constraint_schema and t.relname = lower('{0}')
AND rc.unique_constraint_name = ccu.constraint_name ;", m_Realm);
where tc.table_name = lower('{0}')
and lower(tc.constraint_type) in ('primary key')
and kcu.column_name is not null
;", m_Realm);
using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString))
using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn)) using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn))