public override void GetAllTable(string connName) { try { this.TableInfos = new List <TableInfo>(); string sql = "Select name from sqlite_master where type='table'"; adoHelper = new ADOHelper(connName); DataTable allTable = adoHelper.ExecuteDataTable(sql); foreach (DataRow row in allTable.Rows) { string tableName = row[0].ToString(); TableInfo ti = new TableInfo(); ti.TableName = tableName; ti.SchemasTableName = tableName; GetTableStructure(ti); if (ti.ColumnInfoCollection == null || ti.ColumnInfoCollection.Count == 0) { continue; } TableInfos.Add(ti); } } catch (Exception ex) { throw ex; } }
public override void GetAllTable(string connName) { try { this.TableInfos = new List <TableInfo>(); string sql = "select t.name tablename,s.name schemasName from sys.sysobjects t join sys.schemas s on t.uid=s.schema_id " + "where t.xtype='U' order by s.name,t.name"; adoHelper = new ADOHelper(connName); DataTable allTable = adoHelper.ExecuteDataTable(sql); foreach (DataRow row in allTable.Rows) { string tableName = row[0].ToString(); string schemasName = row[1].ToString(); TableInfo ti = new TableInfo(); ti.TableName = tableName; ti.SchemasTableName = tableName; if (!schemasName.Equals("dbo")) { ti.SchemasTableName = schemasName + "." + tableName; } GetTableStructure(ti); if (ti.ColumnInfoCollection == null || ti.ColumnInfoCollection.Count == 0) { continue; } TableInfos.Add(ti); } } catch (Exception ex) { throw ex; } }
TableInfo GetTableInfo(Type type) { var tableInfos = default(TableInfos); var cs = _connection.ConnectionString; lock (_tableInfosLock) { if (!_tableInfos.TryGetValue(cs, out tableInfos)) { tableInfos = new TableInfos(); _tableInfos.Add(cs, tableInfos); } } return(tableInfos.GetTableInfo(type, this)); }
/// <summary> /// Implements the opening of a table using a given path. /// </summary> /// <param name="tablePath">table name or 'Path' to the table which is comprised of the sql database file followed by ; and the tablename</param> /// <returns>Table template that matches the table name (cached)</returns> public override PluginTableTemplate OpenTable(string tablePath) { //var tableName = System.IO.Path.GetFileNameWithoutExtension(tablePath); //if (!this.GetTableNames().Contains(tableName)) // throw new GeodatabaseTableException($"The table {tableName} was not found"); var ti = TableInfos.Where((i) => i.TableName.EndsWith(tablePath) || i.Path.EndsWith(tablePath)).FirstOrDefault(); if (ti == null) { throw new GeodatabaseTableException($"The table {tablePath} was not found"); } _tables[ti.TableName] = new ProSqlPluginTableTemplate(_sqlDb, ti); return(_tables[ti.TableName]); }
public List <ColumnInfo> GetColumnDataGridDataSource(string tableId) { var list = new List <ColumnInfo>(); if (!string.IsNullOrEmpty(tableId) && TableInfos != null) { var table = TableInfos.FirstOrDefault(t => t.Id == tableId); if (table != null) { list = table.ColumnInfos; } } return(list); }
private bool IsStillNeeded(ColumnInfo columnInfo) { return(TableInfos.Any(t => t.ID == columnInfo.TableInfo_ID)); }
public void Check(ICheckNotifier notifier) { if (TargetDatabase == null) { notifier.OnCheckPerformed(new CheckEventArgs("No TargetDatabase has been set", CheckResult.Fail)); } else if (!TargetDatabase.Exists()) { notifier.OnCheckPerformed(new CheckEventArgs("TargetDatabase '" + TargetDatabase + "' does not exist", CheckResult.Fail)); } var toMigrateTables = TableInfos.Except(SkippedTables).ToArray(); if (!toMigrateTables.Any()) { notifier.OnCheckPerformed(new CheckEventArgs("There are no TableInfos selected for anonymisation", CheckResult.Fail)); } try { var joinInfos = GetJoinInfosRequiredCatalogue(); notifier.OnCheckPerformed(new CheckEventArgs("Generated Catalogue SQL succesfully", CheckResult.Success)); foreach (JoinInfo joinInfo in joinInfos) { notifier.OnCheckPerformed(new CheckEventArgs("Found required JoinInfo '" + joinInfo + "' that will have to be migrated", CheckResult.Success)); } foreach (Lookup lookup in GetLookupsRequiredCatalogue()) { notifier.OnCheckPerformed(new CheckEventArgs("Found required Lookup '" + lookup + "' that will have to be migrated", CheckResult.Success)); //for each key involved in the lookup foreach (ColumnInfo c in new[] { lookup.ForeignKey, lookup.PrimaryKey, lookup.Description }) { //lookup / table has already been migrated if (SkippedTables.Any(t => t.ID == c.TableInfo_ID)) { continue; } //make sure that the plan is sensible if (GetPlanForColumnInfo(c).Plan != Plan.PassThroughUnchanged) { notifier.OnCheckPerformed(new CheckEventArgs("ColumnInfo '" + c + "' is part of a Lookup so must PassThroughUnchanged", CheckResult.Fail)); } } } } catch (Exception ex) { notifier.OnCheckPerformed(new CheckEventArgs("Failed to generate Catalogue SQL", CheckResult.Fail, ex)); } if (DateColumn != null) { var dateColumnPlan = GetPlanForColumnInfo(DateColumn); if (dateColumnPlan.Plan != Plan.PassThroughUnchanged) { if (notifier.OnCheckPerformed(new CheckEventArgs("Plan for " + DateColumn + " must be PassThroughUnchanged", CheckResult.Fail, null, "Set plan to PassThroughUnchanged"))) { dateColumnPlan.Plan = Plan.PassThroughUnchanged; } } //get a count of the number of non lookup used tables var usedTables = TableInfos.Except(SkippedTables).Count(t => !t.IsLookupTable()); if (usedTables > 1) { notifier.OnCheckPerformed( new CheckEventArgs( "You cannot have a date based migration because you are trying to migrate " + usedTables + " TableInfos at once", CheckResult.Fail)); } } if (Plans.Any(p => p.Value.Plan == Plan.Dilute)) { if (GetIdentifierDumpServer() == null) { notifier.OnCheckPerformed(new CheckEventArgs("No default Identifier Dump server has been configured", CheckResult.Fail)); } } var refactorer = new SelectSQLRefactorer(); foreach (ExtractionInformation e in _allExtractionInformations) { if (!refactorer.IsRefactorable(e)) { notifier.OnCheckPerformed(new CheckEventArgs("ExtractionInformation '" + e + "' is a not refactorable due to reason:" + refactorer.GetReasonNotRefactorable(e), CheckResult.Fail)); } } notifier.OnCheckPerformed(new CheckEventArgs($"Preparing to evaluate {toMigrateTables.Length}' tables ({string.Join(",",toMigrateTables.Select(t=>t.GetFullyQualifiedName()))})", CheckResult.Success)); foreach (TableInfo tableInfo in toMigrateTables) { notifier.OnCheckPerformed(new CheckEventArgs("Evaluating TableInfo '" + tableInfo + "'", CheckResult.Success)); if (TargetDatabase != null && TargetDatabase.ExpectTable(tableInfo.GetRuntimeName()).Exists()) { notifier.OnCheckPerformed(new CheckEventArgs("Table '" + tableInfo + "' already exists in Database '" + TargetDatabase + "'", CheckResult.Fail)); } var pks = tableInfo.ColumnInfos.Where(c => c.IsPrimaryKey).ToArray(); if (!pks.Any()) { notifier.OnCheckPerformed(new CheckEventArgs("TableInfo '" + tableInfo + "' does not have any Primary Keys, it cannot be anonymised", CheckResult.Fail)); } if (tableInfo.IsTableValuedFunction) { notifier.OnCheckPerformed(new CheckEventArgs("TableInfo '" + tableInfo + "' is an IsTableValuedFunction so cannot be anonymised", CheckResult.Fail)); } EnsureNotAlreadySharedLocally(notifier, tableInfo); EnsureNotAlreadySharedLocally(notifier, Catalogue); } //check the column level plans foreach (var p in Plans.Values) { p.Check(notifier); } }