Issue Details (XML | Word | Printable)

Key: TORQUE-105
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Sylvain Benoist
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Torque

Column specification assumes NULL as implicit choice

Created: 18/Oct/07 02:18 PM   Updated: 03/Nov/07 04:58 PM
Return to search
Component/s: Generator
Affects Version/s: 3.3-RC2
Fix Version/s: 3.3-RC3

Time Tracking:
Not Specified

Environment: Maven2 plugin, Torque 3.3-RC2 ; tested with Sybase 15.0.2 DEV Edition Windows - should affect all Sybase

Resolution Date: 03/Nov/07 04:58 PM


 Description  « Hide
When defining a column in a table with the Torque XML model, the assumption is that if the 'required' attribute is not present, or false, then the column is produced with no explicit NULL/ NOT NULL text. This leaves the door open to database specific behaviors.

For example, Sybase... see http://manuals.sybase.com/onlinebooks/group-as/asg1250e/svrtsg/@Generic__BookTextView/15380.
It says that by default, Sybase assumes that a column without an explicit NULL or NOT NULL will be translated into a NOT NULL.

This means that from the following XML snippet :

<table name="country" description="Country data">
   <column name="country_id" domain="dm_CountryId" required="true" primaryKey="true" />
   <column name="country_name" domain="dm_GenericName30" required="true" />
   <column name="iso_source" domain="dm_Boolean" required="true" />
   <column name="iso_threechar_code" type="CHAR" size="3" required="false" />
   <column name="iso_numeric_code" type="INTEGER" required="false"/>
   <column name="active" domain="dm_Boolean" required="true" />
</table>

I end up with the following DDL :

CREATE TABLE country
(
                country_id CHAR (2) NOT NULL,
                country_name VARCHAR (30) NOT NULL,
                iso_source CHAR (1) default 'Y' NOT NULL,
                iso_threechar_code CHAR (3),
                iso_numeric_code INT,
                active CHAR (1) default 'Y' NOT NULL,
    CONSTRAINT country_PK PRIMARY KEY(country_id)
)
go

And Sybase default this to have all columns as NOT NULL, which is not what I specified in my XML.

To avoid being dependent on a database configuration option, it would be better to make things completely explicit, so that
when the 'required' XML attribute is either absent or false, the generated DDL specifies 'NULL' instead of an empty string.




 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Sylvain Benoist added a comment - 31/Oct/07 03:50 PM
Suggest overriding getNullString method in org.apache.torque.engine.platform.PlatformSybaseImpl,
or even DefaultPlatformImpl if this behavior should be applied consistently to all platforms.

public String getNullString(boolean notNull)
    {
        return (notNull ? "NOT NULL" : "NULL");
    }


What bothers me is that this implementation is no longer in sync with all the comments that I have seen that indicate that the method returns an empty string for 'NULL' - this may break code that tests for string length for example.

Thomas Fischer added a comment - 03/Nov/07 04:58 PM
Made changes to org.apache.torque.engine.platform.PlatformSybaseImpl as suggested. All other Dbs known to me have nullable columns as default, so I'm leaving PlatformDefaultImpl as it is.

Thanks for the patch.

Thomas Fischer made changes - 03/Nov/07 04:58 PM
Field Original Value New Value
Resolution Fixed [ 1 ]
Fix Version/s 3.3-RC3 [ 12312398 ]
Status Open [ 1 ] Closed [ 6 ]