コード例 #1
0
        /// <summary>
        /// Matches Character Set against differing data contexts and returns a string containing
        /// the collation for the target data context or string.Empty if it was not found.
        /// </summary>
        /// <param name="sourceDataContext">The source DataContext.</param>
        /// <param name="targetDataContext">The target Datacontext.</param>
        /// <param name="userTableColumn">The user-table column to pull Character Set from.</param>
        /// <returns>
        ///     The target Character Set to use for the given user-table column or string.Empty if one was not found.
        /// </returns>
        public static string ConvertCharacterSet(DataContext sourceDataContext, DataContext targetDataContext, UserTableColumn userTableColumn)
        {
            // TODO: adjust to use sourceUserTableColumn.CharacterSet once added.
            if (string.IsNullOrEmpty(userTableColumn.Collation))
            {
                return(string.Empty);
            }

            if (sourceDataContext.ContextType == targetDataContext.ContextType)
            {
                return(userTableColumn.Collation);
            }

            switch (sourceDataContext.ContextType)
            {
            case DataContextType.MySql:
                if (!MySqlCharacterSets.Contains(userTableColumn.Collation))
                {
                    return(string.Empty);
                }

                switch (targetDataContext.ContextType)
                {
                case DataContextType.SqlServer:
                    string collation;
                    return(!MySqlToSqlServerLookup.TryGetValue(userTableColumn.Collation, out collation)
                                ? string.Empty
                                : collation);

                default:
                    return(string.Empty);
                }

            case DataContextType.SqlServer:
                if (!SqlServerCharacterSets.Contains(userTableColumn.Collation))
                {
                    return(string.Empty);
                }

                switch (targetDataContext.ContextType)
                {
                case DataContextType.MySql:
                    string collation;
                    return(!SqlServerToMySqlLookup.TryGetValue(userTableColumn.Collation, out collation)
                                ? string.Empty
                                : collation);

                default:
                    return(string.Empty);
                }

            default:
                return(string.Empty);
            }
        }
コード例 #2
0
        /// <summary>
        /// Compares the Character Set between source and target user-table columns and even
        /// matches against differing data contexts.
        /// </summary>
        /// <param name="sourceDataContext">The source DataContext.</param>
        /// <param name="targetDataContext">The target DataContext.</param>
        /// <param name="sourceUserTableColumn">The source user-table column to get a character set from.</param>
        /// <param name="targetUserTableColumn">The target user-table column to get a character set from.</param>
        /// <returns>
        ///     True - The character sets matched between differing datasources.
        ///     False - The character sets could not be matched up.
        /// </returns>
        public static bool CompareCharacterSet(DataContext sourceDataContext, DataContext targetDataContext, UserTableColumn sourceUserTableColumn, UserTableColumn targetUserTableColumn)
        {
            // TODO: adjust to use sourceUserTableColumn.CharacterSet once added.
            if (string.IsNullOrEmpty(sourceUserTableColumn.Collation) && string.IsNullOrEmpty(targetUserTableColumn.Collation))
            {
                return(true);
            }

            if (string.IsNullOrEmpty(sourceUserTableColumn.Collation))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(targetUserTableColumn.Collation))
            {
                return(false);
            }

            if (sourceDataContext.ContextType == targetDataContext.ContextType)
            {
                if (StringComparer.OrdinalIgnoreCase.Compare(
                        sourceUserTableColumn.Collation, targetUserTableColumn.Collation) != 0)
                {
                    return(false);
                }
            }

            switch (sourceDataContext.ContextType)
            {
            case DataContextType.MySql:
                if (!MySqlCharacterSets.Contains(sourceUserTableColumn.Collation))
                {
                    return(true);
                }

                switch (targetDataContext.ContextType)
                {
                case DataContextType.SqlServer:
                    string collation;
                    return(!MySqlToSqlServerLookup.TryGetValue(sourceUserTableColumn.Collation, out collation)
                                ? true
                                : StringComparer.OrdinalIgnoreCase.Compare(
                               collation, targetUserTableColumn.Collation) == 0);

                default:
                    return(true);
                }

            case DataContextType.SqlServer:
                if (!SqlServerCharacterSets.Contains(sourceUserTableColumn.Collation))
                {
                    return(true);
                }

                switch (targetDataContext.ContextType)
                {
                case DataContextType.MySql:
                    string collation;
                    return(!SqlServerToMySqlLookup.TryGetValue(sourceUserTableColumn.Collation, out collation)
                                ? true
                                : StringComparer.OrdinalIgnoreCase.Compare(
                               collation, targetUserTableColumn.Collation) == 0);

                default:
                    return(true);
                }

            default:
                return(true);
            }
        }