/// <summary>The exec load database details.</summary> /// <returns>The exec load database details.</returns> private bool ExecLoadDatabaseDetails() { bool populate = false; string connection = string.Empty; bool success = false; try { _hostWindow.SetPointerState(Cursors.WaitCursor); if (_metaDataService == null) { _metaDataService = DatabaseMetaDataService.Create(_services.Settings.ConnectionDefinition.ProviderName); } connection = _metaDataService.GetDescription(); populate = true; } catch (Exception exp) { string msg = string.Format( "{0}\r\n\r\nCheck the connection and select 'Reset Database Connection'.", exp.Message); _hostWindow.DisplaySimpleMessageBox(_hostWindow.Instance, msg, "DB Connection Error"); _hostWindow.SetStatus(this, exp.Message); } finally { _hostWindow.SetPointerState(Cursors.Default); } if (populate) { try { _hostWindow.SetPointerState(Cursors.WaitCursor); _model = _metaDataService.GetDbObjectModel(_services.Settings.ConnectionDefinition.ConnectionString); } finally { _hostWindow.SetPointerState(Cursors.Default); } BuildTreeFromDbModel(connection); _hostWindow.SetStatus(this, string.Empty); success = true; } else { _populated = false; DatabaseTreeView.CollapseAll(); } return(success); }
/// <summary>The get table or view by name.</summary> /// <param name="model">The model.</param> /// <param name="tableName">The table name.</param> /// <returns></returns> protected DbModelTable GetTableOrViewByName(DbModelInstance model, string tableName) { DbModelTable tableOrView = model.FindTable(tableName); if (tableOrView == null) { // check the views tableOrView = model.FindView(tableName); } return(tableOrView); }
/// <summary>Execute the command.</summary> public override void Execute() { IQueryEditor editor = ActiveFormAsSqlQueryEditor; string tableName = HostWindow.DatabaseInspector.RightClickedTableName; DbModelInstance model = HostWindow.DatabaseInspector.DbSchema; if (tableName != null && editor != null) { StringWriter sql = new StringWriter(); SqlWriter.WriteUpdate(sql, GetTableOrViewByName(model, tableName)); editor.InsertText(sql.ToString()); } }
/// <summary>The get tables and views.</summary> private void GetTablesAndViews() { if (_metaDataService == null) { _metaDataService = DatabaseMetaDataService.Create(_services.Settings.ConnectionDefinition.ProviderName); DbModelInstance model = _metaDataService.GetDbObjectModel(_services.Settings.ConnectionDefinition.ConnectionString); List <string> tableNames = new List <string>(); foreach (DbModelTable table in model.Tables) { tableNames.Add(Utility.MakeSqlFriendly(table.FullName)); } foreach (DbModelView view in model.Views) { tableNames.Add(Utility.MakeSqlFriendly(view.FullName)); } cboTableName.Items.AddRange(tableNames.ToArray()); } }
public void nvelocity_with_dbmodel2() { DbModelInstance model = new DbModelInstance(); model.ConnectionString = "conn str"; model.ProviderName = "sql.foo"; DbModelTable table = new DbModelTable { Name = "MyTable" }; model.Add(table); table.Add(new DbModelColumn { Name = "ID" }); table.Add(new DbModelColumn { Name = "FirstName" }); Dictionary <string, object> items = new Dictionary <string, object>(); items.Add("model", model); string template = @"Template Test ($num): ConnectionString: ""$model.ConnectionString"" ProviderName: ""$model.ProviderName"" #foreach ($table in $model.Tables) $table.Name #foreach ($c in $table.Columns) * $c.Name #end #end "; string s = _formatter.Format(template, items); Console.WriteLine(s); Assert.That(s.Length, Is.GreaterThan(0)); }