[ http://issues.apache.org/jira/browse/DDLUTILS-73?page=all ]

Thomas Dudziak updated DDLUTILS-73:
-----------------------------------

    Component: Core - PostgreSql

> SQL syntax bug in PostgreSQL 8.1 for ALTER COLUMN
> -------------------------------------------------
>
>          Key: DDLUTILS-73
>          URL: http://issues.apache.org/jira/browse/DDLUTILS-73
>      Project: DdlUtils
>         Type: Bug

>   Components: Core - PostgreSql
>  Environment: PostgreSQL 8.1
>     Reporter: Vignesh Swaminathan
>     Assignee: Thomas Dudziak

>
> The following code has to be added to PostgreSQLBuilder class to make it work 
> for altering columns in PostgreSQL
> /**
>      * Generates the alter statement to add or modify a single column on a 
> table.
>      *
>      * @param table       The table the index is on
>      * @param column      The column to drop
>      * @param isNewColumn Whether the column should be added
>      */
>     public void writeColumnAlterStmt(Table table, Column column, boolean 
> isNewColumn) throws IOException
>     {
>         writeTableAlterStmt(table);
>         print(isNewColumn ? "ADD " : "ALTER ");
>         if(isNewColumn) 
>               writeColumn(table, column); 
>               else
>                       writeAlterColumn(table, column);
>         printEndOfStatement();
>     }
>     
>     /** 
>      * Outputs the DDL for the specified column.
>      * 
>      * @param table  The table containing the column
>      * @param column The column
>      */
>     protected void writeAlterColumn(Table table, Column column) throws 
> IOException
>     {
>         //see comments in columnsDiffer about null/"" defaults
>         printIdentifier(getColumnName(column));
>         print(" TYPE ");
>         print(getSqlType(column));
>         if ((column.getDefaultValue() != null) ||
>             (getPlatformInfo().isIdentitySpecUsesDefaultValue() && 
> column.isAutoIncrement()))
>         {
>             if (!getPlatformInfo().isSupportingDefaultValuesForLongTypes() && 
>                 ((column.getTypeCode() == Types.LONGVARBINARY) || 
> (column.getTypeCode() == Types.LONGVARCHAR)))
>             {
>                 throw new DynaSqlException("The platform does not support 
> default values for LONGVARCHAR or LONGVARBINARY columns");
>             }
>             print(" DEFAULT ");
>             writeColumnDefaultValue(table, column);
>         }
>         if (column.isRequired())
>         {
>             print(" ");
>             writeColumnNotNullableStmt();
>         }
>         else if (getPlatformInfo().isRequiringNullAsDefaultValue() &&
>                  getPlatformInfo().hasNullDefault(column.getTypeCode()))
>         {
>             print(" ");
>             writeColumnNullableStmt();
>         }
>         if (column.isAutoIncrement() && 
> !getPlatformInfo().isIdentitySpecUsesDefaultValue())
>         {
>             if (!getPlatformInfo().isSupportingNonPKIdentityColumns() && 
> !column.isPrimaryKey())
>             {
>                 throw new DynaSqlException("Column "+column.getName()+" in 
> table "+table.getName()+" is auto-incrementing but not a primary key column, 
> which is not supported by the platform");
>             }
>             print(" ");
>             writeColumnAutoIncrementStmt(table, column);
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira

Reply via email to