Kaydet (Commit) 159dd286 authored tarafından Tamas Bunth's avatar Tamas Bunth Kaydeden (comit) Tamás Bunth

dbaccess: Enable hsql migration by default

Also make Firebird driver not experimental anymore.

With hsql migration enabled, the hsqldb related unit tests can be
reused, because the underlying DBMS is transparent. To achieve that, I
added firebird_sdbc component to hsqldb CppunitTest_* files.

This commit also contains fixes for upcoming bugs while migrating from
hsqldb to firebird, shown by hsqldb related unit tests:

- null values: in case of null values, the setNull method should be used
  instead of nothing. (malformed string otherwise)

Remove DBACCESS_HSQL_MIGRATION environment variable, since migration is
default from now on.

JunitTest_dbaccess_complex was based on HSQLDB. This commit replaces
"if exists" hsql specific solution with firebird specific. Also disable
test for queries with named parameters.

Change-Id: Ieb68f5ad3a11389599c4f268ea4df82a83643b82
Reviewed-on: https://gerrit.libreoffice.org/52008Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarTamás Bunth <btomi96@gmail.com>
üst 1a9bfdd8
......@@ -32,6 +32,7 @@ $(eval $(call gb_Jar_add_sourcefiles,ConnectivityTools,\
connectivity/qa/connectivity/tools/DatabaseAccess \
connectivity/qa/connectivity/tools/DataSource \
connectivity/qa/connectivity/tools/DbaseDatabase \
connectivity/qa/connectivity/tools/FirebirdDatabase \
connectivity/qa/connectivity/tools/FlatFileDatabase \
connectivity/qa/connectivity/tools/HsqlColumnDescriptor \
connectivity/qa/connectivity/tools/HsqlDatabase \
......
......@@ -43,7 +43,7 @@ public class CRMDatabase
private static final String INTEGER = "INTEGER";
private static final String VARCHAR50 = "VARCHAR(50)";
private final XMultiServiceFactory m_orb;
private final HsqlDatabase m_database;
private final FirebirdDatabase m_database;
private final Connection m_connection;
/** constructs the CRM database
......@@ -52,7 +52,7 @@ public class CRMDatabase
{
m_orb = _orb;
m_database = new HsqlDatabase( m_orb );
m_database = new FirebirdDatabase( m_orb );
if ( _withUI )
{
......@@ -81,14 +81,14 @@ public class CRMDatabase
{
m_orb = _orb;
m_database = new HsqlDatabase( m_orb, _existingDocumentURL );
m_database = new FirebirdDatabase( m_orb, _existingDocumentURL );
m_connection = m_database.defaultConnection();
}
/** returns the database document underlying the CRM database
*/
public final HsqlDatabase getDatabase()
public final FirebirdDatabase getDatabase()
{
return m_database;
}
......@@ -141,7 +141,7 @@ public class CRMDatabase
new HsqlColumnDescriptor( "ID",INTEGER, HsqlColumnDescriptor.PRIMARY ),
new HsqlColumnDescriptor( "Name",VARCHAR50),
new HsqlColumnDescriptor( "Description", "VARCHAR(1024)" ),
new HsqlColumnDescriptor( "Image", "LONGVARBINARY" ) } );
new HsqlColumnDescriptor( "Image", "BLOB SUB_TYPE -9546" ) } );
m_database.createTable( table, true );
m_database.executeSQL( "INSERT INTO \"categories\" ( \"ID\", \"Name\" ) VALUES ( 1, 'Food' )" );
......@@ -166,7 +166,7 @@ public class CRMDatabase
new HsqlColumnDescriptor( "Address",VARCHAR50),
new HsqlColumnDescriptor( "City",VARCHAR50),
new HsqlColumnDescriptor( "Postal",VARCHAR50),
new HsqlColumnDescriptor( "Comment","LONGVARCHAR")} );
new HsqlColumnDescriptor( "Comment","BLOB SUB_TYPE 1")} );
m_database.createTable( table, true );
m_database.executeSQL( "INSERT INTO \"customers\" VALUES(1,'Food, Inc.','Down Under','Melbourne','509','Preferred') " );
......@@ -182,8 +182,8 @@ public class CRMDatabase
new HsqlColumnDescriptor( "ShipDate", "DATE" ) } );
m_database.createTable( table, true );
m_database.executeSQL( "INSERT INTO \"orders\" (\"ID\", \"CustomerID\", \"OrderDate\") VALUES(1, 1, {D '2009-01-01'})" );
m_database.executeSQL( "INSERT INTO \"orders\" VALUES(2, 2, {D '2009-01-01'}, {D '2009-01-23'})" );
m_database.executeSQL( "INSERT INTO \"orders\" (\"ID\", \"CustomerID\", \"OrderDate\") VALUES(1, 1, DATE '2009-01-01')" );
m_database.executeSQL( "INSERT INTO \"orders\" VALUES(2, 2, DATE '2009-01-01', DATE '2009-01-23')" );
table = new HsqlTableDescriptor( "orders_details",
new HsqlColumnDescriptor[] {
......
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
package connectivity.tools;
import com.sun.star.beans.PropertyValue;
import com.sun.star.beans.PropertyState;
import com.sun.star.beans.XPropertySet;
import com.sun.star.container.ElementExistException;
import com.sun.star.frame.XStorable;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.sdb.XOfficeDatabaseDocument;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbcx.XAppend;
import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.uno.UnoRuntime;
import helper.URLHelper;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import org.junit.Assert;
public class FirebirdDatabase extends AbstractDatabase
{
public FirebirdDatabase(final XMultiServiceFactory orb) throws Exception
{
super(orb);
createDBDocument();
}
public FirebirdDatabase(final XMultiServiceFactory orb, final String _existingDocumentURL) throws Exception
{
super(orb, _existingDocumentURL);
}
/** creates an empty database document in a temporary location
*/
private void createDBDocument() throws Exception
{
Assert.assertNull(m_documentFile);
m_documentFile = File.createTempFile("testdb", ".odb");
if ( m_documentFile.exists() )
m_documentFile.delete();
m_databaseDocumentFile = URLHelper.getFileURLFromSystemPath(m_documentFile);
m_databaseDocument = UnoRuntime.queryInterface(
XOfficeDatabaseDocument.class, m_orb.createInstance("com.sun.star.sdb.OfficeDatabaseDocument"));
m_dataSource = new DataSource(m_databaseDocument.getDataSource());
final XPropertySet dsProperties = UnoRuntime.queryInterface(XPropertySet.class, m_databaseDocument.getDataSource());
dsProperties.setPropertyValue("URL", "sdbc:embedded:hsqldb");
final XStorable storable = UnoRuntime.queryInterface(XStorable.class, m_databaseDocument);
storable.storeAsURL( m_databaseDocumentFile, new PropertyValue[]
{ new PropertyValue( "PickListEntry", 0, false, PropertyState.DIRECT_VALUE )
} );
}
@Override protected final void delete() {
if (m_documentFile != null) {
boolean ok = m_documentFile.delete();
//TODO: fails on Windows: Assert.assertTrue("delete " + m_documentFile.getPath(), ok);
}
}
/** drops the table with a given name
@param _name
the name of the table to drop
*/
private void dropTable(final String _name) throws SQLException
{
final StringBuffer dropStatement = new StringBuffer("EXECUTE BLOCK AS BEGIN"
+ " if (exists(select 1 from rdb$relations where rdb$relation_name ='");
dropStatement.append(_name);
dropStatement.append("')) then execute statement 'DROP TABLE ");
dropStatement.append(_name);
dropStatement.append("'; END");
executeSQL(dropStatement.toString());
}
public void createTable(final HsqlTableDescriptor _tableDesc, final boolean _dropIfExists) throws SQLException
{
if (_dropIfExists)
{
dropTable(_tableDesc.getName());
}
createTable(_tableDesc);
}
/** creates a table
*/
public void createTable(final HsqlTableDescriptor _tableDesc) throws SQLException
{
StringBuffer createStatement = new StringBuffer("CREATE TABLE \"");
createStatement.append(_tableDesc.getName());
createStatement.append("\" ( ");
String primaryKeyList = "";
final HashMap<String, String> foreignKeys = new HashMap<String, String>();
final HashMap<String, String> foreignKeyRefs = new HashMap<String, String>();
final HsqlColumnDescriptor[] columns = _tableDesc.getColumns();
for (int i = 0; i < columns.length; ++i)
{
if (i > 0)
{
createStatement.append(", ");
}
createStatement.append("\"").append(columns[i].getName());
createStatement.append("\" ").append(columns[i].getTypeName());
if (columns[i].isRequired())
{
createStatement.append(" NOT NULL");
}
if (columns[i].isPrimaryKey())
{
if (primaryKeyList.length() > 0)
{
primaryKeyList += ", ";
}
primaryKeyList += "\"" + columns[i].getName() + "\"";
}
if (columns[i].isForeignKey())
{
final String foreignTable = columns[i].getForeignTable();
String foreignKeysForTable = foreignKeys.containsKey(foreignTable) ? foreignKeys.get(foreignTable) : "";
if (foreignKeysForTable.length() > 0)
{
foreignKeysForTable += ", ";
}
foreignKeysForTable += "\"" + columns[i].getName() + "\"";
foreignKeys.put(foreignTable, foreignKeysForTable);
final StringBuffer foreignKeyRefsForTable = new StringBuffer(foreignKeyRefs.containsKey(foreignTable) ? foreignKeyRefs.get(foreignTable) : "");
if (foreignKeyRefsForTable.length() > 0)
{
foreignKeyRefsForTable.append(", ");
}
foreignKeyRefsForTable.append("\"").append(columns[i].getForeignColumn()).append("\"");
foreignKeyRefs.put(foreignTable, foreignKeyRefsForTable.toString());
}
}
if (primaryKeyList.length() > 0)
{
createStatement.append(", PRIMARY KEY (");
createStatement.append(primaryKeyList);
createStatement.append(')');
}
for (Map.Entry<String, String> foreignKey : foreignKeys.entrySet())
{
final String foreignTable = foreignKey.getKey();
createStatement.append(", FOREIGN KEY (");
createStatement.append(foreignKey.getValue());
createStatement.append(") REFERENCES \"");
createStatement.append(foreignTable);
createStatement.append("\"(");
createStatement.append(foreignKeyRefs.get(foreignTable));
createStatement.append(')');
}
createStatement.append(')');
executeSQL(createStatement.toString());
}
/** creates a table in the database. using the SDBCX-API
*/
public void createTableInSDBCX(final HsqlTableDescriptor _tableDesc) throws SQLException, ElementExistException
{
final XPropertySet sdbcxDescriptor = _tableDesc.createSdbcxDescriptor(defaultConnection());
final XTablesSupplier suppTables = UnoRuntime.queryInterface( XTablesSupplier.class, defaultConnection().getXConnection() );
final XAppend appendTable = UnoRuntime.queryInterface( XAppend.class, suppTables.getTables() );
appendTable.appendByDescriptor(sdbcxDescriptor);
}
private File m_documentFile;
}
......@@ -29,7 +29,6 @@
#include <osl/file.hxx>
#include <osl/process.h>
#include <rtl/bootstrap.hxx>
#include <svtools/miscopt.hxx>
#include <unotools/localfilehelper.hxx>
using namespace com::sun::star;
......@@ -191,10 +190,7 @@ Reference< XConnection > SAL_CALL FirebirdDriver::connect(
sal_Bool SAL_CALL FirebirdDriver::acceptsURL( const OUString& url )
{
SvtMiscOptions aMiscOptions;
return aMiscOptions.IsExperimentalMode() &&
(url == "sdbc:embedded:firebird" || url.startsWith("sdbc:firebird:"));
return (url == "sdbc:embedded:firebird" || url.startsWith("sdbc:firebird:"));
}
Sequence< DriverPropertyInfo > SAL_CALL FirebirdDriver::getPropertyInfo(
......
......@@ -834,6 +834,7 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex,
}
else if( dType == SQL_VARYING )
{
setParameterNull(nParameterIndex, false);
const sal_Int32 nMaxSize = 0xFFFF;
Sequence<sal_Int8> xBytesCopy(xBytes);
// First 2 bytes indicate string size
......@@ -848,6 +849,7 @@ void SAL_CALL OPreparedStatement::setBytes(sal_Int32 nParameterIndex,
}
else if( dType == SQL_TEXT )
{
setParameterNull(nParameterIndex, false);
memcpy(pVar->sqldata, xBytes.getConstArray(), xBytes.getLength() );
// Fill remainder with spaces
memset(pVar->sqldata + xBytes.getLength(), 0, pVar->sqllen - xBytes.getLength());
......
......@@ -433,6 +433,8 @@ sal_Int32 OStatementCommonBase::getStatementChangeCount()
case isc_info_sql_stmt_delete:
aDesiredInfoType = isc_info_req_delete_count;
break;
case isc_info_sql_stmt_exec_procedure:
return 0; // cannot determine
default:
throw SQLException(); // TODO: better error message?
}
......
......@@ -71,6 +71,7 @@ $(eval $(call gb_CppunitTest_use_components,dbaccess_RowSetClones,\
basic/util/sb \
comphelper/util/comphelp \
configmgr/source/configmgr \
connectivity/source/drivers/firebird/firebird_sdbc \
connectivity/source/drivers/hsqldb/hsqldb \
connectivity/source/drivers/jdbc/jdbc \
connectivity/source/manager/sdbc2 \
......
......@@ -22,6 +22,7 @@ $(eval $(call gb_CppunitTest_use_libraries,dbaccess_hsqldb_test, \
cppuhelper \
dbaxml \
dbtools \
firebird_sdbc \
jvmfwk \
sal \
subsequenttest \
......@@ -48,6 +49,7 @@ $(eval $(call gb_CppunitTest_use_components,dbaccess_hsqldb_test,\
comphelper/util/comphelp \
configmgr/source/configmgr \
connectivity/source/cpool/dbpool2 \
connectivity/source/drivers/firebird/firebird_sdbc \
connectivity/source/drivers/hsqldb/hsqldb \
connectivity/source/drivers/jdbc/jdbc \
connectivity/source/manager/sdbc2 \
......
......@@ -48,7 +48,7 @@ $(eval $(call gb_Module_add_check_targets,dbaccess,\
CppunitTest_dbaccess_hsqlschema_import \
))
ifeq ($(ENABLE_JAVA),TRUE)
ifeq ($(ENABLE_FIREBIRD_SDBC),TRUE)
$(eval $(call gb_Module_add_check_targets,dbaccess,\
CppunitTest_dbaccess_hsqldb_test \
CppunitTest_dbaccess_RowSetClones \
......@@ -58,20 +58,23 @@ endif
# This runs a suite of performance tests on embedded firebird and HSQLDB.
# Instructions on running the test can be found in qa/unit/embeddedb_performancetest
ifeq ($(ENABLE_FIREBIRD_SDBC),TRUE)
ifeq ($(ENABLE_JAVA),TRUE)
$(eval $(call gb_Module_add_check_targets,dbaccess,\
CppunitTest_dbaccess_embeddeddb_performancetest \
))
endif
endif
ifeq ($(ENABLE_FIREBIRD_SDBC),TRUE)
$(eval $(call gb_Module_add_subsequentcheck_targets,dbaccess,\
JunitTest_dbaccess_complex \
))
endif
$(eval $(call gb_Module_add_subsequentcheck_targets,dbaccess,\
JunitTest_dbaccess_unoapi \
))
ifneq ($(DISABLE_PYTHON),TRUE)
ifneq ($(ENABLE_JAVA),)
ifneq ($(ENABLE_FIREBIRD_SDBC),)
$(eval $(call gb_Module_add_subsequentcheck_targets,dbaccess,\
PythonTest_dbaccess_python \
))
......
DBACCESS_HSQL_MIGRATION: Migrate embedded HSQLDB database
......@@ -30,7 +30,7 @@ import com.sun.star.sdbcx.XTablesSupplier;
import com.sun.star.uno.Exception;
import com.sun.star.uno.UnoRuntime;
import connectivity.tools.HsqlColumnDescriptor;
import connectivity.tools.HsqlDatabase;
import connectivity.tools.FirebirdDatabase;
import connectivity.tools.HsqlTableDescriptor;
import java.io.IOException;
......@@ -47,7 +47,7 @@ import static org.junit.Assert.*;
public class ApplicationController extends TestCase
{
private HsqlDatabase m_database;
private FirebirdDatabase m_database;
private XOfficeDatabaseDocument m_databaseDocument;
private XDatabaseDocumentUI m_documentUI;
......@@ -76,8 +76,8 @@ public class ApplicationController extends TestCase
// create/load the new database document
m_database = (_documentURL == null)
? new HsqlDatabase(getMSF())
: new HsqlDatabase(getMSF(), _documentURL);
? new FirebirdDatabase(getMSF())
: new FirebirdDatabase(getMSF(), _documentURL);
m_databaseDocument = m_database.getDatabaseDocument();
// load it into a frame
......
......@@ -21,7 +21,7 @@ import com.sun.star.container.XNameAccess;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XNamingService;
import connectivity.tools.CRMDatabase;
import connectivity.tools.HsqlDatabase;
import connectivity.tools.FirebirdDatabase;
// ---------- junit imports -----------------
import org.junit.Test;
......@@ -32,7 +32,7 @@ import static org.junit.Assert.*;
public class DataSource extends TestCase
{
HsqlDatabase m_database;
FirebirdDatabase m_database;
connectivity.tools.DataSource m_dataSource;
......
......@@ -34,7 +34,7 @@ import static org.junit.Assert.*;
public class Query extends TestCase
{
connectivity.tools.HsqlDatabase m_database;
connectivity.tools.FirebirdDatabase m_database;
private void createTestCase()
......
......@@ -41,7 +41,7 @@ import com.sun.star.uno.UnoRuntime;
import connectivity.tools.CRMDatabase;
import connectivity.tools.DataSource;
import connectivity.tools.HsqlDatabase;
import connectivity.tools.FirebirdDatabase;
import connectivity.tools.sdb.Connection;
import java.lang.reflect.Method;
import java.util.Random;
......@@ -59,7 +59,7 @@ public class RowSet extends TestCase
static final int MAX_FETCH_ROWS = 10;
private static final String NEXT = "next";
private static final String TEST21 = "Test21";
HsqlDatabase m_database;
FirebirdDatabase m_database;
DataSource m_dataSource;
XRowSet m_rowSet;
XResultSet m_resultSet;
......@@ -220,8 +220,10 @@ public class RowSet extends TestCase
void createStructure() throws SQLException
{
m_database.executeSQL("DROP TABLE \"TEST1\" IF EXISTS");
m_database.executeSQL("CREATE TABLE \"TEST1\" (\"ID\" integer not null primary key, \"col2\" varchar(50) )");
m_database.executeSQL("EXECUTE BLOCK AS BEGIN"
+ " if (not exists(select 1 from rdb$relations where rdb$relation_name = '\"TEST1\"')) then"
+ " execute statement 'CREATE TABLE \"TEST1\" (\"ID\" integer not null primary key, \"col2\" varchar(50) )';"
+ " END");
final Connection connection = m_database.defaultConnection();
final XPreparedStatement prep = connection.prepareStatement("INSERT INTO \"TEST1\" values (?,?)");
......@@ -931,12 +933,12 @@ public class RowSet extends TestCase
// use an own RowSet instance, not the one which is also used for the other cases
testTableParameters();
testParametrizedQuery();
testParametersInFilter();
//testParametrizedQuery();
//testParametersInFilter();
testParametersAfterNormalExecute();
//testParametersAfterNormalExecute();
testParametersInteraction();
//testParametersInteraction();
}
}
......@@ -30,21 +30,12 @@ public:
void testEmptyDBConnection();
void testIntegerDatabase();
virtual void setUp() override;
CPPUNIT_TEST_SUITE(FirebirdTest);
CPPUNIT_TEST(testEmptyDBConnection);
CPPUNIT_TEST(testIntegerDatabase);
CPPUNIT_TEST_SUITE_END();
};
void FirebirdTest::setUp()
{
DBTestBase::setUp();
SvtMiscOptions aMiscOptions;
aMiscOptions.SetExperimentalMode(true);
}
/**
* Test the loading of an "empty" file, i.e. the embedded database has not yet
* been initialised (as occurs when a new .odb is created and opened by base).
......
......@@ -27,8 +27,6 @@ class HsqlBinaryImportTest : public DBTestBase
public:
void testBinaryImport();
virtual void setUp() override;
CPPUNIT_TEST_SUITE(HsqlBinaryImportTest);
CPPUNIT_TEST(testBinaryImport);
......@@ -36,14 +34,6 @@ public:
CPPUNIT_TEST_SUITE_END();
};
void HsqlBinaryImportTest::setUp()
{
DBTestBase::setUp();
SvtMiscOptions aMiscOptions;
aMiscOptions.SetExperimentalMode(true);
osl_setEnvironment(OUString{ "DBACCESS_HSQL_MIGRATION" }.pData, OUString{ "1" }.pData);
}
void HsqlBinaryImportTest::testBinaryImport()
{
uno::Reference<XOfficeDatabaseDocument> xDocument
......
......@@ -580,6 +580,14 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString
Reference< XConnection > xReturn;
Reference< XDriverManager > xManager;
bool bNeedMigration = false;
if( m_pImpl->m_sConnectURL == "sdbc:embedded:hsqldb")
{
m_pImpl->m_sConnectURL = "sdbc:embedded:firebird";
bNeedMigration = true;
}
try {
xManager.set( ConnectionPool::create( m_pImpl->m_aContext ), UNO_QUERY_THROW );
} catch( const Exception& ) { }
......@@ -598,7 +606,6 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString
}
const char* pExceptionMessageId = RID_STR_COULDNOTCONNECT_UNSPECIFIED;
bool bNeedMigration = false;
if (xManager.is())
{
sal_Int32 nAdditionalArgs(0);
......@@ -621,17 +628,6 @@ Reference< XConnection > ODatabaseSource::buildLowLevelConnection(const OUString
Reference< XDriver > xDriver;
try
{
// check if migration is needed
OUString sMigrEnvValue;
osl_getEnvironment(OUString("DBACCESS_HSQL_MIGRATION").pData,
&sMigrEnvValue.pData);
if( m_pImpl->m_sConnectURL == "sdbc:embedded:hsqldb" &&
!sMigrEnvValue.isEmpty() )
{
// TODO target could be anything else
m_pImpl->m_sConnectURL = "sdbc:embedded:firebird";
bNeedMigration = true;
}
// choose driver
Reference< XDriverAccess > xAccessDrivers( xManager, UNO_QUERY );
......
......@@ -144,7 +144,7 @@ OUString FbCreateStmtParser::compose() const
// TODO autoincremental default value with "START WITH"
if (columnIter->isAutoIncremental())
lcl_appendWithSpace(sSql, "GENERATED BY DEFAULT AS IDENTITY");
lcl_appendWithSpace(sSql, "GENERATED BY DEFAULT AS IDENTITY (START WITH 0)");
else if (!columnIter->isNullable())
lcl_appendWithSpace(sSql, "NOT NULL");
......
......@@ -25,7 +25,7 @@
namespace dbahsql
{
using ColumnTypeVector = std::vector<sal_Int32>;
using ColumnTypeVector = std::vector<ColumnDefinition>;
HsqlBinaryNode::HsqlBinaryNode(sal_Int32 nPos)
: m_nPos(nPos)
......
......@@ -14,6 +14,7 @@
#include <cppuhelper/implbase.hxx>
#include "rowinputbinary.hxx"
#include "columndef.hxx"
namespace dbahsql
{
......@@ -30,7 +31,7 @@ public:
sal_Int32 getLeft() const;
sal_Int32 getRight() const;
std::vector<css::uno::Any> readRow(HsqlRowInputStream& rInput,
const std::vector<sal_Int32>& aColTypes);
const std::vector<ColumnDefinition>& aColTypes);
};
}
......
......@@ -40,7 +40,7 @@ using namespace css::io;
using namespace css::uno;
using namespace css::sdbc;
using ColumnTypeVector = std::vector<sal_Int32>;
using ColumnTypeVector = std::vector<dbahsql::ColumnDefinition>;
using RowVector = std::vector<Any>;
using IndexVector = std::vector<sal_Int32>;
......@@ -48,9 +48,13 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
const ColumnTypeVector& rColTypes)
{
assert(row.size() == rColTypes.size());
size_t nColIndex = 0;
for (size_t i = 0; i < rColTypes.size(); ++i)
{
switch (rColTypes.at(i))
if (!row.at(i).hasValue())
xParam->setNull(i + 1, rColTypes.at(i).getDataType());
switch (rColTypes.at(i).getDataType())
{
case DataType::CHAR:
case DataType::VARCHAR:
......@@ -59,7 +63,7 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
OUString sVal;
if (row.at(i) >>= sVal)
{
xParam->setString(i + 1, sVal);
xParam->setString(nColIndex + 1, sVal);
}
}
break;
......@@ -69,7 +73,7 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
sal_Int16 nVal;
if (row.at(i) >>= nVal)
{
xParam->setShort(i + 1, nVal);
xParam->setShort(nColIndex + 1, nVal);
}
}
break;
......@@ -78,7 +82,7 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
sal_Int32 nVal;
if (row.at(i) >>= nVal)
{
xParam->setInt(i + 1, nVal);
xParam->setInt(nColIndex + 1, nVal);
}
}
break;
......@@ -87,7 +91,7 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
sal_Int64 nVal;
if (row.at(i) >>= nVal)
{
xParam->setLong(i + 1, nVal);
xParam->setLong(nColIndex + 1, nVal);
}
}
break;
......@@ -98,7 +102,7 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
double nVal;
if (row.at(i) >>= nVal)
{
xParam->setDouble(i + 1, nVal);
xParam->setDouble(nColIndex + 1, nVal);
}
}
break;
......@@ -110,7 +114,8 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
{
sal_Int32 nScale = 0;
if (aNumeric[1] >>= nScale)
xParam->setObjectWithInfo(i + 1, aNumeric[0], rColTypes.at(i), nScale);
xParam->setObjectWithInfo(nColIndex + 1, aNumeric[0],
rColTypes.at(i).getDataType(), nScale);
}
}
break;
......@@ -119,7 +124,7 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
css::util::Date date;
if (row.at(i) >>= date)
{
xParam->setDate(i + 1, date);
xParam->setDate(nColIndex + 1, date);
}
}
break;
......@@ -128,7 +133,7 @@ void lcl_setParams(const RowVector& row, Reference<XParameters>& xParam,
css::util::Time time;