public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } // load FKs try { MetadataItem obj = foreignKeys.Parent.Object; string[] restrictions = new string[5]; restrictions[2] = obj.Name; DataTable schemaTable = _connection.GetSchema(VistaDBConnection.SchemaConstants.SCHEMA_FOREIGNKEYCOLUMNS, restrictions); MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions); mrf.PkNameFieldName = "FKEY_TO_TABLE"; mrf.PkFieldName = "FKEY_TO_COLUMN"; mrf.FkFieldName = "FKEY_FROM_COLUMN"; mrf.ForeignKeyIdFieldName = "FKEY_TO_TABLE"; mrf.Datatable = schemaTable; mrf.LoadMetadata(); } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } }
public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions) { if (databases.Parent.Server == null) { if (!Connected) { Connect(); } try { DataTable schemaTable = _connection.GetSchema("Databases"); using (MetadataNamespacesFetcherFromDatatable mdf = new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions)) { mdf.Datatable = schemaTable; mdf.NameFieldName = "database_name"; mdf.LoadMetadata(); } } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } } }
public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } // load FKs try { MetadataItem obj = foreignKeys.Parent.Object; string[] restrictions = new string[3]; restrictions[2] = obj.Name; DataTable schemaTable = _connection.GetSchema("ForeignKeyColumns", restrictions); MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions); mrf.PkNameFieldName = "REFERENCED_TABLE_NAME"; mrf.PkFieldName = "REFERENCED_COLUMN_NAME"; mrf.FkFieldName = "COLUMN_NAME"; mrf.OrdinalFieldName = "ORDINAL_POSITION"; mrf.TrimSpaces = true; mrf.Datatable = schemaTable; mrf.LoadMetadata(); } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } }
private void createQueryBuilder(string connectionString, bool loadDefaultDatabaseOnly = false, bool loadSystemObjects = false, bool withFields = true) { this._qb = new QueryBuilder( ) { SyntaxProvider = new SQLiteSyntaxProvider( ), MetadataProvider = new SQLiteMetadataProvider( ) }; SQLiteConnectionParameters connParms = new SQLiteConnectionParameters( ); connParms.FileName = connectionString; connParms.Password = "******"; //string cs = SQLiteConnectionProvider.GetConnectionString( connectionString ); string cs = @"Data Source=" + connectionString;//+ ";Version=3;"; this._qb.MetadataProvider.Connection = new System.Data.SQLite.SQLiteConnection(cs); { MetadataLoadingOptions loadingOptions = this._qb.SQLContext.MetadataContainer.LoadingOptions; loadingOptions.LoadDefaultDatabaseOnly = loadDefaultDatabaseOnly; loadingOptions.LoadSystemObjects = loadSystemObjects; //loadingOptions.IncludeFilter.Types = MetadataType.Field; //loadingOptions.ExcludeFilter.Schemas.Add("dbo"); } //qb.InitializeDatabaseSchemaTree(); this._qb.MetadataContainer.LoadAll(withFields); } // createQueryBuilder(...)
public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions) { MetadataItem obj = foreignKeys.Parent.Object; if (obj.Server == null) { MetadataItem database = obj.Database; try { string[] restrictions = new string[5]; restrictions[0] = database != null ? database.Name : null; restrictions[2] = obj.Name; DataTable schemaTable = _connection.GetSchema("ForeignKeys", restrictions); MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions) { PkDatabaseFieldName = "FKEY_TO_CATALOG", PkNameFieldName = "FKEY_TO_TABLE", PkFieldName = "FKEY_TO_COLUMN", FkFieldName = "FKEY_FROM_COLUMN", OrdinalFieldName = "FKEY_FROM_ORDINAL_POSITION", Datatable = schemaTable }; mrf.LoadMetadata(); } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } } }
private List <string> LoadMetadata(MetadataType type) { var loadingOptions = new MetadataLoadingOptions { LoadDefaultDatabaseOnly = type != MetadataType.Database, LoadSystemObjects = true }; var container = new MetadataContainer(TemporaryMetadataContainer.SQLContext) { LoadingOptions = loadingOptions }; var list = new MetadataList(container); list.Load(type, false); //list.Load(MetadataType.Database, false); //if (type == MetadataType.Schema) //{ // var defaultDb = list.Databases.FirstOrDefault(x => x.Default); // if (defaultDb != null) // { // defaultDb.Items.Load(type, false); // list = defaultDb.Items; // } //} return(list.Select(x => x.Name).ToList()); }
private void ClearFilters(MetadataLoadingOptions options) { options.ExcludeFilter.Objects.Clear(); options.IncludeFilter.Objects.Clear(); options.ExcludeFilter.Schemas.Clear(); options.IncludeFilter.Schemas.Clear(); }
protected override void OnClosing(CancelEventArgs e) { _loader?.Stop(); if (_isSaveChanges) { MetadataLoadingOptions loadingOptions = EditedMetadataContainer.LoadingOptions; EditedMetadataContainer.Assign(TemporaryMetadataContainer); EditedMetadataContainer.LoadingOptions = loadingOptions; } base.OnClosing(e); }
private void LoadDatabaseList() { DefaultDatabase = null; _databases = null; if (Connection.MetadataProvider != null && Connection.SyntaxProvider.IsSupportDatabases()) { _temporarySqlContext.MetadataProvider = Connection.MetadataProvider; _temporarySqlContext.SyntaxProvider = Connection.SyntaxProvider; MetadataLoadingOptions oldOptions = new MetadataLoadingOptions(); oldOptions.Assign(TemporaryMetadataContainer.LoadingOptions); MetadataLoadingOptions tempOptions = new MetadataLoadingOptions { LoadDefaultDatabaseOnly = false, LoadSystemObjects = true }; try { TemporaryMetadataContainer.LoadingOptions = tempOptions; MetadataList list = new MetadataList(TemporaryMetadataContainer); list.Load(MetadataType.Database, false); _databases = list.Databases; } finally { TemporaryMetadataContainer.LoadingOptions = oldOptions; tempOptions.Dispose(); } } _wizardPageLoadOpts.ChecklistDatabases.Items.Clear(); if (_databases == null) { return; } foreach (MetadataNamespace database in _databases) { if (database.Default) { DefaultDatabase = database.Name; } _wizardPageLoadOpts.ChecklistDatabases.Items.Add(new DatabaseObjectForListbox(database.Name, database.Default)); } }
public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } // load from OLEDB catalogs try { DataTable schemaTable = _connection.GetSchema("Tables"); string databaseFieldName = "TABLE_CATALOG"; if (schemaTable.Columns[databaseFieldName] == null) { databaseFieldName = "TABLE_CAT"; } using (MetadataNamespacesFetcherFromDatatable mdf = new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions)) { mdf.Datatable = schemaTable; mdf.NameFieldName = databaseFieldName; mdf.LoadMetadata(); } } catch { // loading from OLEDB catalog failed } // load default database string currentDatabase = Connection.Database; if (!string.IsNullOrEmpty(currentDatabase)) { MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database); if (database == null) { database = new MetadataNamespace(databases, MetadataType.Database); database.Name = currentDatabase; databases.Add(database); } database.Default = true; } }
public override void LoadSchemas(MetadataList schemas, MetadataLoadingOptions loadingOptions) { MetadataNamespace database = schemas.Parent.Database; if (schemas.Parent.Server == null && database != null) { if (!Connected) { Connect(); } try { string[] restrictions = new string[1]; restrictions[0] = database.Name; using (DataTable schemaTable = _connection.GetSchema("Tables", restrictions)) { using (MetadataNamespacesFetcherFromDatatable mdf = new MetadataNamespacesFetcherFromDatatable(schemas, MetadataType.Schema, loadingOptions)) { mdf.Datatable = schemaTable; mdf.NameFieldName = "TABLE_SCHEMA"; mdf.LoadMetadata(); } } using (DataTable schemaTable = _connection.GetSchema("Views", restrictions)) { using (MetadataNamespacesFetcherFromDatatable mdf = new MetadataNamespacesFetcherFromDatatable(schemas, MetadataType.Schema, loadingOptions)) { mdf.Datatable = schemaTable; mdf.NameFieldName = "TABLE_SCHEMA"; mdf.LoadMetadata(); } } } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } } }
// -------------------------------------------------------------------------------------- internal void createQueryBuilder(string connectionString, bool loadDefaultDatabaseOnly, bool loadSystemObjects, bool withFields) { this._qb = new QueryBuilder() { SyntaxProvider = new MSSQLSyntaxProvider(), MetadataProvider = new MSSQLMetadataProvider() }; this._qb.MetadataProvider.Connection = new SqlConnection(connectionString); { MetadataLoadingOptions loadingOptions = this._qb.SQLContext.MetadataContainer.LoadingOptions; loadingOptions.LoadDefaultDatabaseOnly = loadDefaultDatabaseOnly; loadingOptions.LoadSystemObjects = loadSystemObjects; //loadingOptions.IncludeFilter.Types = MetadataType.Field; //loadingOptions.ExcludeFilter.Schemas.Add("dbo"); } //qb.InitializeDatabaseSchemaTree(); this._qb.MetadataContainer.LoadAll(withFields); } // createQueryBuilder(...)
private List <string> LoadMetadata(MetadataType type) { var loadingOptions = new MetadataLoadingOptions { LoadDefaultDatabaseOnly = type != MetadataType.Database, LoadSystemObjects = true }; var container = new MetadataContainer(TemporaryMetadataContainer.SQLContext) { LoadingOptions = loadingOptions }; var list = new MetadataList(container); list.Load(type, false); return(list.Select(x => x.Name).ToList()); }
public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } // load FKs try { MetadataItem obj = foreignKeys.Parent.Object; MetadataItem database = obj.Database; string[] restrictions = new string[2]; restrictions[0] = database != null ? database.Name : string.Empty; restrictions[1] = obj.Name; DataTable schemaTable = _connection.GetSchema("Foreign Key Columns", restrictions); MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions); if (foreignKeys.SQLContext.SyntaxProvider.IsSupportSchemas()) { mrf.PkSchemaFieldName = "TABLE_SCHEMA"; } else { mrf.PkDatabaseFieldName = "TABLE_SCHEMA"; } mrf.PkNameFieldName = "TABLE_NAME"; mrf.PkFieldName = "COLUMN_NAME"; mrf.FkFieldName = "REFERENCED_COLUMN_NAME"; mrf.OrdinalFieldName = "ORDINAL_POSITION"; mrf.Datatable = schemaTable; mrf.LoadMetadata(); } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } }
public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } MetadataItem obj = foreignKeys.Parent.Object; if (obj.Server == null) { MetadataItem schema = obj.Schema; MetadataItem database = obj.Database; try { object[] restrictions = new object[6]; restrictions[3] = database != null ? database.Name : null; restrictions[4] = schema != null ? schema.Name : null; restrictions[5] = obj.Name; DataTable schemaTable = _connection.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, restrictions); MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions); mrf.PkDatabaseFieldName = "PK_TABLE_CATALOG"; mrf.PkSchemaFieldName = "PK_TABLE_SCHEMA"; mrf.PkNameFieldName = "PK_TABLE_NAME"; mrf.PkFieldName = "PK_COLUMN_NAME"; mrf.FkFieldName = "FK_COLUMN_NAME"; mrf.OrdinalFieldName = "ORDINAL"; mrf.Datatable = schemaTable; mrf.LoadMetadata(); } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } } }
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); } } }
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); } } }
public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions) { MetadataItem obj = foreignKeys.Parent.Object; if (obj.Server == null) { MetadataItem schema = obj.Schema; MetadataItem database = obj.Database; try { string[] restrictions = new string[6]; restrictions[3] = database != null ? database.Name : null; restrictions[4] = schema != null ? schema.Name : null; restrictions[5] = obj.Name; DataTable schemaTable = _connection.GetSchema("ForeignKeys", restrictions); if (schemaTable.Columns.Contains("PKTABLE_NAME") && schemaTable.Columns.Contains("PKCOLUMN_NAME") && schemaTable.Columns.Contains("FKCOLUMN_NAME")) { MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions); mrf.PkDatabaseFieldName = "PKTABLE_CAT"; mrf.PkSchemaFieldName = "PKTABLE_SCHEM"; mrf.PkNameFieldName = "PKTABLE_NAME"; mrf.PkFieldName = "PKCOLUMN_NAME"; mrf.FkFieldName = "FKCOLUMN_NAME"; mrf.OrdinalFieldName = "KEY_SEQ"; mrf.Datatable = schemaTable; mrf.LoadMetadata(); } } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } } }
public override void LoadForeignKeys(MetadataList foreignKeys, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } MetadataItem obj = foreignKeys.Parent.Object; MetadataItem schema = obj.Schema; MetadataItem database = obj.Database; try { string[] restrictions = new string[6]; restrictions[3] = database != null ? database.Name : null; restrictions[4] = schema != null ? schema.Name : null; restrictions[5] = obj.Name; DataTable schemaTable = _connection.GetSchema(DB2MetaDataCollectionNames.ForeignKeys, restrictions); MetadataForeignKeysFetcherFromDatatable mrf = new MetadataForeignKeysFetcherFromDatatable(foreignKeys, loadingOptions); mrf.PkSchemaFieldName = "PKTABLE_SCHEMA"; mrf.PkDatabaseFieldName = "PKTABLE_CATALOG"; mrf.PkNameFieldName = "PKTABLE_NAME"; mrf.FkFieldName = "FKTABLE_NAME"; mrf.PkFieldName = "PKCOLUMN_NAME"; mrf.FkFieldName = "FKCOLUMN_NAME"; mrf.OrdinalFieldName = "KEY_SEQ"; mrf.Datatable = schemaTable; mrf.LoadMetadata(); } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } }
public override void LoadFields(MetadataList fields, MetadataLoadingOptions loadingOptions) { MetadataItem obj = fields.Parent.Object; MetadataNamespace schema = obj.Schema; MetadataNamespace database = obj.Database; if (schema != null && database != null && obj.Server == null) { string[] restrictions = new string[3]; restrictions[0] = database.Name; restrictions[1] = schema.Name; restrictions[2] = obj.Name; using (DataTable dataTable = _connection.GetSchema("Columns", restrictions)) { MetadataFieldsFetcherFromDatatable mff = new MetadataFieldsFetcherFromDatatable(fields.SQLContext); mff.Datatable = dataTable; mff.NameFieldName = "COLUMN_NAME"; mff.NullableFieldName = "IS_NULLABLE"; mff.NullableValue = "YES"; mff.ServerTypeFieldName = "DATA_TYPE"; mff.SizeFieldName = "CHARACTER_MAXIMUM_LENGTH"; mff.PrecisionFieldName = "NUMERIC_PRECISION"; mff.ScaleFieldName = "NUMERIC_SCALE"; mff.DefaultValueFieldName = "COLUMN_DEFAULT"; mff.LoadFields(fields); } base.LoadFields(fields, loadingOptions); } }
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); } }
public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } try { MetadataNamespacesFetcherFromDatatable mnf = new MetadataNamespacesFetcherFromDatatable(databases, MetadataType.Database, loadingOptions); mnf.NameFieldName = "TABLE_CAT"; using (DataTable schemaTable = _connection.GetSchema("Tables")) { // pre-ODBC v3 if (schemaTable.Columns.IndexOf("TABLE_CAT") == -1) { // ODBC v2 if (schemaTable.Columns.IndexOf("TABLE_QUALIFIER") != -1) { mnf.NameFieldName = "TABLE_QUALIFIER"; } // ODBC v1? else if (schemaTable.Columns.IndexOf("QUALIFIERNAME") != -1) { mnf.NameFieldName = "QUALIFIERNAME"; } } mnf.Datatable = schemaTable; mnf.LoadMetadata(); } } catch (Exception exception) { throw new QueryBuilderException(exception.Message, exception); } }
public override void LoadDatabases(MetadataList databases, MetadataLoadingOptions loadingOptions) { if (databases.Parent.Server == null) { if (!Connected) { Connect(); } string currentDatabase = Connection.Database; if (!String.IsNullOrEmpty(currentDatabase)) { MetadataNamespace database = databases.FindItem <MetadataNamespace>(currentDatabase, MetadataType.Database); if (database == null) { database = new MetadataNamespace(databases, MetadataType.Database); database.Name = currentDatabase; databases.Add(database); } database.Default = true; } } }
public override void LoadFields(MetadataList fields, MetadataLoadingOptions loadingOptions) { base.LoadFields(fields, loadingOptions); LoadFieldsFromGetSchema(fields, loadingOptions); }
private void LoadFieldsFromGetSchema(MetadataList fields, MetadataLoadingOptions loadingOptions) { SQLContext sqlContext = fields.SQLContext; string olddb = Connection.Database; try { // load tables string[] restrictions = new string[3]; if (sqlContext.SyntaxProvider.IsSupportDatabases()) { MetadataNamespace database = fields.Parent.Database; if (database != null) { restrictions[0] = database.Name; } else { return; } } else { restrictions[0] = null; } if (sqlContext.SyntaxProvider.IsSupportSchemas()) { MetadataNamespace schema = fields.Parent.Schema; if (schema != null) { restrictions[1] = schema.Name; } else { return; } } else { restrictions[1] = null; } MetadataObject obj = fields.Parent.Object; if (obj == null) { return; } restrictions[2] = obj.Name; try { if (!string.IsNullOrEmpty(restrictions[0]) && Connection.Database != restrictions[0]) { Connection.ChangeDatabase(restrictions[0]); } DataTable schemaTable = _connection.GetSchema("Columns", restrictions); schemaTable.DefaultView.Sort = "ORDINAL_POSITION"; DataTable ordinalSortedColumns = schemaTable.DefaultView.ToTable(); MetadataFieldsFetcherFromDatatable mof = new MetadataFieldsFetcherFromDatatable(sqlContext); mof.NameFieldName = "COLUMN_NAME"; mof.ServerTypeFieldName = "TYPE_NAME"; mof.SizeFieldName = "COLUMN_SIZE"; mof.ScaleFieldName = "DECIMAL_DIGITS"; mof.DescriptionFieldName = "REMARKS"; mof.Datatable = ordinalSortedColumns; mof.LoadFields(fields); } 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; 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 LoadSchemas(MetadataList schemas, MetadataLoadingOptions loadingOptions) { if (!Connected) { Connect(); } SQLContext sqlContext = schemas.SQLContext; string olddb = Connection.Database; try { try { // load tables string[] restrictions = new string[1]; if (sqlContext.SyntaxProvider.IsSupportDatabases()) { MetadataNamespace database = schemas.Parent.Database; if (database != null) { restrictions[0] = database.Name; } else { return; } } else { restrictions[0] = null; } DataTable schemaTable = _connection.GetSchema("Tables", restrictions); DataColumn schemaColumn = (schemaTable.Columns["TABLE_SCHEM"] ?? schemaTable.Columns["TABLE_OWNER"]) ?? schemaTable.Columns["TABLEOWNER"] ?? schemaTable.Columns["OWNERNAME"]; if (schemaColumn == null) { return; } using (MetadataNamespacesFetcherFromStringList mnf = new MetadataNamespacesFetcherFromStringList(schemas, MetadataType.Schema, loadingOptions)) { for (int i = 0; i < schemaTable.Rows.Count; i++) { DataRow currentRow = schemaTable.Rows[i]; if (!currentRow.IsNull(schemaColumn)) { string schemaName = Convert.ToString(currentRow[schemaColumn]); if (mnf.AllNamespaces.IndexOf(schemaName) == -1) { mnf.AllNamespaces.Add(schemaName); } } } if (mnf.AllNamespaces.Count > 1 || mnf.AllNamespaces.Count == 1 && !string.IsNullOrEmpty(mnf.AllNamespaces[0])) { mnf.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 bool GetReferencingObjectNames(UpdatableObjectList <MetadataQualifiedName> list, MetadataObject forObject, MetadataLoadingOptions loadingOptions) { if (forObject.Server == null) { MetadataNamespace database = forObject.Database; MetadataNamespace schema = forObject.Schema; string[] restrictions = new string[6]; restrictions[0] = database != null ? database.Name : null; restrictions[1] = schema != null ? schema.Name : null; restrictions[2] = forObject.Name; using (DataTable foreignKeys = _connection.GetSchema("ForeignKeys", restrictions)) { int databaseField = foreignKeys.Columns.IndexOf("FKTABLE_CAT"); int schemaField = foreignKeys.Columns.IndexOf("FKTABLE_SCHEM"); int nameField = foreignKeys.Columns.IndexOf("FKTABLE_NAME"); foreach (DataRow row in foreignKeys.Rows) { object referencingName = nameField != -1 ? row[nameField] : null; object referencingSchema = schemaField != -1 ? row[schemaField] : null; object referencingDatabase = databaseField != -1 ? row[databaseField] : null; MetadataQualifiedName name = new MetadataQualifiedName(); if (referencingName != null) { name.Add(referencingName.ToString(), MetadataType.Objects); } if (referencingSchema != null) { name.Add(referencingSchema.ToString(), MetadataType.Schema); } if (referencingDatabase != null) { name.Add(referencingDatabase.ToString(), MetadataType.Schema); } list.Add(name); } return(true); } } return(false); }