Example #1
0
        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 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);
        }
        // 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);
        }
Example #4
0
        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 virtual ViewSchemaCollection GetViews()
        {
            ViewSchemaCollection collection = new ViewSchemaCollection();

            IPooledDbConnection conn = connectionPool.Request();

            try {
                //restrictions: database, schema, table
                DataTable dt = conn.GetSchema(viewsCollectionString, null, connectionPool.ConnectionContext.ConnectionSettings.Database);
                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    DataRow row = dt.Rows[r];
                    collection.Add(GetView(row));
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(collection);
        }
Example #6
0
 public ViewSchemaCollection(ViewSchemaCollection collection)
     : base(collection, true)
 {
 }