[ 1746898 ] Error DB_PostgreSQL.convertStatement with ''

This commit is contained in:
Heng Sin Low 2007-07-03 03:49:51 +00:00
parent ae6380c79f
commit 8094eec76e
2 changed files with 21 additions and 43 deletions

View File

@ -88,6 +88,8 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
else if (isCreate && cmpString.indexOf(" VIEW ") != -1)
;
else if (cmpString.indexOf("ALTER TABLE") != -1) {
statement = recoverQuotedStrings(statement, retVars);
retVars.clear();
statement = convertDDL(convertComplexStatement(statement));
/*
} else if (cmpString.indexOf("ROWNUM") != -1) {
@ -103,7 +105,8 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
} else {
statement = convertComplexStatement(convertAlias(statement));
}
statement = recoverQuotedStrings(statement, retVars);
if (retVars.size() > 0)
statement = recoverQuotedStrings(statement, retVars);
result.add(statement);
return result;
@ -993,7 +996,8 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
} else if (action.equals(" MODIFY "))
{
rest = rest.trim();
if (rest.toUpperCase().startsWith("NOT ") || rest.toUpperCase().startsWith("NULL "))
if (rest.toUpperCase().startsWith("NOT ") || rest.toUpperCase().startsWith("NULL ")
|| rest.toUpperCase().equals("NULL") || rest.toUpperCase().equals("NOT NULL"))
{
type = null;
}
@ -1016,60 +1020,24 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
rest = "";
}
// Check if default value is already quoted
defaultvalue = defaultvalue.trim();
if(defaultvalue.startsWith("'") && defaultvalue.endsWith("'"))
defaultvalue = defaultvalue.substring(1, defaultvalue.length() - 1);
/*
if (defaultvalue.equalsIgnoreCase("NULL")) {
DDL += sqlStatement.substring(0, begin_col
- action.length())
+ " ALTER COLUMN "
+ column
+ " SET DEFAULT "
+ defaultvalue + "; ";
} else {
// Check if default value is already quoted, no need to double quote
if(defaultvalue.startsWith("'") && defaultvalue.endsWith("'"))
{
DDL += sqlStatement.substring(0, begin_col
- action.length())
+ " ALTER COLUMN "
+ column
+ " SET DEFAULT "
+ defaultvalue + "; ";
}
else
{
DDL += sqlStatement.substring(0, begin_col
- action.length())
+ " ALTER COLUMN "
+ column
+ " SET DEFAULT '"
+ defaultvalue + "'; ";
}
}*/
if (rest != null && rest.toUpperCase().indexOf("NOT NULL") >= 0)
nullclause = "NOT NULL";
else if (rest != null && rest.toUpperCase().indexOf("NULL") >= 0)
nullclause = "NULL";
/*
DDL += sqlStatement.substring(0, begin_col - action.length())
+ " ALTER COLUMN " + column + " SET " + rest.trim()
+ ";";*/
// return DDL;
}
else if ( rest != null && rest.toUpperCase().indexOf("NOT NULL") >= 0 ) {
nullclause = "NOT NULL";
/*
DDL += sqlStatement.substring(0, begin_col - action.length())
+ " ALTER COLUMN " + column + " SET " + rest.trim()
+ ";";*/
}
else if ( rest != null && rest.toUpperCase().indexOf("NULL") >= 0) {
nullclause = "NULL";
/*
DDL += sqlStatement.substring(0, begin_col - action.length())
+ " ALTER COLUMN " + column + " DROP NOT NULL"
+ ";";*/
}
DDL = "insert into t_alter_column values('";

View File

@ -84,6 +84,16 @@ public final class Convert_PostgreSQLTest extends TestCase{
sqe = "insert into t_alter_column values('sometablename','someColumnName','VARCHAR(64)',null,null)";
r = convert.convert(sql);
assertEquals(sqe, r[0].trim());
sql = "ALTER TABLE S_Resource MODIFY IsActive CHAR(1) DEFAULT 'Y'";
sqe = "insert into t_alter_column values('s_resource','IsActive','CHAR(1)',null,'Y')";
r = convert.convert(sql);
assertEquals(sqe, r[0].trim());
sql = "ALTER TABLE PP_Order_NodeNext MODIFY PP_Order_NodeNext_ID NULL";
sqe = "insert into t_alter_column values('pp_order_nodenext','PP_Order_NodeNext_ID',null,'NULL',null)";
r = convert.convert(sql);
assertEquals(sqe, r[0].trim());
}
// Convert.recoverQuotedStrings() error on strings with "<-->" - teo_sarca [ 1705768 ]