Fixed bug id 1645823 - String index out of range -1 translating ALTER TABLE
This commit is contained in:
parent
b2d61c3067
commit
fe4456a8ef
|
@ -1605,7 +1605,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
|
|||
String action = null;
|
||||
int begin_col = -1;
|
||||
if (sqlStatement.toUpperCase().indexOf(" MODIFY ") > 0) {
|
||||
action = " ALTER ";
|
||||
action = " MODIFY ";
|
||||
begin_col = sqlStatement.toUpperCase().indexOf(" MODIFY ")
|
||||
+ action.length();
|
||||
} else if (sqlStatement.toUpperCase().indexOf(" ADD ") > 0) {
|
||||
|
@ -1648,11 +1648,10 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
|
|||
DDL = sqlStatement
|
||||
.substring(0, begin_col - action.length())
|
||||
+ action + "COLUMN " + column + " " + type + "; ";
|
||||
else if (action.equals(" ALTER "))
|
||||
else if (action.equals(" MODIFY "))
|
||||
DDL = sqlStatement
|
||||
.substring(0, begin_col - action.length())
|
||||
+ action
|
||||
+ "COLUMN "
|
||||
+ " ALTER COLUMN "
|
||||
+ column
|
||||
+ " TYPE "
|
||||
+ type
|
||||
|
@ -1662,17 +1661,28 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
|
|||
begin_default = sqlStatement.toUpperCase().indexOf(
|
||||
" DEFAULT ") + 9;
|
||||
defaultvalue = sqlStatement.substring(begin_default);
|
||||
String rest = defaultvalue.substring(defaultvalue
|
||||
.indexOf(" "));
|
||||
defaultvalue = defaultvalue.substring(0, defaultvalue
|
||||
.indexOf(" "));
|
||||
int nextspace = defaultvalue.indexOf(" ");
|
||||
String rest = null;
|
||||
if (nextspace > -1) {
|
||||
rest = defaultvalue.substring(nextspace);
|
||||
defaultvalue = defaultvalue.substring(0, defaultvalue.indexOf(" "));
|
||||
}
|
||||
|
||||
DDL += sqlStatement.substring(0, begin_col
|
||||
- action.length())
|
||||
+ " ALTER COLUMN "
|
||||
+ column
|
||||
+ " SET DEFAULT '"
|
||||
+ defaultvalue + "'; ";
|
||||
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
|
||||
|
|
|
@ -30,6 +30,14 @@ public final class Convert_PostgreSQLTest {
|
|||
|
||||
// Line 407 of ImportProduct.java
|
||||
|
||||
sql = "ALTER TABLE LPI_Publication MODIFY AD_Client_ID NUMERIC(10) DEFAULT NULL";
|
||||
sqe = "ALTER TABLE LPI_Publication MODIFY COLUMN AD_Client_ID TYPE NUMERIC(10); ALTER TABLE LPI_Publication ALTER COLUMN AD_Client_ID SET DEFAULT 'NULL'; ";
|
||||
|
||||
r = convert.convert(sql);
|
||||
verify(sql, r, sqe);
|
||||
|
||||
// Line 407 of ImportProduct.java
|
||||
|
||||
sql = "UPDATE M_PRODUCT SET (Value,Name,Description,DocumentNote,Help,UPC,SKU,C_UOM_ID,M_Product_Category_ID,Classification,ProductType,Volume,Weight,ShelfWidth,ShelfHeight,ShelfDepth,UnitsPerPallet,Discontinued,DiscontinuedBy,Updated,UpdatedBy)= (SELECT Value,Name,Description,DocumentNote,Help,UPC,SKU,C_UOM_ID,M_Product_Category_ID,Classification,ProductType,Volume,Weight,ShelfWidth,ShelfHeight,ShelfDepth,UnitsPerPallet,Discontinued,DiscontinuedBy,SysDate,UpdatedBy FROM I_Product WHERE I_Product_ID=?) WHERE M_Product_ID=?";
|
||||
sqe = "UPDATE M_PRODUCT SET Value=I_Product.Value,Name=I_Product.Name,Description=I_Product.Description,DocumentNote=I_Product.DocumentNote,Help=I_Product.Help,UPC=I_Product.UPC,SKU=I_Product.SKU,C_UOM_ID=I_Product.C_UOM_ID,M_Product_Category_ID=I_Product.M_Product_Category_ID,Classification=I_Product.Classification,ProductType=I_Product.ProductType,Volume=I_Product.Volume,Weight=I_Product.Weight,ShelfWidth=I_Product.ShelfWidth,ShelfHeight=I_Product.ShelfHeight,ShelfDepth=I_Product.ShelfDepth,UnitsPerPallet=I_Product.UnitsPerPallet,Discontinued=I_Product.Discontinued,DiscontinuedBy=I_Product.DiscontinuedBy,Updated=CURRENT_TIMESTAMP,UpdatedBy=I_Product.UpdatedBy FROM I_Product WHERE I_Product.I_Product_ID=? AND M_PRODUCT.M_Product_ID=?";
|
||||
|
||||
|
|
Loading…
Reference in New Issue