[ 1707540 ] Dependency problem when modifying AD Columns and Sync.

This commit is contained in:
Heng Sin Low 2007-04-30 15:47:10 +00:00
parent c1d74f01e0
commit 95e8919c4e
2 changed files with 64 additions and 18 deletions

View File

@ -967,6 +967,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
String column = null; String column = null;
String type = null; String type = null;
String defaultvalue = null; String defaultvalue = null;
String nullclause = null;
String DDL = null; String DDL = null;
if (begin_col != -1) { if (begin_col != -1) {
@ -984,20 +985,26 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
.substring(0, begin_col - action.length()) .substring(0, begin_col - action.length())
+ action + "COLUMN " + column + " " + rest; + action + "COLUMN " + column + " " + rest;
else if (action.equals(" MODIFY ")) else if (action.equals(" MODIFY "))
{
rest = rest.trim();
if (rest.toUpperCase().startsWith("NOT ") || rest.toUpperCase().startsWith("NULL "))
{
type = null;
}
else
{ {
int typeEnd = rest.indexOf(' '); int typeEnd = rest.indexOf(' ');
// System.out.println(" type 1 :" + type); type = rest.substring(0, typeEnd).trim();
type = rest.substring(0, typeEnd);
rest = rest.substring(typeEnd); rest = rest.substring(typeEnd);
// System.out.println(" type:" + type); }
/*
DDL = sqlStatement DDL = sqlStatement
.substring(0, begin_col - action.length()) .substring(0, begin_col - action.length())
+ " ALTER COLUMN " + " ALTER COLUMN "
+ column + column
+ " TYPE " + " TYPE "
+ type + type
+ "; "; + "; ";*/
if (rest.toUpperCase().indexOf(" DEFAULT ") != -1) { if (rest.toUpperCase().indexOf(" DEFAULT ") != -1) {
begin_default = rest.toUpperCase().indexOf( begin_default = rest.toUpperCase().indexOf(
@ -1007,8 +1014,13 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
if (nextspace > -1) { if (nextspace > -1) {
rest = defaultvalue.substring(nextspace); rest = defaultvalue.substring(nextspace);
defaultvalue = defaultvalue.substring(0, defaultvalue.indexOf(' ')); defaultvalue = defaultvalue.substring(0, defaultvalue.indexOf(' '));
} else {
rest = "";
} }
// Check if default value is already quoted
if(defaultvalue.startsWith("'") && defaultvalue.endsWith("'"))
defaultvalue = defaultvalue.substring(1, defaultvalue.length() - 1);
/*
if (defaultvalue.equalsIgnoreCase("NULL")) { if (defaultvalue.equalsIgnoreCase("NULL")) {
DDL += sqlStatement.substring(0, begin_col DDL += sqlStatement.substring(0, begin_col
- action.length()) - action.length())
@ -1036,25 +1048,50 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
+ " SET DEFAULT '" + " SET DEFAULT '"
+ defaultvalue + "'; "; + defaultvalue + "'; ";
} }
} }*/
if (rest != null && rest.toUpperCase().indexOf("NOT NULL") >= 0) 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()) DDL += sqlStatement.substring(0, begin_col - action.length())
+ " ALTER COLUMN " + column + " SET " + rest.trim() + " ALTER COLUMN " + column + " SET " + rest.trim()
+ ";"; + ";";*/
// return DDL; // return DDL;
} }
else if ( rest.toUpperCase().indexOf("NOT NULL") >= 0 ) { else if ( rest != null && rest.toUpperCase().indexOf("NOT NULL") >= 0 ) {
nullclause = "NOT NULL";
/*
DDL += sqlStatement.substring(0, begin_col - action.length()) DDL += sqlStatement.substring(0, begin_col - action.length())
+ " ALTER COLUMN " + column + " SET " + rest.trim() + " ALTER COLUMN " + column + " SET " + rest.trim()
+ ";"; + ";";*/
} }
else if ( rest.toUpperCase().indexOf("NULL") >= 0) { else if ( rest != null && rest.toUpperCase().indexOf("NULL") >= 0) {
nullclause = "NULL";
/*
DDL += sqlStatement.substring(0, begin_col - action.length()) DDL += sqlStatement.substring(0, begin_col - action.length())
+ " ALTER COLUMN " + column + " DROP NOT NULL" + " ALTER COLUMN " + column + " DROP NOT NULL"
+ ";"; + ";";*/
} }
// System.out.println("DDL" + DDL); DDL = "insert into t_alter_column values('";
String tableName = sqlStatement.substring(0, begin_col - action.length());
tableName = tableName.toUpperCase().replaceAll("ALTER TABLE", "");
tableName = tableName.trim().toLowerCase();
DDL = DDL + tableName + "','" + column + "',";
if (type != null)
DDL = DDL + "'" + type +"',";
else
DDL = DDL + "null,";
if (nullclause != null)
DDL = DDL + "'" + nullclause + "',";
else
DDL = DDL + "null,";
if (defaultvalue != null)
DDL = DDL + "'" + defaultvalue + "'";
else
DDL = DDL + "null";
DDL = DDL + ")";
} }
return DDL; return DDL;
} }

View File

@ -44,14 +44,22 @@ public final class Convert_PostgreSQLTest {
r = convert.convert(sql); r = convert.convert(sql);
verify(sql, r, sqe); verify(sql, r, sqe);
//[ 1707540 ] Dependency problem when modifying AD Columns and Sync.
//[ 1707611 ] Column synchronization for mandatory columns doesn't work //[ 1707611 ] Column synchronization for mandatory columns doesn't work
sql = "ALTER TABLE Test MODIFY T_Integer NUMBER(10) NOT NULL"; sql = "ALTER TABLE Test MODIFY T_Integer NUMBER(10) NOT NULL";
sqe = "ALTER TABLE Test ALTER COLUMN T_Integer TYPE NUMERIC(10); ALTER TABLE Test ALTER COLUMN T_Integer SET NOT NULL;"; //sqe = "ALTER TABLE Test ALTER COLUMN T_Integer TYPE NUMERIC(10); ALTER TABLE Test ALTER COLUMN T_Integer SET NOT NULL;";
sqe = "insert into t_alter_column values('test','T_Integer','NUMERIC(10)','NOT NULL',null)";
r = convert.convert(sql); r = convert.convert(sql);
verify(sql, r, sqe); verify(sql, r, sqe);
sql = "ALTER TABLE Test MODIFY T_Integer NUMBER(10) NULL"; sql = "ALTER TABLE Test MODIFY T_Integer NUMBER(10) NULL";
sqe = "ALTER TABLE Test ALTER COLUMN T_Integer TYPE NUMERIC(10); ALTER TABLE Test ALTER COLUMN T_Integer DROP NOT NULL;"; //sqe = "ALTER TABLE Test ALTER COLUMN T_Integer TYPE NUMERIC(10); ALTER TABLE Test ALTER COLUMN T_Integer DROP NOT NULL;";
sqe = "insert into t_alter_column values('test','T_Integer','NUMERIC(10)','NULL',null)";
r = convert.convert(sql);
verify(sql, r, sqe);
sql = "ALTER TABLE Test MODIFY T_Integer NOT NULL";
sqe = "insert into t_alter_column values('test','T_Integer',null,'NOT NULL',null)";
r = convert.convert(sql); r = convert.convert(sql);
verify(sql, r, sqe); verify(sql, r, sqe);
@ -94,7 +102,8 @@ public final class Convert_PostgreSQLTest {
// Line 407 of ImportProduct.java // Line 407 of ImportProduct.java
sql = "ALTER TABLE LPI_Publication MODIFY AD_Client_ID NUMERIC(10) DEFAULT NULL"; sql = "ALTER TABLE LPI_Publication MODIFY AD_Client_ID NUMERIC(10) DEFAULT NULL";
sqe = "ALTER TABLE LPI_Publication ALTER COLUMN AD_Client_ID TYPE NUMERIC(10); ALTER TABLE LPI_Publication ALTER COLUMN AD_Client_ID SET DEFAULT NULL; "; //sqe = "ALTER TABLE LPI_Publication ALTER COLUMN AD_Client_ID TYPE NUMERIC(10); ALTER TABLE LPI_Publication ALTER COLUMN AD_Client_ID SET DEFAULT 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);
verify(sql, r, sqe); verify(sql, r, sqe);