private void CheckForProblemsInSQLFile(ICheckNotifier notifier) { try { var sql = File.ReadAllText(Path); //lets check for any SQL that indicates user is trying to modify a STAGING table in a RAW script (for example) foreach (TableInfo tableInfo in LoadMetadata.GetDistinctTableInfoList(false)) { //for each stage get all the object names that are in that stage foreach (var stage in new[] { LoadStage.AdjustRaw, LoadStage.AdjustStaging, LoadStage.PostLoad }) { //process task belongs in that stage anyway so nothing is prohibited if (stage == (LoadStage == LoadStage.Mounting? LoadStage.AdjustRaw:LoadStage)) { continue; } //figure out what is prohibited string prohibitedSql = tableInfo.GetQuerySyntaxHelper().EnsureFullyQualified(tableInfo.GetDatabaseRuntimeName(stage), null, tableInfo.GetRuntimeName(stage)); //if we reference it, complain if (sql.Contains(prohibitedSql)) { notifier.OnCheckPerformed( new CheckEventArgs( "Sql in file '" + Path + "' contains a reference to '" + prohibitedSql + "' which is prohibited since the ProcessTask ('" + Name + "') runs in LoadStage " + LoadStage, CheckResult.Warning)); } } } } catch (Exception e) { notifier.OnCheckPerformed(new CheckEventArgs("Failed to check the contents of the SQL file '" + Path + "'", CheckResult.Fail, e)); } }
/// <summary> /// Returns all tables loaded by the parent <see cref="LoadMetadata"/> /// </summary> /// <returns></returns> public IEnumerable <TableInfo> GetTableInfos() { return(LoadMetadata.GetDistinctTableInfoList(true)); }