[Libreoffice-commits] core.git: 7 commits - connectivity/source
Andrzej J.R. Hunt
andrzej at ahunt.org
Mon Jul 22 09:08:48 PDT 2013
connectivity/source/drivers/firebird/FConnection.cxx | 19
connectivity/source/drivers/firebird/FDatabaseMetaData.cxx | 64 +-
connectivity/source/drivers/firebird/FPreparedStatement.cxx | 261 +++++++-----
connectivity/source/drivers/firebird/FPreparedStatement.hxx | 19
connectivity/source/drivers/firebird/FResultSetMetaData.cxx | 2
connectivity/source/drivers/firebird/FStatement.cxx | 93 ----
connectivity/source/drivers/firebird/FStatement.hxx | 6
connectivity/source/drivers/firebird/Util.cxx | 69 +++
connectivity/source/drivers/firebird/Util.hxx | 6
9 files changed, 320 insertions(+), 219 deletions(-)
New commits:
commit 86ec35f71d28061a21c00b12c23c41351002a701
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Jul 22 18:05:08 2013 +0200
Fix implicit conversion error (firebird-sdbc).
Change-Id: I67ecd01655bdde73a279926c65f81555e550b7ca
diff --git a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
index c2dde74..35fa88e 100644
--- a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
@@ -705,11 +705,17 @@ sal_Int32 SAL_CALL ODatabaseMetaData::getMaxUserNameLength( ) throw(SQLExceptio
{
return 31;
}
-// -------------------------------------------------------------------------
-sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType( sal_Int32 setType ) throw(SQLException, RuntimeException)
+
+sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetType(sal_Int32 setType)
+ throw(SQLException, RuntimeException)
{
- (void) setType;
- return sal_False;
+ switch (setType)
+ {
+ case ResultSetType::FORWARD_ONLY:
+ return sal_True;
+ default:
+ return sal_False;
+ }
}
// -------------------------------------------------------------------------
sal_Bool SAL_CALL ODatabaseMetaData::supportsResultSetConcurrency( sal_Int32 setType, sal_Int32 concurrency ) throw(SQLException, RuntimeException)
@@ -1038,11 +1044,11 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
// 18. Is nullable
if (xRow->getShort(9))
{
- aCurrentRow.push_back(new ORowSetValueDecorator("NO"));
+ aCurrentRow.push_back(new ORowSetValueDecorator(OUString("NO")));
}
else
{
- aCurrentRow.push_back(new ORowSetValueDecorator("YES"));
+ aCurrentRow.push_back(new ORowSetValueDecorator(OUString("YES")));
}
aResults.push_back(aCurrentRow);
commit 7ae8da726747ce661dcd223b864d819f8b207819
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Jul 22 17:47:38 2013 +0200
Further minor fixes (firebird-sdbc).
Change-Id: I1ed77e7910bd59aa0534ff7fb32d96e3432b58d3
diff --git a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
index bad5ad6..c2dde74 100644
--- a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
@@ -245,7 +245,7 @@ sal_Int32 SAL_CALL ODatabaseMetaData::getMaxIndexLength( ) throw(SQLException,
// -------------------------------------------------------------------------
sal_Bool SAL_CALL ODatabaseMetaData::supportsNonNullableColumns( ) throw(SQLException, RuntimeException)
{
- return sal_False;
+ return sal_True;
}
// -------------------------------------------------------------------------
OUString SAL_CALL ODatabaseMetaData::getIdentifierQuoteString( ) throw(SQLException, RuntimeException)
@@ -921,10 +921,12 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
while( rs->next() )
{
- ODatabaseMetaDataResultSet::ORow aCurrentRow(16);
+ ODatabaseMetaDataResultSet::ORow aCurrentRow(18);
- // 1. TABLE_CAT (catalog) may be null -- thus we omit it.
- // 2. TABLE_SCHEM (schema) may be null -- thus we omit it.
+ // 1. TABLE_CAT (catalog) may be null
+ aCurrentRow.push_back(new ORowSetValueDecorator());
+ // 2. TABLE_SCHEM (schema) may be null
+ aCurrentRow.push_back(new ORowSetValueDecorator());
// 3. TABLE_NAME
{
OUString aTableName = xRow->getString(1);
@@ -989,23 +991,25 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
}
// 12. Comments -- may be omitted
{
+ OUString aDescription;
uno::Reference< XBlob > xDescriptionBlob = xRow->getBlob(3);
if (xDescriptionBlob.is())
{
sal_Int32 aBlobLength = (sal_Int32) xDescriptionBlob->length();
- OUString aDescription = OUString((char*) xDescriptionBlob->getBytes(0, aBlobLength).getArray(),
+ aDescription = OUString((char*) xDescriptionBlob->getBytes(0, aBlobLength).getArray(),
aBlobLength,
RTL_TEXTENCODING_UTF8);
- aCurrentRow.push_back(new ORowSetValueDecorator(aDescription));
}
+ aCurrentRow.push_back(new ORowSetValueDecorator(aDescription));
}
// 13. Default -- may be omitted.
{
uno::Reference< XBlob > xDefaultValueBlob = xRow->getBlob(4);
if (xDefaultValueBlob.is())
{
- // TODO: push to back
+ // TODO: Implement
}
+ aCurrentRow.push_back(new ORowSetValueDecorator());
}
// 14. Unused
aCurrentRow.push_back(new ORowSetValueDecorator());
@@ -1024,10 +1028,12 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
{
aCurrentRow.push_back(new ORowSetValueDecorator(sal_Int32(0)));
}
- // 17. Index in column
+ // 17. Index of column
{
short aColumnNumber = xRow->getShort(5);
- aCurrentRow.push_back(new ORowSetValueDecorator(aColumnNumber));
+ // Firebird stores column numbers beginning with 0 internally
+ // SDBC expects column numbering to begin with 1.
+ aCurrentRow.push_back(new ORowSetValueDecorator(aColumnNumber + 1));
}
// 18. Is nullable
if (xRow->getShort(9))
diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx
index 721a887..c220700 100644
--- a/connectivity/source/drivers/firebird/FStatement.cxx
+++ b/connectivity/source/drivers/firebird/FStatement.cxx
@@ -340,10 +340,10 @@ uno::Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery(const OUStri
return m_xResultSet;
}
-sal_Bool SAL_CALL OStatement_Base::execute(const OUString& sql) throw(SQLException, RuntimeException)
+sal_Bool SAL_CALL OStatement_Base::execute(const OUString& sqlIn) throw(SQLException, RuntimeException)
{
SAL_INFO("connectivity.firebird", "executeQuery(). "
- "Got called with sql: " << sql);
+ "Got called with sql: " << sqlIn);
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
@@ -352,6 +352,7 @@ sal_Bool SAL_CALL OStatement_Base::execute(const OUString& sql) throw(SQLExcepti
isc_stmt_handle aStatementHandle = 0;
int aErr = 0;
+ const OUString sql = sanitizeSqlString(sqlIn);
aErr = prepareAndDescribeStatement(sql,
aStatementHandle,
commit cd30d13c3d99bf8152dffec152fe3eecd6f4d406
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Jul 22 15:36:38 2013 +0200
Join on correct fields for getColumns() (firebird-sdbc)
Change-Id: I2e3f260b0f043806702fb03ff74c1ef6bbe9cc62
diff --git a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
index 2efde9b..bad5ad6 100644
--- a/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
+++ b/connectivity/source/drivers/firebird/FDatabaseMetaData.cxx
@@ -182,7 +182,7 @@ sal_Int32 SAL_CALL ODatabaseMetaData::getMaxStatementLength() throw(SQLException
sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTableNameLength() throw(SQLException, RuntimeException)
{
- return 32;
+ return 31;
}
// -------------------------------------------------------------------------
sal_Int32 SAL_CALL ODatabaseMetaData::getMaxTablesInSelect( ) throw(SQLException, RuntimeException)
@@ -877,32 +877,42 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getColumns(
"fields.RDB$NULL_FLAG " // 9
"FROM RDB$RELATION_FIELDS relfields "
"JOIN RDB$FIELDS fields "
- "on (relfields.RDB$FIELD_NAME = fields.RDB$FIELD_NAME) ");
+ "on (fields.RDB$FIELD_NAME = relfields.RDB$FIELD_SOURCE) ");
+ if (!tableNamePattern.isEmpty() && !columnNamePattern.isEmpty())
+ {
+ queryBuf.append("WHERE ");
+ }
if (!tableNamePattern.isEmpty())
{
OUString sAppend;
if (tableNamePattern.match("%"))
- sAppend = "AND RDB$RELATION_NAME LIKE '%' ";
+ sAppend = "relfields.RDB$RELATION_NAME LIKE '%' ";
else
- sAppend = "AND RDB$RELATION_NAME = '%' ";
+ sAppend = "relfields.RDB$RELATION_NAME = '%' ";
queryBuf.append(sAppend.replaceAll("%", tableNamePattern));
}
if (!columnNamePattern.isEmpty())
{
+ if (!tableNamePattern.isEmpty())
+ queryBuf.append("AND ");
+
OUString sAppend;
if (columnNamePattern.match("%"))
- sAppend = "AND RDB$FIELD_NAME LIKE '%' ";
+ sAppend = "relfields.RDB$FIELD_NAME LIKE '%' ";
else
- sAppend = "AND RDB$FIELD_NAME = '%' ";
+ sAppend = "relfields.RDB$FIELD_NAME = '%' ";
queryBuf.append(sAppend.replaceAll("%", columnNamePattern));
}
OUString query = queryBuf.makeStringAndClear();
+ SAL_INFO("connectivity.firebird", "Retrieving columns with " <<
+ OUStringToOString(query,RTL_TEXTENCODING_UTF8).getStr());
+
uno::Reference< XStatement > statement = m_pConnection->createStatement();
uno::Reference< XResultSet > rs = statement->executeQuery(query.getStr());
uno::Reference< XRow > xRow( rs, UNO_QUERY_THROW );
commit 2d134a5fbc925fa73f32f406d3c268c22d4d92ac
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Jul 22 14:54:39 2013 +0200
sqltype indicates isNullable. (firebird-sdbc)
Change-Id: I1cf454847f7dc83195596b7274f4fa2c434fcc69
diff --git a/connectivity/source/drivers/firebird/FResultSetMetaData.cxx b/connectivity/source/drivers/firebird/FResultSetMetaData.cxx
index 266664e..578a081 100644
--- a/connectivity/source/drivers/firebird/FResultSetMetaData.cxx
+++ b/connectivity/source/drivers/firebird/FResultSetMetaData.cxx
@@ -184,7 +184,7 @@ sal_Int32 SAL_CALL OResultSetMetaData::getScale(sal_Int32 column)
sal_Int32 SAL_CALL OResultSetMetaData::isNullable(sal_Int32 column)
throw(SQLException, RuntimeException)
{
- if (*m_pSqlda->sqlvar[column-1].sqlind & 1)
+ if (m_pSqlda->sqlvar[column-1].sqltype & 1)
return ColumnValue::NULLABLE;
else
return ColumnValue::NO_NULLS;
commit f98a193a187ef72e7b2e81b95c82186bc6912ab6
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Jul 22 14:50:47 2013 +0200
Implement the first parts of FPreparedStatement.
Change-Id: Iad9561fa6b200ce5efcacc4c0b7b822aaaf9adb0
diff --git a/connectivity/source/drivers/firebird/FPreparedStatement.cxx b/connectivity/source/drivers/firebird/FPreparedStatement.cxx
index babde41..b4ab043 100644
--- a/connectivity/source/drivers/firebird/FPreparedStatement.cxx
+++ b/connectivity/source/drivers/firebird/FPreparedStatement.cxx
@@ -33,19 +33,26 @@
*
*************************************************************************/
-#include <stdio.h>
-#include <osl/diagnose.h>
+#include "FConnection.hxx"
#include "FPreparedStatement.hxx"
-#include <com/sun/star/sdbc/DataType.hpp>
#include "FResultSetMetaData.hxx"
#include "FResultSet.hxx"
+#include "Util.hxx"
+
+#include <comphelper/sequence.hxx>
#include <cppuhelper/typeprovider.hxx>
+#include <osl/diagnose.h>
+#include <propertyids.hxx>
+
+#include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
-#include "propertyids.hxx"
-#include <comphelper/sequence.hxx>
-using namespace ::comphelper;
using namespace connectivity::firebird;
+
+using namespace ::comphelper;
+using namespace ::osl;
+
+using namespace com::sun::star;
using namespace com::sun::star::uno;
using namespace com::sun::star::lang;
using namespace com::sun::star::beans;
@@ -67,173 +74,247 @@ OPreparedStatement::OPreparedStatement( OConnection* _pConnection,
const OUString& sql)
:OStatement_BASE2(_pConnection)
,m_aTypeInfo(_TypeInfo)
- ,m_nNumParams(0)
,m_sSqlStatement(sql)
- ,m_bPrepared(sal_False)
+ ,m_statementHandle(0)
+ ,m_pOutSqlda(0)
+ ,m_pInSqlda(0)
{
- SAL_INFO("connectivity.firebird", "OPreparedStatement_BASE(). "
+ SAL_INFO("connectivity.firebird", "OPreparedStatement(). "
"sql: " << sql);
+}
+
+void OPreparedStatement::ensurePrepared()
+ throw (SQLException)
+{
+ MutexGuard aGuard(m_pConnection->getMutex());
+ checkDisposed(OStatement_BASE::rBHelper.bDisposed);
-// prepareQuery(m_sSqlStatement);
- (void) sql;
+ if (m_statementHandle)
+ return;
+
+ ISC_STATUS aErr = 0;
+
+ if (!m_pInSqlda)
+ {
+ m_pInSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(10));
+ m_pInSqlda->version = SQLDA_VERSION1;
+ m_pInSqlda->sqln = 10;
+ } // TODO: free this on closing
+
+ aErr = prepareAndDescribeStatement(m_sSqlStatement,
+ m_statementHandle,
+ m_pOutSqlda,
+ m_pInSqlda);
+ if (aErr)
+ {
+ SAL_WARN("connectivity.firebird", "prepareAndDescribeStatement failed");
+ }
+ else if (m_statementHandle)
+ {
+ isc_dsql_describe_bind(m_statusVector,
+ &m_statementHandle,
+ 1,
+ m_pInSqlda);
+ }
+
+ if (aErr)
+ {
+ SAL_WARN("connectivity.firebird", "isc_dsql_describe_bind failed");
+ }
+ else if (m_pInSqlda->sqld > m_pInSqlda->sqln) // Not large enough
+ {
+ short nItems = m_pInSqlda->sqld;
+ free(m_pInSqlda);
+ m_pInSqlda = (XSQLDA*) malloc(XSQLDA_LENGTH(nItems));
+ m_pInSqlda->version = SQLDA_VERSION1;
+ m_pInSqlda->sqln = nItems;
+ isc_dsql_describe_bind(m_statusVector,
+ &m_statementHandle,
+ 1,
+ m_pInSqlda);
+ }
+// char aItems[] = {
+// isc_info_sql_num_variables
+// };
+// char aResultBuffer[8];
+// isc_dsql_sql_info(m_statusVector,
+// &m_statementHandle,
+// sizeof(aItems),
+// aItems,
+// sizeof(aResultBuffer),
+// aResultBuffer);
+// if (aResultBuffer[0] == isc_info_sql_num_variables)
+// {
+// short aVarLength = (short) isc_vax_integer(aResultBuffer+1, 2);
+// m_nNumParams = isc_vax_integer(aResultBuffer+3, aVarLength);
+// }
+// }
+ mallocSQLVAR(m_pInSqlda);
+ OConnection::evaluateStatusVector(m_statusVector,
+ m_sSqlStatement,
+ *this);
}
-// -----------------------------------------------------------------------------
OPreparedStatement::~OPreparedStatement()
{
}
-// -----------------------------------------------------------------------------
+
void SAL_CALL OPreparedStatement::acquire() throw()
{
OStatement_BASE2::acquire();
}
-// -----------------------------------------------------------------------------
+
void SAL_CALL OPreparedStatement::release() throw()
{
OStatement_BASE2::release();
}
-// -----------------------------------------------------------------------------
-Any SAL_CALL OPreparedStatement::queryInterface( const Type & rType ) throw(RuntimeException)
+
+Any SAL_CALL OPreparedStatement::queryInterface(const Type& rType)
+ throw(RuntimeException)
{
Any aRet = OStatement_BASE2::queryInterface(rType);
if(!aRet.hasValue())
aRet = OPreparedStatement_BASE::queryInterface(rType);
return aRet;
}
-// -------------------------------------------------------------------------
-::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL OPreparedStatement::getTypes( ) throw(::com::sun::star::uno::RuntimeException)
+
+uno::Sequence< Type > SAL_CALL OPreparedStatement::getTypes()
+ throw(RuntimeException)
{
- return concatSequences(OPreparedStatement_BASE::getTypes(),OStatement_BASE2::getTypes());
+ return concatSequences(OPreparedStatement_BASE::getTypes(),
+ OStatement_BASE2::getTypes());
}
-// -------------------------------------------------------------------------
-Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData( ) throw(SQLException, RuntimeException)
+Reference< XResultSetMetaData > SAL_CALL OPreparedStatement::getMetaData()
+ throw(SQLException, RuntimeException)
{
::osl::MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
+ // TODO: implement
// if(!m_xMetaData.is())
// m_xMetaData = new OResultSetMetaData(m_pConnection, m_pSqlda);
// TODO: uncomment once PreparedStatement reimplemented with SQLDA
return m_xMetaData;
}
-// -------------------------------------------------------------------------
-void SAL_CALL OPreparedStatement::close( ) throw(SQLException, RuntimeException)
+void SAL_CALL OPreparedStatement::close() throw(SQLException, RuntimeException)
{
SAL_INFO("connectivity.firebird", "close()");
- ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
+ MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
-
- // Reset last warning message
-
- try {
- clearWarnings ();
- OStatement_BASE2::close();
- }
- catch (SQLException &) {
- // If we get an error, ignore
+ if (m_statementHandle)
+ {
+ // TODO: implement
}
- // Remove this Statement object from the Connection object's
- // list
+ OStatement_BASE2::close();
}
-// -------------------------------------------------------------------------
-sal_Bool SAL_CALL OPreparedStatement::execute( ) throw(SQLException, RuntimeException)
+sal_Bool SAL_CALL OPreparedStatement::execute()
+ throw(SQLException, RuntimeException)
{
- ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
+ MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
-
- // same as in statement with the difference that this statement also can contain parameter
+ // TODO: implement
return sal_False;
}
-// -------------------------------------------------------------------------
-sal_Int32 SAL_CALL OPreparedStatement::executeUpdate( ) throw(SQLException, RuntimeException)
+sal_Int32 SAL_CALL OPreparedStatement::executeUpdate()
+ throw(SQLException, RuntimeException)
{
- ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
+ MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
- // same as in statement with the difference that this statement also can contain parameter
+ // TODO: implement
return 0;
}
-// -------------------------------------------------------------------------
-void SAL_CALL OPreparedStatement::setString( sal_Int32 parameterIndex, const ::rtl::OUString& x ) throw(SQLException, RuntimeException)
+void SAL_CALL OPreparedStatement::setString(sal_Int32 nParameterIndex,
+ const OUString& x)
+ throw(SQLException, RuntimeException)
{
SAL_INFO("connectivity.firebird", "setString(). "
- "parameterIndex: " << parameterIndex << " , "
+ "parameterIndex: " << nParameterIndex << " , "
"x: " << x);
- ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
+ MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
+ ensurePrepared();
- if (NULL == m_INsqlda)
- {
- SAL_WARN("connectivity.firebird", "setString(). "
- "The query has not input parameters.");
- return;
- }
+ checkParameterIndex(nParameterIndex);
OString str = OUStringToOString(x , RTL_TEXTENCODING_UTF8 );
- SAL_INFO("connectivity.firebird", "setString(). "
- "Setting parameter as: " << str);
- XSQLVAR *var = m_INsqlda->sqlvar + (parameterIndex - 1);
+ XSQLVAR* pVar = m_pOutSqlda->sqlvar + (nParameterIndex - 1);
- int dtype = (var->sqltype & ~1); // drop flag bit for now
- switch(dtype) {
+ int dtype = (pVar->sqltype & ~1); // drop flag bit for now
+ switch (dtype) {
case SQL_VARYING:
- var->sqltype = SQL_TEXT;
+ pVar->sqltype = SQL_TEXT;
case SQL_TEXT:
- var->sqllen = str.getLength();
- var->sqldata = (char *)malloc(sizeof(char)*var->sqllen);
- sprintf(var->sqldata , "%s", str.getStr());
+ if (str.getLength() > pVar->sqllen)
+ { // Cut off overflow
+ memcpy(pVar->sqldata, str.getStr(), pVar->sqllen);
+ }
+ else
+ {
+ memcpy(pVar->sqldata, str.getStr(), str.getLength());
+ // Fill remainder with spaces
+ // TODO: would 0 be better here for filling?
+ memset(pVar->sqldata + str.getLength(), ' ', pVar->sqllen - str.getLength());
+ }
break;
default:
- OSL_ASSERT( false );
+ // TODO: sane error message
+ throw SQLException();
}
-
- sprintf(var->sqldata , "%s", OUStringToOString(x , RTL_TEXTENCODING_UTF8 ).getStr());
}
-// -------------------------------------------------------------------------
-Reference< XConnection > SAL_CALL OPreparedStatement::getConnection( ) throw(SQLException, RuntimeException)
+Reference< XConnection > SAL_CALL OPreparedStatement::getConnection()
+ throw(SQLException, RuntimeException)
{
- ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
+ MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
- return (Reference< XConnection >)m_pConnection;
+ return Reference< XConnection >(m_pConnection);
}
-// -------------------------------------------------------------------------
-Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery( ) throw(SQLException, RuntimeException)
+Reference< XResultSet > SAL_CALL OPreparedStatement::executeQuery()
+ throw(SQLException, RuntimeException)
{
SAL_INFO("connectivity.firebird", "executeQuery(). "
"Got called with sql: " << m_sSqlStatement);
- ::osl::MutexGuard aGuard( m_pConnection->getMutex() );
+ MutexGuard aGuard( m_pConnection->getMutex() );
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
+ ensurePrepared();
-// ISC_STATUS_ARRAY status; /* status vector */
+ ISC_STATUS aErr;
-// if (isc_dsql_execute(status, &m_pConnection->getTransaction(), &m_statementHandle, 1, m_INsqlda))
-// if (pr_error(status, "execute query"))
-// return NULL;
-
- isc_stmt_handle aHandle = 0;
- Reference< OResultSet > pResult( new OResultSet( m_pConnection, this, aHandle, 0) );
- //initializeResultSet( pResult.get() );
- Reference< XResultSet > xRS = pResult.get();
+ aErr = isc_dsql_execute(m_statusVector,
+ &m_pConnection->getTransaction(),
+ &m_statementHandle,
+ 1,
+ m_pInSqlda);
+ if (aErr)
+ {
+ SAL_WARN("connectivity.firebird", "isc_dsql_execute failed" );
+ OConnection::evaluateStatusVector(m_statusVector,
+ "isc_dsql_execute",
+ *this);
+ }
- SAL_INFO("connectivity.firebird", "executeQuery(). "
- "Query executed.");
+ uno::Reference< OResultSet > pResult(new OResultSet(m_pConnection,
+ uno::Reference< XStatement >(this),
+ m_statementHandle,
+ m_pOutSqlda));
+ m_xResultSet = pResult.get();
- return xRS;
+ return m_xResultSet;
}
// -------------------------------------------------------------------------
@@ -490,13 +571,15 @@ void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,cons
OStatement_Base::setFastPropertyValue_NoBroadcast(nHandle,rValue);
}
}
-// -----------------------------------------------------------------------------
-void OPreparedStatement::checkParameterIndex(sal_Int32 _parameterIndex)
+
+void OPreparedStatement::checkParameterIndex(sal_Int32 nParameterIndex)
+ throw(SQLException)
{
- if( !_parameterIndex || _parameterIndex > m_nNumParams)
+ ensurePrepared();
+ if ((nParameterIndex == 0) || (nParameterIndex > m_pOutSqlda->sqld))
throw SQLException();
+ // TODO: sane error message here.
}
-// -----------------------------------------------------------------------------
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/firebird/FPreparedStatement.hxx b/connectivity/source/drivers/firebird/FPreparedStatement.hxx
index e6577b5..b6976a6 100644
--- a/connectivity/source/drivers/firebird/FPreparedStatement.hxx
+++ b/connectivity/source/drivers/firebird/FPreparedStatement.hxx
@@ -73,21 +73,22 @@ namespace connectivity
};
::std::vector< Parameter> m_aParameters;
- //====================================================================
- // Data attributes
- //====================================================================
+
TTypeInfoVector m_aTypeInfo; // Hashtable containing an entry
// for each row returned by
// DatabaseMetaData.getTypeInfo.
- sal_Int32 m_nNumParams; // Number of parameter markers
- // for the prepared statement
-
::rtl::OUString m_sSqlStatement;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSetMetaData > m_xMetaData;
- sal_Bool m_bPrepared;
- void checkParameterIndex(sal_Int32 _parameterIndex);
+ isc_stmt_handle m_statementHandle;
+ XSQLDA* m_pOutSqlda;
+ XSQLDA* m_pInSqlda;
+ void checkParameterIndex(sal_Int32 nParameterIndex)
+ throw(::com::sun::star::sdbc::SQLException);
+
+ void ensurePrepared()
+ throw(::com::sun::star::sdbc::SQLException);
protected:
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,
@@ -117,7 +118,7 @@ namespace connectivity
virtual sal_Bool SAL_CALL execute( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
// XParameters
- virtual void SAL_CALL setNull( sal_Int32 parameterIndex, sal_Int32 sqlType ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
+ virtual void SAL_CALL setNull( sal_Int32 nParameterIndex, sal_Int32 sqlType ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setObjectNull( sal_Int32 parameterIndex, sal_Int32 sqlType, const ::rtl::OUString& typeName ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setBoolean( sal_Int32 parameterIndex, sal_Bool x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
virtual void SAL_CALL setByte( sal_Int32 parameterIndex, sal_Int8 x ) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);
diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx
index 7085b67..721a887 100644
--- a/connectivity/source/drivers/firebird/FStatement.cxx
+++ b/connectivity/source/drivers/firebird/FStatement.cxx
@@ -210,7 +210,7 @@ OUString OStatement_Base::sanitizeSqlString(const OUString& sqlIn)
{
// TODO: verify this is all we need.
static const sal_Unicode pattern('"');
- static const sal_Unicode empty('\'');
+ static const sal_Unicode empty(' ');
return sqlIn.replace(pattern, empty);
}
@@ -297,11 +297,13 @@ int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn,
return aErr;
}
-uno::Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery(const OUString& sql) throw(SQLException, RuntimeException)
+uno::Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery(const OUString& sqlIn) throw(SQLException, RuntimeException)
{
MutexGuard aGuard(m_pConnection->getMutex());
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
+ const OUString sql = sanitizeSqlString(sqlIn);
+
XSQLDA* pOutSqlda = 0;
isc_stmt_handle aStatementHandle = 0;
int aErr = 0;
diff --git a/connectivity/source/drivers/firebird/FStatement.hxx b/connectivity/source/drivers/firebird/FStatement.hxx
index 8113f57..8b12382 100644
--- a/connectivity/source/drivers/firebird/FStatement.hxx
+++ b/connectivity/source/drivers/firebird/FStatement.hxx
@@ -77,7 +77,6 @@ namespace connectivity
OConnection* m_pConnection;
- XSQLDA * m_INsqlda;
ISC_STATUS_ARRAY m_statusVector;
protected:
@@ -146,7 +145,6 @@ namespace connectivity
// other methods
OConnection* getOwnConnection() const { return m_pConnection;}
- inline XSQLDA * getINsqlda() const { return m_INsqlda; }
};
class OStatement_BASE2 :public OStatement_Base
commit 291b87962dbbd6859ec5156f69fbdf5a6e74be75
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Jul 22 13:29:02 2013 +0200
Move allocation of SQLVAR memory to Util (firebird-sdbc).
(Is also needed for allocating sqlin data in prepared statement.)
Change-Id: Id572ddbc582c709c8d361ca6e9a670fb8f2d2165
diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx
index 9eac403..7085b67 100644
--- a/connectivity/source/drivers/firebird/FStatement.cxx
+++ b/connectivity/source/drivers/firebird/FStatement.cxx
@@ -36,8 +36,7 @@
#include "FStatement.hxx"
#include "FConnection.hxx"
#include "FResultSet.hxx"
-#include <propertyids.hxx>
-#include <TConnection.hxx>
+#include "Util.hxx"
#include <ibase.h>
@@ -45,7 +44,9 @@
#include <cppuhelper/typeprovider.hxx>
#include <osl/diagnose.h>
#include <osl/thread.h>
+#include <propertyids.hxx>
#include <rtl/ustrbuf.hxx>
+#include <TConnection.hxx>
#include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
#include <com/sun/star/sdbc/ResultSetType.hpp>
@@ -215,7 +216,8 @@ OUString OStatement_Base::sanitizeSqlString(const OUString& sqlIn)
int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn,
isc_stmt_handle& aStatementHandle,
- XSQLDA*& pOutSqlda)
+ XSQLDA*& pOutSqlda,
+ XSQLDA* pInSqlda)
{
MutexGuard aGuard(m_pConnection->getMutex());
@@ -247,7 +249,7 @@ int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn,
0,
OUStringToOString(sql, RTL_TEXTENCODING_UTF8).getStr(),
1,
- NULL);
+ pInSqlda);
}
if (aErr)
@@ -280,7 +282,6 @@ int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn,
1,
pOutSqlda);
}
- XSQLVAR* pVar = pOutSqlda->sqlvar;
// Process each XSQLVAR parameter structure in the output XSQLDA
if (aErr)
@@ -290,68 +291,7 @@ int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn,
}
else
{
- // TODO: confirm the sizings below.
- for (int i=0; i < pOutSqlda->sqld; i++, pVar++)
- {
- int dtype = (pVar->sqltype & ~1); /* drop flag bit for now */
- switch(dtype) {
- case SQL_TEXT:
- pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen);
- break;
- case SQL_VARYING:
- pVar->sqltype = SQL_TEXT;
- pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen);
- break;
- case SQL_SHORT:
- pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen);
- break;
- case SQL_LONG:
- pVar->sqldata = (char *)malloc(sizeof(long));
- break;
- case SQL_FLOAT:
- pVar->sqldata = (char *)malloc(sizeof(double));
- break;
- case SQL_DOUBLE:
- pVar->sqldata = (char *)malloc(sizeof(double));
- break;
- case SQL_D_FLOAT:
- pVar->sqldata = (char *)malloc(sizeof(double));
- break;
- case SQL_TIMESTAMP:
- pVar->sqldata = (char *)malloc(sizeof(time_t));
- break;
- case SQL_BLOB:
- pVar->sqldata = (char*) malloc(sizeof(ISC_QUAD));
- break;
- case SQL_ARRAY:
- assert(false); // TODO: implement
- break;
- case SQL_TYPE_TIME:
- assert(false); // TODO: implement
- break;
- case SQL_TYPE_DATE:
- assert(false); // TODO: implement
- break;
- case SQL_INT64:
- pVar->sqldata = (char *)malloc(sizeof(int));
- break;
- case SQL_NULL:
- assert(false); // TODO: implement
- break;
- case SQL_QUAD:
- assert(false); // TODO: implement
- break;
- default:
- SAL_WARN("connectivity.firebird", "Unknown type: " << dtype);
- assert(false);
- break;
- }
- if (pVar->sqltype & 1)
- {
- /* allocate variable to hold NULL status */
- pVar->sqlind = (short *)malloc(sizeof(short));
- }
- }
+ mallocSQLVAR(pOutSqlda);
}
return aErr;
diff --git a/connectivity/source/drivers/firebird/FStatement.hxx b/connectivity/source/drivers/firebird/FStatement.hxx
index 514f109..8113f57 100644
--- a/connectivity/source/drivers/firebird/FStatement.hxx
+++ b/connectivity/source/drivers/firebird/FStatement.hxx
@@ -103,7 +103,8 @@ namespace connectivity
virtual ~OStatement_Base();
int prepareAndDescribeStatement(const OUString& sqlIn,
isc_stmt_handle& aStatementHandle,
- XSQLDA*& pOutSqlda);
+ XSQLDA*& pOutSqlda,
+ XSQLDA* pInSqlda=0);
::rtl::OUString sanitizeSqlString(const OUString& sqlIn);
public:
diff --git a/connectivity/source/drivers/firebird/Util.cxx b/connectivity/source/drivers/firebird/Util.cxx
index 0c23495..bc77775 100644
--- a/connectivity/source/drivers/firebird/Util.cxx
+++ b/connectivity/source/drivers/firebird/Util.cxx
@@ -9,8 +9,6 @@
#include "Util.hxx"
-#include <ibase.h>
-
using namespace ::connectivity;
using namespace ::rtl;
@@ -148,4 +146,71 @@ short firebird::getFBTypeFromBlrType(short blrType)
return 0;
}
}
+
+void firebird::mallocSQLVAR(XSQLDA* pSqlda)
+{
+ // TODO: confirm the sizings below.
+ XSQLVAR* pVar = pSqlda->sqlvar;
+ for (int i=0; i < pSqlda->sqld; i++, pVar++)
+ {
+ int dtype = (pVar->sqltype & ~1); /* drop flag bit for now */
+ switch(dtype) {
+ case SQL_TEXT:
+ pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen);
+ break;
+ case SQL_VARYING:
+ pVar->sqltype = SQL_TEXT;
+ pVar->sqldata = (char *)malloc(sizeof(char)*pVar->sqllen);
+ break;
+ case SQL_SHORT:
+ pVar->sqldata = (char *)malloc(sizeof(short));
+ break;
+ case SQL_LONG:
+ pVar->sqldata = (char *)malloc(sizeof(long));
+ break;
+ case SQL_FLOAT:
+ pVar->sqldata = (char *)malloc(sizeof(double));
+ break;
+ case SQL_DOUBLE:
+ pVar->sqldata = (char *)malloc(sizeof(double));
+ break;
+ case SQL_D_FLOAT:
+ pVar->sqldata = (char *)malloc(sizeof(double));
+ break;
+ case SQL_TIMESTAMP:
+ pVar->sqldata = (char *)malloc(sizeof(time_t));
+ break;
+ case SQL_BLOB:
+ pVar->sqldata = (char*) malloc(sizeof(ISC_QUAD));
+ break;
+ case SQL_ARRAY:
+ assert(false); // TODO: implement
+ break;
+ case SQL_TYPE_TIME:
+ assert(false); // TODO: implement
+ break;
+ case SQL_TYPE_DATE:
+ assert(false); // TODO: implement
+ break;
+ case SQL_INT64:
+ pVar->sqldata = (char *)malloc(sizeof(int));
+ break;
+ case SQL_NULL:
+ assert(false); // TODO: implement
+ break;
+ case SQL_QUAD:
+ assert(false); // TODO: implement
+ break;
+ default:
+ SAL_WARN("connectivity.firebird", "Unknown type: " << dtype);
+ assert(false);
+ break;
+ }
+ if (pVar->sqltype & 1)
+ {
+ /* allocate variable to hold NULL status */
+ pVar->sqlind = (short *)malloc(sizeof(short));
+ }
+ }
+}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
diff --git a/connectivity/source/drivers/firebird/Util.hxx b/connectivity/source/drivers/firebird/Util.hxx
index 0d68099..f3039db 100644
--- a/connectivity/source/drivers/firebird/Util.hxx
+++ b/connectivity/source/drivers/firebird/Util.hxx
@@ -10,6 +10,8 @@
#ifndef CONNECTIVITY_FIREBIRD_UTIL_HXX
#define CONNECTIVITY_FIREBIRD_UTIL_HXX
+#include <ibase.h>
+
#include <rtl/ustring.hxx>
#include <com/sun/star/sdbc/DataType.hpp>
@@ -28,6 +30,10 @@ namespace connectivity
* between the two when retrieving column metadata.
*/
short getFBTypeFromBlrType(short blrType);
+
+ void mallocSQLVAR(XSQLDA* pSqlda);
+
+// void freeSQLVAR(XSQLDA* pSqlda);
}
}
#endif //CONNECTIVITY_FIREBIRD_UTIL_HXX
commit dc3202517d2f48cea27e712a30be79acfdabb5f3
Author: Andrzej J.R. Hunt <andrzej at ahunt.org>
Date: Mon Jul 22 11:19:01 2013 +0200
Remove some unnecessary uses of XSQLDA->sqlvar (firebird-sdbc).
Change-Id: I69ea81a66decb817d5962206e4a6c30537bce02c
diff --git a/connectivity/source/drivers/firebird/FConnection.cxx b/connectivity/source/drivers/firebird/FConnection.cxx
index 3c05d06..ed9e367 100644
--- a/connectivity/source/drivers/firebird/FConnection.cxx
+++ b/connectivity/source/drivers/firebird/FConnection.cxx
@@ -325,31 +325,22 @@ Reference< XStatement > SAL_CALL OConnection::createStatement( )
}
Reference< XPreparedStatement > SAL_CALL OConnection::prepareStatement(
- const ::rtl::OUString& _sSql ) throw(SQLException, RuntimeException)
+ const OUString& _sSql)
+ throw(SQLException, RuntimeException)
{
- SAL_INFO("connectivity.firebird", "prepareStatement(). "
- "Got called with sql: " << _sSql);
-
- MutexGuard aGuard( m_aMutex );
+ SAL_INFO("connectivity.firebird", "prepareStatement() "
+ "called with sql: " << _sSql);
+ MutexGuard aGuard(m_aMutex);
checkDisposed(OConnection_BASE::rBHelper.bDisposed);
- // the pre
if(m_aTypeInfo.empty())
buildTypeInfo();
- SAL_INFO("connectivity.firebird", "prepareStatement(). "
- "Creating prepared statement.");
-
- // create a statement
- // the statement can only be executed more than once
Reference< XPreparedStatement > xReturn = new OPreparedStatement(this,
m_aTypeInfo,
_sSql);
m_aStatements.push_back(WeakReferenceHelper(xReturn));
- SAL_INFO("connectivity.firebird", "prepareStatement(). "
- "Prepared Statement created.");
-
return xReturn;
}
diff --git a/connectivity/source/drivers/firebird/FStatement.cxx b/connectivity/source/drivers/firebird/FStatement.cxx
index 5ccd0c0..9eac403 100644
--- a/connectivity/source/drivers/firebird/FStatement.cxx
+++ b/connectivity/source/drivers/firebird/FStatement.cxx
@@ -215,8 +215,7 @@ OUString OStatement_Base::sanitizeSqlString(const OUString& sqlIn)
int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn,
isc_stmt_handle& aStatementHandle,
- XSQLDA*& pOutSqlda,
- XSQLVAR*& pVar)
+ XSQLDA*& pOutSqlda)
{
MutexGuard aGuard(m_pConnection->getMutex());
@@ -281,7 +280,7 @@ int OStatement_Base::prepareAndDescribeStatement(const OUString& sqlIn,
1,
pOutSqlda);
}
- pVar = pOutSqlda->sqlvar;
+ XSQLVAR* pVar = pOutSqlda->sqlvar;
// Process each XSQLVAR parameter structure in the output XSQLDA
if (aErr)
@@ -364,16 +363,13 @@ uno::Reference< XResultSet > SAL_CALL OStatement_Base::executeQuery(const OUStri
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
XSQLDA* pOutSqlda = 0;
- XSQLVAR* pVar = 0;
isc_stmt_handle aStatementHandle = 0;
int aErr = 0;
aErr = prepareAndDescribeStatement(sql,
aStatementHandle,
- pOutSqlda,
- pVar);
-
+ pOutSqlda);
if (aErr)
{
SAL_WARN("connectivity.firebird", "prepareAndDescribeStatement failed");
@@ -411,15 +407,13 @@ sal_Bool SAL_CALL OStatement_Base::execute(const OUString& sql) throw(SQLExcepti
checkDisposed(OStatement_BASE::rBHelper.bDisposed);
XSQLDA* pOutSqlda = 0;
- XSQLVAR* pVar = 0;
isc_stmt_handle aStatementHandle = 0;
int aErr = 0;
aErr = prepareAndDescribeStatement(sql,
aStatementHandle,
- pOutSqlda,
- pVar);
+ pOutSqlda);
if (aErr)
{
diff --git a/connectivity/source/drivers/firebird/FStatement.hxx b/connectivity/source/drivers/firebird/FStatement.hxx
index 0311491..514f109 100644
--- a/connectivity/source/drivers/firebird/FStatement.hxx
+++ b/connectivity/source/drivers/firebird/FStatement.hxx
@@ -77,7 +77,6 @@ namespace connectivity
OConnection* m_pConnection;
- XSQLDA * m_OUTsqlda;
XSQLDA * m_INsqlda;
ISC_STATUS_ARRAY m_statusVector;
protected:
@@ -104,8 +103,7 @@ namespace connectivity
virtual ~OStatement_Base();
int prepareAndDescribeStatement(const OUString& sqlIn,
isc_stmt_handle& aStatementHandle,
- XSQLDA*& pOutSqlda,
- XSQLVAR*& pVar);
+ XSQLDA*& pOutSqlda);
::rtl::OUString sanitizeSqlString(const OUString& sqlIn);
public:
@@ -147,7 +145,6 @@ namespace connectivity
// other methods
OConnection* getOwnConnection() const { return m_pConnection;}
- inline XSQLDA * getOUTsqlda() const { return m_OUTsqlda; }
inline XSQLDA * getINsqlda() const { return m_INsqlda; }
};
More information about the Libreoffice-commits
mailing list