[Libreoffice-commits] core.git: Branch 'aoo/trunk' - connectivity/java
Damjan Jovanovic
damjan at apache.org
Wed Sep 20 00:09:44 UTC 2017
connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumn.java | 6 -
connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java | 38 ++++++----
connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/descriptors/SdbcxColumnDescriptor.java | 6 -
3 files changed, 31 insertions(+), 19 deletions(-)
New commits:
commit 268b9efd71b0c1799f7d76bb10962c6904768679
Author: Damjan Jovanovic <damjan at apache.org>
Date: Tue Sep 19 23:31:29 2017 +0000
When an unknown column is passed to ColumnContainer, which it will be when
a new column is created, re-read it from the database.
Strings in UNO can't be null. Ensure this is the case in Column and
SdbcxColumnDescriptor.
Patch by: me
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumn.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumn.java
index aad4d3182f83..4149c1b2c55e 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumn.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumn.java
@@ -40,9 +40,9 @@ public class OColumn extends ODescriptor implements XNamed, XDataDescriptorFacto
"com.sun.star.sdbcx.Column"
};
- private String typeName;
- private String description;
- private String defaultValue;
+ private String typeName = "";
+ private String description = "";
+ private String defaultValue = "";
private int isNullable;
private int precision;
private int scale;
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
index 5ac10788385b..67f0162f2755 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/OColumnContainer.java
@@ -79,6 +79,23 @@ public class OColumnContainer extends OContainer {
boolean isAutoIncrement = false;
boolean isCurrency = false;
int dataType = DataType.OTHER;
+
+ ColumnDescription columnDescription = columnDescriptions.get(name);
+ if (columnDescription == null) {
+ // could be a recently added column. Refresh:
+ List<ColumnDescription> newColumns = new SqlTableHelper().readColumns(metadata, table.catalogName, table.schemaName, table.getName());
+ for (ColumnDescription newColumnDescription : newColumns) {
+ if (newColumnDescription.columnName.equals(name)) {
+ columnDescriptions.put(name, newColumnDescription);
+ break;
+ }
+ }
+ columnDescription = columnDescriptions.get(name);
+ }
+ if (columnDescription == null) {
+ throw new SQLException("No column " + name + " found");
+ }
+
ExtraColumnInfo columnInfo = extraColumnInfo.get(name);
if (columnInfo == null) {
String composedName = DbTools.composeTableNameForSelect(metadata.getConnection(), table);
@@ -91,20 +108,15 @@ public class OColumnContainer extends OContainer {
isCurrency = columnInfo.isCurrency;
dataType = columnInfo.dataType;
}
- ColumnDescription columnDescription = columnDescriptions.get(name);
- if (columnDescription != null) {
- XNameAccess primaryKeyColumns = DbTools.getPrimaryKeyColumns(UnoRuntime.queryInterface(XPropertySet.class, table));
- int nullable = columnDescription.nullable;
- if (nullable != ColumnValue.NO_NULLS && primaryKeyColumns != null && primaryKeyColumns.hasByName(name)) {
- nullable = ColumnValue.NO_NULLS;
- }
- return new OColumn(name, columnDescription.typeName, columnDescription.defaultValue, columnDescription.remarks,
- nullable, columnDescription.columnSize, columnDescription.decimalDigits, columnDescription.type,
- isAutoIncrement, false, isCurrency, isCaseSensitive());
- } else {
- // FIXME: do something like the C++ implementation does?
- throw new SQLException();
+
+ XNameAccess primaryKeyColumns = DbTools.getPrimaryKeyColumns(UnoRuntime.queryInterface(XPropertySet.class, table));
+ int nullable = columnDescription.nullable;
+ if (nullable != ColumnValue.NO_NULLS && primaryKeyColumns != null && primaryKeyColumns.hasByName(name)) {
+ nullable = ColumnValue.NO_NULLS;
}
+ return new OColumn(name, columnDescription.typeName, columnDescription.defaultValue, columnDescription.remarks,
+ nullable, columnDescription.columnSize, columnDescription.decimalDigits, columnDescription.type,
+ isAutoIncrement, false, isCurrency, isCaseSensitive());
}
@Override
diff --git a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/descriptors/SdbcxColumnDescriptor.java b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/descriptors/SdbcxColumnDescriptor.java
index ebf87ab98a35..3b540041652e 100644
--- a/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/descriptors/SdbcxColumnDescriptor.java
+++ b/connectivity/java/sdbc_postgresql/src/com/sun/star/sdbcx/comp/postgresql/sdbcx/descriptors/SdbcxColumnDescriptor.java
@@ -34,14 +34,14 @@ public class SdbcxColumnDescriptor extends ODescriptor implements XServiceInfo {
};
protected int type;
- protected String typeName;
+ protected String typeName = "";
protected int precision;
protected int scale;
protected int isNullable;
protected boolean isAutoIncrement;
protected boolean isRowVersion;
- protected String description;
- protected String defaultValue;
+ protected String description = "";
+ protected String defaultValue = "";
protected boolean isCurrency;
public SdbcxColumnDescriptor(boolean isCaseSensitive) {
More information about the Libreoffice-commits
mailing list