* Fixed add column with default value failed - reported by Tim during testing of 2pack import of Libero.

This commit is contained in:
Heng Sin Low 2007-07-02 03:32:51 +00:00
parent d6b1908660
commit 9a929f1dc6
2 changed files with 55 additions and 12 deletions

View File

@ -941,11 +941,56 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
// + 1)); // + 1));
String rest = sqlStatement.substring(end_col + 1); String rest = sqlStatement.substring(end_col + 1);
if (action.equals(" ADD ")) if (action.equals(" ADD ")) {
DDL = sqlStatement if (rest.toUpperCase().indexOf(" DEFAULT ") != -1) {
String beforeDefault = rest.substring(0, rest.toUpperCase().indexOf(" DEFAULT "));
begin_default = rest.toUpperCase().indexOf(
" DEFAULT ") + 9;
defaultvalue = rest.substring(begin_default);
int nextspace = defaultvalue.indexOf(' ');
if (nextspace > -1) {
rest = defaultvalue.substring(nextspace);
defaultvalue = defaultvalue.substring(0, defaultvalue.indexOf(' '));
} else {
rest = "";
}
if (defaultvalue.equalsIgnoreCase("NULL")) {
DDL = sqlStatement.substring(0, begin_col
- action.length())
+ " ADD COLUMN "
+ column
+ " " + beforeDefault.trim()
+ " DEFAULT "
+ defaultvalue.trim() + " " + rest.trim();
} 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())
+ " ADD COLUMN "
+ column
+ " " + beforeDefault.trim()
+ " DEFAULT "
+ defaultvalue.trim() + " " + rest.trim();
}
else
{
DDL = sqlStatement.substring(0, begin_col
- action.length())
+ " ADD COLUMN "
+ column
+ " " + beforeDefault.trim()
+ " DEFAULT '"
+ defaultvalue.trim() + "' " + rest.trim();
}
}
} else {
DDL = sqlStatement
.substring(0, begin_col - action.length()) .substring(0, begin_col - action.length())
+ action + "COLUMN " + column + " " + rest; + action + "COLUMN " + column + " " + rest.trim();
else if (action.equals(" MODIFY ")) }
} else if (action.equals(" MODIFY "))
{ {
rest = rest.trim(); rest = rest.trim();
if (rest.toUpperCase().startsWith("NOT ") || rest.toUpperCase().startsWith("NULL ")) if (rest.toUpperCase().startsWith("NOT ") || rest.toUpperCase().startsWith("NULL "))
@ -958,14 +1003,6 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
type = rest.substring(0, typeEnd).trim(); type = rest.substring(0, typeEnd).trim();
rest = rest.substring(typeEnd); rest = rest.substring(typeEnd);
} }
/*
DDL = sqlStatement
.substring(0, begin_col - action.length())
+ " ALTER COLUMN "
+ column
+ " TYPE "
+ type
+ "; ";*/
if (rest.toUpperCase().indexOf(" DEFAULT ") != -1) { if (rest.toUpperCase().indexOf(" DEFAULT ") != -1) {
begin_default = rest.toUpperCase().indexOf( begin_default = rest.toUpperCase().indexOf(

View File

@ -72,6 +72,12 @@ public final class Convert_PostgreSQLTest extends TestCase{
sqe = "insert into t_alter_column values('lpi_publication','AD_Client_ID','NUMERIC(10)',null,'NULL')"; sqe = "insert into t_alter_column values('lpi_publication','AD_Client_ID','NUMERIC(10)',null,'NULL')";
r = convert.convert(sql); r = convert.convert(sql);
assertEquals(sqe, r[0]); assertEquals(sqe, r[0]);
//add column with default fail in libero 2pack import
sql = "ALTER TABLE XX ADD A VARCHAR2(10) DEFAULT --";
sqe = "ALTER TABLE XX ADD COLUMN A VARCHAR(10) DEFAULT '--'";
r = convert.convert(sql);
assertEquals(sqe, r[0].trim());
} }
// Convert.recoverQuotedStrings() error on strings with "<-->" - teo_sarca [ 1705768 ] // Convert.recoverQuotedStrings() error on strings with "<-->" - teo_sarca [ 1705768 ]