[Libreoffice-commits] .: Branch 'feature/mork' - connectivity/Library_mork.mk connectivity/source
David Ostrovsky
davido at kemper.freedesktop.org
Tue Aug 14 15:59:16 PDT 2012
connectivity/Library_mork.mk | 1
connectivity/source/drivers/mork/MQueryHelper.cxx | 232 ++++++++++++++++++++++
connectivity/source/drivers/mork/MQueryHelper.hxx | 94 ++++++++
connectivity/source/drivers/mork/MResultSet.cxx | 67 +++---
connectivity/source/drivers/mork/MResultSet.hxx | 2
5 files changed, 370 insertions(+), 26 deletions(-)
New commits:
commit 43a99082cfd87cef7a9958c19ceac26389fe9ff4
Author: David Ostrovsky <david at ostrovsky.org>
Date: Wed Aug 15 00:57:17 2012 +0200
mork driver: connect MQueryHelper with MorkParser
Change-Id: I7f64a7bd9383406a51405a4c2ea0b0c99c2b57de
diff --git a/connectivity/Library_mork.mk b/connectivity/Library_mork.mk
index 97eda03..17de768 100644
--- a/connectivity/Library_mork.mk
+++ b/connectivity/Library_mork.mk
@@ -49,6 +49,7 @@ $(eval $(call gb_Library_add_exception_objects,mork, \
connectivity/source/drivers/mork/MResultSet \
connectivity/source/drivers/mork/MResultSetMetaData \
connectivity/source/drivers/mork/MPreparedStatement \
+ connectivity/source/drivers/mork/MQueryHelper \
connectivity/source/drivers/mork/MServices \
connectivity/source/drivers/mork/MTable \
connectivity/source/drivers/mork/MTables \
diff --git a/connectivity/source/drivers/mork/MQueryHelper.cxx b/connectivity/source/drivers/mork/MQueryHelper.cxx
new file mode 100644
index 0000000..7097110
--- /dev/null
+++ b/connectivity/source/drivers/mork/MQueryHelper.cxx
@@ -0,0 +1,232 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 .
+ */
+
+
+#include "MColumnAlias.hxx"
+#include "MQueryHelper.hxx"
+#include "MConnection.hxx"
+
+#include "MorkParser.hxx"
+#include <stdlib.h>
+#include <sstream>
+#include <string>
+#include <string.h>
+
+
+#include <connectivity/dbexception.hxx>
+
+using namespace connectivity::mork;
+using namespace connectivity;
+using namespace ::com::sun::star::beans;
+using namespace ::com::sun::star::sdbc;
+using namespace connectivity;
+
+
+MQueryHelperResultEntry::MQueryHelperResultEntry()
+{
+}
+
+MQueryHelperResultEntry::~MQueryHelperResultEntry()
+{
+}
+
+void MQueryHelperResultEntry::insert( const rtl::OString &key, rtl::OUString &value )
+{
+ m_Fields[ key ] = value;
+}
+
+rtl::OUString MQueryHelperResultEntry::getValue( const rtl::OString &key ) const
+{
+ FieldMap::const_iterator iter = m_Fields.find( key );
+ if ( iter == m_Fields.end() )
+ {
+ return rtl::OUString();
+ }
+ else
+ {
+ return iter->second;
+ }
+}
+
+void MQueryHelperResultEntry::setValue( const rtl::OString &key, const rtl::OUString & rValue)
+{
+// SAL_INFO("connectivity.mork", "MQueryHelper::setValue()" );
+// SAL_INFO("connectivity.mork", "key: " << &key << " value: " << &rValue);
+
+ m_Fields[ key ] = rValue;
+}
+
+MQueryHelper::MQueryHelper(const OColumnAlias& _ca)
+ :m_nIndex( 0 )
+ ,m_bHasMore( sal_True )
+ ,m_bAtEnd( sal_False )
+ ,m_rColumnAlias( _ca )
+{
+ m_aResults.clear();
+}
+
+MQueryHelper::~MQueryHelper()
+{
+ OSL_TRACE("IN MQueryHelper::~MQueryHelper()");
+ clear_results();
+ OSL_TRACE("OUT MQueryHelper::~MQueryHelper()");
+}
+
+void MQueryHelper::append(MQueryHelperResultEntry* resEnt)
+{
+// SAL_INFO("connectivity.mork", "MQueryHelper::append()" );
+
+ if ( resEnt != NULL ) {
+ m_aResults.push_back( resEnt );
+ m_bAtEnd = sal_False;
+ }
+}
+
+void MQueryHelper::clear_results()
+{
+ resultsArray::iterator iter = m_aResults.begin();
+ while ( iter != m_aResults.end() ) {
+ delete (*iter);
+ ++iter;
+ }
+ m_aResults.clear();
+}
+
+void MQueryHelper::reset()
+{
+ m_nIndex = 0;
+ m_bHasMore = sal_True;
+ m_bAtEnd = sal_False;
+ clear_results();
+}
+
+MQueryHelperResultEntry* MQueryHelper::next()
+{
+ MQueryHelperResultEntry* result;
+ sal_uInt32 index;
+
+ m_aMutex.acquire();
+ index = m_nIndex;
+ m_aMutex.release();
+
+ result = getByIndex( index + 1) ; // Add 1 as Row is numbered from 1 to N
+
+ if ( result ) {
+ m_aMutex.acquire();
+ m_nIndex++;
+ m_aMutex.release();
+ }
+
+ return( result );
+}
+
+MQueryHelperResultEntry*
+MQueryHelper::getByIndex(sal_uInt32 nRow)
+{
+ // Row numbers are from 1 to N, need to ensure this, and then
+ // substract 1
+ if ( nRow < 1 ) {
+ return( NULL );
+ }
+ return m_aResults[nRow -1];
+}
+
+sal_Int32 MQueryHelper::getResultCount() const
+{
+ SAL_INFO("connectivity.mork", "MQueryHelper::getResultCount()" );
+ sal_Int32 result = static_cast<sal_Int32>(m_aResults.size());
+ SAL_INFO("connectivity.mork", "result: " << result);
+
+ return result;
+}
+
+// -------------------------------------------------------------------------
+
+sal_Bool MQueryHelper::getRowValue( ORowSetValue& rValue, sal_Int32 nDBRow,const rtl::OUString& aDBColumnName, sal_Int32 nType )
+{
+ SAL_INFO("connectivity.mork", "MQueryHelper::getRowValue()" );
+ MQueryHelperResultEntry* xResEntry = getByIndex( nDBRow );
+
+ OSL_ENSURE( xResEntry != NULL, "xResEntry == NULL");
+ if (xResEntry == NULL )
+ {
+ rValue.setNull();
+ return sal_False;
+ }
+ switch ( nType )
+ {
+ case DataType::VARCHAR:
+ rValue = xResEntry->getValue( m_rColumnAlias.getProgrammaticNameOrFallbackToUTF8Alias( aDBColumnName ) );
+ break;
+
+ default:
+ rValue.setNull();
+ break;
+ }
+
+ return sal_True;
+}
+
+sal_Int32 MQueryHelper::executeQuery(OConnection* xConnection)
+{
+ SAL_INFO("connectivity.mork", "MQueryHelper::executeQuery()" );
+ reset();
+
+ MorkTableMap::iterator tableIter;
+ MorkTableMap *Tables = xConnection->getMorkParser()->getTables( 0x80 );
+ MorkRowMap *Rows = 0;
+ MorkRowMap::iterator rowIter;
+
+ for ( tableIter = Tables->begin(); tableIter != Tables->end(); tableIter++ )
+ {
+ // Iterate all tables
+ for ( tableIter = Tables->begin(); tableIter != Tables->end(); tableIter++ )
+ {
+ if (tableIter->first != 1) break;
+ Rows = xConnection->getMorkParser()->getRows( 0x80, &tableIter->second );
+ if ( Rows )
+ {
+ // Iterate all rows
+ for ( rowIter = Rows->begin(); rowIter != Rows->end(); rowIter++ )
+ {
+ for (MorkCells::iterator CellsIter = rowIter->second.begin();
+ CellsIter != rowIter->second.end(); CellsIter++ )
+ {
+ std::string column = xConnection->getMorkParser()->getColumn(CellsIter->first);
+ std::string value = xConnection->getMorkParser()->getValue(CellsIter->second);
+
+ //SAL_INFO("connectivity.mork", "key: " << column << " value: " << value);
+
+ MQueryHelperResultEntry* entry = new MQueryHelperResultEntry();
+
+ OString key(column.c_str(), static_cast<sal_Int32>(column.size()));
+ OString valueOString(value.c_str(), static_cast<sal_Int32>(value.size()));
+ rtl::OUString valueOUString = ::rtl::OStringToOUString( valueOString, RTL_TEXTENCODING_UTF8 );
+ entry->setValue(key, valueOUString);
+ append(entry);
+ }
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mork/MQueryHelper.hxx b/connectivity/source/drivers/mork/MQueryHelper.hxx
new file mode 100644
index 0000000..2d186a8
--- /dev/null
+++ b/connectivity/source/drivers/mork/MQueryHelper.hxx
@@ -0,0 +1,94 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * 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 .
+ */
+
+#ifndef _CONNECTIVITY_MORK_QUERYHELPER_HXX_
+#define _CONNECTIVITY_MORK_QUERYHELPER_HXX_
+
+#include <sal/types.h>
+#include <rtl/ustring.hxx>
+#include <osl/mutex.hxx>
+#include <osl/conditn.hxx>
+#include <comphelper/stl_types.hxx>
+#include <osl/thread.hxx>
+#include <connectivity/FValue.hxx>
+
+#include <boost/unordered_map.hpp>
+
+namespace connectivity
+{
+ namespace mork
+ {
+ class OConnection;
+ class MQueryHelperResultEntry
+ {
+ private:
+ typedef ::boost::unordered_map< ::rtl::OString, ::rtl::OUString, ::rtl::OStringHash > FieldMap;
+
+ mutable ::osl::Mutex m_aMutex;
+ FieldMap m_Fields;
+
+ public:
+ MQueryHelperResultEntry();
+ ~MQueryHelperResultEntry();
+
+ void insert( const rtl::OString &key, rtl::OUString &value );
+ rtl::OUString getValue( const rtl::OString &key ) const;
+ void setValue( const rtl::OString &key, const rtl::OUString & rValue);
+ };
+
+ class MQueryHelper
+ {
+ private:
+ typedef std::vector< MQueryHelperResultEntry* > resultsArray;
+
+ mutable ::osl::Mutex m_aMutex;
+ ::osl::Condition m_aCondition;
+ resultsArray m_aResults;
+ sal_uInt32 m_nIndex;
+ sal_Bool m_bHasMore;
+ sal_Bool m_bAtEnd;
+ void append(MQueryHelperResultEntry* resEnt );
+ void clear_results();
+ OColumnAlias m_rColumnAlias;
+
+/*
+ void clearResultOrComplete();
+ void notifyResultOrComplete();
+ sal_Bool waitForResultOrComplete( );
+ void getCardValues(nsIAbCard *card,sal_uInt32 rowIndex=0);
+*/
+
+ public:
+ MQueryHelper(const OColumnAlias& _ca);
+ virtual ~MQueryHelper();
+
+ void reset();
+ MQueryHelperResultEntry* next();
+ MQueryHelperResultEntry* getByIndex( sal_uInt32 nRow );
+ sal_Bool isError() const;
+ sal_Int32 getResultCount() const;
+ sal_Bool getRowValue( ORowSetValue& rValue, sal_Int32 nDBRow,const rtl::OUString& aDBColumnName, sal_Int32 nType );
+ sal_Int32 executeQuery(OConnection* xConnection);
+ };
+ }
+}
+
+#endif // _CONNECTIVITY_MORK_QUERYHELPER_HXX_
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/connectivity/source/drivers/mork/MResultSet.cxx b/connectivity/source/drivers/mork/MResultSet.cxx
index eea07df..d7d7117 100644
--- a/connectivity/source/drivers/mork/MResultSet.cxx
+++ b/connectivity/source/drivers/mork/MResultSet.cxx
@@ -101,6 +101,7 @@ OResultSet::OResultSet(OCommonStatement* pStmt, const ::boost::shared_ptr< conne
,m_pParseTree( _pSQLIterator->getParseTree() )
// TODO
//,m_aQuery( pStmt->getOwnConnection()->getColumnAlias() )
+ ,m_aQueryHelper(pStmt->getOwnConnection()->getColumnAlias())
,m_pTable(NULL)
,m_CurrentRowCount(0)
,m_nParamIndex(0)
@@ -311,11 +312,13 @@ void OResultSet::checkIndex(sal_Int32 columnIndex ) throw(::com::sun::star::sdbc
::dbtools::throwInvalidIndexException(*this);
}
// -------------------------------------------------------------------------
-sal_uInt32 OResultSet::currentRowCount()
+sal_uInt32 OResultSet::currentRowCount()
{
if ( m_bIsAlwaysFalseQuery )
return 0;
- return 0;//m_aQuery.getRealRowCount() - deletedCount();
+ //return 0;//m_aQuery.getRealRowCount() - deletedCount();
+ // new implementation
+ return m_aQueryHelper.getResultCount();
}
// -------------------------------------------------------------------------
@@ -329,7 +332,7 @@ sal_Bool OResultSet::fetchCurrentRow( ) throw(SQLException, RuntimeException)
// -------------------------------------------------------------------------
sal_Bool OResultSet::pushCard(sal_uInt32 /*cardNumber*/) throw(SQLException, RuntimeException)
{
- SAL_WARN("connectivity.mork", "OResultSet::pushCard() NOT IMPLEMENTED!");
+ SAL_INFO("connectivity.mork", "=> OResultSet::pushCard()" );
return sal_True;
/*
if (cardNumber == 0)
@@ -357,11 +360,10 @@ sal_Bool OResultSet::pushCard(sal_uInt32 /*cardNumber*/) throw(SQLException, Run
*/
}
// -------------------------------------------------------------------------
-sal_Bool OResultSet::fetchRow(sal_Int32 /*cardNumber*/,sal_Bool /*bForceReload*/) throw(SQLException, RuntimeException)
+sal_Bool OResultSet::fetchRow(sal_Int32 cardNumber,sal_Bool bForceReload) throw(SQLException, RuntimeException)
{
- SAL_WARN("connectivity.mork", "OResultSet::fetchRow() NOT IMPLEMENTED!");
- return sal_True;
-/*
+ SAL_INFO("connectivity.mork", "=> OResultSet::fetchRow()" );
+
OSL_TRACE("fetchRow, cardNumber = %u", cardNumber );
if (!bForceReload)
{
@@ -376,15 +378,15 @@ sal_Bool OResultSet::fetchRow(sal_Int32 /*cardNumber*/,sal_Bool /*bForceReload*/
throw SQLException();
}
}
- else
- m_aQuery.resyncRow(cardNumber);
+// else
+// m_aQuery.resyncRow(cardNumber);
if ( validRow( cardNumber ) == sal_False )
return sal_False;
(m_aRow->get())[0] = (sal_Int32)cardNumber;
sal_Int32 nCount = m_aColumnNames.getLength();
- m_RowStates = m_aQuery.getRowStates(cardNumber);
+ //m_RowStates = m_aQuery.getRowStates(cardNumber);
for( sal_Int32 i = 1; i <= nCount; i++ )
{
if ( (m_aRow->get())[i].isBound() )
@@ -392,14 +394,15 @@ sal_Bool OResultSet::fetchRow(sal_Int32 /*cardNumber*/,sal_Bool /*bForceReload*/
//
// Everything in the addressbook is a string!
//
- if ( !m_aQuery.getRowValue( (m_aRow->get())[i], cardNumber, m_aColumnNames[i-1], DataType::VARCHAR ))
- {
- m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
- }
+ if ( !m_aQueryHelper.getRowValue( (m_aRow->get())[i], cardNumber, m_aColumnNames[i-1], DataType::VARCHAR ))
+ OSL_FAIL( "getRowValue: failed!" );
+// {
+// m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
+// }
}
}
return sal_True;
-*/
+
}
// -------------------------------------------------------------------------
@@ -1057,16 +1060,22 @@ void OResultSet::fillRowData()
throw( ::com::sun::star::sdbc::SQLException )
{
SAL_INFO("connectivity.mork", "=> OResultSet::fillRowData()" );
-
OSL_ENSURE( m_pStatement, "Require a statement" );
-
m_xColumns = m_pSQLIterator->getSelectColumns();
OSL_ENSURE(m_xColumns.is(), "Need the Columns!!");
-/*
OConnection* xConnection = static_cast<OConnection*>(m_pStatement->getConnection().get());
+ sal_Int32 rv = m_aQueryHelper.executeQuery(xConnection);
+
+ if (rv == -1)
+ {
+ OSL_FAIL( "Error in executeQuery!" );
+ }
+
+
+/*
MQueryExpression queryExpression;
OSQLColumns::Vector::const_iterator aIter = m_xColumns->get().begin();
@@ -1144,6 +1153,7 @@ void OResultSet::fillRowData()
OSL_TRACE( "\tOUT OResultSet::fillRowData()" );
#endif
*/
+
}
#if 0
@@ -1217,6 +1227,10 @@ void SAL_CALL OResultSet::executeQuery() throw( ::com::sun::star::sdbc::SQLExcep
fillRowData();
+ m_pKeySet = new OKeySet();
+ //m_pSortIndex = new OSortIndex(SQL_ORDERBYKEY_DOUBLE, m_aOrderbyAscending);
+ //m_pKeySet = m_pSortIndex->CreateKeySet();
+
OSL_ENSURE(m_xColumns.is(), "Need the Columns!!");
/*
@@ -1525,16 +1539,16 @@ sal_Int32 OResultSet::deletedCount()
}
// -----------------------------------------------------------------------------
-sal_Bool OResultSet::seekRow( eRowPosition /*pos*/, sal_Int32 /*nOffset*/ )
+sal_Bool OResultSet::seekRow( eRowPosition pos, sal_Int32 nOffset )
{
- OSL_FAIL( "OResultSet::seekRow() not implemented" );
-/*
+ SAL_INFO("connectivity.mork", "=> OResultSet::seekRow()" );
+
ResultSetEntryGuard aGuard( *this );
if ( !m_pKeySet.is() )
OSL_FAIL( "OResultSet::STR_ILLEGAL_MOVEMENT" );
// m_pStatement->getOwnConnection()->throwSQLException( STR_ILLEGAL_MOVEMENT, *this );
- sal_Int32 nNumberOfRecords = m_aQuery.getRealRowCount();
+ sal_Int32 nNumberOfRecords = m_aQueryHelper.getResultCount();
sal_Int32 nRetrivedRows = currentRowCount();
sal_Int32 nCurPos = m_nRowPos;
@@ -1582,16 +1596,18 @@ sal_Bool OResultSet::seekRow( eRowPosition /*pos*/, sal_Int32 /*nOffset*/ )
else //The requested row has not been retrived until now. We should get the right card for it.
nCurCard = nCurPos + deletedCount();
- while ( nCurCard > nNumberOfRecords && !m_aQuery.queryComplete() ) {
+ while ( nCurCard > nNumberOfRecords ) {
+/*
m_aQuery.checkRowAvailable( nCurCard );
if ( m_aQuery.hadError() )
{
m_pStatement->getOwnConnection()->throwSQLException( m_aQuery.getError(), *this );
}
- nNumberOfRecords = m_aQuery.getRealRowCount();
+*/
+ nNumberOfRecords = m_aQueryHelper.getResultCount();
}
- if ( nCurCard > nNumberOfRecords && m_aQuery.queryComplete()) {
+ if ( nCurCard > nNumberOfRecords) {
fillKeySet(nNumberOfRecords);
m_nRowPos = static_cast<sal_uInt32>(m_pKeySet->get().size() + 1);
OSL_TRACE("seekRow: return False, m_nRowPos = %u", m_nRowPos );
@@ -1602,7 +1618,6 @@ sal_Bool OResultSet::seekRow( eRowPosition /*pos*/, sal_Int32 /*nOffset*/ )
m_nRowPos = (sal_uInt32)nCurPos;
OSL_TRACE("seekRow: return True, m_nRowPos = %u", m_nRowPos );
fetchCurrentRow();
-*/
return sal_True;
}
// -----------------------------------------------------------------------------
diff --git a/connectivity/source/drivers/mork/MResultSet.hxx b/connectivity/source/drivers/mork/MResultSet.hxx
index 8f8245c..9c9c926 100644
--- a/connectivity/source/drivers/mork/MResultSet.hxx
+++ b/connectivity/source/drivers/mork/MResultSet.hxx
@@ -33,6 +33,7 @@
#include <cppuhelper/compbase12.hxx>
#include <comphelper/proparrhlp.hxx>
#include "MStatement.hxx"
+#include "MQueryHelper.hxx"
#include "connectivity/CommonTools.hxx"
#include "connectivity/FValue.hxx"
#include "connectivity/sqliterator.hxx"
@@ -220,6 +221,7 @@ namespace connectivity
protected:
//MQuery m_aQuery;
+ MQueryHelper m_aQueryHelper;
OTable* m_pTable;
sal_Int32 m_CurrentRowCount;
::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >
More information about the Libreoffice-commits
mailing list