db-ddlutils-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robk99 <ROBEKL...@TX.RR.COM>
Subject Re: Default Value of SYSDATE not set in Oracle TIMESTAMP column
Date Sun, 28 Oct 2007 14:49:52 GMT

Hi Tom, 
I looked at the code and the issue was a result of the value passed to
parsedDefault was stripped of the SYSDATE due to the attempt to convert
SYSDATE to a date or timestamp value by column.getParsedDefaultValue() in
SQLBuilder.java.  (See code below)

/**
     * Prints the default value stmt part for the column.
     * 
     * @param table  The table
     * @param column The column
     */ 

protected void writeColumnDefaultValueStmt(Table table, Column column)
throws IOException
    {
        
    	Object parsedDefault = column.getParsedDefaultValue();
        ...
        ...
    }

/**
     * Tries to parse the default value of the column and returns it as an
object of the
     * corresponding java type. If the value could not be parsed, then the
original
     * definition is returned.
     * 
     * @return The parsed default value
     */
    public Object getParsedDefaultValue()
    {
        if ((_defaultValue != null) && (_defaultValue.length() > 0))
        {
            try
            {
                switch (_typeCode)
                {
                    case Types.TINYINT:
                    ...
                    ...
                    case Types.DATE:
                        return Date.valueOf(_defaultValue);
                    case Types.TIME:
                        return Time.valueOf(_defaultValue);
                    case Types.TIMESTAMP:
                        return Timestamp.valueOf(_defaultValue);
                    ...                }

To correct this I added the following code to writeColumnDefaultValueStmt.

protected void writeColumnDefaultValueStmt(Table table, Column column)
throws IOException
    {
        
    	Object parsedDefault = column.getParsedDefaultValue();

     //Added by Rob Klein 10/28/2007 to correct SYSDATE Default issue
    	if (parsedDefault == null && column.getDefaultValue() != null)
    		parsedDefault = column.getDefaultValue(); 
        ...
        ...
    }

This adds SYSDATE into the parsedDefault variable.

One final change was to unquote the SYSDATE value in the DEFAULT parameter. 
To do this I simply changed the follow code in the Oracle8Builder.java

	/**
     * {@inheritDoc}
     */
    protected void printDefaultValue(Object defaultValue, int typeCode)
throws IOException
    {
    
        if (defaultValue != null)
        {
            String  defaultValueStr = defaultValue.toString();
            boolean shouldUseQuotes = !TypeMap.isNumericType(typeCode) &&
!defaultValueStr.startsWith("TO_DATE(");
    

to

	/**
     * {@inheritDoc}
     */
    protected void printDefaultValue(Object defaultValue, int typeCode)
throws IOException
    {
    
        if (defaultValue != null)
        {
            String  defaultValueStr = defaultValue.toString();
            boolean shouldUseQuotes = !TypeMap.isNumericType(typeCode) &&
!defaultValueStr.startsWith("TO_DATE(") &&
!defaultValueStr.startsWith("SYS");
    
Thanks for the help!
Rob K


Thomas Dudziak wrote:
> 
> 
> Could you post a XML schema that exhibits this problem, and the SQL
> that DdlUtils generates ? It would also be nice if you could file an
> issue in JIRA for this.
> 
> Tom
> 
> 

-- 
View this message in context: http://www.nabble.com/Default-Value-of-SYSDATE-not-set-in-Oracle-TIMESTAMP-column-tf4619496.html#a13454092
Sent from the Apache DdlUtils - User mailing list archive at Nabble.com.


Mime
View raw message