public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            try
            {
                // load tables and views
                DataTable schemaTable = _connection.GetSchema("Tables", null);

                MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                mof.NameFieldName   = "TABLE_NAME";
                mof.TypeFieldName   = "TABLE_TYPE";
                mof.TableType       = new string[] { "TABLE" };
                mof.SystemTableType = new string[] { "SYSTEM_TABLE" };
                mof.ViewType        = new string[] { "VIEW" };
                mof.TrimSpaces      = true;
                mof.Datatable       = schemaTable;

                mof.LoadMetadata();

                // load procedures
                schemaTable = _connection.GetSchema("Procedures", null);

                mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                mof.NameFieldName     = "PROCEDURE_NAME";
                mof.SystemFieldName   = "IS_SYSTEM_PROCEDURE";
                mof.SystemFieldValue  = 1;
                mof.TrimSpaces        = true;
                mof.Datatable         = schemaTable;
                mof.DefaultObjectType = MetadataType.Procedure;

                mof.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            MetadataItem obj = objects.Parent;

            if (obj.Schema == null && obj.Database == null && obj.Server == null)
            {
                if (!Connected)
                {
                    Connect();
                }

                try
                {
                    // load tables
                    DataTable schemaTable = _connection.GetSchema(VistaDBConnection.SchemaConstants.SCHEMA_TABLES);

                    MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                    mof.NameFieldName   = "TABLE_NAME";
                    mof.TypeFieldName   = "TABLE_TYPE";
                    mof.TableType       = new string[] { VistaDBConnection.UserTableType };
                    mof.SystemTableType = new string[] { VistaDBConnection.SystemTableType };
                    mof.Datatable       = schemaTable;

                    mof.LoadMetadata();

                    // load views
                    schemaTable = _connection.GetSchema(VistaDBConnection.SchemaConstants.SCHEMA_VIEWS, null);

                    mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                    mof.NameFieldName     = "TABLE_NAME";
                    mof.Datatable         = schemaTable;
                    mof.DefaultObjectType = MetadataType.View;

                    mof.LoadMetadata();
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
Example #3
0
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            MetadataNamespace database = objects.Parent.Database;
            MetadataNamespace schema   = objects.Parent.Schema;

            if (objects.Parent.Server == null && database != null && schema != null)
            {
                if (!Connected)
                {
                    Connect();
                }

                try
                {
                    string[] restrictions = new string[2];
                    restrictions[0] = database.Name;
                    restrictions[1] = schema.Name;

                    using (DataTable schemaTable = _connection.GetSchema("Tables", restrictions))
                    {
                        MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);

                        mof.Datatable     = schemaTable;
                        mof.NameFieldName = "TABLE_NAME";

                        mof.TypeFieldName = "TABLE_TYPE";
                        mof.TableType     = "BASE TABLE";
                        mof.ViewType      = "VIEW";

                        mof.DefaultObjectType = MetadataType.Table;

                        mof.LoadMetadata();
                    }
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
        }
Example #4
0
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }

            try
            {
                // load tables
                DataTable schemaTable = _connection.GetSchema("Tables");

                MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                mof.NameFieldName   = "TABLE_NAME";
                mof.TypeFieldName   = "TABLE_TYPE";
                mof.TableType       = new string[] { "TABLE" };
                mof.SystemTableType = new string[] { "SYSTEM TABLE" };
                mof.Datatable       = schemaTable;

                mof.LoadMetadata();

                // load views
                schemaTable = _connection.GetSchema("Views");

                mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);

                mof.NameFieldName     = "TABLE_NAME";
                mof.DefaultObjectType = MetadataType.View;
                mof.Datatable         = schemaTable;

                mof.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }
Example #5
0
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }
            SQLContext sqlContext = objects.SQLContext;

            string olddb = Connection.Database;

            try
            {
                try
                {
                    // load tables
                    string[] restrictions = new string[2];

                    if (sqlContext.SyntaxProvider.IsSupportDatabases())
                    {
                        MetadataNamespace database = objects.Parent.Database;
                        if (database != null)
                        {
                            restrictions[0] = database.Name;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        restrictions[0] = null;
                    }

                    if (sqlContext.SyntaxProvider.IsSupportSchemas())
                    {
                        MetadataNamespace schema = objects.Parent.Schema;
                        if (schema != null)
                        {
                            restrictions[1] = schema.Name;
                        }
                        else
                        {
                            return;
                        }
                    }
                    else
                    {
                        restrictions[1] = null;
                    }

                    MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);
                    mof.NameFieldName   = "TABLE_NAME";
                    mof.TypeFieldName   = "TABLE_TYPE";
                    mof.TableType       = new string[] { "TABLE", "LINK", "PASS-THROUGH", "SYNONYM" };
                    mof.SystemTableType = new string[] { "SYSTEM TABLE", "ACCESS TABLE" };
                    mof.ViewType        = new string[] { "VIEW" };
                    mof.SystemViewType  = "SYSTEM VIEW";

                    using (DataTable schemaTable = _connection.GetSchema("Tables", restrictions))
                    {
                        // hack for old outdated ODBC drivers which uses TABLENAME instead TABLE_NAME
                        if (schemaTable.Columns.IndexOf("TABLENAME") != -1)
                        {
                            mof.NameFieldName = "TABLENAME";
                        }

                        // hack for old outdated ODBC drivers which uses TABLETYPE instead TABLE_TYPE
                        if (schemaTable.Columns.IndexOf("TABLETYPE") != -1)
                        {
                            mof.NameFieldName = "TABLETYPE";
                        }

                        mof.DefaultObjectType = MetadataType.Table;
                        mof.Datatable         = schemaTable;
                        mof.LoadMetadata();
                    }

                    using (DataTable schemaTable = _connection.GetSchema("Views", restrictions))
                    {
                        // hack for old outdated ODBC drivers which uses TABLENAME instead TABLE_NAME
                        if (schemaTable.Columns.IndexOf("TABLENAME") != -1)
                        {
                            mof.NameFieldName = "TABLENAME";
                        }

                        // hack for old outdated ODBC drivers which uses TABLETYPE instead TABLE_TYPE
                        if (schemaTable.Columns.IndexOf("TABLETYPE") != -1)
                        {
                            mof.NameFieldName = "TABLETYPE";
                        }

                        mof.DefaultObjectType = MetadataType.View;
                        mof.Datatable         = schemaTable;
                        mof.LoadMetadata();
                    }
                }
                catch (Exception exception)
                {
                    throw new QueryBuilderException(exception.Message, exception);
                }
            }
            finally
            {
                if (Connection.Database != olddb)
                {
                    Connection.ChangeDatabase(olddb);
                }
            }
        }
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }
            SQLContext sqlContext = objects.SQLContext;
            string     olddb      = Connection.Database;

            try
            {
                // load tables
                string[] restrictions = new string[4];
                if (sqlContext.SyntaxProvider.IsSupportDatabases())
                {
                    MetadataNamespace database = objects.Parent.Database;
                    if (database != null)
                    {
                        restrictions[0] = database.Name;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    restrictions[0] = null;
                }
                if (sqlContext.SyntaxProvider.IsSupportSchemas())
                {
                    MetadataNamespace schema = objects.Parent.Schema;
                    if (schema != null)
                    {
                        restrictions[1] = schema.Name;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    restrictions[1] = null;
                }

                try
                {
                    if (!string.IsNullOrEmpty(restrictions[0]) && Connection.Database != restrictions[0])
                    {
                        Connection.ChangeDatabase(restrictions[0]);
                    }
                    DataTable schemaTable = _connection.GetSchema("Tables", restrictions);
                    MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions)
                    {
                        NameFieldName = "TABLE_NAME",
                        TypeFieldName = "TABLE_TYPE",
                        TableType     = new[]
                        {
                            "TABLE",
                            "LINK",
                            "PASS-THROUGH",
                            "SYNONYM",
                            "BASE TABLE"
                        },
                        SystemTableType = new[]
                        {
                            "SYSTEM TABLE",
                            "ACCESS TABLE"
                        },
                        ViewType       = "VIEW",
                        SystemViewType = "SYSTEM VIEW",
                        SynonymType    = "ALIAS",
                        Datatable      = schemaTable
                    };
                    mof.LoadMetadata();
                }
                catch
                {
                    // loading from OLEDB catalog failed
                }
            }
            finally
            {
                if (Connection.Database != olddb)
                {
                    Connection.ChangeDatabase(olddb);
                }
            }
        }
        public override void LoadObjects(MetadataList objects, MetadataLoadingOptions loadingOptions)
        {
            if (!Connected)
            {
                Connect();
            }
            SQLContext sqlContext = objects.SQLContext;

            try
            {
                // load tables and views
                string[] restrictions = new string[2];

                if (sqlContext.SyntaxProvider.IsSupportDatabases())
                {
                    MetadataNamespace database = objects.Parent.Database;
                    if (database != null)
                    {
                        restrictions[0] = database.Name;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    restrictions[0] = null;
                }

                if (sqlContext.SyntaxProvider.IsSupportSchemas())
                {
                    MetadataNamespace schema = objects.Parent.Schema;
                    if (schema != null)
                    {
                        restrictions[1] = schema.Name;
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    restrictions[1] = null;
                }

                DataTable schemaTable = _connection.GetSchema(DB2MetaDataCollectionNames.Tables, restrictions);

                MetadataObjectFetcherFromDatatable mof = new MetadataObjectFetcherFromDatatable(objects, loadingOptions);

                mof.NameFieldName   = "TABLE_NAME";
                mof.TypeFieldName   = "TABLE_TYPE";
                mof.TableType       = new string[] { "TABLE" };
                mof.SystemTableType = new string[] { "SYSTEM TABLE" };
                mof.ViewType        = new string[] { "VIEW", "MATERIALIZED QUERY TABLE" };
                mof.SynonymType     = "ALIAS";
                mof.Datatable       = schemaTable;

                mof.LoadMetadata();
            }
            catch (Exception exception)
            {
                throw new QueryBuilderException(exception.Message, exception);
            }
        }