cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrus Adamchik (JIRA)" <j...@apache.org>
Subject [jira] Updated: (CAY-1395) createSetAllowNullToDb() can lead to data corruption, returns incorrect SQL statement to createSql()
Date Sun, 25 Apr 2010 04:24:51 GMT

     [ https://issues.apache.org/jira/browse/CAY-1395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Andrus Adamchik updated CAY-1395:
---------------------------------

    Fix Version/s: 3.0.1
                       (was: 3.0-final)

> createSetAllowNullToDb() can lead to data corruption, returns incorrect SQL statement
to createSql() 
> -----------------------------------------------------------------------------------------------------
>
>                 Key: CAY-1395
>                 URL: https://issues.apache.org/jira/browse/CAY-1395
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Core Library
>    Affects Versions: 3.0RC2
>            Reporter: √ėyvind Harboe
>             Fix For: 3.0.1
>
>
> SQLServerManagerFactory.createSetAllowNullToDb() can cause data corruption.
> The problem is that it assumes that the column passed in to the constructor contains
the properties read from the database.
> Consider a text field where the column passed to the constructor is *shorter* than what's
currently used in the database.
> In the use of a a merger context one could decide *only* to try to change the allow null
property and leave the length of the text field alone.  In this case changing the allow null
property will truncate the length of the text field as a side effect.
> Consider the MS SQL server syntax to set the NOT NULL (do not allow null) syntax:
> ALTER TABLE consequence ALTER COLUMN cons_id int NOT NULL
> Here the type of the field must preceed the NOT NULL and hence you have to *know* the
type in the database to modify the allow null property while leaving the type alone...
> SetNotNullToDb() does not suffer from this problem as it changes *only* the allow null
property.
>     @Override
>     public List<String> createSql(DbAdapter adapter) {
>         StringBuilder sqlBuffer = new StringBuilder();
>         QuotingStrategy context = adapter.getQuotingStrategy(getEntity()
>                 .getDataMap()
>                 .isQuotingSQLIdentifiers());
>         sqlBuffer.append("ALTER TABLE ");
>         sqlBuffer.append(context.quoteFullyQualifiedName(getEntity()));
>         sqlBuffer.append(" ALTER COLUMN ");
>         sqlBuffer.append(context.quoteString(getColumn().getName()));
>         sqlBuffer.append(" SET NOT NULL");
>         return Collections.singletonList(sqlBuffer.toString());
>     }
> I've hacked up SQLMergerFactory locally and it appears to work fine in my particular
case:
>         return new SetAllowNullToDb(entity, column) {
>             @Override
>             public List<String> createSql(DbAdapter adapter) {
>                 StringBuffer sqlBuffer = new StringBuffer();
>                 QuotingStrategy context = adapter.getQuotingStrategy(getEntity()
>                         .getDataMap()
>                         .isQuotingSQLIdentifiers());
>                 sqlBuffer.append("ALTER TABLE ");
>                 sqlBuffer.append(context.quoteFullyQualifiedName(getEntity()));
>                 sqlBuffer.append(" ALTER COLUMN ");
>                 /* Kludge!!!! how should this be handled really??? */
>                 column.setMandatory(false);
>                 adapter.createTableAppendColumn(sqlBuffer, column);
>                 return Collections.singletonList(sqlBuffer.toString());
>             }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message