Files
libreoffice/connectivity/source/drivers/flat/ETable.cxx

670 lines
25 KiB
C++
Raw Normal View History

2000-10-05 13:47:22 +00:00
/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
2000-10-05 13:47:22 +00:00
*
* $RCSfile: ETable.cxx,v $
2000-10-05 13:47:22 +00:00
*
* $Revision: 1.53 $
2000-10-05 13:47:22 +00:00
*
* last change: $Author: hr $ $Date: 2006-04-19 13:16:36 $
2000-10-05 13:47:22 +00:00
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
2000-10-05 13:47:22 +00:00
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
2000-10-05 13:47:22 +00:00
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
2000-10-05 13:47:22 +00:00
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
2000-10-05 13:47:22 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
2000-10-05 13:47:22 +00:00
*
************************************************************************/
2000-10-30 10:00:36 +00:00
#include <ctype.h>
2000-10-05 13:47:22 +00:00
#ifndef _CONNECTIVITY_FLAT_TABLE_HXX_
#include "flat/ETable.hxx"
#endif
#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_
#include <com/sun/star/sdbc/ColumnValue.hpp>
#endif
#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_
#include <com/sun/star/sdbc/DataType.hpp>
#endif
#ifndef _COM_SUN_STAR_UCB_XCONTENTACCESS_HPP_
#include <com/sun/star/ucb/XContentAccess.hpp>
#endif
#ifndef _COM_SUN_STAR_SQLC_XROW_HPP_
#include <com/sun/star/sdbc/XRow.hpp>
#endif
#ifndef _SV_CONVERTER_HXX_
#include <svtools/converter.hxx>
#endif
#ifndef _CONNECTIVITY_FLAT_ECONNECTION_HXX_
#include "flat/EConnection.hxx"
#endif
#ifndef _CONNECTIVITY_FLAT_COLUMNS_HXX_
#include "flat/EColumns.hxx"
#endif
#ifndef _OSL_THREAD_H_
#include <osl/thread.h>
#endif
#ifndef _CONFIG_HXX
#include <tools/config.hxx>
2000-10-05 13:47:22 +00:00
#endif
2000-10-11 09:48:50 +00:00
#ifndef _COMPHELPER_SEQUENCE_HXX_
#include <comphelper/sequence.hxx>
2000-10-05 13:47:22 +00:00
#endif
#ifndef _ZFORLIST_HXX //autogen
#include <svtools/zforlist.hxx>
#endif
#ifndef INCLUDED_RTL_MATH_HXX
#include <rtl/math.hxx>
2000-10-05 13:47:22 +00:00
#endif
#include <stdio.h> //sprintf
#ifndef _UCBHELPER_CONTENT_HXX
#include <ucbhelper/content.hxx>
#endif
#ifndef _COMPHELPER_EXTRACT_HXX_
#include <comphelper/extract.hxx>
2000-10-05 13:47:22 +00:00
#endif
2000-10-11 09:48:50 +00:00
#ifndef _COMPHELPER_NUMBERS_HXX_
#include <comphelper/numbers.hxx>
2000-10-05 13:47:22 +00:00
#endif
#ifndef _CONNECTIVITY_FLAT_EDRIVER_HXX_
#include "flat/EDriver.hxx"
#endif
#ifndef _COM_SUN_STAR_UTIL_NUMBERFORMAT_HPP_
#include <com/sun/star/util/NumberFormat.hpp>
#endif
#ifndef _UTL_CONFIGMGR_HXX_
#include <unotools/configmgr.hxx>
#endif
#ifndef INCLUDED_I18NPOOL_MSLANGID_HXX
#include <i18npool/mslangid.hxx>
2000-10-05 13:47:22 +00:00
#endif
2000-12-06 11:07:47 +00:00
#ifndef _DBHELPER_DBCONVERSION_HXX_
#include "connectivity/dbconversion.hxx"
#endif
2001-05-18 07:33:49 +00:00
#ifndef _COMPHELPER_TYPES_HXX_
#include <comphelper/types.hxx>
#endif
2000-10-05 13:47:22 +00:00
2001-05-18 07:33:49 +00:00
using namespace ::comphelper;
2000-10-05 13:47:22 +00:00
using namespace connectivity;
using namespace connectivity::flat;
using namespace connectivity::file;
using namespace ucb;
2001-05-18 07:33:49 +00:00
using namespace ::cppu;
2000-10-19 10:56:36 +00:00
using namespace utl;
2000-10-05 13:47:22 +00:00
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::ucb;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::sdbcx;
using namespace ::com::sun::star::sdbc;
using namespace ::com::sun::star::container;
using namespace ::com::sun::star::lang;
2000-12-14 07:32:10 +00:00
2000-10-05 13:47:22 +00:00
// -------------------------------------------------------------------------
void OFlatTable::fillColumns(const ::com::sun::star::lang::Locale& _aLocale)
2000-10-05 13:47:22 +00:00
{
BOOL bRead = TRUE;
OFlatString aHeaderLine;
OFlatConnection* pConnection = (OFlatConnection*)m_pConnection;
if (pConnection->isHeaderLine())
{
while(bRead && !aHeaderLine.Len())
{
bRead = m_pFileStream->ReadByteStringLine(aHeaderLine,pConnection->getTextEncoding());
2000-10-05 13:47:22 +00:00
}
}
// read first row
OFlatString aFirstLine;
bRead = m_pFileStream->ReadByteStringLine(aFirstLine,pConnection->getTextEncoding());
2000-10-05 13:47:22 +00:00
if (!pConnection->isHeaderLine() || !aHeaderLine.Len())
{
while(bRead && !aFirstLine.Len())
{
bRead = m_pFileStream->ReadByteStringLine(aFirstLine,pConnection->getTextEncoding());
2000-10-05 13:47:22 +00:00
}
// use first row as headerline because we need the number of columns
aHeaderLine = aFirstLine;
}
// column count
xub_StrLen nFieldCount = aHeaderLine.GetTokenCount(pConnection->getFieldDelimiter(),pConnection->getStringDelimiter());
if(!m_aColumns.isValid())
m_aColumns = new OSQLColumns();
else
m_aColumns->clear();
m_aTypes.clear();
m_aPrecisions.clear();
m_aScales.clear();
// reserve some space
m_aColumns->reserve(nFieldCount);
m_aTypes.reserve(nFieldCount);
m_aPrecisions.reserve(nFieldCount);
m_aScales.reserve(nFieldCount);
sal_Bool bCase = getConnection()->getMetaData()->storesMixedCaseQuotedIdentifiers();
CharClass aCharClass(pConnection->getDriver()->getFactory(),_aLocale);
2000-10-05 13:47:22 +00:00
// read description
sal_Unicode cDecimalDelimiter = pConnection->getDecimalDelimiter();
sal_Unicode cThousandDelimiter = pConnection->getThousandDelimiter();
String aColumnName;
2000-10-05 13:47:22 +00:00
::rtl::OUString aTypeName;
::comphelper::UStringMixEqual aCase(bCase);
xub_StrLen nStartPosHeaderLine = 0; // use for eficient way to get the tokens
xub_StrLen nStartPosFirstLine = 0; // use for eficient way to get the tokens
xub_StrLen nStartPosFirstLine2 = 0;
2000-10-05 13:47:22 +00:00
for (xub_StrLen i = 0; i < nFieldCount; i++)
{
if (pConnection->isHeaderLine())
{
aHeaderLine.GetTokenSpecial(aColumnName,nStartPosHeaderLine,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter());
if ( !aColumnName.Len() )
{
aColumnName = 'C';
aColumnName += String::CreateFromInt32(i+1);
}
2000-10-05 13:47:22 +00:00
}
else
{
// no column name so ...
aColumnName = 'C';
aColumnName += String::CreateFromInt32(i+1);
2000-10-05 13:47:22 +00:00
}
sal_Int32 eType;
UINT16 nPrecision = 0;
UINT16 nScale = 0;
BOOL bNumeric = FALSE;
double nRes=0.0;
ULONG nIndex = 0;
// first without fielddelimiter
String aField;
aFirstLine.GetTokenSpecial(aField,nStartPosFirstLine,pConnection->getFieldDelimiter(),'\0');
2000-10-05 13:47:22 +00:00
if (aField.Len() == 0 ||
(pConnection->getStringDelimiter() && pConnection->getStringDelimiter() == aField.GetChar(0)))
{
bNumeric = FALSE;
nStartPosFirstLine2 = nStartPosFirstLine;
2000-10-05 13:47:22 +00:00
}
else
{
String aField2;
if ( pConnection->getStringDelimiter() != '\0' )
aFirstLine.GetTokenSpecial(aField2,nStartPosFirstLine2,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter());
else
aField2 = aField;
2000-10-05 13:47:22 +00:00
2000-12-13 14:21:14 +00:00
if (aField2.Len() == 0)
2000-10-05 13:47:22 +00:00
{
bNumeric = FALSE;
}
else
{
bNumeric = TRUE;
xub_StrLen nDot = 0;
2000-12-13 14:21:14 +00:00
for (xub_StrLen j = 0; j < aField2.Len(); j++)
2000-10-05 13:47:22 +00:00
{
sal_Unicode c = aField2.GetChar(j);
2000-10-05 13:47:22 +00:00
// nur Ziffern und Dezimalpunkt und Tausender-Trennzeichen?
if ((!cDecimalDelimiter || c != cDecimalDelimiter) &&
(!cThousandDelimiter || c != cThousandDelimiter) &&
!aCharClass.isDigit(aField2,j))
2000-10-05 13:47:22 +00:00
{
bNumeric = FALSE;
break;
}
if (cDecimalDelimiter && c == cDecimalDelimiter)
{
nPrecision = 15; // we have an decimal value
nScale = 2;
nDot++;
}
}
if (nDot > 1) // if there is more than one dot it isn't a number
bNumeric = FALSE;
if (bNumeric && cThousandDelimiter)
{
// Ist der Trenner richtig angegeben?
String aValue = aField2.GetToken(0,cDecimalDelimiter);
2000-12-13 14:21:14 +00:00
for (sal_Int32 j = aValue.Len() - 4; j >= 0; j -= 4)
2000-10-05 13:47:22 +00:00
{
sal_Unicode c = aValue.GetChar(static_cast<sal_uInt16>(j));
2000-10-05 13:47:22 +00:00
// nur Ziffern und Dezimalpunkt und Tausender-Trennzeichen?
if (c == cThousandDelimiter && j)
continue;
else
{
bNumeric = FALSE;
break;
}
}
}
// jetzt koennte es noch ein Datumsfeld sein
2000-10-05 13:47:22 +00:00
if (!bNumeric)
{
try
{
nIndex = m_xNumberFormatter->detectNumberFormat(::com::sun::star::util::NumberFormat::ALL,aField2);
}
catch(Exception&)
{
}
2000-10-05 13:47:22 +00:00
}
}
}
sal_Int32 nFlags = 0;
if (bNumeric)
{
if (cDecimalDelimiter)
{
if(nPrecision)
{
eType = DataType::DECIMAL;
aTypeName = ::rtl::OUString::createFromAscii("DECIMAL");
}
else
{
eType = DataType::DOUBLE;
aTypeName = ::rtl::OUString::createFromAscii("DOUBLE");
}
}
else
eType = DataType::INTEGER;
nFlags = ColumnSearch::BASIC;
}
else
{
2000-10-11 09:48:50 +00:00
switch (comphelper::getNumberFormatType(m_xNumberFormatter,nIndex))
2000-10-05 13:47:22 +00:00
{
case NUMBERFORMAT_DATE:
eType = DataType::DATE;
aTypeName = ::rtl::OUString::createFromAscii("DATE");
break;
case NUMBERFORMAT_DATETIME:
eType = DataType::TIMESTAMP;
aTypeName = ::rtl::OUString::createFromAscii("TIMESTAMP");
break;
case NUMBERFORMAT_TIME:
eType = DataType::TIME;
aTypeName = ::rtl::OUString::createFromAscii("TIME");
break;
default:
eType = DataType::VARCHAR;
nPrecision = 0; // nyi: Daten koennen aber laenger sein!
nScale = 0;
aTypeName = ::rtl::OUString::createFromAscii("VARCHAR");
};
nFlags |= ColumnSearch::CHAR;
}
2001-01-15 08:33:09 +00:00
// check if the columname already exists
String aAlias(aColumnName);
2000-12-14 12:15:04 +00:00
OSQLColumns::const_iterator aFind = connectivity::find(m_aColumns->begin(),m_aColumns->end(),aAlias,aCase);
sal_Int32 nExprCnt = 0;
while(aFind != m_aColumns->end())
{
(aAlias = aColumnName) += String::CreateFromInt32(++nExprCnt);
2000-12-14 12:15:04 +00:00
aFind = connectivity::find(m_aColumns->begin(),m_aColumns->end(),aAlias,aCase);
}
2001-01-15 08:33:09 +00:00
2000-10-05 13:47:22 +00:00
sdbcx::OColumn* pColumn = new sdbcx::OColumn(aAlias,aTypeName,::rtl::OUString(),
ColumnValue::NULLABLE,
nPrecision,
nScale,
eType,
sal_False,
sal_False,
sal_False,
bCase);
2000-10-30 07:07:33 +00:00
Reference< XPropertySet> xCol = pColumn;
2000-10-05 13:47:22 +00:00
m_aColumns->push_back(xCol);
2001-07-30 07:53:02 +00:00
m_aTypes.push_back(eType);
m_aPrecisions.push_back(nPrecision);
m_aScales.push_back(nScale);
2000-10-05 13:47:22 +00:00
}
2000-11-16 09:47:23 +00:00
m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN);
2000-10-05 13:47:22 +00:00
}
// -------------------------------------------------------------------------
OFlatTable::OFlatTable(sdbcx::OCollection* _pTables,OFlatConnection* _pConnection) : OFlatTable_BASE(_pTables,_pConnection)
2000-10-05 13:47:22 +00:00
{
}
// -------------------------------------------------------------------------
OFlatTable::OFlatTable(sdbcx::OCollection* _pTables,OFlatConnection* _pConnection,
2000-10-05 13:47:22 +00:00
const ::rtl::OUString& _Name,
const ::rtl::OUString& _Type,
const ::rtl::OUString& _Description ,
const ::rtl::OUString& _SchemaName,
const ::rtl::OUString& _CatalogName
) : OFlatTable_BASE(_pTables,_pConnection,_Name,
2000-10-05 13:47:22 +00:00
_Type,
_Description,
_SchemaName,
_CatalogName)
,m_nRowPos(0)
,m_nMaxRowCount(0)
{
2002-10-08 07:26:17 +00:00
}
// -----------------------------------------------------------------------------
void OFlatTable::construct()
{
2000-10-05 13:47:22 +00:00
Any aValue = ConfigManager::GetDirectConfigProperty(ConfigManager::LOCALE);
LanguageType eLanguage = MsLangId::convertIsoStringToLanguage(comphelper::getString(aValue),'-');
2001-07-30 07:53:02 +00:00
::com::sun::star::lang::Locale aAppLocale(MsLangId::convertLanguageToLocale(eLanguage));
2000-10-05 13:47:22 +00:00
Sequence< ::com::sun::star::uno::Any > aArg(1);
aArg[0] <<= aAppLocale;
2002-10-08 07:26:17 +00:00
Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier(m_pConnection->getDriver()->getFactory()->createInstanceWithArguments(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatsSupplier"),aArg),UNO_QUERY);
m_xNumberFormatter = Reference< ::com::sun::star::util::XNumberFormatter >(m_pConnection->getDriver()->getFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.util.NumberFormatter")),UNO_QUERY);
2000-10-05 13:47:22 +00:00
m_xNumberFormatter->attachNumberFormatsSupplier(xSupplier);
INetURLObject aURL;
2000-11-16 09:47:23 +00:00
aURL.SetURL(getEntry());
2000-10-05 13:47:22 +00:00
if(aURL.getExtension() != rtl::OUString(m_pConnection->getExtension()))
2000-10-05 13:47:22 +00:00
aURL.setExtension(m_pConnection->getExtension());
2001-07-16 08:58:40 +00:00
String aFileName = aURL.GetMainURL(INetURLObject::NO_DECODE);
2000-11-16 09:47:23 +00:00
m_pFileStream = createStream_simpleError( aFileName,STREAM_READWRITE | STREAM_NOCREATE | STREAM_SHARE_DENYWRITE);
2000-11-16 09:47:23 +00:00
if(!m_pFileStream)
m_pFileStream = createStream_simpleError( aFileName,STREAM_READ | STREAM_NOCREATE | STREAM_SHARE_DENYNONE);
2000-10-05 13:47:22 +00:00
2000-11-16 09:47:23 +00:00
if(m_pFileStream)
2000-10-05 13:47:22 +00:00
{
2000-11-16 09:47:23 +00:00
m_pFileStream->Seek(STREAM_SEEK_TO_END);
sal_Int32 nSize = m_pFileStream->Tell();
m_pFileStream->Seek(STREAM_SEEK_TO_BEGIN);
2000-10-05 13:47:22 +00:00
// Buffersize abhaengig von der Filegroesse
2000-11-16 09:47:23 +00:00
m_pFileStream->SetBufferSize(nSize > 1000000 ? 32768 :
2000-10-05 13:47:22 +00:00
nSize > 100000 ? 16384 :
nSize > 10000 ? 4096 : 1024);
fillColumns(aAppLocale);
2000-10-05 13:47:22 +00:00
refreshColumns();
}
}
// -------------------------------------------------------------------------
String OFlatTable::getEntry()
{
::rtl::OUString sURL;
try
2000-10-05 13:47:22 +00:00
{
Reference< XResultSet > xDir = m_pConnection->getDir()->getStaticResultSet();
Reference< XRow> xRow(xDir,UNO_QUERY);
::rtl::OUString sName;
::rtl::OUString sExt;
INetURLObject aURL;
xDir->beforeFirst();
static const ::rtl::OUString s_sSeparator(RTL_CONSTASCII_USTRINGPARAM("/"));
while(xDir->next())
{
sName = xRow->getString(1);
aURL.SetSmartProtocol(INET_PROT_FILE);
String sUrl = m_pConnection->getURL() + s_sSeparator + sName;
aURL.SetSmartURL( sUrl );
// cut the extension
sExt = aURL.getExtension();
// name and extension have to coincide
if ( m_pConnection->matchesExtension( sExt ) )
{
sName = sName.replaceAt(sName.getLength()-(sExt.getLength()+1),sExt.getLength()+1,::rtl::OUString());
if ( sName == m_Name )
{
Reference< XContentAccess > xContentAccess( xDir, UNO_QUERY );
sURL = xContentAccess->queryContentIdentifierString();
break;
}
}
2000-10-05 13:47:22 +00:00
}
xDir->beforeFirst(); // move back to before first record
}
catch(Exception&)
{
OSL_ASSERT(0);
2000-10-05 13:47:22 +00:00
}
return sURL.getStr();
2000-10-05 13:47:22 +00:00
}
// -------------------------------------------------------------------------
void OFlatTable::refreshColumns()
{
::osl::MutexGuard aGuard( m_aMutex );
TStringVector aVector;
aVector.reserve(m_aColumns->size());
2000-10-05 13:47:22 +00:00
for(OSQLColumns::const_iterator aIter = m_aColumns->begin();aIter != m_aColumns->end();++aIter)
aVector.push_back(Reference< XNamed>(*aIter,UNO_QUERY)->getName());
if(m_pColumns)
m_pColumns->reFill(aVector);
else
m_pColumns = new OFlatColumns(this,m_aMutex,aVector);
2000-10-05 13:47:22 +00:00
}
// -------------------------------------------------------------------------
void SAL_CALL OFlatTable::disposing(void)
{
OFileTable::disposing();
::osl::MutexGuard aGuard(m_aMutex);
m_aColumns = NULL;
2000-10-05 13:47:22 +00:00
}
// -------------------------------------------------------------------------
Sequence< Type > SAL_CALL OFlatTable::getTypes( ) throw(RuntimeException)
{
Sequence< Type > aTypes = OTable_TYPEDEF::getTypes();
2001-10-18 12:24:06 +00:00
::std::vector<Type> aOwnTypes;
aOwnTypes.reserve(aTypes.getLength());
2000-10-05 13:47:22 +00:00
const Type* pBegin = aTypes.getConstArray();
const Type* pEnd = pBegin + aTypes.getLength();
2001-05-31 05:11:58 +00:00
for(;pBegin != pEnd;++pBegin)
2000-10-05 13:47:22 +00:00
{
if(!(*pBegin == ::getCppuType((const Reference<XKeysSupplier>*)0) ||
*pBegin == ::getCppuType((const Reference<XRename>*)0) ||
*pBegin == ::getCppuType((const Reference<XIndexesSupplier>*)0) ||
*pBegin == ::getCppuType((const Reference<XAlterTable>*)0) ||
*pBegin == ::getCppuType((const Reference<XDataDescriptorFactory>*)0)))
{
2001-10-18 12:24:06 +00:00
aOwnTypes.push_back(*pBegin);
2000-10-05 13:47:22 +00:00
}
}
Type *pTypes = aOwnTypes.empty() ? 0 : &aOwnTypes[0];
return Sequence< Type >(pTypes, aOwnTypes.size());
2000-10-05 13:47:22 +00:00
}
// -------------------------------------------------------------------------
Any SAL_CALL OFlatTable::queryInterface( const Type & rType ) throw(RuntimeException)
{
if( rType == ::getCppuType((const Reference<XKeysSupplier>*)0) ||
rType == ::getCppuType((const Reference<XIndexesSupplier>*)0) ||
rType == ::getCppuType((const Reference<XRename>*)0) ||
rType == ::getCppuType((const Reference<XAlterTable>*)0) ||
rType == ::getCppuType((const Reference<XDataDescriptorFactory>*)0))
return Any();
Any aRet = OTable_TYPEDEF::queryInterface(rType);
return aRet.hasValue() ? aRet : ::cppu::queryInterface(rType,static_cast< ::com::sun::star::lang::XUnoTunnel*> (this));
2000-10-05 13:47:22 +00:00
}
//--------------------------------------------------------------------------
Sequence< sal_Int8 > OFlatTable::getUnoTunnelImplementationId()
{
static ::cppu::OImplementationId * pId = 0;
if (! pId)
{
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if (! pId)
{
static ::cppu::OImplementationId aId;
pId = &aId;
}
}
return pId->getImplementationId();
}
// com::sun::star::lang::XUnoTunnel
//------------------------------------------------------------------
sal_Int64 OFlatTable::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
{
return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
?
(sal_Int64)this
:
OFlatTable_BASE::getSomething(rId);
2000-10-05 13:47:22 +00:00
}
//------------------------------------------------------------------
sal_Bool OFlatTable::fetchRow(OValueRefRow& _rRow,const OSQLColumns & _rCols,sal_Bool bIsTable,sal_Bool bRetrieveData)
2000-10-05 13:47:22 +00:00
{
*(*_rRow)[0] = m_nFilePos;
2000-10-05 13:47:22 +00:00
if (!bRetrieveData)
return TRUE;
2001-07-30 07:53:02 +00:00
OFlatConnection* pConnection = (OFlatConnection*)m_pConnection;
2000-10-05 13:47:22 +00:00
sal_Int32 nByteOffset = 1;
// Felder:
xub_StrLen nStartPos = 0;
String aStr;
2000-10-05 13:47:22 +00:00
OSQLColumns::const_iterator aIter = _rCols.begin();
OSQLColumns::const_iterator aEnd = _rCols.end();
for (sal_Int32 i = 1; aIter != aEnd && i < _rRow->size();++aIter, i++)
2000-10-05 13:47:22 +00:00
{
m_aCurrentLine.GetTokenSpecial(aStr,nStartPos,pConnection->getFieldDelimiter(),pConnection->getStringDelimiter());
2000-10-05 13:47:22 +00:00
if (aStr.Len() == 0)
(*_rRow)[i]->setNull();
2001-07-30 07:53:02 +00:00
else
2000-10-05 13:47:22 +00:00
{
2001-07-30 07:53:02 +00:00
// Laengen je nach Datentyp:
sal_Int32 nLen,
nType;
if(bIsTable)
2000-10-05 13:47:22 +00:00
{
nLen = m_aPrecisions[i];
nType = m_aTypes[i];
2001-07-30 07:53:02 +00:00
}
else
{
Reference< XPropertySet> xColumn = *aIter;
xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PRECISION)) >>= nLen;
xColumn->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_TYPE)) >>= nType;
}
switch(nType)
{
case DataType::TIMESTAMP:
case DataType::DATE:
case DataType::TIME:
2000-10-05 13:47:22 +00:00
{
2001-07-30 07:53:02 +00:00
double nRes = 0.0;
try
{
nRes = m_xNumberFormatter->convertStringToNumber(::com::sun::star::util::NumberFormat::ALL,aStr);
2001-07-30 07:53:02 +00:00
Reference<XPropertySet> xProp(m_xNumberFormatter->getNumberFormatsSupplier()->getNumberFormatSettings(),UNO_QUERY);
com::sun::star::util::Date aDate;
xProp->getPropertyValue(::rtl::OUString::createFromAscii("NullDate")) >>= aDate;
2000-10-05 13:47:22 +00:00
2001-07-30 07:53:02 +00:00
switch(nType)
{
case DataType::DATE:
*(*_rRow)[i] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDate(nRes,aDate));
2001-07-30 07:53:02 +00:00
break;
case DataType::TIMESTAMP:
*(*_rRow)[i] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toDateTime(nRes,aDate));
2001-07-30 07:53:02 +00:00
break;
default:
*(*_rRow)[i] = ::dbtools::DBTypeConversion::toDouble(::dbtools::DBTypeConversion::toTime(nRes));
2001-07-30 07:53:02 +00:00
}
}
catch(Exception&)
2000-10-05 13:47:22 +00:00
{
(*_rRow)[i]->setNull();
2000-10-05 13:47:22 +00:00
}
2001-07-30 07:53:02 +00:00
} break;
case DataType::DOUBLE:
case DataType::INTEGER:
case DataType::DECIMAL: // #99178# OJ
case DataType::NUMERIC:
2000-10-05 13:47:22 +00:00
{
sal_Unicode cDecimalDelimiter = pConnection->getDecimalDelimiter();
sal_Unicode cThousandDelimiter = pConnection->getThousandDelimiter();
String aStrConverted;
2000-10-05 13:47:22 +00:00
2001-07-30 07:53:02 +00:00
OSL_ENSURE(cDecimalDelimiter && nType != DataType::INTEGER ||
!cDecimalDelimiter && nType == DataType::INTEGER,
"FalscherTyp");
2000-10-05 13:47:22 +00:00
2001-07-30 07:53:02 +00:00
// In Standard-Notation (DezimalPUNKT ohne Tausender-Komma) umwandeln:
for (xub_StrLen j = 0; j < aStr.Len(); ++j)
2000-10-05 13:47:22 +00:00
{
2001-07-30 07:53:02 +00:00
if (cDecimalDelimiter && aStr.GetChar(j) == cDecimalDelimiter)
aStrConverted += '.';
else if ( aStr.GetChar(j) == '.' ) // special case, if decimal seperator isn't '.' we have to vut the string after it
continue; // #99189# OJ
2001-07-30 07:53:02 +00:00
else if (cThousandDelimiter && aStr.GetChar(j) == cThousandDelimiter)
{
// weglassen
}
else
aStrConverted += aStr.GetChar(j) ;
2000-10-05 13:47:22 +00:00
}
double nVal = ::rtl::math::stringToDouble(aStrConverted,'.',',',NULL,NULL);
// #99178# OJ
if ( DataType::DECIMAL == nType || DataType::NUMERIC == nType )
*(*_rRow)[i] = ORowSetValue(String::CreateFromDouble(nVal));
else
*(*_rRow)[i] = nVal;
2001-07-30 07:53:02 +00:00
} break;
2001-07-30 07:53:02 +00:00
default:
{
// Wert als String in Variable der Row uebernehmen
*(*_rRow)[i] = ORowSetValue(aStr);
2000-10-05 13:47:22 +00:00
}
2001-07-30 07:53:02 +00:00
break;
2000-10-05 13:47:22 +00:00
}
}
}
return sal_True;
}
2001-07-30 07:53:02 +00:00
// -----------------------------------------------------------------------------
2000-10-05 13:47:22 +00:00