示例#1
0
        public override bool CanAlterColumn(IPlatformTableSourceColumnInfo existingColumn, IPlatformTableSourceColumnInfo newColumn,
                                            out string errorMessage)
        {
            errorMessage = "";
            //text -> : -- Cannot alter column 't' because it is 'text'.
            //image ->       -- Cannot alter column 'v' because it is 'image'.
            // x -> CLOB (opposed to varchar2)   -- Operand type clash: x is incompatible with text
            // x -> BinaryData -- Operand type clash: x is incompatible with binarydata
            // x -> datetime -- Operand type clash: x is incompatible with datetime
            //datetime -> x except varchar -- Operand type clash: datetime is incompatible with x

            // Data type conversions
            if (existingColumn.DataType.Type == DBDataType.TEXT && existingColumn.DataType.Length > PlatformDataTypeInfo.VARCHAR_MAXLENGTH &&
                newColumn.DataType.Type == DBDataType.TEXT && newColumn.DataType.Length < PlatformDataTypeInfo.VARCHAR_MAXLENGTH)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, true) +
                               string.Format(" This is because the column was previously defined with a length greater than {0}.",
                                             PlatformDataTypeInfo.VARCHAR_MAXLENGTH);
                return(false);
            }
            if (existingColumn.DataType.Type == DBDataType.BINARY_DATA)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, true);
                return(false);
            }
            if (newColumn.DataType.Type == DBDataType.TEXT && newColumn.DataType.Length > PlatformDataTypeInfo.VARCHAR_MAXLENGTH)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, false) +
                               string.Format(" This is because the column is now defined with a length greater than {0}.",
                                             PlatformDataTypeInfo.VARCHAR_MAXLENGTH);
                return(false);
            }
            if (newColumn.DataType.Type.IsOneOf(DBDataType.BINARY_DATA, DBDataType.DATE_TIME))
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, false);
                return(false);
            }

            if (existingColumn.DataType.Type == DBDataType.DATE_TIME && newColumn.DataType.Type != DBDataType.TEXT)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, false);
                return(false);
            }

            // Autonumber conversions
            if (existingColumn.IsAutoGenerated && !newColumn.IsAutoGenerated)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn.TableSource.Name, existingColumn.Name, "Autonumber", existingColumn.DataType.Type.ToText(), newColumn.DataType.SqlDataType, newColumn.DataType.Type.ToText(), true);
                return(false);
            }
            if (!existingColumn.IsAutoGenerated && newColumn.IsAutoGenerated)
            {
                // Change is allowed if the table is empty
                bool hasRows;
                using (IDbConnection conn = DatabaseServices.TransactionService.CreateConnection()) {
                    using (IDbCommand cmd = DatabaseServices.ExecutionService.CreateCommand(conn,
                                                                                            "select count(1) from " + Identifiers.EscapeAndQualifyIdentifierForLocalDatabase(existingColumn.TableSource.Name))) {
                        hasRows = Convert.ToInt32(cmd.ExecuteScalar()) > 0;
                    }
                }
                if (hasRows)
                {
                    errorMessage = GetColumnCannotBeChangedMessage(existingColumn.TableSource.Name, existingColumn.Name,
                                                                   existingColumn.DataType.SqlDataType, existingColumn.DataType.Type.ToText(), "Autonumber",
                                                                   newColumn.DataType.Type.ToText(), false);
                    return(false);
                }
            }

            return(true);
        }
示例#2
0
        public override bool CanAlterColumn(IPlatformTableSourceColumnInfo existingColumn, IPlatformTableSourceColumnInfo newColumn,
                                            out string errorMessage)
        {
            errorMessage = "";

            if (newColumn.IsAutoGenerated && newColumn.IsPrimaryKey == false)
            {
                errorMessage = string.Format("Column {0} of table {1} can't be Auto Number if it's not the identifier of the entity.", newColumn.Name, newColumn.TableSource.Name);
                return(false);
            }

            // Data type conversions
            if (existingColumn.DataType.Type == DBDataType.TEXT && existingColumn.DataType.Length > MySQLPlatformDataTypeInfo.VARCHAR_MAXLENGTH &&
                newColumn.DataType.Type == DBDataType.TEXT && newColumn.DataType.Length < MySQLPlatformDataTypeInfo.VARCHAR_MAXLENGTH)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, true) +
                               string.Format(" This is because the column was previously defined with a length greater than {0}.",
                                             MySQLPlatformDataTypeInfo.VARCHAR_MAXLENGTH);
                return(false);
            }

            if (existingColumn.DataType.Type == DBDataType.BINARY_DATA)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, true);
                return(false);
            }

            if (newColumn.DataType.Type.IsOneOf(DBDataType.BINARY_DATA, DBDataType.DATE_TIME))
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, false);
                return(false);
            }

            if (existingColumn.DataType.Type == DBDataType.DATE_TIME && newColumn.DataType.Type != DBDataType.TEXT)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn, newColumn, false);
                return(false);
            }

            // Autonumber conversions
            if (existingColumn.IsAutoGenerated && !newColumn.IsAutoGenerated)
            {
                errorMessage = GetColumnCannotBeChangedMessage(existingColumn.TableSource.Name, existingColumn.Name, "Autonumber", existingColumn.DataType.Type.ToText(), newColumn.DataType.SqlDataType, newColumn.DataType.Type.ToText(), true);
                return(false);
            }
            if (!existingColumn.IsAutoGenerated && newColumn.IsAutoGenerated)
            {
                // Change is allowed if the table is empty
                bool hasRows;
                using (IDbConnection conn = DatabaseServices.TransactionService.CreateConnection()) {
                    using (IDbCommand cmd = DatabaseServices.ExecutionService.CreateCommand(conn,
                                                                                            "select count(1) from " + Identifiers.EscapeAndQualifyIdentifierForLocalDatabase(existingColumn.TableSource.Name))) {
                        hasRows = Convert.ToInt32(cmd.ExecuteScalar()) > 0;
                    }
                }
                if (hasRows)
                {
                    errorMessage = GetColumnCannotBeChangedMessage(existingColumn.TableSource.Name, existingColumn.Name,
                                                                   existingColumn.DataType.SqlDataType, existingColumn.DataType.Type.ToText(), "Autonumber",
                                                                   newColumn.DataType.Type.ToText(), false);
                    return(false);
                }
            }

            return(true);
        }