private void LoadConstraints(Condition cond) { using (DbCommand cmd = m_conn.CreateCommand()) { string sql = CreateQuery("table_constraints", new string[] { "constraint_schema", "constraint_name", "table_schema", "table_name", "constraint_type" }, cond); if (sql == null) { return; } cmd.CommandText = sql; using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { TableAnalyser.Key key = new TableAnalyser.Key(); ReadValue(reader, "table_schema", ref key.tblschema); ReadValue(reader, "table_name", ref key.tblname); ReadValue(reader, "constraint_schema", ref key.keyschema); ReadValue(reader, "constraint_name", ref key.keyname); ReadValue(reader, "constraint_type", ref key.keytype); m_analyser.keys.Add(key); } } } }
private void LoadReferentialConstraints(Condition cond) { using (DbCommand cmd = m_conn.CreateCommand()) { cmd.CommandText = CreateQuery("referential_constraints", new string[] { "constraint_schema", "constraint_name", "unique_constraint_schema", "unique_constraint_name", "update_rule", "delete_rule" }, cond); using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { string fkschema = null, fkname = null; string pkschema = null, pkname = null; ReadValue(reader, "constraint_schema", ref fkschema); ReadValue(reader, "constraint_name", ref fkname); ReadValue(reader, "unique_constraint_schema", ref pkschema); ReadValue(reader, "unique_constraint_name", ref pkname); TableAnalyser.Key fk = m_analyser.FindKey(fkschema, fkname); TableAnalyser.Key pk = m_analyser.FindKey(pkschema, pkname); if (pk == null || fk == null) { continue; } fk.dstpkschema = pk.keyschema; fk.dstpkname = pk.keyname; List <TableAnalyser.Col> pkcols = new List <TableAnalyser.Col>(), fkcols = new List <TableAnalyser.Col>(); fkcols.AddRange(m_analyser.GetCols(fk)); pkcols.AddRange(m_analyser.GetCols(pk)); if (fkcols.Count == pkcols.Count) { fk.dsttblschema = pk.tblschema; fk.dsttblname = pk.tblname; for (int i = 0; i < fkcols.Count; i++) { fkcols[i].dstcolname = pkcols[i].colname; } } } } } }
private void LoadCheckConstraints(Condition cond) { using (DbCommand cmd = m_conn.CreateCommand()) { cmd.CommandText = CreateQuery("check_constraints", new string[] { "constraint_schema", "constraint_name", "table_schema", "table_name", "check_clause" }, cond); using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { TableAnalyser.Key key = new TableAnalyser.Key(); ReadValue(reader, "table_schema", ref key.tblschema); ReadValue(reader, "table_name", ref key.tblname); ReadValue(reader, "constraint_schema", ref key.keyschema); ReadValue(reader, "constraint_name", ref key.keyname); ReadValue(reader, "check_clause", ref key.checkexpr); key.keytype = "CHECK"; m_analyser.keys.Add(key); } } } }
private void LoadForeignKeyRules(Condition cond) { using (DbCommand cmd = m_conn.CreateCommand()) { cmd.CommandText = CreateQuery("referential_constraints", new string[] { "constraint_schema", "constraint_name", "table_schema", "table_name", "update_rule", "delete_rule" }, cond); using (DbDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { TableAnalyser.Key key = new TableAnalyser.Key(); ReadValue(reader, "table_schema", ref key.tblschema); ReadValue(reader, "table_name", ref key.tblname); ReadValue(reader, "constraint_schema", ref key.keyschema); ReadValue(reader, "constraint_name", ref key.keyname); ReadValue(reader, "update_rule", ref key.updaterule); ReadValue(reader, "delete_rule", ref key.deleterule); key.keytype = "FOREIGN KEY"; m_analyser.keys.Add(key); } } } }