public List <ConstraintInfo> GetPrimaryKeyOnTable(string connectionString, string tableName)
        {
            List <ConstraintInfo> list = new List <ConstraintInfo>();

            SqlConnection conn;

            using (IDataReader reader = SqlCommandX.Instance.GetReader(
                       connectionString, query_pk_on_table(table_name), CommandType.Text,
                       out conn))
            {
                while (reader.Read())
                {
                    ConstraintInfo cs = new ConstraintInfo();
                    if (DBNull.Value != reader["table_name"])
                    {
                        cs.table_name = reader["table_name"].ToString();
                    }
                    if (DBNull.Value != reader["field_name"])
                    {
                        cs.field_name = reader["field_name"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_type"])
                    {
                        cs.constraint_type = reader["constraint_type"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_name"])
                    {
                        cs.constraint_name = reader["constraint_name"].ToString();
                    }

                    if (DBNull.Value != reader["match_type"])
                    {
                        cs.match_type = reader["match_type"].ToString();
                    }

                    if (DBNull.Value != reader["on_update"])
                    {
                        cs.on_update = reader["on_update"].ToString();
                    }

                    if (DBNull.Value != reader["on_delete"])
                    {
                        cs.on_delete = reader["on_delete"].ToString();
                    }

                    if (DBNull.Value != reader["references_table"])
                    {
                        cs.references_table = reader["references_table"].ToString();
                    }

                    if (DBNull.Value != reader["references_field"])
                    {
                        cs.references_field = reader["references_field"].ToString();
                    }

                    if (DBNull.Value != reader["field_position"])
                    {
                        cs.field_position = int.Parse(reader["field_position"].ToString());
                    }
                    list.Add(cs);
                }
            }
            return(list);
        }
        /// <summary>
        /// Get list of all constraints, you can apply table filter
        /// </summary>
        public static List<ConstraintInfo> GetConstraints(string connectionString, params string[] filterTables)
        {
            List<ConstraintInfo> list = new List<ConstraintInfo>();
            SqlConnection conn;
            string query = filterTables.Length > 0 ? ConstraintInfo.queryWithFilter(filterTables) : ConstraintInfo.query;
            using (IDataReader reader = SqlCommandX.Instance.GetReader(
                connectionString, query, CommandType.Text, out conn))
            {
                while (reader.Read())
                {
                    ConstraintInfo cs = new ConstraintInfo();
                    if (DBNull.Value != reader["table_name"])
                    {
                        cs.table_name = reader["table_name"].ToString();
                    }
                    if (DBNull.Value != reader["field_name"])
                    {
                        cs.field_name = reader["field_name"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_type"])
                    {
                        cs.constraint_type = reader["constraint_type"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_name"])
                    {
                        cs.constraint_name = reader["constraint_name"].ToString();
                    }

                    if (DBNull.Value != reader["match_type"])
                    {
                        cs.match_type = reader["match_type"].ToString();
                    }

                    if (DBNull.Value != reader["on_update"])
                    {
                        cs.on_update = reader["on_update"].ToString();
                    }

                    if (DBNull.Value != reader["on_delete"])
                    {
                        cs.on_delete = reader["on_delete"].ToString();
                    }

                    if (DBNull.Value != reader["references_table"])
                    {
                        cs.references_table = reader["references_table"].ToString();
                    }

                    if (DBNull.Value != reader["references_field"])
                    {
                        cs.references_field = reader["references_field"].ToString();
                    }

                    if (DBNull.Value != reader["field_position"])
                    {
                        cs.field_position = int.Parse(reader["field_position"].ToString());
                    }
                    list.Add(cs);
                }
            }
            conn.Destroy();
            return list;
        }
Пример #3
0
        /// <summary>
        /// Get list of all constraints, you can apply table filter
        /// </summary>
        public static List <ConstraintInfo> GetConstraints(string connectionString, params string[] filterTables)
        {
            List <ConstraintInfo> list = new List <ConstraintInfo>();
            SqlConnection         conn;
            string query = filterTables.Length > 0 ? ConstraintInfo.queryWithFilter(filterTables) : ConstraintInfo.query;

            using (IDataReader reader = SqlCommandX.Instance.GetReader(
                       connectionString, query, CommandType.Text, out conn))
            {
                while (reader.Read())
                {
                    ConstraintInfo cs = new ConstraintInfo();
                    if (DBNull.Value != reader["table_name"])
                    {
                        cs.table_name = reader["table_name"].ToString();
                    }
                    if (DBNull.Value != reader["field_name"])
                    {
                        cs.field_name = reader["field_name"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_type"])
                    {
                        cs.constraint_type = reader["constraint_type"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_name"])
                    {
                        cs.constraint_name = reader["constraint_name"].ToString();
                    }

                    if (DBNull.Value != reader["match_type"])
                    {
                        cs.match_type = reader["match_type"].ToString();
                    }

                    if (DBNull.Value != reader["on_update"])
                    {
                        cs.on_update = reader["on_update"].ToString();
                    }

                    if (DBNull.Value != reader["on_delete"])
                    {
                        cs.on_delete = reader["on_delete"].ToString();
                    }

                    if (DBNull.Value != reader["references_table"])
                    {
                        cs.references_table = reader["references_table"].ToString();
                    }

                    if (DBNull.Value != reader["references_field"])
                    {
                        cs.references_field = reader["references_field"].ToString();
                    }

                    if (DBNull.Value != reader["field_position"])
                    {
                        cs.field_position = int.Parse(reader["field_position"].ToString());
                    }
                    list.Add(cs);
                }
            }
            conn.Destroy();
            return(list);
        }
        public List<ConstraintInfo> GetPrimaryKeyOnTable(string connectionString, string tableName)
        {
            List<ConstraintInfo> list = new List<ConstraintInfo>();

            SqlConnection conn;
            using (IDataReader reader = SqlCommandX.Instance.GetReader(
                connectionString, query_pk_on_table(table_name), CommandType.Text,
                out conn))
            {
                while (reader.Read())
                {
                    ConstraintInfo cs = new ConstraintInfo();
                    if (DBNull.Value != reader["table_name"])
                    {
                        cs.table_name = reader["table_name"].ToString();
                    }
                    if (DBNull.Value != reader["field_name"])
                    {
                        cs.field_name = reader["field_name"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_type"])
                    {
                        cs.constraint_type = reader["constraint_type"].ToString();
                    }
                    if (DBNull.Value != reader["constraint_name"])
                    {
                        cs.constraint_name = reader["constraint_name"].ToString();
                    }

                    if (DBNull.Value != reader["match_type"])
                    {
                        cs.match_type = reader["match_type"].ToString();
                    }

                    if (DBNull.Value != reader["on_update"])
                    {
                        cs.on_update = reader["on_update"].ToString();
                    }

                    if (DBNull.Value != reader["on_delete"])
                    {
                        cs.on_delete = reader["on_delete"].ToString();
                    }

                    if (DBNull.Value != reader["references_table"])
                    {
                        cs.references_table = reader["references_table"].ToString();
                    }

                    if (DBNull.Value != reader["references_field"])
                    {
                        cs.references_field = reader["references_field"].ToString();
                    }

                    if (DBNull.Value != reader["field_position"])
                    {
                        cs.field_position = int.Parse(reader["field_position"].ToString());
                    }
                    list.Add(cs);
                }
            }
            return list;
        }