public ViewSchema (ViewSchema view) : base (view) { this.isSystemView = view.isSystemView; this.statement = view.statement; this.columns = new ColumnSchemaCollection (view.columns); }
public virtual ViewSchema CreateViewSchema(string name) { ViewSchema schema = new ViewSchema(this); schema.Name = name; return(schema); }
public ViewSchemaContainer (ViewSchema schema) { if (schema == null) throw new ArgumentNullException ("schema"); this.schema = schema; }
public override ICollection <ColumnSchema> GetViewColumns(ViewSchema view) { CheckConnectionState(); List <ColumnSchema> columns = new List <ColumnSchema> (); //TODO: return(columns); }
//http://www.sqlite.org/lang_createview.html public override void CreateView(ViewSchema view) { IPooledDbConnection conn = connectionPool.Request(); IDbCommand command = conn.CreateCommand(view.Definition); using (command) conn.ExecuteNonQuery(command); conn.Release(); }
protected virtual ColumnSchema GetViewColumn(DataRow row, ViewSchema view) { ColumnSchema schema = new ColumnSchema(this, view); schema.SchemaName = view.SchemaName; schema.Name = GetRowString(row, viewColumnItemStrings[0]); return(schema); }
protected virtual ViewSchema GetView(DataRow row) { ViewSchema schema = new ViewSchema(this); schema.SchemaName = GetRowString(row, viewItemStrings[0]); schema.Name = GetRowString(row, viewItemStrings[1]); schema.Comment = GetRowString(row, viewItemStrings[2]); return(schema); }
public void Initialize (ViewSchema view) { if (view == null) throw new ArgumentNullException ("view"); this.view = view; if (action == SchemaActions.Alter) { // sqlEditor.Text = schemaProvider.GetViewAlterStatement (view); commentEditor.Comment = view.Comment; } }
public override object Clone() { ViewSchema clone = new ViewSchema(this); if (clone.columns != null) { foreach (ColumnSchema column in clone.columns) { column.Parent = clone; } } return(clone); }
public override ViewSchemaCollection GetViews() { ViewSchemaCollection views = new ViewSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); IDbCommand command = conn.CreateCommand( "SELECT v.schemaname, v.viewname, v.viewowner, v.definition," + " (c.oid <= " + LastSystemOID + "), " + "(SELECT description from pg_description pd, " + " pg_class pc WHERE pc.oid=pd.objoid AND pc.relname=" + " v.viewname) " + "FROM pg_views v, pg_class c " + "WHERE v.viewname = c.relname " + "ORDER BY viewname" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema(this); view.Name = r.GetString(1); view.OwnerName = r.GetString(2); view.SchemaName = r.GetString(0); view.IsSystemView = r.GetBoolean(4); view.Comment = r.IsDBNull(5) ? null : r.GetString(5); // StringBuilder sb = new StringBuilder(); // sb.AppendFormat ("-- View: {0}\n", view.Name); // sb.AppendFormat ("-- DROP VIEW {0};\n\n", view.Name); // sb.AppendFormat ("CREATE VIEW {0} AS (\n", view.Name); // string core = r.GetString(3); // sb.AppendFormat (" {0}\n);", core.Substring (0, core.Length-1)); // view.Definition = sb.ToString (); views.Add(view); } r.Close(); } } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(views); }
public override ColumnSchemaCollection GetViewColumns(ViewSchema view) { ColumnSchemaCollection columns = new ColumnSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); IDbCommand command = conn.CreateCommand( "SELECT attname, typname, attlen, attnotnull " + "FROM " + " pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef " + " ON a.attrelid=adef.adrelid " + " AND a.attnum=adef.adnum " + " LEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid " + "WHERE " + " a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='" + view.Name + "') " + " AND a.attnum > 0 AND NOT a.attisdropped " + " ORDER BY a.attnum;" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ColumnSchema column = new ColumnSchema(this, view); column.Name = r.GetString(0); column.DataTypeName = r.GetString(1); column.SchemaName = view.SchemaName; column.IsNullable = r.GetBoolean(3); column.DataType.LengthRange.Default = r.GetInt32(2); columns.Add(column); } r.Close(); }; } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(columns); }
// see: http://dev.mysql.com/doc/refman/5.1/en/views-table.html public override ViewSchemaCollection GetViews() { ViewSchemaCollection views = new ViewSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); IDbCommand command = conn.CreateCommand( "SELECT TABLE_NAME, TABLE_SCHEMA FROM information_schema.VIEWS where TABLE_SCHEMA = '" + ConnectionPool.ConnectionContext.ConnectionSettings.Database + "' ORDER BY TABLE_NAME" ); try { using (command) { if (GetMainVersion(command) >= 5) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema(this); view.Name = r.GetString(0); view.OwnerName = r.GetString(1); IPooledDbConnection conn2 = connectionPool.Request(); IDbCommand command2 = conn2.CreateCommand("SHOW CREATE TABLE `" + view.Name + "`;"); using (IDataReader r2 = command2.ExecuteReader()) { r2.Read(); view.Definition = r2.GetString(1); } conn2.Release(); views.Add(view); } r.Close(); } } //else: do nothing, since views are only supported since mysql 5.x } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(views); }
public override ViewSchemaCollection GetViews() { ViewSchemaCollection views = new ViewSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); IDbCommand command = conn.CreateCommand( "SELECT su.name AS owner, so.name as table_name, so.id as table_id, " + " so.crdate as created_date, so.xtype as table_type " + "FROM dbo.sysobjects so, dbo.sysusers su " + "WHERE xtype = 'V' " + "AND su.uid = so.uid " + "ORDER BY 1, 2" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema(this); view.Name = r.GetString(1); view.SchemaName = r.GetString(0); view.OwnerName = r.GetString(0); StringBuilder sb = new StringBuilder(); sb.AppendFormat("-- View: {0}\n", view.Name); sb.AppendFormat("-- DROP VIEW {0};\n\n", view.Name); sb.AppendFormat(" {0}\n);", GetSource("[" + view.OwnerName + "].[" + view.Name + "]")); view.Definition = sb.ToString(); views.Add(view); } r.Close(); } } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(views); }
public ViewEditorDialog (ISchemaProvider schemaProvider, ViewSchema view, bool create) { if (schemaProvider == null) throw new ArgumentNullException ("schemaProvider"); if (view == null) throw new ArgumentNullException ("view"); this.schemaProvider = schemaProvider; this.view = view; this.action = create ? SchemaActions.Create : SchemaActions.Alter; this.Build(); if (create) Title = GettextCatalog.GetString ("Create View"); else Title = GettextCatalog.GetString ("Alter View"); notebook = new Notebook (); sqlEditor = new SqlEditorWidget (); sqlEditor.TextChanged += new EventHandler (SqlChanged); notebook.AppendPage (sqlEditor, new Label (GettextCatalog.GetString ("Definition"))); IDbFactory fac = schemaProvider.ConnectionPool.DbFactory; if (fac.IsCapabilitySupported ("View", action, ViewCapabilities.Comment)) { commentEditor = new CommentEditorWidget (); notebook.AppendPage (commentEditor, new Label (GettextCatalog.GetString ("Comment"))); } notebook.Page = 0; entryName.Text = view.Name; if (!create) { sqlEditor.Text = schemaProvider.GetViewAlterStatement (view); commentEditor.Comment = view.Comment; } vboxContent.PackStart (notebook, true, true, 0); vboxContent.ShowAll (); SetWarning (null); }
public override ICollection <ViewSchema> GetViews() { CheckConnectionState(); List <ViewSchema> views = new List <ViewSchema> (); IDbCommand command = connectionProvider.CreateCommand( "SELECT su.name AS owner, so.name as table_name, so.id as table_id, " + " so.crdate as created_date, so.type as table_type " + "FROM dbo.sysobjects so, dbo.sysusers su " + "WHERE type = 'V' " + "AND su.uid = so.uid " + "ORDER BY 1, 2" ); using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read()) { ViewSchema view = new ViewSchema(this); view.Name = r.GetString(1); view.SchemaName = r.GetString(0); view.OwnerName = r.GetString(0); view.IsSystemView = r.GetString(4).Trim().Equals("S"); StringBuilder sb = new StringBuilder(); sb.AppendFormat("-- View: {0}\n", view.Name); sb.AppendFormat("-- DROP VIEW {0};\n\n", view.Name); string source = GetSource(view.Owner + "." + view.Name); sb.AppendFormat(" {0}\n);", source); view.Definition = sb.ToString(); //view.Comment = r.GetString(5); views.Add(view); } r.Close(); } connectionProvider.Close(command.Connection); } return(views); }
public virtual ColumnSchemaCollection GetViewColumns(ViewSchema view) { ColumnSchemaCollection collection = new ColumnSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); try { //restrictions: database, schema, table, column DataTable dt = conn.GetSchema(viewColumnsCollectionString, null, view.SchemaName, view.Name); for (int r = 0; r < dt.Rows.Count; r++) { DataRow row = dt.Rows[r]; collection.Add(GetViewColumn(row, view)); } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(collection); }
public override ColumnSchemaCollection GetViewColumns(ViewSchema view) { ColumnSchemaCollection columns = new ColumnSchemaCollection(); IPooledDbConnection conn = connectionPool.Request(); IDbCommand command = conn.CreateCommand( "SELECT * FROM \"" + view.Name + "\" WHERE 1 = 0" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { for (int i = 0; i < r.FieldCount; i++) { ColumnSchema column = new ColumnSchema(this, view); column.Name = r.GetName(i); column.DataTypeName = r.GetDataTypeName(i); column.DefaultValue = ""; column.Definition = ""; column.OwnerName = view.OwnerName; column.SchemaName = view.OwnerName; columns.Add(column); } r.Close(); } } } catch (Exception e) { QueryService.RaiseException(e); } conn.Release(); return(columns); }
public override ICollection<ViewSchema> GetViews () { CheckConnectionState (); List<ViewSchema> views = new List<ViewSchema> (); IDbCommand command = connectionProvider.CreateCommand ( "SELECT RDB$RELATION_NAME, RDB$SYSTEM_FLAG, RDB$OWNER_NAME, RDB$DESCRIPTION, RDB$VIEW_SOURCE FROM RDB$RELATIONS "+ "WHERE RDB$VIEW_SOURCE IS NOT NULL;" ); using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString (0); view.IsSystemView = (!r.IsDBNull (1) && r.GetInt32 (1) != 0); view.OwnerName = r.GetString (2); view.Comment = r.GetString (3); //TODO: view.Definition = 4 (ascii blob) views.Add (view); } r.Close (); } connectionProvider.Close (command.Connection); } return views;
public override ICollection<ColumnSchema> GetViewColumns (ViewSchema view) { return GetTableOrViewColumns (view.Name);
public virtual string GetViewAlterStatement (ViewSchema view) { throw new NotImplementedException (); }
public bool ShowViewEditorDialog (ISchemaProvider schemaProvider, ViewSchema view, bool create) { return RunDialog (new ViewEditorDialog (schemaProvider, view, create));
//http://www.sqlite.org/lang_createview.html public override void CreateView (ViewSchema view) { IPooledDbConnection conn = connectionPool.Request (); IDbCommand command = conn.CreateCommand (view.Definition); using (command) conn.ExecuteNonQuery (command); conn.Release (); }
public override string GetViewAlterStatement (ViewSchema view) { return String.Concat ("DROP VIEW IF EXISTS ", view.Name, "; ", Environment.NewLine, view.Definition); }
//http://www.postgresql.org/docs/8.2/interactive/sql-altertable.html public override void RenameView (ViewSchema view, string name) { //this is no copy paste error, it really is "ALTER TABLE" ExecuteNonQuery ("ALTER TABLE " + view.Name + " RENAME TO " + name + ";"); view.Name = name;
public bool ShowViewEditorDialog(ISchemaProvider schemaProvider, ViewSchema view, bool create) { return(RunDialog(new ViewEditorDialog(schemaProvider, view, create))); }
public override string GetViewAlterStatement (ViewSchema view) { //'CREATE ' <-- after this we insert return view.Definition.Insert (6, "OR REPLACE ");
public override ICollection <ColumnSchema> GetViewColumns(ViewSchema view) { return(GetTableOrViewColumns(view.Name)); }
public override ICollection<ViewSchema> GetViews () { CheckConnectionState (); List<ViewSchema> views = new List<ViewSchema> (); IDbCommand command = connectionProvider.CreateCommand ( "SELECT OWNER, VIEW_NAME, TEXT " + "FROM ALL_VIEWS " + "ORDER BY OWNER, VIEW_NAME" ); using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString(1); view.SchemaName = r.GetString (0); view.OwnerName = r.GetString (0); view.Definition = r.GetString (2); view.IsSystemView = IsSystem (view.OwnerName); views.Add (view); } r.Close (); } connectionProvider.Close (command.Connection); } return views;
public override ViewSchemaCollection GetViews () { ViewSchemaCollection views = new ViewSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); IDbCommand command = conn.CreateCommand ( "SELECT name, sql FROM sqlite_master WHERE type = 'views'" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.SchemaName = "main"; view.Name = r.GetString (0); view.Definition = r.GetString (1); views.Add (view); } r.Close (); } } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return views; }
public override ICollection<ViewSchema> GetViews () { CheckConnectionState (); List<ViewSchema> views = new List<ViewSchema> (); IDbCommand command = connectionProvider.CreateCommand ( "SELECT su.name AS owner, so.name as table_name, so.id as table_id, " + " so.crdate as created_date, so.type as table_type " + "FROM dbo.sysobjects so, dbo.sysusers su " + "WHERE type = 'V' " + "AND su.uid = so.uid " + "ORDER BY 1, 2" ); using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString (1); view.SchemaName = r.GetString (0); view.OwnerName = r.GetString (0); view.IsSystemView = r.GetString (4).Trim ().Equals ("S"); StringBuilder sb = new StringBuilder (); sb.AppendFormat ("-- View: {0}\n", view.Name); sb.AppendFormat ("-- DROP VIEW {0};\n\n", view.Name); string source = GetSource (view.Owner + "." + view.Name); sb.AppendFormat (" {0}\n);", source); view.Definition = sb.ToString (); //view.Comment = r.GetString(5); views.Add (view); } r.Close (); } connectionProvider.Close (command.Connection); } return views;
//http://www.postgresql.org/docs/8.2/interactive/sql-dropview.html public override void DropView(ViewSchema view) { ExecuteNonQuery("DROP VIEW IF EXISTS " + view.Name + ";"); }
//http://www.postgresql.org/docs/8.2/interactive/sql-createview.html public override void CreateView (ViewSchema view) { throw new NotImplementedException ();
//http://www.sqlite.org/lang_dropview.html public override void DropView (ViewSchema view) { ExecuteNonQuery ("DROP VIEW IF EXISTS " + view.Name); }
public virtual void RenameView(ViewSchema view, string name) { throw new NotImplementedException(); }
public ViewNode (DatabaseConnectionContext context, ViewSchema view) : base (context) { if (view == null) throw new ArgumentNullException ("view"); this.view = view; }
public override string GetViewAlterStatement(ViewSchema view) { //'CREATE ' <-- after this we insert return(view.Definition.Insert(6, "OR REPLACE ")); }
//http://msdn2.microsoft.com/en-us/library/aa225939(SQL.80).aspx public override void AlterView(ViewSchema view) { ExecuteNonQuery(view.Definition); }
//http://msdn2.microsoft.com/en-US/library/aa238878(SQL.80).aspx public override void RenameView(ViewSchema view, string name) { Rename(view.Name, name, "OBJECT"); view.Name = name; }
public virtual void DropView(ViewSchema view) { throw new NotImplementedException(); }
public override ColumnSchemaCollection GetViewColumns (ViewSchema view) { ColumnSchemaCollection columns = new ColumnSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); IDbCommand command = conn.CreateCommand ( "SELECT attname, typname, attlen, attnotnull " + "FROM " + " pg_catalog.pg_attribute a LEFT JOIN pg_catalog.pg_attrdef adef " + " ON a.attrelid=adef.adrelid " + " AND a.attnum=adef.adnum " + " LEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid " + "WHERE " + " a.attrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='" + view.Name + "') " + " AND a.attnum > 0 AND NOT a.attisdropped " + " ORDER BY a.attnum;" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ColumnSchema column = new ColumnSchema (this, view); column.Name = r.GetString(0); column.DataTypeName = r.GetString (1); column.SchemaName = view.SchemaName; column.IsNullable = r.GetBoolean (3); column.DataType.LengthRange.Default = r.GetInt32 (2); columns.Add (column); } r.Close (); }; } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return columns;
public virtual string GetViewAlterStatement(ViewSchema view) { throw new NotImplementedException(); }
public override ICollection<ColumnSchema> GetViewColumns (ViewSchema view) { CheckConnectionState (); List<ColumnSchema> columns = new List<ColumnSchema> (); //TODO: return columns;
public override ICollection<ColumnSchema> GetViewColumns (ViewSchema view) { CheckConnectionState (); List<ColumnSchema> columns = new List<ColumnSchema> (); IDbCommand command = connectionProvider.CreateCommand ( "SELECT * " + " FROM " + view.Name + " WHERE 1 = 0" ); using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { for (int i = 0; i < r.FieldCount; i++) { ColumnSchema column = new ColumnSchema (this); column.Name = r.GetString (0); column.DataTypeName = r.GetString (1); column.SchemaName = view.SchemaName; column.NotNull = r.GetBoolean (3); column.Length = r.GetInt32 (2); columns.Add (column); } } r.Close (); }; connectionProvider.Close (command.Connection); } return columns;
protected virtual ViewSchema GetView (DataRow row) { ViewSchema schema = new ViewSchema (this); schema.SchemaName = GetRowString (row, viewItemStrings[0]); schema.Name = GetRowString (row, viewItemStrings[1]); schema.Comment = GetRowString (row, viewItemStrings[2]); return schema; }
public override object Clone () { ViewSchema clone = new ViewSchema (this); if (clone.columns != null) { foreach (ColumnSchema column in clone.columns) column.Parent = clone; } return clone; }
public virtual ColumnSchemaCollection GetViewColumns (ViewSchema view) { ColumnSchemaCollection collection = new ColumnSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); try { //restrictions: database, schema, table, column DataTable dt = conn.GetSchema (viewColumnsCollectionString, null, view.SchemaName, view.Name); for (int r = 0; r < dt.Rows.Count; r++) { DataRow row = dt.Rows[r]; collection.Add (GetViewColumn (row, view)); } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return collection; }
protected virtual ColumnSchema GetViewColumn (DataRow row, ViewSchema view) { ColumnSchema schema = new ColumnSchema (this, view); schema.SchemaName = view.SchemaName; schema.Name = GetRowString (row, viewColumnItemStrings[0]); return schema; }
public virtual void DropView (ViewSchema view) { throw new NotImplementedException (); }
//http://msdn2.microsoft.com/en-us/library/aa258254(SQL.80).aspx public override void CreateView(ViewSchema view) { throw new NotImplementedException(); }
public virtual void RenameView (ViewSchema view, string name) { throw new NotImplementedException (); }
//http://msdn2.microsoft.com/en-us/library/aa258835(SQL.80).aspx public override void DropView(ViewSchema view) { ExecuteNonQuery("DROP VIEW " + view.Name); }
public virtual ViewSchema GetNewViewSchema (string name) { ViewSchema schema = new ViewSchema (this); schema.Name = name; return schema; }
public override string GetViewAlterStatement(ViewSchema view) { return(String.Concat("DROP VIEW ", view.Name, "; ", Environment.NewLine, view.Definition)); }
public override ViewSchemaCollection GetViews () { ViewSchemaCollection views = new ViewSchemaCollection (); IPooledDbConnection conn = connectionPool.Request (); IDbCommand command = conn.CreateCommand ( "SELECT v.schemaname, v.viewname, v.viewowner, v.definition," + " (c.oid <= " + LastSystemOID + "), " + "(SELECT description from pg_description pd, " + " pg_class pc WHERE pc.oid=pd.objoid AND pc.relname=" + " v.viewname) " + "FROM pg_views v, pg_class c " + "WHERE v.viewname = c.relname " + "ORDER BY viewname" ); try { using (command) { using (IDataReader r = command.ExecuteReader()) { while (r.Read ()) { ViewSchema view = new ViewSchema (this); view.Name = r.GetString (1); view.OwnerName = r.GetString (2); view.SchemaName = r.GetString (0); view.IsSystemView = r.GetBoolean (4); view.Comment = r.IsDBNull (5) ? null : r.GetString (5); // StringBuilder sb = new StringBuilder(); // sb.AppendFormat ("-- View: {0}\n", view.Name); // sb.AppendFormat ("-- DROP VIEW {0};\n\n", view.Name); // sb.AppendFormat ("CREATE VIEW {0} AS (\n", view.Name); // string core = r.GetString(3); // sb.AppendFormat (" {0}\n);", core.Substring (0, core.Length-1)); // view.Definition = sb.ToString (); views.Add (view); } r.Close (); } } } catch (Exception e) { QueryService.RaiseException (e); } conn.Release (); return views;