예제 #1
0
        public IConnectionProvider GetConnectionProvider(IShellContext context)
        {
            string providerString         = GetProviderString(context);
            string providerStringReplaced = context.Replace(providerString);
            var    conn = ConnectionProvider.FromString(context.ServiceProvider, providerStringReplaced);

            if (conn == null)
            {
                throw new Exception("DBSH-00150 Connection not defined, provider string:" + providerString);
            }
            return(conn);
        }
예제 #2
0
 public DatabaseInfo GetDatabaseStructure(string connectionKey)
 {
     if (!_dbCache.ContainsKey(connectionKey))
     {
         IConnectionProvider connection = ConnectionProvider.FromString(ServiceProvider, connectionKey);
         _logger.LogInformation("DBSH-00076 Downloading structure for connection {connection}", connection);
         this.Info(String.Format("DBSH-00149 Downloading structure for connection {0}", connection));
         var analyser = connection.Factory.CreateAnalyser();
         using (var conn = connection.Connect())
         {
             analyser.Connection = conn;
             analyser.FullAnalysis();
             _dbCache[connectionKey] = analyser.Structure;
         }
     }
     return(_dbCache[connectionKey]);
 }
예제 #3
0
        public override void Run()
        {
            // build service containing all supported database egnines and file formats, with default logging
            var serviceProvider = DbShellUtility.BuildDefaultServiceProvider();

            // create connection provider from provider string
            var connectionProvider = ConnectionProvider.FromString(serviceProvider, ProviderString);

            using (var conn = connectionProvider.Connect())
            {
                // create analyser - object which analyses database structure
                var analyser = connectionProvider.Factory.CreateAnalyser();

                // assign DbConnection to analyse
                analyser.Connection = conn;

                // analyse only tables. If this line is omited, all database objects (eg. views, stored procedures...) will be analysed
                analyser.Phase = DatabaseAnalysePhase.Tables;

                // perform full analysis (other option is IncrementalAnalysis, when changes are detected)
                analyser.FullAnalysis();

                // get result structure
                var analysedStructure = analyser.Structure;

                // print table and column names
                foreach (var table in analysedStructure.Tables)
                {
                    Console.WriteLine(table.Name);
                    foreach (var column in table.Columns)
                    {
                        Console.WriteLine("    " + column.Name + " " + column.DataType);
                    }
                }
            }
        }