예제 #1
0
        /// <summary>
        /// Gets a cannonical definition of the field.
        /// </summary>
        public string GetDefinition()
        {
            var result = string.Format("{0} {1}", _name, _dataType.ToString());

            if (_dataType == DbDataType.Char || _dataType == DbDataType.VarChar || _dataType == DbDataType.Decimal)
            {
                result = string.Format("{0}({1})", result, _length.ToString());
            }
            if (_dataType == DbDataType.Enum)
            {
                result = string.Format("{0}({1})", result, _enumValues);
            }

            if (_notNull)
            {
                result = result + " NOT NULL";
            }
            if (_unsigned && _dataType.IsDbDataTypeInteger())
            {
                result = result + " UNSIGNED";
            }
            if (_autoincrement && _dataType.IsDbDataTypeInteger())
            {
                result = result + " AUTOINCREMENT";
            }

            if (_indexType == DbIndexType.Primary)
            {
                result = result + " PRIMARY KEY";
            }
            if (_collationType == DbFieldCollationType.ASCII_Binary)
            {
                result = result + " COLLATE ascii_bin";
            }
            else if (_collationType == DbFieldCollationType.ASCII_CaseInsensitive)
            {
                result = result + " COLLATE ascii_ci";
            }
            if (_indexType == DbIndexType.Simple)
            {
                result = string.Format("{0} INDEX {1}", result, _indexName);
            }
            if (_indexType == DbIndexType.Unique)
            {
                result = string.Format("{0} UNIQUE INDEX {1}", result, _indexName);
            }
            if (_indexType == DbIndexType.ForeignKey || _indexType == DbIndexType.ForeignPrimary)
            {
                result = string.Format(
                    "{0} FOREIGN KEY {1} REFERENCES {2}({3}) ON UPDATE {4} ON DELETE {5}",
                    result, _indexName, _refTable, _refField, _onUpdateForeignKey.ToString().ToUpperInvariant(),
                    _onDeleteForeignKey.ToString().ToUpperInvariant());
            }


            return(result);
        }
예제 #2
0
        /// <summary>
        /// Gets the mysql native foreign index change action type.
        /// </summary>
        /// <param name="actionType">the canonical foreign index change action type to translate</param>
        internal static string GetNativeActionType(this DbForeignKeyActionType actionType)
        {
            switch (actionType)
            {
            case DbForeignKeyActionType.Restrict:
                return("RESTRICT");

            case DbForeignKeyActionType.Cascade:
                return("CASCADE");

            case DbForeignKeyActionType.SetNull:
                return("SET NULL");

            default:
                throw new NotImplementedException(string.Format(Properties.Resources.EnumValueNotImplementedException,
                                                                actionType.ToString()));
            }
        }