Author: damjan
Date: Thu Nov  9 02:13:13 2017
New Revision: 1814693

URL: http://svn.apache.org/viewvc?rev=1814693&view=rev
Log:
UNO hates null strings, and the C++ implementation of the SDBC-JDBC bridge
was converting nulls to empty strings, so do the same.

Fix parsing strings into UNO timestamps.

Dispose of all undisposed statements when the JDBC connection is disposed.

Patch by: me


Modified:
    
openoffice/trunk/main/connectivity/java/dbtools/src/org/apache/openoffice/comp/sdbc/dbtools/util/DBTypeConversion.java
    
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLCallableStatement.java
    
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLConnection.java
    
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLDatabaseMetaData.java
    
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSet.java
    
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSetMetaData.java

Modified: 
openoffice/trunk/main/connectivity/java/dbtools/src/org/apache/openoffice/comp/sdbc/dbtools/util/DBTypeConversion.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/dbtools/src/org/apache/openoffice/comp/sdbc/dbtools/util/DBTypeConversion.java?rev=1814693&r1=1814692&r2=1814693&view=diff
==============================================================================
--- 
openoffice/trunk/main/connectivity/java/dbtools/src/org/apache/openoffice/comp/sdbc/dbtools/util/DBTypeConversion.java
 (original)
+++ 
openoffice/trunk/main/connectivity/java/dbtools/src/org/apache/openoffice/comp/sdbc/dbtools/util/DBTypeConversion.java
 Thu Nov  9 02:13:13 2017
@@ -406,7 +406,9 @@ public class DBTypeConversion {
             if (dot >= 0) {
                 nSecond = (short)safeParseInt(secondAndNano.substring(0, dot));
                 String nano = secondAndNano.substring(dot + 1);
-                nano = nano.substring(0, 2);
+                if (nano.length() > 2) {
+                    nano = nano.substring(0, 2);
+                }
                 nano = nano + "00".substring(0, 2 - nano.length());
                 nHundredthSeconds = (short)safeParseInt(nano);
             } else {

Modified: 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLCallableStatement.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLCallableStatement.java?rev=1814693&r1=1814692&r2=1814693&view=diff
==============================================================================
--- 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLCallableStatement.java
 (original)
+++ 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLCallableStatement.java
 Thu Nov  9 02:13:13 2017
@@ -120,7 +120,7 @@ public class JavaSQLCallableStatement ex
             if (jdbcDate != null) {
                 return DBTypeConversion.toDate(jdbcDate.toString());
             } else {
-                return null;
+                return new Date();
             }
         } catch (java.sql.SQLException exception) {
             throw Tools.toUnoException(this, exception);
@@ -270,7 +270,12 @@ public class JavaSQLCallableStatement ex
     public synchronized String getString(int columnIndex) throws SQLException {
         createStatement();
         try {
-            return 
((java.sql.CallableStatement)jdbcStatement).getString(columnIndex);
+            String string = 
((java.sql.CallableStatement)jdbcStatement).getString(columnIndex);
+            if (string != null) {
+                return string;
+            } else {
+                return "";
+            }
         } catch (java.sql.SQLException exception) {
             throw Tools.toUnoException(this, exception);
         }

Modified: 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLConnection.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLConnection.java?rev=1814693&r1=1814692&r2=1814693&view=diff
==============================================================================
--- 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLConnection.java
 (original)
+++ 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLConnection.java
 Thu Nov  9 02:13:13 2017
@@ -20,8 +20,11 @@
  *************************************************************/
 package com.sun.star.comp.sdbc;
 
+import java.util.Iterator;
 import java.util.Properties;
+import java.util.Set;
 
+import org.apache.openoffice.comp.sdbc.dbtools.comphelper.CompHelper;
 import org.apache.openoffice.comp.sdbc.dbtools.util.AutoRetrievingBase;
 import org.apache.openoffice.comp.sdbc.dbtools.util.Resources;
 import org.apache.openoffice.comp.sdbc.dbtools.util.SharedResources;
@@ -85,6 +88,11 @@ public class JavaSQLConnection extends C
     protected synchronized void postDisposing() {
         logger.log(LogLevel.INFO, Resources.STR_LOG_SHUTDOWN_CONNECTION);
         try {
+            for (Iterator<?> it = statements.keySet().iterator(); 
it.hasNext();) {
+                JavaSQLStatementBase statement = (JavaSQLStatementBase) 
it.next();
+                it.remove();
+                CompHelper.disposeComponent(statement);
+            }
             if (connection != null) {
                 connection.close();
             }
@@ -187,7 +195,12 @@ public class JavaSQLConnection extends C
     public synchronized String getCatalog() throws SQLException {
         checkDisposed();
         try {
-            return connection.getCatalog();
+            String catalog = connection.getCatalog();
+            if (catalog != null) {
+                return catalog;
+            } else {
+                return "";
+            }
         } catch (java.sql.SQLException sqlException) {
             throw Tools.toUnoException(this, sqlException);
         }
@@ -243,6 +256,10 @@ public class JavaSQLConnection extends C
         checkDisposed();
         try {
             String ret = connection.nativeSQL(sql);
+            if (ret == null) {
+                // UNO hates null strings
+                ret = "";
+            }
             logger.log(LogLevel.FINER, Resources.STR_LOG_NATIVE_SQL, sql, ret);
             return ret;
         } catch (java.sql.SQLException sqlException) {

Modified: 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLDatabaseMetaData.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLDatabaseMetaData.java?rev=1814693&r1=1814692&r2=1814693&view=diff
==============================================================================
--- 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLDatabaseMetaData.java
 (original)
+++ 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLDatabaseMetaData.java
 Thu Nov  9 02:13:13 2017
@@ -93,7 +93,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getCatalogSeparator() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getCatalogSeparator();
+            String catalogSeparator = 
jdbcDatabaseMetaData.getCatalogSeparator();
+            if (catalogSeparator == null) {
+                catalogSeparator = "";
+            }
+            return catalogSeparator;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -705,7 +709,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getCatalogTerm() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getCatalogTerm();
+            String catalogTerm = jdbcDatabaseMetaData.getCatalogTerm();
+            if (catalogTerm == null) {
+                catalogTerm = "";
+            }
+            return catalogTerm;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -714,7 +722,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getIdentifierQuoteString() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getIdentifierQuoteString();
+            String identifierQuoteString = 
jdbcDatabaseMetaData.getIdentifierQuoteString();
+            if (identifierQuoteString == null) {
+                identifierQuoteString = "";
+            }
+            return identifierQuoteString;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -723,7 +735,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getExtraNameCharacters() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getExtraNameCharacters();
+            String extraNameCharacters = 
jdbcDatabaseMetaData.getExtraNameCharacters();
+            if (extraNameCharacters == null) {
+                extraNameCharacters = "";
+            }
+            return extraNameCharacters;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1340,7 +1356,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getUserName() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getUserName();
+            String username = jdbcDatabaseMetaData.getUserName();
+            if (username == null) {
+                username = "";
+            }
+            return username;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1349,7 +1369,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getDriverName() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getDriverName();
+            String driverName = jdbcDatabaseMetaData.getDriverName();
+            if (driverName == null) {
+                driverName = "";
+            }
+            return driverName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1358,7 +1382,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getDriverVersion() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getDriverVersion();
+            String driverVersion = jdbcDatabaseMetaData.getDriverVersion();
+            if (driverVersion == null) {
+                driverVersion = "";
+            }
+            return driverVersion;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1367,7 +1395,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getDatabaseProductVersion() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getDatabaseProductVersion();
+            String databaseProductVersion = 
jdbcDatabaseMetaData.getDatabaseProductVersion();
+            if (databaseProductVersion == null) {
+                databaseProductVersion = "";
+            }
+            return databaseProductVersion;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1376,7 +1408,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getDatabaseProductName() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getDatabaseProductName();
+            String databaseProductName = 
jdbcDatabaseMetaData.getDatabaseProductName();
+            if (databaseProductName == null) {
+                databaseProductName = "";
+            }
+            return databaseProductName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1385,7 +1421,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getProcedureTerm() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getProcedureTerm();
+            String procedureTerm = jdbcDatabaseMetaData.getProcedureTerm();
+            if (procedureTerm == null) {
+                procedureTerm = "";
+            }
+            return procedureTerm;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1394,7 +1434,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getSchemaTerm() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getSchemaTerm();
+            String schemaTerm = jdbcDatabaseMetaData.getSchemaTerm();
+            if (schemaTerm == null) {
+                schemaTerm = "";
+            }
+            return schemaTerm;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1422,7 +1466,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getSQLKeywords() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getSQLKeywords();
+            String sqlKeywords = jdbcDatabaseMetaData.getSQLKeywords();
+            if (sqlKeywords == null) {
+                sqlKeywords = "";
+            }
+            return sqlKeywords;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1431,7 +1479,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getSearchStringEscape() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getSearchStringEscape();
+            String searchStringEscape = 
jdbcDatabaseMetaData.getSearchStringEscape();
+            if (searchStringEscape == null) {
+                searchStringEscape = "";
+            }
+            return searchStringEscape;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1440,7 +1492,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getStringFunctions() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getStringFunctions();
+            String stringFunctions = jdbcDatabaseMetaData.getStringFunctions();
+            if (stringFunctions == null) {
+                stringFunctions = "";
+            }
+            return stringFunctions;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1449,7 +1505,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getTimeDateFunctions() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getTimeDateFunctions();
+            String timeDateFunctions = 
jdbcDatabaseMetaData.getTimeDateFunctions();
+            if (timeDateFunctions == null) {
+                timeDateFunctions = "";
+            }
+            return timeDateFunctions;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1458,7 +1518,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getSystemFunctions() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getSystemFunctions();
+            String systemFunctions = jdbcDatabaseMetaData.getSystemFunctions();
+            if (systemFunctions == null) {
+                systemFunctions = "";
+            }
+            return systemFunctions;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -1467,7 +1531,11 @@ public class JavaSQLDatabaseMetaData ext
     @Override
     public String getNumericFunctions() throws SQLException {
         try {
-            return jdbcDatabaseMetaData.getNumericFunctions();
+            String numericFunctions = 
jdbcDatabaseMetaData.getNumericFunctions();
+            if (numericFunctions == null) {
+                numericFunctions = "";
+            }
+            return numericFunctions;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }

Modified: 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSet.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSet.java?rev=1814693&r1=1814692&r2=1814693&view=diff
==============================================================================
--- 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSet.java
 (original)
+++ 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSet.java
 Thu Nov  9 02:13:13 2017
@@ -196,7 +196,11 @@ public class JavaSQLResultSet extends Pr
     
     private String getCursorName() throws WrappedTargetException {
         try {
-            return jdbcResultSet.getCursorName();
+            String cursorName = jdbcResultSet.getCursorName();
+            if (cursorName == null) {
+                cursorName = "";
+            }
+            return cursorName;
         } catch (java.sql.SQLException exception) {
             throw new WrappedTargetException("SQL error", this, 
Tools.toUnoException(this, exception));
         }

Modified: 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSetMetaData.java
URL: 
http://svn.apache.org/viewvc/openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSetMetaData.java?rev=1814693&r1=1814692&r2=1814693&view=diff
==============================================================================
--- 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSetMetaData.java
 (original)
+++ 
openoffice/trunk/main/connectivity/java/sdbc_jdbc/src/com/sun/star/comp/sdbc/JavaSQLResultSetMetaData.java
 Thu Nov  9 02:13:13 2017
@@ -77,7 +77,11 @@ public class JavaSQLResultSetMetaData ex
     @Override
     public String getSchemaName(int column) throws SQLException {
         try {
-            return jdbcResultSetMetaData.getSchemaName(column);
+            String schemaName = jdbcResultSetMetaData.getSchemaName(column);
+            if (schemaName == null) {
+                schemaName = "";
+            }
+            return schemaName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -86,7 +90,11 @@ public class JavaSQLResultSetMetaData ex
     @Override
     public String getColumnName(int column) throws SQLException {
         try {
-            return jdbcResultSetMetaData.getColumnName(column);
+            String columnName = jdbcResultSetMetaData.getColumnName(column);
+            if (columnName == null) {
+                columnName = "";
+            }
+            return columnName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -95,7 +103,11 @@ public class JavaSQLResultSetMetaData ex
     @Override
     public String getTableName(int column) throws SQLException {
         try {
-            return jdbcResultSetMetaData.getTableName(column);
+            String tableName = jdbcResultSetMetaData.getTableName(column);
+            if (tableName == null) {
+                tableName = "";
+            }
+            return tableName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -104,7 +116,11 @@ public class JavaSQLResultSetMetaData ex
     @Override
     public String getCatalogName(int column) throws SQLException {
         try {
-            return jdbcResultSetMetaData.getCatalogName(column);
+            String catalogName = jdbcResultSetMetaData.getCatalogName(column);
+            if (catalogName == null) {
+                catalogName = "";
+            }
+            return catalogName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -113,7 +129,11 @@ public class JavaSQLResultSetMetaData ex
     @Override
     public String getColumnTypeName(int column) throws SQLException {
         try {
-            return jdbcResultSetMetaData.getColumnTypeName(column);
+            String columnTypeName = 
jdbcResultSetMetaData.getColumnTypeName(column);
+            if (columnTypeName == null) {
+                columnTypeName = "";
+            }
+            return columnTypeName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -122,7 +142,11 @@ public class JavaSQLResultSetMetaData ex
     @Override
     public String getColumnLabel(int column) throws SQLException {
         try {
-            return jdbcResultSetMetaData.getColumnLabel(column);
+            String columnLabel = jdbcResultSetMetaData.getColumnLabel(column);
+            if (columnLabel == null) {
+                columnLabel = "";
+            }
+            return columnLabel;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }
@@ -131,7 +155,11 @@ public class JavaSQLResultSetMetaData ex
     @Override
     public String getColumnServiceName(int column) throws SQLException {
         try {
-            return jdbcResultSetMetaData.getColumnClassName(column);
+            String columnServiceName = 
jdbcResultSetMetaData.getColumnClassName(column);
+            if (columnServiceName == null) {
+                columnServiceName = "";
+            }
+            return columnServiceName;
         } catch (java.sql.SQLException jdbcSQLException) {
             throw Tools.toUnoException(this, jdbcSQLException);
         }


Reply via email to