Exemplo n.º 1
0
        /// <summary>
        /// Returns a list of table sources (e.g. tables, views) that belong to a given database.
        /// The returned table sources must have different display names.
        /// </summary>
        /// <param name="database">Database from which we want to fetch the list of tables</param>
        /// <param name="isTableSourceToIgnore">The delegate to call to see if the table source should be ignored and excluded from the returned list</param>
        /// <returns>List of available table sources in the given database</returns>
        /// <exception cref="System.Data.Common.DbException">if an error occurs while accessing the database</exception>
        public override IEnumerable <ITableSourceInfo> ListTableSources(IDatabaseInfo database, IsTableSourceToIgnore isTableSourceToIgnore)
        {
            SnowflakeDatabaseInfo databaseInfo = database as SnowflakeDatabaseInfo;

            if (databaseInfo == null)
            {
                return(null);
            }

            IList <ITableSourceInfo> tables = new List <ITableSourceInfo>();

            using (IDbConnection conn = DatabaseServices.TransactionService.CreateConnection())
            {
                //Fetch Tables
                GetTableOrViewInfo(databaseInfo, isTableSourceToIgnore, true, conn, ref tables);

                //Fetch Views
                GetTableOrViewInfo(databaseInfo, isTableSourceToIgnore, false, conn, ref tables);
            }
            return(tables);
        }
Exemplo n.º 2
0
        private void GetTableOrViewInfo(SnowflakeDatabaseInfo databaseInfo, IsTableSourceToIgnore isTableSourceToIgnore, bool showTables, IDbConnection conn, ref IList <ITableSourceInfo> tables)
        {
            string sql = string.Format("SHOW {1} IN SCHEMA {0}", databaseInfo.Identifier, showTables ? "TABLES" : "VIEWS");

            IDbCommand cmd = DatabaseServices.ExecutionService.CreateCommand(conn, sql);

            cmd.CommandTimeout = QueryTimeout;

            using (IDataReader reader = cmd.ExecuteReader())
            {
                while (reader.Read())
                {
                    string tableName = (string)reader["name"];
                    if (!isTableSourceToIgnore(tableName))
                    {
                        string qualifiedTableName = GetQualifiedIdentifier(databaseInfo.Identifier, tableName);
                        tables.Add(new SnowflakeTableSourceInfo(DatabaseServices, databaseInfo, tableName, qualifiedTableName));
                    }
                }
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TableSourceInfo"/> class.
 /// </summary>
 /// <param name="databaseServices">The database services.</param>
 /// <param name="database">The database.</param>
 /// <param name="name">The name.</param>
 /// <param name="qualifiedName">Name of the qualified.</param>
 public SnowflakeTableSourceInfo(IDatabaseServices databaseServices, SnowflakeDatabaseInfo database, string name, string qualifiedName) : base(databaseServices, database, name, qualifiedName)
 {
 }