IDEMPIERE-4179 Add quote column name support to AdempiereDatabase
interface
This commit is contained in:
parent
41711e3437
commit
8445b0cb3d
|
@ -353,6 +353,15 @@ public interface AdempiereDatabase
|
||||||
*/
|
*/
|
||||||
public String intersectClauseForCSV(String columnName, String csv);
|
public String intersectClauseForCSV(String columnName, String csv);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Quote column name if necessary (usually to avoid conflict with reserved keywords)
|
||||||
|
* @param columnName
|
||||||
|
* @return columnName or quoted columnName
|
||||||
|
*/
|
||||||
|
public default String quoteColumnName(String columnName) {
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return true if using native dialect, false if using oracle dialect
|
* @return true if using native dialect, false if using oracle dialect
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.adempiere.exceptions.AdempiereException;
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
|
import org.compiere.util.DB;
|
||||||
|
|
||||||
|
|
||||||
public class MViewComponent extends X_AD_ViewComponent {
|
public class MViewComponent extends X_AD_ViewComponent {
|
||||||
|
@ -143,9 +144,9 @@ public class MViewComponent extends X_AD_ViewComponent {
|
||||||
colSQL = "NULL";
|
colSQL = "NULL";
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(colSQL);
|
sb.append(DB.getDatabase().quoteColumnName(colSQL));
|
||||||
if (!colName.equals("*"))
|
if (!colName.equals("*"))
|
||||||
sb.append(" AS ").append(colName);
|
sb.append(" AS ").append(DB.getDatabase().quoteColumnName(colName));
|
||||||
}
|
}
|
||||||
|
|
||||||
sb.append(" ").append(getFromClause());
|
sb.append(" ").append(getFromClause());
|
||||||
|
|
|
@ -1323,7 +1323,12 @@ public abstract class PO
|
||||||
{
|
{
|
||||||
if (i != 0)
|
if (i != 0)
|
||||||
sql.append(",");
|
sql.append(",");
|
||||||
sql.append(p_info.getColumnSQL(i)); // Normal and Virtual Column
|
String columnSQL = p_info.getColumnSQL(i);
|
||||||
|
if (!p_info.isVirtualColumn(i))
|
||||||
|
{
|
||||||
|
columnSQL = DB.getDatabase().quoteColumnName(columnSQL);
|
||||||
|
}
|
||||||
|
sql.append(columnSQL); // Normal and Virtual Column
|
||||||
}
|
}
|
||||||
sql.append(" FROM ").append(p_info.getTableName())
|
sql.append(" FROM ").append(p_info.getTableName())
|
||||||
.append(" WHERE ")
|
.append(" WHERE ")
|
||||||
|
@ -2545,7 +2550,7 @@ public abstract class PO
|
||||||
if (changes)
|
if (changes)
|
||||||
sql.append(", ");
|
sql.append(", ");
|
||||||
changes = true;
|
changes = true;
|
||||||
sql.append(columnName).append("=");
|
sql.append(DB.getDatabase().quoteColumnName(columnName)).append("=");
|
||||||
|
|
||||||
if (withValues)
|
if (withValues)
|
||||||
{
|
{
|
||||||
|
@ -2888,7 +2893,7 @@ public abstract class PO
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
doComma = true;
|
doComma = true;
|
||||||
sqlInsert.append(p_info.getColumnName(i));
|
sqlInsert.append(DB.getDatabase().quoteColumnName(p_info.getColumnName(i)));
|
||||||
//
|
//
|
||||||
// Based on class of definition, not class of value
|
// Based on class of definition, not class of value
|
||||||
Class<?> c = p_info.getColumnClass(i);
|
Class<?> c = p_info.getColumnClass(i);
|
||||||
|
|
|
@ -814,6 +814,8 @@ public class POInfo implements Serializable
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
sql.append(",");
|
sql.append(",");
|
||||||
String columnSQL = getColumnSQL(i);
|
String columnSQL = getColumnSQL(i);
|
||||||
|
if (!virtual)
|
||||||
|
columnSQL = DB.getDatabase().quoteColumnName(columnSQL);
|
||||||
if (fullyQualified && !virtual)
|
if (fullyQualified && !virtual)
|
||||||
sql.append(getTableName()).append(".");
|
sql.append(getTableName()).append(".");
|
||||||
sql.append(columnSQL); // Normal and Virtual Column
|
sql.append(columnSQL); // Normal and Virtual Column
|
||||||
|
|
|
@ -35,6 +35,8 @@ import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -135,6 +137,8 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
||||||
|
|
||||||
private Random rand = new Random();
|
private Random rand = new Random();
|
||||||
|
|
||||||
|
private static final List<String> reservedKeywords = Arrays.asList("limit","action","old","new");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Database Name
|
* Get Database Name
|
||||||
* @return database short name
|
* @return database short name
|
||||||
|
@ -1175,6 +1179,22 @@ public class DB_PostgreSQL implements AdempiereDatabase
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String quoteColumnName(String columnName) {
|
||||||
|
if (!isNativeMode()) {
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
|
||||||
|
String lowerCase = columnName.toLowerCase();
|
||||||
|
if (reservedKeywords.contains(lowerCase)) {
|
||||||
|
StringBuilder sql = new StringBuilder("\"");
|
||||||
|
sql.append(lowerCase).append("\"");
|
||||||
|
return sql.toString();
|
||||||
|
} else {
|
||||||
|
return columnName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String intersectClauseForCSV(String columnName, String csv) {
|
public String intersectClauseForCSV(String columnName, String csv) {
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
Loading…
Reference in New Issue