Ejemplo n.º 1
0
        public virtual IEnumerable <DBTableInfo> GetTablesInfo(DBConnection connection, string schemaName = null, string tableName = null)
        {
            var     tableFilter  = !string.IsNullOrEmpty(tableName) ? $" and table_name = '{tableName}'" : string.Empty;
            var     schemaFilter = !string.IsNullOrEmpty(schemaName) ? $" where table_schema = '{schemaName}'{tableFilter}" : string.Empty;
            QResult list         = connection.ExecuteQResult($"select * from information_schema.tables{schemaFilter} order by table_name");
            int     iSchema      = list.GetIndex("table_schema");
            int     iName        = list.GetIndex("table_name");
            int     iIndex       = list.GetIndex("table_type");

            foreach (object[] item in list.Values)
            {
                var table = new DBTableInfo()
                {
                    Schema = item[iSchema].ToString(),
                    Name   = item[iName].ToString(),
                    View   = item[iIndex].ToString().IndexOf("view", StringComparison.OrdinalIgnoreCase) >= 0,
                };
                GetColumnsInfo(connection, table);
                GetConstraintInfo(connection, table);
                yield return(table);
            }
        }