Example #1
0
        /// <summary>
        /// Gets the DataType adjusted for the stage at which the ColumnInfo is at, this is almost always the same as Data_type.  The only
        /// time it is different is when there is an ANOTable involved e.g. ANOLocation could be a varchar(6) like 'AB10_L' after anonymisation
        /// but if the LoadStage is AdjustRaw then it would have a value like 'NH10' (varchar(4) - the unanonymised state).
        /// </summary>
        /// <param name="loadStage"></param>
        /// <returns></returns>
        public string GetRuntimeDataType(LoadStage loadStage)
        {
            if (loadStage <= LoadStage.AdjustRaw)
            {
                //if it has an ANO transform
                if (ANOTable_ID != null)
                {
                    return(ANOTable.GetRuntimeDataType(loadStage));    //get the datatype from the ANOTable because ColumnInfo is of mutable type depending on whether it has been anonymised yet
                }
                //it doesn't have an ANOtransform but it might be the subject of dilution
                var discard = TableInfo.PreLoadDiscardedColumns.SingleOrDefault(c => c.GetRuntimeName().Equals(GetRuntimeName(), StringComparison.InvariantCultureIgnoreCase));

                //The column exists both in the live database and in the identifier dump.  This is because it goes through horrendous bitcrushing operations e.g. Load RAW with full
                //postcode varchar(8) and ship postcode off to identifier dump but also let it go through to live but only as the first 4 letters varchar(4).  so the datatype of the column
                //in RAW is varchar(8) but in Live is varchar(4)
                if (discard != null)
                {
                    return(discard.Data_type);
                }

                return(Data_type);
            }

            //The user is asking about a stage other than RAW so tell them about the final column type state
            return(Data_type);
        }
        public void Synchronize(ICheckNotifier notifier)
        {
            IdentifierDumper dumper = new IdentifierDumper(_tableToSync);

            dumper.Check(notifier);

            CheckForDuplicateANOVsRegularNames();

            var columnInfosWithANOTransforms = _tableToSync.ColumnInfos.Where(c => c.ANOTable_ID != null).ToArray();

            if (!columnInfosWithANOTransforms.Any())
            {
                notifier.OnCheckPerformed(
                    new CheckEventArgs(
                        "There are no ANOTables configured for this table so skipping ANOTable checking",
                        CheckResult.Success));
            }

            foreach (ColumnInfo columnInfoWithANOTransform in columnInfosWithANOTransforms)
            {
                ANOTable anoTable = columnInfoWithANOTransform.ANOTable;
                anoTable.Check(new ThrowImmediatelyCheckNotifier());

                if (!anoTable.GetRuntimeDataType(LoadStage.PostLoad).Equals(columnInfoWithANOTransform.Data_type))
                {
                    throw new ANOConfigurationException("Mismatch between anoTable.GetRuntimeDataType(LoadStage.PostLoad) = " + anoTable.GetRuntimeDataType(LoadStage.PostLoad) + " and column " + columnInfoWithANOTransform + " datatype = " + columnInfoWithANOTransform.Data_type);
                }

                notifier.OnCheckPerformed(
                    new CheckEventArgs(
                        "ANOTable " + anoTable + " has shared compatible datatype " + columnInfoWithANOTransform.Data_type + " with ColumnInfo " +
                        columnInfoWithANOTransform, CheckResult.Success));
            }
        }
Example #3
0
        public string GetEndpointDataType()
        {
            var sourceTypeTranslater = _querySyntaxHelper.TypeTranslater;

            //if we have picked a destination
            ITypeTranslater destinationTypeTranslater;

            if (_planManager.TargetDatabase != null)
            {
                destinationTypeTranslater = _planManager.TargetDatabase.Server.GetQuerySyntaxHelper().TypeTranslater;//ensure we handle type translation between the two platforms
            }
            else
            {
                destinationTypeTranslater = sourceTypeTranslater;//otherwise (we haven't picked a destination yet)
            }
            switch (Plan)
            {
            case Plan.Drop:
                return(null);

            case Plan.ANO:
                if (ANOTable == null)
                {
                    return("Unknown");
                }

                return(sourceTypeTranslater.TranslateSQLDBType(ANOTable.GetRuntimeDataType(LoadStage.PostLoad), destinationTypeTranslater));

            case Plan.Dilute:
                if (Dilution == null)
                {
                    return("Unknown");
                }

                return(destinationTypeTranslater.GetSQLDBTypeForCSharpType(Dilution.ExpectedDestinationType));

            case Plan.PassThroughUnchanged:

                //if they have an identity column then we substitute it for int in the destination
                if (ColumnInfo.IsAutoIncrement)
                {
                    return(destinationTypeTranslater.GetSQLDBTypeForCSharpType(new DatabaseTypeRequest(typeof(int))));
                }

                return(sourceTypeTranslater.TranslateSQLDBType(ColumnInfo.Data_type, destinationTypeTranslater));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #4
0
        private void SetEnabledness()
        {
            DiscoveredTable pushedTable;

            try
            {
                pushedTable = _anoTable.GetPushedTable();
            }
            catch (Exception e)
            {
                CommonFunctionality.Fatal("Could not reach ANO Server", e);
                return;
            }

            bool isPushed = pushedTable != null;

            nIntegers.Enabled       = !isPushed;
            nCharacters.Enabled     = !isPushed;
            btnFinalise.Enabled     = !isPushed;
            tbInputDataType.Enabled = !isPushed;

            btnDropANOTable.Enabled = isPushed;
            gbPushedTable.Visible   = isPushed;

            if (isPushed)
            {
                tbInputDataType.Text = _anoTable.GetRuntimeDataType(LoadStage.AdjustRaw);

                lblANOTableName.Text = pushedTable.GetRuntimeName();
                var cols = pushedTable.DiscoverColumns();

                lblPrivate.Text = cols[0].GetRuntimeName() + " " + cols[0].DataType.SQLType;
                lblPublic.Text  = cols[1].GetRuntimeName() + " " + cols[1].DataType.SQLType;

                lblRowCount.Text = pushedTable.GetRowCount() + " rows";
            }
        }
        private void AddNewANOColumnInfo(Func <string, bool> shouldApplySql, DbConnection con, ICheckNotifier notifier)
        {
            string anoColumnNameWillBe = "ANO" + _colToNuke.GetRuntimeName(LoadStage.PostLoad);

            string alterSql = "ALTER TABLE " + _tableInfo.Name + " ADD " + anoColumnNameWillBe + " " + _toConformTo.GetRuntimeDataType(LoadStage.PostLoad);

            if (shouldApplySql(alterSql))
            {
                var cmd = DatabaseCommandHelper.GetCommand(alterSql, con);
                cmd.ExecuteNonQuery();

                TableInfoSynchronizer synchronizer = new TableInfoSynchronizer(_tableInfo);
                synchronizer.Synchronize(notifier);

                //now get the new ANO columninfo
                _newANOColumnInfo             = _tableInfo.ColumnInfos.Single(c => c.GetRuntimeName().Equals(anoColumnNameWillBe));
                _newANOColumnInfo.ANOTable_ID = _toConformTo.ID;
                _newANOColumnInfo.SaveToDatabase();
            }
            else
            {
                throw new Exception("User chose not to apply part of the operation");
            }
        }
Example #6
0
 public string GetDestinationColumnExpectedDataType()
 {
     return(_anoTable.GetRuntimeDataType(LoadStage.PostLoad));
 }