* [ 1668720 ] Convert failing in alter table
This commit is contained in:
parent
fa9bf55dba
commit
f68c37b45f
|
@ -1636,9 +1636,13 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
|
||||||
begin_col = sqlStatement.toUpperCase().indexOf(" MODIFY ")
|
begin_col = sqlStatement.toUpperCase().indexOf(" MODIFY ")
|
||||||
+ action.length();
|
+ action.length();
|
||||||
} else if (sqlStatement.toUpperCase().indexOf(" ADD ") > 0) {
|
} else if (sqlStatement.toUpperCase().indexOf(" ADD ") > 0) {
|
||||||
action = " ADD ";
|
if (sqlStatement.toUpperCase().indexOf(" ADD CONSTRAINT ") < 0 &&
|
||||||
begin_col = sqlStatement.toUpperCase().indexOf(" ADD ")
|
sqlStatement.toUpperCase().indexOf(" ADD FOREIGN KEY " ) < 0 )
|
||||||
+ action.length();
|
{
|
||||||
|
action = " ADD ";
|
||||||
|
begin_col = sqlStatement.toUpperCase().indexOf(" ADD ")
|
||||||
|
+ action.length();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println( "MODIFY :" +
|
// System.out.println( "MODIFY :" +
|
||||||
|
@ -1667,15 +1671,20 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
|
||||||
// begin_col + "en column:" + end_col );
|
// begin_col + "en column:" + end_col );
|
||||||
// System.out.println(" type " + sqlStatement.substring(end_col
|
// System.out.println(" type " + sqlStatement.substring(end_col
|
||||||
// + 1));
|
// + 1));
|
||||||
type = sqlStatement.substring(end_col + 1) + " ";
|
String rest = sqlStatement.substring(end_col + 1);
|
||||||
// System.out.println(" type 1 :" + type);
|
|
||||||
type = type.substring(0, type.indexOf(' '));
|
|
||||||
// System.out.println(" type:" + type);
|
|
||||||
if (action.equals(" ADD "))
|
if (action.equals(" ADD "))
|
||||||
DDL = sqlStatement
|
DDL = sqlStatement
|
||||||
.substring(0, begin_col - action.length())
|
.substring(0, begin_col - action.length())
|
||||||
+ action + "COLUMN " + column + " " + type + "; ";
|
+ action + "COLUMN " + column + " " + rest;
|
||||||
else if (action.equals(" MODIFY "))
|
else if (action.equals(" MODIFY "))
|
||||||
|
{
|
||||||
|
int typeEnd = rest.indexOf(' ');
|
||||||
|
// System.out.println(" type 1 :" + type);
|
||||||
|
type = rest.substring(0, 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 "
|
||||||
|
@ -1684,40 +1693,40 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
|
||||||
+ type
|
+ type
|
||||||
+ "; ";
|
+ "; ";
|
||||||
|
|
||||||
if (sqlStatement.toUpperCase().indexOf(" DEFAULT ") != -1) {
|
if (rest.toUpperCase().indexOf(" DEFAULT ") != -1) {
|
||||||
begin_default = sqlStatement.toUpperCase().indexOf(
|
begin_default = rest.toUpperCase().indexOf(
|
||||||
" DEFAULT ") + 9;
|
" DEFAULT ") + 9;
|
||||||
defaultvalue = sqlStatement.substring(begin_default);
|
defaultvalue = rest.substring(begin_default);
|
||||||
int nextspace = defaultvalue.indexOf(' ');
|
int nextspace = defaultvalue.indexOf(' ');
|
||||||
String rest = null;
|
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(' '));
|
}
|
||||||
|
|
||||||
|
if (defaultvalue.equalsIgnoreCase("NULL")) {
|
||||||
|
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.indexOf(" NOT NULL ") == 0)
|
||||||
|
DDL += sqlStatement.substring(0, begin_col)
|
||||||
|
+ " ALTER COLUMN " + column + " SET " + rest
|
||||||
|
+ ";";
|
||||||
|
// return DDL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defaultvalue.equalsIgnoreCase("NULL")) {
|
// System.out.println("DDL" + DDL);
|
||||||
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.indexOf(" NOT NULL ") == 0)
|
|
||||||
DDL += sqlStatement.substring(0, begin_col)
|
|
||||||
+ " ALTER COLUMN " + column + " SET " + rest
|
|
||||||
+ ";";
|
|
||||||
// return DDL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println("DDL" + DDL);
|
|
||||||
return DDL;
|
return DDL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,18 @@ public final class Convert_PostgreSQLTest {
|
||||||
String sqe;
|
String sqe;
|
||||||
String[] r;
|
String[] r;
|
||||||
|
|
||||||
|
//[ 1668720 ] Convert failing in alter table
|
||||||
|
sql = "ALTER TABLE GT_TaxBase ADD CONSTRAINT GT_TaxBase_Key PRIMARY KEY (GT_TaxBase_ID)";
|
||||||
|
sqe = "ALTER TABLE GT_TaxBase ADD CONSTRAINT GT_TaxBase_Key PRIMARY KEY (GT_TaxBase_ID)";
|
||||||
|
r = convert.convert(sql);
|
||||||
|
verify(sql, r, sqe);
|
||||||
|
|
||||||
|
//[ 1668720 ] Convert failing in alter table
|
||||||
|
sql = "ALTER TABLE GT_TaxBase ADD GT_TaxBase_ID NUMBER(10) NOT NULL";
|
||||||
|
sqe = "ALTER TABLE GT_TaxBase ADD COLUMN GT_TaxBase_ID NUMERIC(10) NOT NULL";
|
||||||
|
r = convert.convert(sql);
|
||||||
|
verify(sql, r, sqe);
|
||||||
|
|
||||||
//[ 1662983 ] Convert cutting backslash from string
|
//[ 1662983 ] Convert cutting backslash from string
|
||||||
sql = "SELECT 'C:\\Documentos\\Test' FROM DUAL";
|
sql = "SELECT 'C:\\Documentos\\Test' FROM DUAL";
|
||||||
sqe = "SELECT E'C:\\\\Documentos\\\\Test'";
|
sqe = "SELECT E'C:\\\\Documentos\\\\Test'";
|
||||||
|
|
Loading…
Reference in New Issue