public ColumnSchema (ISchemaProvider schemaProvider, ISchema parent, string name) : base (schemaProvider) { this.constraints = new ConstraintSchemaCollection (); this.parent = parent; this.name = name; }
public TableSchema (TableSchema table) : base (table) { isSystemTable = table.isSystemTable; tableSpaceName = table.tableSpaceName; columns = new ColumnSchemaCollection (table.columns); constraints = new ConstraintSchemaCollection (table.constraints); triggers = new TriggerSchemaCollection (table.triggers); }
public TableSchema (ISchemaProvider schemaProvider, string name) : base (schemaProvider) { Name = name; columns = new ColumnSchemaCollection (); constraints = new ConstraintSchemaCollection (); triggers = new TriggerSchemaCollection (); }
public UniqueConstraintEditorWidget (ISchemaProvider schemaProvider, SchemaActions action, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (schemaProvider == null) throw new ArgumentNullException ("schemaProvider"); this.schemaProvider = schemaProvider; this.table = table; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore (typeof (string), typeof (bool), typeof (string), typeof (object)); listUnique.Model = store; listUnique.Selection.Changed += new EventHandler (SelectionChanged); columnSelecter.ColumnToggled += new EventHandler (ColumnToggled); TreeViewColumn colName = new TreeViewColumn (); TreeViewColumn colIsColConstraint = new TreeViewColumn (); colName.Title = GettextCatalog.GetString ("Name"); colIsColConstraint.Title = GettextCatalog.GetString ("Column Constraint"); CellRendererText nameRenderer = new CellRendererText (); CellRendererToggle toggleRenderer = new CellRendererToggle (); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler (NameEdited); toggleRenderer.Activatable = true; toggleRenderer.Toggled += new ToggledHandler (IsColumnConstraintToggled); colName.PackStart (nameRenderer, true); colIsColConstraint.PackStart (toggleRenderer, true); colName.AddAttribute (nameRenderer, "text", colNameIndex); colIsColConstraint.AddAttribute (toggleRenderer, "active", colIsColumnConstraintIndex); listUnique.AppendColumn (colName); listUnique.AppendColumn (colIsColConstraint); columnSelecter.Initialize (columns); foreach (UniqueConstraintSchema uni in constraints.GetConstraints (ConstraintType.Unique)) AddConstraint (uni); //TODO: also col constraints ShowAll (); }
public ColumnSchema (ColumnSchema column) : base (column) { parent = column.parent; //do not clone, this would create an infinite loop dataType = column.dataType; hasDefaultValue = column.hasDefaultValue; defaultValue = column.defaultValue; nullable = column.nullable; position = column.position; constraints = new ConstraintSchemaCollection (column.constraints); }
public PrimaryKeyConstraintEditorWidget(ISchemaProvider schemaProvider, SchemaActions action, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) { throw new ArgumentNullException("columns"); } if (table == null) { throw new ArgumentNullException("table"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (schemaProvider == null) { throw new ArgumentNullException("schemaProvider"); } this.schemaProvider = schemaProvider; this.table = table; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore(typeof(string), typeof(string), typeof(object)); listPK.Model = store; TreeViewColumn colName = new TreeViewColumn(); colName.Title = GettextCatalog.GetString("Name"); CellRendererText nameRenderer = new CellRendererText(); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler(NameEdited); colName.PackStart(nameRenderer, true); colName.AddAttribute(nameRenderer, "text", colNameIndex); listPK.AppendColumn(colName); columnSelecter.Initialize(columns); listPK.Selection.Changed += new EventHandler(SelectionChanged); columnSelecter.ColumnToggled += new EventHandler(ColumnToggled); foreach (PrimaryKeyConstraintSchema pk in constraints.GetConstraints(ConstraintType.PrimaryKey)) { AddConstraint(pk); } ShowAll(); }
public override ConstraintSchemaCollection GetColumnConstraints(TableSchema table, ColumnSchema column) { ConstraintSchemaCollection constraints = new ConstraintSchemaCollection(); using (IPooledDbConnection conn = connectionPool.Request()) { using (IDbCommand command = conn.CreateCommand(String.Format("DESCRIBE {0}", table.Name))) { try { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { if (r.IsDBNull(3) || String.Compare(r.GetString(0), column.Name, true) != 0) { continue; } string key = r.GetString(3).ToUpper(); ConstraintSchema constraint = null; if (key.Contains("PRI")) { constraint = CreatePrimaryKeyConstraintSchema("pk_" + column.Name); } else if (key.Contains("UNI")) { constraint = CreateUniqueConstraintSchema("uni_" + column.Name); } else { continue; } constraint.IsColumnConstraint = true; constraint.OwnerName = r.GetString(0); constraints.Add(constraint); } r.Close(); } } catch (Exception e) { QueryService.RaiseException(e); } finally { conn.Release(); } } } return(constraints); }
private void InitializeThreaded(object state) { tables = schemaProvider.GetTables(); dataTypes = schemaProvider.GetDataTypes(); columns = originalTable.Columns; constraints = originalTable.Constraints; triggers = originalTable.Triggers; //TODO: indices indexes = new IndexSchemaCollection(); System.Text.StringBuilder builder = new System.Text.StringBuilder(); builder.Append("Loading editor for TABLE "); builder.Append(originalTable.Name); builder.AppendLine(); builder.Append(" columns = "); builder.Append(columns.Count); builder.AppendLine(); builder.Append("constraints = "); builder.Append(constraints.Count); builder.AppendLine(); try { foreach (ColumnSchema col in columns) { int dummy = col.Constraints.Count; //get column constraints builder.Append("CONSTRAINTS "); builder.Append(col.Name); builder.Append(" "); builder.Append(dummy); builder.AppendLine(); } LoggingService.LogDebug(builder.ToString()); } catch (Exception ee) { LoggingService.LogDebug(builder.ToString()); LoggingService.LogError(ee.ToString()); } if (action == SchemaActions.Alter) //make a duplicate if we are going to alter the table { this.table = originalTable.Clone() as TableSchema; } DispatchService.GuiDispatch(delegate() { InitializeGui(); }); }
public PrimaryKeyConstraintEditorWidget (ISchemaProvider schemaProvider, SchemaActions action, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (schemaProvider == null) throw new ArgumentNullException ("schemaProvider"); this.schemaProvider = schemaProvider; this.table = table; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore (typeof (string), typeof (string), typeof (object)); listPK.Model = store; TreeViewColumn colName = new TreeViewColumn (); colName.Title = GettextCatalog.GetString ("Name"); CellRendererText nameRenderer = new CellRendererText (); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler (NameEdited); colName.PackStart (nameRenderer, true); colName.AddAttribute (nameRenderer, "text", colNameIndex); listPK.AppendColumn (colName); columnSelecter.Initialize (columns); listPK.Selection.Changed += new EventHandler (SelectionChanged); columnSelecter.ColumnToggled += new EventHandler (ColumnToggled); foreach (PrimaryKeyConstraintSchema pk in constraints.GetConstraints (ConstraintType.PrimaryKey)) AddConstraint (pk); ShowAll (); }
public void Initialize (TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints, DataTypeSchemaCollection dataTypes) { if (columns == null) throw new ArgumentNullException ("columns"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (table == null) throw new ArgumentNullException ("table"); if (tables == null) throw new ArgumentNullException ("tables"); IDbFactory fac = schemaProvider.ConnectionPool.DbFactory; if (fac.IsCapabilitySupported ("Table", action, TableCapabilities.PrimaryKeyConstraint)) { //not for column constraints, since they are already editable in the column editor pkEditor = new PrimaryKeyConstraintEditorWidget (schemaProvider, action, table, columns, constraints); pkEditor.ContentChanged += new EventHandler (OnContentChanged); notebook.AppendPage (pkEditor, new Label (GettextCatalog.GetString ("Primary Key"))); } if (fac.IsCapabilitySupported ("Table", action, TableCapabilities.ForeignKeyConstraint) || fac.IsCapabilitySupported ("TableColumn", action, TableCapabilities.ForeignKeyConstraint)) { fkEditor = new ForeignKeyConstraintEditorWidget (schemaProvider, action, tables, table, columns, constraints); fkEditor.ContentChanged += new EventHandler (OnContentChanged); notebook.AppendPage (fkEditor, new Label (GettextCatalog.GetString ("Foreign Key"))); } if (fac.IsCapabilitySupported ("Table", action, TableCapabilities.CheckConstraint) || fac.IsCapabilitySupported ("TableColumn", action, TableCapabilities.CheckConstraint)) { checkEditor = new CheckConstraintEditorWidget (schemaProvider, action, table, columns, constraints); checkEditor.ContentChanged += new EventHandler (OnContentChanged); notebook.AppendPage (checkEditor, new Label (GettextCatalog.GetString ("Check"))); } if (fac.IsCapabilitySupported ("Table", action, TableCapabilities.UniqueConstraint) || fac.IsCapabilitySupported ("TableColumn", action, TableCapabilities.CheckConstraint)) { uniqueEditor = new UniqueConstraintEditorWidget (schemaProvider, action, table, columns, constraints); uniqueEditor.ContentChanged += new EventHandler (OnContentChanged); notebook.AppendPage (uniqueEditor, new Label (GettextCatalog.GetString ("Unique"))); } ShowAll (); }
public void Initialize(TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) { throw new ArgumentNullException("columns"); } if (table == null) { throw new ArgumentNullException("table"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } this.table = table; this.columns = columns; this.constraints = constraints; columnSelecter.Initialize(columns); RefreshConstraints(); }
protected string GetTableDefinition(TableSchema table) { StringBuilder sb = new StringBuilder(); sb.AppendFormat("-- Table: {0}\n", table.Name); sb.AppendFormat("-- DROP TABLE {0};\n\n", table.Name); sb.AppendFormat("CREATE TABLE {0} (\n", table.Name); ColumnSchemaCollection columns = table.Columns; string[] parts = new string[columns.Count]; int i = 0; foreach (ColumnSchema col in columns) { parts[i++] = col.Definition; } sb.Append(String.Join(",\n", parts)); ConstraintSchemaCollection constraints = table.Constraints; parts = new string[constraints.Count]; if (constraints.Count > 0) { sb.Append(",\n"); } i = 0; foreach (ConstraintSchema constr in constraints) { parts[i++] = "\t" + constr.Definition; } sb.Append(String.Join(",\n", parts)); sb.Append("\n);\n"); //sb.AppendFormat ("COMMENT ON TABLE {0} IS '{1}';", table.Name, table.Comment); return(sb.ToString()); }
public override ConstraintSchemaCollection GetTableConstraints(TableSchema table) { ConstraintSchemaCollection constraints = new ConstraintSchemaCollection(); using (IPooledDbConnection conn = connectionPool.Request()) { using (IDbCommand command = conn.CreateCommand(string.Concat("SHOW TABLE STATUS FROM `", table.SchemaName, "`;"))) { try { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { string[] chunks = ((string)r["Comment"]).Split(';'); // the values we are looking for are in the format: // (`table`) REFER `database\table2` (`table2`) foreach (string chunk in chunks) { if (constraintRegex.IsMatch(chunk)) { MatchCollection matches = constraintRegex.Matches(chunk); ForeignKeyConstraintSchema constraint = new ForeignKeyConstraintSchema(this); constraint.ReferenceTableName = matches[1].Groups[1].ToString(); constraint.Name = matches[0].Groups[1].ToString(); constraints.Add(constraint); } } } r.Close(); } } catch (Exception e) { // Don't raise error, if the table doesn't exists return an empty collection } finally { conn.Release(); } } } return(constraints); }
public void Initialize(TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints, DataTypeSchemaCollection dataTypes) { Runtime.LoggingService.Error("CEW: Initialize"); if (columns == null) { throw new ArgumentNullException("columns"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (table == null) { throw new ArgumentNullException("table"); } if (dataTypes == null) { throw new ArgumentNullException("dataTypes"); } this.table = table; this.columns = columns; this.constraints = constraints; this.dataTypes = dataTypes; foreach (ColumnSchema column in columns) { AppendColumnSchema(column); } foreach (DataTypeSchema dataType in dataTypes) { storeTypes.AppendValues(dataType.Name, storeTypes); } Runtime.LoggingService.Error("CEW: Initialize 2"); }
//TODO: difference between columns and reference columns + combo events public ForeignKeyConstraintEditorWidget(ISchemaProvider schemaProvider, SchemaActions action, TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) { throw new ArgumentNullException("columns"); } if (table == null) { throw new ArgumentNullException("table"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (schemaProvider == null) { throw new ArgumentNullException("schemaProvider"); } if (tables == null) { throw new ArgumentNullException("tables"); } this.schemaProvider = schemaProvider; this.table = table; this.tables = tables; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore(typeof(string), typeof(string), typeof(bool), typeof(string), typeof(string), typeof(string), typeof(string), typeof(object)); listFK.Model = store; storeActions = new ListStore(typeof(string), typeof(int)); storeTables = new ListStore(typeof(string)); IDbFactory fac = schemaProvider.ConnectionPool.DbFactory; if (fac.IsCapabilitySupported("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.Cascade)) { storeActions.AppendValues("Cascade", ForeignKeyAction.Cascade); } if (fac.IsCapabilitySupported("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.Restrict)) { storeActions.AppendValues("Restrict", ForeignKeyAction.Restrict); } if (fac.IsCapabilitySupported("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.NoAction)) { storeActions.AppendValues("No Action", ForeignKeyAction.NoAction); } if (fac.IsCapabilitySupported("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.SetNull)) { storeActions.AppendValues("Set Null", ForeignKeyAction.SetNull); } if (fac.IsCapabilitySupported("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.SetDefault)) { storeActions.AppendValues("Set Default", ForeignKeyAction.SetDefault); } foreach (TableSchema tbl in tables) { if (tbl.Name != table.Name) { storeTables.AppendValues(tbl.Name); } } TreeViewColumn colName = new TreeViewColumn(); TreeViewColumn colRefTable = new TreeViewColumn(); TreeViewColumn colIsColumnConstraint = new TreeViewColumn(); TreeViewColumn colDeleteAction = new TreeViewColumn(); TreeViewColumn colUpdateAction = new TreeViewColumn(); colName.Title = GettextCatalog.GetString("Name"); colRefTable.Title = GettextCatalog.GetString("Reference Table"); colIsColumnConstraint.Title = GettextCatalog.GetString("Column Constraint"); colDeleteAction.Title = GettextCatalog.GetString("Delete Action"); colUpdateAction.Title = GettextCatalog.GetString("Update Action"); colRefTable.MinWidth = 120; CellRendererText nameRenderer = new CellRendererText(); CellRendererCombo refTableRenderer = new CellRendererCombo(); CellRendererToggle isColumnConstraintRenderer = new CellRendererToggle(); CellRendererCombo deleteActionRenderer = new CellRendererCombo(); CellRendererCombo updateActionRenderer = new CellRendererCombo(); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler(NameEdited); refTableRenderer.Model = storeTables; refTableRenderer.TextColumn = 0; refTableRenderer.Editable = true; refTableRenderer.Edited += new EditedHandler(RefTableEdited); isColumnConstraintRenderer.Activatable = true; isColumnConstraintRenderer.Toggled += new ToggledHandler(IsColumnConstraintToggled); deleteActionRenderer.Model = storeActions; deleteActionRenderer.TextColumn = 0; deleteActionRenderer.Editable = true; deleteActionRenderer.Edited += new EditedHandler(DeleteActionEdited); updateActionRenderer.Model = storeActions; updateActionRenderer.TextColumn = 0; updateActionRenderer.Editable = true; updateActionRenderer.Edited += new EditedHandler(UpdateActionEdited); colName.PackStart(nameRenderer, true); colRefTable.PackStart(refTableRenderer, true); colIsColumnConstraint.PackStart(isColumnConstraintRenderer, true); colDeleteAction.PackStart(deleteActionRenderer, true); colUpdateAction.PackStart(updateActionRenderer, true); colName.AddAttribute(nameRenderer, "text", colNameIndex); colRefTable.AddAttribute(refTableRenderer, "text", colReferenceTableIndex); colIsColumnConstraint.AddAttribute(isColumnConstraintRenderer, "active", colIsColumnConstraintIndex); colDeleteAction.AddAttribute(deleteActionRenderer, "text", colDeleteActionIndex); colUpdateAction.AddAttribute(updateActionRenderer, "text", colUpdateActionIndex); listFK.AppendColumn(colName); listFK.AppendColumn(colRefTable); listFK.AppendColumn(colIsColumnConstraint); listFK.AppendColumn(colDeleteAction); listFK.AppendColumn(colUpdateAction); columnSelecter.ColumnToggled += new EventHandler(ColumnToggled); referenceColumnSelecter.ColumnToggled += new EventHandler(ReferenceColumnToggled); listFK.Selection.Changed += new EventHandler(SelectionChanged); ShowAll(); }
public override ConstraintSchemaCollection GetColumnConstraints (TableSchema table, ColumnSchema column) { ConstraintSchemaCollection constraints = new ConstraintSchemaCollection (); using (IPooledDbConnection conn = connectionPool.Request ()) { using (IDbCommand command = conn.CreateCommand (String.Format ("DESCRIBE {0}", table.Name))) { try { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { if (r.IsDBNull (3) || String.Compare (r.GetString (0), column.Name, true) != 0) continue; string key = r.GetString (3).ToUpper (); ConstraintSchema constraint = null; if (key.Contains ("PRI")) constraint = CreatePrimaryKeyConstraintSchema ("pk_" + column.Name); else if (key.Contains ("UNI")) constraint = CreateUniqueConstraintSchema ("uni_" + column.Name); else continue; constraint.IsColumnConstraint = true; constraint.OwnerName = r.GetString (0); constraints.Add (constraint); } r.Close (); } } catch (Exception e) { QueryService.RaiseException (e); } finally { conn.Release (); } } } return constraints; }
public void Initialize (TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints, DataTypeSchemaCollection dataTypes) { Runtime.LoggingService.Error ("CEW: Initialize"); if (columns == null) throw new ArgumentNullException ("columns"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (table == null) throw new ArgumentNullException ("table"); if (dataTypes == null) throw new ArgumentNullException ("dataTypes"); this.table = table; this.columns = columns; this.constraints = constraints; this.dataTypes = dataTypes; foreach (ColumnSchema column in columns) AppendColumnSchema (column); foreach (DataTypeSchema dataType in dataTypes) storeTypes.AppendValues (dataType.Name, storeTypes); Runtime.LoggingService.Error ("CEW: Initialize 2"); }
//http://www.sqlite.org/pragma.html public virtual ConstraintSchemaCollection GetConstraints (TableSchema table, ColumnSchema column) { if (table == null) throw new ArgumentNullException ("table"); string columnName = column == null ? null : column.Name; ConstraintSchemaCollection constraints = new ConstraintSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); //fk and unique IDbCommand command = conn.CreateCommand ("SELECT name, tbl_name FROM sqlite_master WHERE sql IS NULL AND type = 'index'"); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ConstraintSchema constraint = null; if (r.IsDBNull (1) || r.GetString (1) == null) { constraint = new UniqueConstraintSchema (this); } else { ForeignKeyConstraintSchema fkc = new ForeignKeyConstraintSchema (this); fkc.ReferenceTableName = r.GetString (1); constraint = fkc; } constraint.Name = r.GetString (0); constraints.Add (constraint); } r.Close (); } } //pk, column if (columnName != null) { command = conn.CreateCommand ( "PRAGMA table_info('" + table.Name + "')" ); using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { if (r.GetInt32 (5) == 1 && r.GetString (1) == columnName) { PrimaryKeyConstraintSchema constraint = new PrimaryKeyConstraintSchema (this); ColumnSchema priColumn = new ColumnSchema (this, table); priColumn.Name = r.GetString (1); constraint.Columns.Add (priColumn); constraint.IsColumnConstraint = true; constraint.Name = "pk_" + table.Name + "_" + priColumn.Name; constraints.Add (constraint); } } r.Close (); } } } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return constraints; }
public void Initialize (TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); this.table = table; this.columns = columns; this.constraints = constraints; columnSelecter.Initialize (columns); foreach (UniqueConstraintSchema uni in constraints.GetConstraints (ConstraintType.Unique)) AddConstraint (uni); //TODO: also col constraints }
public UniqueConstraintEditorWidget(ISchemaProvider schemaProvider, SchemaActions action, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) { throw new ArgumentNullException("columns"); } if (table == null) { throw new ArgumentNullException("table"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (schemaProvider == null) { throw new ArgumentNullException("schemaProvider"); } this.schemaProvider = schemaProvider; this.table = table; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore(typeof(string), typeof(bool), typeof(string), typeof(object)); listUnique.Model = store; listUnique.Selection.Changed += new EventHandler(SelectionChanged); columnSelecter.ColumnToggled += new EventHandler(ColumnToggled); TreeViewColumn colName = new TreeViewColumn(); TreeViewColumn colIsColConstraint = new TreeViewColumn(); colName.Title = GettextCatalog.GetString("Name"); colIsColConstraint.Title = GettextCatalog.GetString("Column Constraint"); CellRendererText nameRenderer = new CellRendererText(); CellRendererToggle toggleRenderer = new CellRendererToggle(); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler(NameEdited); toggleRenderer.Activatable = true; toggleRenderer.Toggled += new ToggledHandler(IsColumnConstraintToggled); colName.PackStart(nameRenderer, true); colIsColConstraint.PackStart(toggleRenderer, true); colName.AddAttribute(nameRenderer, "text", colNameIndex); colIsColConstraint.AddAttribute(toggleRenderer, "active", colIsColumnConstraintIndex); listUnique.AppendColumn(colName); listUnique.AppendColumn(colIsColConstraint); columnSelecter.Initialize(columns); foreach (UniqueConstraintSchema uni in constraints.GetConstraints(ConstraintType.Unique)) { AddConstraint(uni); } //TODO: also col constraints ShowAll(); }
public CheckConstraintEditorWidget (ISchemaProvider schemaProvider, SchemaActions action, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (schemaProvider == null) throw new ArgumentNullException ("schemaProvider"); this.schemaProvider = schemaProvider; this.table = table; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore (typeof (string), typeof (string), typeof (bool), typeof (string), typeof (object)); storeColumns = new SortedColumnListStore (columns); listCheck.Model = store; TreeViewColumn colName = new TreeViewColumn (); TreeViewColumn colColumn = new TreeViewColumn (); TreeViewColumn colIsColumnConstraint = new TreeViewColumn (); colName.Title = GettextCatalog.GetString ("Name"); colColumn.Title = GettextCatalog.GetString ("Column"); colIsColumnConstraint.Title = GettextCatalog.GetString ("Column Constraint"); colColumn.MinWidth = 120; //request a bigger width CellRendererText nameRenderer = new CellRendererText (); CellRendererCombo columnRenderer = new CellRendererCombo (); CellRendererToggle isColumnConstraintRenderer = new CellRendererToggle (); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler (NameEdited); columnRenderer.Model = storeColumns.Store; columnRenderer.TextColumn = SortedColumnListStore.ColNameIndex; columnRenderer.Editable = true; columnRenderer.Edited += new EditedHandler (ColumnEdited); isColumnConstraintRenderer.Activatable = true; isColumnConstraintRenderer.Toggled += new ToggledHandler (IsColumnConstraintToggled); colName.PackStart (nameRenderer, true); colColumn.PackStart (columnRenderer, true); colIsColumnConstraint.PackStart (isColumnConstraintRenderer, true); colName.AddAttribute (nameRenderer, "text", colNameIndex); colColumn.AddAttribute (columnRenderer, "text", colColumnNameIndex); colIsColumnConstraint.AddAttribute (isColumnConstraintRenderer, "active", colIsColumnConstraintIndex); IDbFactory fac = schemaProvider.ConnectionPool.DbFactory; columnConstraintsSupported = fac.IsCapabilitySupported ("TableColumn", action, TableCapabilities.CheckConstraint); tableConstraintsSupported = fac.IsCapabilitySupported ("Table", action, TableCapabilities.CheckConstraint); listCheck.AppendColumn (colName); if (columnConstraintsSupported) listCheck.AppendColumn (colColumn); if (columnConstraintsSupported && tableConstraintsSupported) listCheck.AppendColumn (colIsColumnConstraint); listCheck.Selection.Changed += new EventHandler (OnSelectionChanged); sqlEditor.TextChanged += new EventHandler (SourceChanged); foreach (CheckConstraintSchema check in constraints.GetConstraints (ConstraintType.Check)) AddConstraint (check); //TODO: also col constraints ShowAll (); }
public void Initialize (TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); this.table = table; this.columns = columns; this.constraints = constraints; foreach (CheckConstraintSchema check in constraints.GetConstraints (ConstraintType.Check)) AddConstraint (check); storeColumns = new SortedColumnListStore (columns); columnRenderer.Model = storeColumns.Store; //TODO: also col constraints }
public void Initialize(TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints, DataTypeSchemaCollection dataTypes) { if (columns == null) { throw new ArgumentNullException("columns"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (table == null) { throw new ArgumentNullException("table"); } if (tables == null) { throw new ArgumentNullException("tables"); } IDbFactory fac = schemaProvider.ConnectionPool.DbFactory; if (fac.IsCapabilitySupported("Table", action, TableCapabilities.PrimaryKeyConstraint)) { //not for column constraints, since they are already editable in the column editor pkEditor = new PrimaryKeyConstraintEditorWidget(schemaProvider, action, table, columns, constraints); pkEditor.ContentChanged += new EventHandler(OnContentChanged); notebook.AppendPage(pkEditor, new Label(GettextCatalog.GetString("Primary Key"))); } if (fac.IsCapabilitySupported("Table", action, TableCapabilities.ForeignKeyConstraint) || fac.IsCapabilitySupported("TableColumn", action, TableCapabilities.ForeignKeyConstraint)) { fkEditor = new ForeignKeyConstraintEditorWidget(schemaProvider, action, tables, table, columns, constraints); fkEditor.ContentChanged += new EventHandler(OnContentChanged); notebook.AppendPage(fkEditor, new Label(GettextCatalog.GetString("Foreign Key"))); } if (fac.IsCapabilitySupported("Table", action, TableCapabilities.CheckConstraint) || fac.IsCapabilitySupported("TableColumn", action, TableCapabilities.CheckConstraint)) { checkEditor = new CheckConstraintEditorWidget(schemaProvider, action, table, columns, constraints); checkEditor.ContentChanged += new EventHandler(OnContentChanged); notebook.AppendPage(checkEditor, new Label(GettextCatalog.GetString("Check"))); } if (fac.IsCapabilitySupported("Table", action, TableCapabilities.UniqueConstraint) || fac.IsCapabilitySupported("TableColumn", action, TableCapabilities.CheckConstraint)) { uniqueEditor = new UniqueConstraintEditorWidget(schemaProvider, action, table, columns, constraints); uniqueEditor.ContentChanged += new EventHandler(OnContentChanged); notebook.AppendPage(uniqueEditor, new Label(GettextCatalog.GetString("Unique"))); } ShowAll(); }
public void Initialize(TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints, DataTypeSchemaCollection dataTypes) { if (columns == null) { throw new ArgumentNullException("columns"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (table == null) { throw new ArgumentNullException("table"); } if (tables == null) { throw new ArgumentNullException("tables"); } if (pkEditor != null) { pkEditor.Initialize(table, columns, constraints); } if (fkEditor != null) { fkEditor.Initialize(tables, table, columns, constraints); } if (checkEditor != null) { checkEditor.Initialize(table, columns, constraints); } if (uniqueEditor != null) { uniqueEditor.Initialize(table, columns, constraints); } }
//http://www.sqlite.org/pragma.html public virtual ConstraintSchemaCollection GetConstraints(TableSchema table, ColumnSchema column) { if (table == null) { throw new ArgumentNullException("table"); } string columnName = column == null ? null : column.Name; ConstraintSchemaCollection constraints = new ConstraintSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); //fk and unique IDbCommand command = conn.CreateCommand("SELECT name, tbl_name FROM sqlite_master WHERE sql IS NULL AND type = 'index'"); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ConstraintSchema constraint = null; if (r.IsDBNull(1) || r.GetString(1) == null) { constraint = new UniqueConstraintSchema(this); } else { ForeignKeyConstraintSchema fkc = new ForeignKeyConstraintSchema(this); fkc.ReferenceTableName = r.GetString(1); constraint = fkc; } constraint.Name = r.GetString(0); constraints.Add(constraint); } r.Close(); } } //pk, column if (columnName != null) { command = conn.CreateCommand( "PRAGMA table_info('" + table.Name + "')" ); using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { if (r.GetInt32(5) == 1 && r.GetString(1) == columnName) { PrimaryKeyConstraintSchema constraint = new PrimaryKeyConstraintSchema(this); ColumnSchema priColumn = new ColumnSchema(this, table); priColumn.Name = r.GetString(1); constraint.Columns.Add(priColumn); constraint.IsColumnConstraint = true; constraint.Name = "pk_" + table.Name + "_" + priColumn.Name; constraints.Add(constraint); } } r.Close(); } } } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(constraints); }
/// <summary> /// Refresh the information associated with this table. /// </summary> public override void Refresh() { // TODO: Update Name, etc. columns = null; constraints = null; triggers = null; definition = null; }
public override ConstraintSchemaCollection GetTableConstraints (TableSchema table) { ConstraintSchemaCollection constraints = new ConstraintSchemaCollection (); using (IPooledDbConnection conn = connectionPool.Request ()) { using (IDbCommand command = conn.CreateCommand (string.Format (@"select sysobjects.name, sysobjects.xtype from sysobjects inner join sysobjects sysobjectsParents ON sysobjectsParents.id = sysobjects.parent_obj where sysobjectsParents.name = '{0}' and sysobjects.xtype in ('C', 'UQ', 'F','PK','CK')", table.Name))) try { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ConstraintSchema constraint = null; switch (r.GetString (1)) { case "F": //foreign key constraint = new ForeignKeyConstraintSchema (this); break; case "PK": //primary key constraint = new PrimaryKeyConstraintSchema (this); break; case "C": case "CK": //check constraint constraint = new CheckConstraintSchema (this); break; case "UQ": constraint = new UniqueConstraintSchema (this); break; default: break; } if (constraint != null) { constraint.Name = r.GetString (0); constraints.Add (constraint); } } r.Close (); } } catch (Exception e) { QueryService.RaiseException (e); } finally { conn.Release (); } } return constraints;
public override ConstraintSchemaCollection GetTableConstraints (TableSchema table) { ConstraintSchemaCollection constraints = new ConstraintSchemaCollection (); using (IPooledDbConnection conn = connectionPool.Request ()) { using (IDbCommand command = conn.CreateCommand (String.Format ( @"SELECT pc.conname, pg_catalog.pg_get_constraintdef(pc.oid, true) AS consrc, pc.contype, CASE WHEN pc.contype='u' OR pc.contype='p' THEN ( SELECT indisclustered FROM pg_catalog.pg_depend pd, pg_catalog.pg_class pl, pg_catalog.pg_index pi WHERE pd.refclassid=pc.tableoid AND pd.refobjid=pc.oid AND pd.objid=pl.oid AND pl.oid=pi.indexrelid) ELSE NULL END AS indisclustered FROM pg_catalog.pg_constraint pc WHERE pc.conrelid = ( SELECT oid FROM pg_catalog.pg_class WHERE relname='{0}' AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace WHERE nspname='{1}')) ORDER BY 1;", table.Name, table.SchemaName))) { try { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ConstraintSchema constraint = null; //TODO: Add support for Check constraints. switch (r.GetString (2)) { case "f": string match = @".*REFERENCES (.+)\(.*\).*"; constraint = new ForeignKeyConstraintSchema (this); if (Regex.IsMatch (r.GetString (1), match)) (constraint as ForeignKeyConstraintSchema).ReferenceTableName = Regex.Match (r.GetString (1), match).Groups[0].Captures[0].Value; break; case "u": constraint = new UniqueConstraintSchema (this); break; case "p": default: constraint = new PrimaryKeyConstraintSchema (this); break; } constraint.Name = r.GetString (0); constraint.Definition = r.GetString (1); int parenOpen = constraint.Definition.IndexOf ('('); if (parenOpen > 0) { int parenClose = constraint.Definition.IndexOf (')'); string colstr = constraint.Definition.Substring (parenOpen + 1, parenClose - parenOpen - 1); foreach (string col in colstr.Split (',')) { ColumnSchema column = new ColumnSchema (this, table); column.Name = col.Trim (); constraint.Columns.Add (column); } } constraints.Add (constraint); } r.Close (); } } catch (Exception) { // Don't raise error, if the table doesn't exists return an empty collection } finally { conn.Release (); } } } return constraints;
public void Initialize (TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints, DataTypeSchemaCollection dataTypes) { if (columns == null) throw new ArgumentNullException ("columns"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (table == null) throw new ArgumentNullException ("table"); if (tables == null) throw new ArgumentNullException ("tables"); if (pkEditor != null) pkEditor.Initialize (table, columns, constraints); if (fkEditor != null) fkEditor.Initialize (tables, table, columns, constraints); if (checkEditor != null) checkEditor.Initialize (table, columns, constraints); if (uniqueEditor != null) uniqueEditor.Initialize (table, columns, constraints); }
private void InitializeThreaded (object state) { tables = schemaProvider.GetTables (); dataTypes = schemaProvider.GetDataTypes (); columns = originalTable.Columns; constraints = originalTable.Constraints; triggers = originalTable.Triggers; //TODO: indices indexes = new IndexSchemaCollection (); System.Text.StringBuilder builder = new System.Text.StringBuilder (); builder.Append ("Loading editor for TABLE "); builder.Append (originalTable.Name); builder.AppendLine (); builder.Append (" columns = "); builder.Append (columns.Count); builder.AppendLine (); builder.Append ("constraints = "); builder.Append (constraints.Count); builder.AppendLine (); try { foreach (ColumnSchema col in columns) { int dummy = col.Constraints.Count; //get column constraints builder.Append ("CONSTRAINTS "); builder.Append (col.Name); builder.Append (" "); builder.Append (dummy); builder.AppendLine (); } LoggingService.LogDebug (builder.ToString ()); } catch (Exception ee) { LoggingService.LogDebug (builder.ToString ()); LoggingService.LogError (ee.ToString ()); } if (action == SchemaActions.Alter) //make a duplicate if we are going to alter the table this.table = originalTable.Clone () as TableSchema; DispatchService.GuiDispatch (delegate () { InitializeGui (); }); }
public void Initialize(TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) { throw new ArgumentNullException("columns"); } if (table == null) { throw new ArgumentNullException("table"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (tables == null) { throw new ArgumentNullException("tables"); } this.table = table; this.tables = tables; this.columns = columns; this.constraints = constraints; columnSelecter.Initialize(columns); foreach (TableSchema tbl in tables) { if (tbl.Name != table.Name) { storeTables.AppendValues(tbl.Name, tbl); } } }
//TODO: difference between columns and reference columns + combo events public ForeignKeyConstraintEditorWidget (ISchemaProvider schemaProvider, SchemaActions action, TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (schemaProvider == null) throw new ArgumentNullException ("schemaProvider"); if (tables == null) throw new ArgumentNullException ("tables"); this.schemaProvider = schemaProvider; this.table = table; this.tables = tables; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore (typeof (string), typeof (string), typeof (bool), typeof (string), typeof (string), typeof (string), typeof (string), typeof (object)); listFK.Model = store; storeActions = new ListStore (typeof (string), typeof (int)); storeTables = new ListStore (typeof (string)); IDbFactory fac = schemaProvider.ConnectionPool.DbFactory; if (fac.IsCapabilitySupported ("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.Cascade)) storeActions.AppendValues ("Cascade", ForeignKeyAction.Cascade); if (fac.IsCapabilitySupported ("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.Restrict)) storeActions.AppendValues ("Restrict", ForeignKeyAction.Restrict); if (fac.IsCapabilitySupported ("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.NoAction)) storeActions.AppendValues ("No Action", ForeignKeyAction.NoAction); if (fac.IsCapabilitySupported ("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.SetNull)) storeActions.AppendValues ("Set Null", ForeignKeyAction.SetNull); if (fac.IsCapabilitySupported ("ForeignKeyConstraint", action, ForeignKeyConstraintCapabilities.SetDefault)) storeActions.AppendValues ("Set Default", ForeignKeyAction.SetDefault); foreach (TableSchema tbl in tables) if (tbl.Name != table.Name) storeTables.AppendValues (tbl.Name); TreeViewColumn colName = new TreeViewColumn (); TreeViewColumn colRefTable = new TreeViewColumn (); TreeViewColumn colIsColumnConstraint = new TreeViewColumn (); TreeViewColumn colDeleteAction = new TreeViewColumn (); TreeViewColumn colUpdateAction = new TreeViewColumn (); colName.Title = GettextCatalog.GetString ("Name"); colRefTable.Title = GettextCatalog.GetString ("Reference Table"); colIsColumnConstraint.Title = GettextCatalog.GetString ("Column Constraint"); colDeleteAction.Title = GettextCatalog.GetString ("Delete Action"); colUpdateAction.Title = GettextCatalog.GetString ("Update Action"); colRefTable.MinWidth = 120; CellRendererText nameRenderer = new CellRendererText (); CellRendererCombo refTableRenderer = new CellRendererCombo (); CellRendererToggle isColumnConstraintRenderer = new CellRendererToggle (); CellRendererCombo deleteActionRenderer = new CellRendererCombo (); CellRendererCombo updateActionRenderer = new CellRendererCombo (); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler (NameEdited); refTableRenderer.Model = storeTables; refTableRenderer.TextColumn = 0; refTableRenderer.Editable = true; refTableRenderer.Edited += new EditedHandler (RefTableEdited); isColumnConstraintRenderer.Activatable = true; isColumnConstraintRenderer.Toggled += new ToggledHandler (IsColumnConstraintToggled); deleteActionRenderer.Model = storeActions; deleteActionRenderer.TextColumn = 0; deleteActionRenderer.Editable = true; deleteActionRenderer.Edited += new EditedHandler (DeleteActionEdited); updateActionRenderer.Model = storeActions; updateActionRenderer.TextColumn = 0; updateActionRenderer.Editable = true; updateActionRenderer.Edited += new EditedHandler (UpdateActionEdited); colName.PackStart (nameRenderer, true); colRefTable.PackStart (refTableRenderer, true); colIsColumnConstraint.PackStart (isColumnConstraintRenderer, true); colDeleteAction.PackStart (deleteActionRenderer, true); colUpdateAction.PackStart (updateActionRenderer, true); colName.AddAttribute (nameRenderer, "text", colNameIndex); colRefTable.AddAttribute (refTableRenderer, "text", colReferenceTableIndex); colIsColumnConstraint.AddAttribute (isColumnConstraintRenderer, "active", colIsColumnConstraintIndex); colDeleteAction.AddAttribute (deleteActionRenderer, "text", colDeleteActionIndex); colUpdateAction.AddAttribute (updateActionRenderer, "text", colUpdateActionIndex); listFK.AppendColumn (colName); listFK.AppendColumn (colRefTable); listFK.AppendColumn (colIsColumnConstraint); listFK.AppendColumn (colDeleteAction); listFK.AppendColumn (colUpdateAction); columnSelecter.ColumnToggled += new EventHandler (ColumnToggled); referenceColumnSelecter.ColumnToggled += new EventHandler (ReferenceColumnToggled); listFK.Selection.Changed += new EventHandler (SelectionChanged); ShowAll (); }
public void Initialize (TableSchemaCollection tables, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); if (tables == null) throw new ArgumentNullException ("tables"); this.table = table; this.tables = tables; this.columns = columns; this.constraints = constraints; columnSelecter.Initialize (columns); foreach (TableSchema tbl in tables) if (tbl.Name != table.Name) storeTables.AppendValues (tbl.Name, tbl); }
private void InitializeThreaded (object state) { tables = schemaProvider.GetTables (); dataTypes = schemaProvider.GetDataTypes (); columns = originalTable.Columns; constraints = originalTable.Constraints; triggers = originalTable.Triggers; //TODO: indices indexes = new IndexSchemaCollection (); Runtime.LoggingService.Error ("TABLE " + originalTable.Name); Runtime.LoggingService.Error (" columns = " + columns.Count); Runtime.LoggingService.Error (" constraints = " + constraints.Count); try { foreach (ColumnSchema col in columns) { int dummy = col.Constraints.Count; //get column constraints Runtime.LoggingService.Error ("CONSTRAINTS " + col.Name + " " + dummy); } } catch (Exception ee) { Runtime.LoggingService.Error (ee); Runtime.LoggingService.Error (ee.StackTrace); } if (action == SchemaActions.Alter) //make a duplicate if we are going to alter the table this.table = originalTable.Clone () as TableSchema; DispatchService.GuiDispatch (delegate () { InitializeGui (); }); }
public void Initialize (TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) throw new ArgumentNullException ("columns"); if (table == null) throw new ArgumentNullException ("table"); if (constraints == null) throw new ArgumentNullException ("constraints"); this.table = table; this.columns = columns; this.constraints = constraints; columnSelecter.Initialize (columns); RefreshConstraints (); }
public override ConstraintSchemaCollection GetTableConstraints (TableSchema table) { ConstraintSchemaCollection constraints = new ConstraintSchemaCollection (); using (IPooledDbConnection conn = connectionPool.Request ()) { using (IDbCommand command = conn.CreateCommand (string.Concat ("SHOW TABLE STATUS FROM `", table.SchemaName, "`;"))) { try { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { string[] chunks = ((string)r["Comment"]).Split (';'); // the values we are looking for are in the format: // (`table`) REFER `database\table2` (`table2`) foreach (string chunk in chunks) { if (constraintRegex.IsMatch (chunk)) { MatchCollection matches = constraintRegex.Matches (chunk); ForeignKeyConstraintSchema constraint = new ForeignKeyConstraintSchema (this); constraint.ReferenceTableName = matches[1].Groups[1].ToString (); constraint.Name = matches[0].Groups[1].ToString (); constraints.Add (constraint); } } } r.Close (); } } catch (Exception e) { // Don't raise error, if the table doesn't exists return an empty collection } finally { conn.Release (); } } } return constraints; }
public CheckConstraintEditorWidget(ISchemaProvider schemaProvider, SchemaActions action, TableSchema table, ColumnSchemaCollection columns, ConstraintSchemaCollection constraints) { if (columns == null) { throw new ArgumentNullException("columns"); } if (table == null) { throw new ArgumentNullException("table"); } if (constraints == null) { throw new ArgumentNullException("constraints"); } if (schemaProvider == null) { throw new ArgumentNullException("schemaProvider"); } this.schemaProvider = schemaProvider; this.table = table; this.columns = columns; this.constraints = constraints; this.action = action; this.Build(); store = new ListStore(typeof(string), typeof(string), typeof(bool), typeof(string), typeof(object)); storeColumns = new SortedColumnListStore(columns); listCheck.Model = store; TreeViewColumn colName = new TreeViewColumn(); TreeViewColumn colColumn = new TreeViewColumn(); TreeViewColumn colIsColumnConstraint = new TreeViewColumn(); colName.Title = GettextCatalog.GetString("Name"); colColumn.Title = GettextCatalog.GetString("Column"); colIsColumnConstraint.Title = GettextCatalog.GetString("Column Constraint"); colColumn.MinWidth = 120; //request a bigger width CellRendererText nameRenderer = new CellRendererText(); CellRendererCombo columnRenderer = new CellRendererCombo(); CellRendererToggle isColumnConstraintRenderer = new CellRendererToggle(); nameRenderer.Editable = true; nameRenderer.Edited += new EditedHandler(NameEdited); columnRenderer.Model = storeColumns.Store; columnRenderer.TextColumn = SortedColumnListStore.ColNameIndex; columnRenderer.Editable = true; columnRenderer.Edited += new EditedHandler(ColumnEdited); isColumnConstraintRenderer.Activatable = true; isColumnConstraintRenderer.Toggled += new ToggledHandler(IsColumnConstraintToggled); colName.PackStart(nameRenderer, true); colColumn.PackStart(columnRenderer, true); colIsColumnConstraint.PackStart(isColumnConstraintRenderer, true); colName.AddAttribute(nameRenderer, "text", colNameIndex); colColumn.AddAttribute(columnRenderer, "text", colColumnNameIndex); colIsColumnConstraint.AddAttribute(isColumnConstraintRenderer, "active", colIsColumnConstraintIndex); IDbFactory fac = schemaProvider.ConnectionPool.DbFactory; columnConstraintsSupported = fac.IsCapabilitySupported("TableColumn", action, TableCapabilities.CheckConstraint); tableConstraintsSupported = fac.IsCapabilitySupported("Table", action, TableCapabilities.CheckConstraint); listCheck.AppendColumn(colName); if (columnConstraintsSupported) { listCheck.AppendColumn(colColumn); } if (columnConstraintsSupported && tableConstraintsSupported) { listCheck.AppendColumn(colIsColumnConstraint); } listCheck.Selection.Changed += new EventHandler(OnSelectionChanged); sqlEditor.TextChanged += new EventHandler(SourceChanged); foreach (CheckConstraintSchema check in constraints.GetConstraints(ConstraintType.Check)) { AddConstraint(check); } //TODO: also col constraints ShowAll(); }
public virtual ConstraintSchemaCollection GetTableConstraints (TableSchema table) { ConstraintSchemaCollection collection = new ConstraintSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); try { //restrictions: database, schema, table, name DataTable dt = conn.GetSchema (foreignKeysCollectionString, null, connectionPool.ConnectionContext.ConnectionSettings.Database); for (int r = 0; r < dt.Rows.Count; r++) { DataRow row = dt.Rows[r]; collection.Add (GetTableConstraint (row, table)); } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return collection; }
public override void Refresh() { constraints = null; }