コード例 #1
0
        /// <summary>
        /// Composes a source query for a remote table
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public SourceTableQuery PrepareCopyRemoteTable(TableReference table)
        {
            // -- Load schema
            var sm = this.GetSchemaManager(false);
            var ds = sm.Datasets[table.DatasetName];

            // Graywulf dataset has to be converted to prevent registry access
            if (ds is GraywulfDataset)
            {
                ds = new SqlServerDataset(ds);
            }

            // --- Generate most restrictive query

            // Find the query specification this table belongs to
            var qs = ((TableSource)table.Node).QuerySpecification;

            // Run the normalizer to convert where clause to a normal form
            var cnr = new SearchConditionNormalizer();

            cnr.NormalizeQuerySpecification(qs);

            var cg  = SqlCodeGeneratorFactory.CreateCodeGenerator(ds);
            var sql = cg.GenerateMostRestrictiveTableQuery(table, true, 0);

            return(new SourceTableQuery()
            {
                Dataset = ds,
                Query = sql
            });
        }
コード例 #2
0
        protected void RenderTable()
        {
            var tableOrView = (schema::TableOrView)SchemaManager.GetDatabaseObjectByKey(Request.QueryString["objid"]);

            var codegen = SqlCodeGeneratorFactory.CreateCodeGenerator(tableOrView.Dataset);

            var sql = codegen.GenerateSelectStarQuery(tableOrView, 100);

            DbProviderFactory dbf;
            string            cstr;

            GetServerSettings(tableOrView.Dataset, out cstr, out dbf);

            using (var cn = dbf.CreateConnection())
            {
                cn.ConnectionString = tableOrView.Dataset.ConnectionString;
                cn.Open();

                using (var cmd = cn.CreateCommand())
                {
                    cmd.CommandText = sql;
                    cmd.CommandType = CommandType.Text;

                    using (var dr = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
                    {
                        RenderTable(Response.Output, dr);
                    }
                }
            }
        }