User: vg      
Date: 05/03/23 01:43:05

Modified:
 /dba/connectivity/source/parse/
  sqlnode.cxx

Log:
 INTEGRATION: CWS dba26 (1.35.66); FILE MERGED
 2005/03/15 14:42:39 fs 1.35.66.1: #i26655# unified the date handling - now 
also recognizing date values if enclosed in ' signs (i.e. as string)

File Changes:

Directory: /dba/connectivity/source/parse/
==========================================

File [changed]: sqlnode.cxx
Url: 
http://dba.openoffice.org/source/browse/dba/connectivity/source/parse/sqlnode.cxx?r1=1.35&r2=1.36
Delta lines:  +54 -80
---------------------
--- sqlnode.cxx 9 Sep 2004 09:04:29 -0000       1.35
+++ sqlnode.cxx 23 Mar 2005 09:43:02 -0000      1.36
@@ -166,7 +166,7 @@
 
 namespace
 {
-       sal_Bool lcl_convertDateFormat(const Reference< XNumberFormatter > & 
_xFormatter,sal_Int32 _nKey,const ::rtl::OUString& _sValue,double& _nrValue)
+       sal_Bool lcl_saveConvertToNumber(const Reference< XNumberFormatter > & 
_xFormatter,sal_Int32 _nKey,const ::rtl::OUString& _sValue,double& _nrValue)
        {
                sal_Bool bRet = sal_False;
                try
@@ -638,7 +638,7 @@
                                                case DataType::TIME:
                                                case DataType::TIMESTAMP:
                                                        if (m_xFormatter.is())
-                                                               nErg = 
buildDate(pLiteral->getTokenValue(),nType,pAppend,pLiteral,pCompare);
+                                                               nErg = 
buildDate( nType, pAppend, pLiteral, pCompare );
                                                        else
                                                                nErg = 
buildNode(pAppend,pLiteral,pCompare);
 
@@ -655,57 +655,7 @@
                                                case DataType::TIMESTAMP:
                                                        nErg = -1;
                                                        if (m_xFormatter.is())
-                                                       {
-                                                               try
-                                                               {
-                                                                       // do 
we have a date
-                                                                       if ( 
!m_nFormatKey )
-                                                                       {
-                                                                               
Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xFormatSup = 
m_xFormatter->getNumberFormatsSupplier();
-                                                                               
Reference< ::com::sun::star::util::XNumberFormatTypes >  
xFormatTypes(xFormatSup->getNumberFormats(),UNO_QUERY);
-                                                                               
m_nFormatKey = 
::dbtools::getDefaultNumberFormat(m_xField,xFormatTypes,*m_pLocale);
-                                                                       }
-                                                                       double 
fValue = m_xFormatter->convertStringToNumber(m_nFormatKey, 
pLiteral->getTokenValue().getStr());
-                                                                       nErg = 
buildNode_Date(fValue, nType, pAppend,pLiteral,pCompare);
-                                                               }
-                                                               catch( 
Exception& )
-                                                               {
-                                                                       
Reference< ::com::sun::star::util::XNumberFormatsSupplier >  xFormatSup = 
m_xFormatter->getNumberFormatsSupplier();
-                                                                       
Reference< ::com::sun::star::util::XNumberFormatTypes >  
xFormatTypes(xFormatSup->getNumberFormats(),UNO_QUERY);
-                                                                       if 
(xFormatTypes.is())
-                                                                       {
-                                                                               
try
-                                                                               
{
-                                                                               
        
-                                                                               
        double fValue = m_xFormatter->convertStringToNumber(
-                                                                               
                
xFormatTypes->getStandardFormat(::com::sun::star::util::NumberFormat::DATE, 
*m_pLocale),
-                                                                               
                                                                                
pLiteral->getTokenValue().getStr());
-                                                                               
        nErg = buildNode_Date(fValue, nType, pAppend,pLiteral,pCompare);
-                                                                               
        
-                                                                               
}
-                                                                               
catch( Exception& )
-                                                                               
{
-                                                                               
        try
-                                                                               
        {
-                                                                               
                double fValue = m_xFormatter->convertStringToNumber(
-                                                                               
                        
xFormatTypes->getFormatIndex(::com::sun::star::i18n::NumberFormatIndex::DATE_DIN_YYYYMMDD,
 *m_pLocale),
-                                                                               
                                                                                
        pLiteral->getTokenValue());
-                                                                               
                nErg = buildNode_Date(fValue, nType, pAppend,pLiteral,pCompare);
-                                                                               
        }
-                                                                               
        catch( Exception& )
-                                                                               
        {       
-                                                                               
                nErg = -1;
-                                                                               
                m_sErrorMessage = 
m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
-                                                                               
        }
-                                                                               
}
-                                                                       }
-                                                                       else
-                                                                       {
-                                                                               
nErg = -1;
-                                                                               
m_sErrorMessage = 
m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
-                                                                       }
-                                                               }
-                                                       }
+                                                               nErg = 
buildDate( nType, pAppend, pLiteral, pCompare );
                                                        else
                                                                m_sErrorMessage 
= m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
                                                        break;
@@ -1013,8 +963,8 @@
                                        if ( xFormats.is() )
                                        {
                                                ::com::sun::star::lang::Locale 
aLocale;
-                                               aLocale.Language = 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en_US"));
-                                               aLocale.Country = 
aLocale.Language;
+                                               aLocale.Language = 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
+                                               aLocale.Country = 
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US"));
                                                ::rtl::OUString 
sFormat(RTL_CONSTASCII_USTRINGPARAM("YYYY-MM-DD"));
                                                m_nDateFormatKey = 
xFormats->queryKey(sFormat,aLocale,sal_False);
                                                if ( m_nDateFormatKey == 
sal_Int32(-1) )
@@ -1165,39 +1115,63 @@
 }
 
 // 
-----------------------------------------------------------------------------
-sal_Int16 OSQLParser::buildDate(const ::rtl::OUString& _sValue,sal_Int32 
_nType,OSQLParseNode*& pAppend,OSQLParseNode* pLiteral,OSQLParseNode*& pCompare)
+sal_Int16 OSQLParser::buildDate(sal_Int32 _nType,OSQLParseNode*& 
pAppend,OSQLParseNode* pLiteral,OSQLParseNode*& pCompare)
 {
-       sal_Int16 nErg = 0;
+       sal_Int16 nErg = -1;
        double fValue = 0.0;
+    ::rtl::OUString sValue = pLiteral->getTokenValue();
                                                                
-       sal_Bool bBuildDate = 
lcl_convertDateFormat(m_xFormatter,m_nFormatKey,_sValue,fValue);
-       if ( !bBuildDate )
-       {
+    Reference< XNumberFormatsSupplier > xFormatSup = 
m_xFormatter->getNumberFormatsSupplier();
+       Reference< XNumberFormatTypes > xFormatTypes;
+    if ( xFormatSup.is() )
+        xFormatTypes = xFormatTypes.query( xFormatSup->getNumberFormats() );
+
+    // if there is no format key, yet, make sure we have a feasible one for 
our locale
                try
                {
-                       Reference< 
::com::sun::star::util::XNumberFormatsSupplier >  xFormatSup = 
m_xFormatter->getNumberFormatsSupplier();
-                       Reference< ::com::sun::star::util::XNumberFormatTypes > 
 xFormatTypes(xFormatSup->getNumberFormats(),UNO_QUERY);
-                       sal_Int32 nStandardFormat = 0;
-                       if ( xFormatTypes.is() )
+               if ( !m_nFormatKey && xFormatTypes.is() )
+                       m_nFormatKey = ::dbtools::getDefaultNumberFormat( 
m_xField, xFormatTypes, *m_pLocale );
+    }
+    catch( Exception& ) { }
+
+    // try converting the string into a date, according to our format key
+    sal_Int32 nTryFormat = m_nFormatKey;
+    bool bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, 
fValue );
+
+    // If our format key didn't do, try the default date format for our locale.
+    if ( !bSuccess && xFormatTypes.is() )
+    {
+               try
                        {
-                               nStandardFormat = 
xFormatTypes->getStandardFormat(::com::sun::star::util::NumberFormat::DATE, 
*m_pLocale);
-                               bBuildDate = 
lcl_convertDateFormat(m_xFormatter,nStandardFormat,_sValue,fValue);
+            nTryFormat = xFormatTypes->getStandardFormat( NumberFormat::DATE, 
*m_pLocale );
                        }
+        catch( Exception& ) { }
+        bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, 
fValue );
                }
-               catch(Exception&)
+
+    // if this also didn't do, try ISO format
+    if ( !bSuccess && xFormatTypes.is() )
+    {
+               try
                {
+            nTryFormat = xFormatTypes->getFormatIndex( 
NumberFormatIndex::DATE_DIN_YYYYMMDD, *m_pLocale );
                }
-               if ( !bBuildDate )
-                       bBuildDate = 
lcl_convertDateFormat(m_xFormatter,m_nDateFormatKey,_sValue,fValue);
+        catch( Exception& ) { }
+        bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, 
fValue );
        }
 
-       if ( bBuildDate )
-               nErg = buildNode_Date(fValue, _nType, 
pAppend,pLiteral,pCompare);
-       else
+    // if this also didn't do, try fallback date format (en-US)
+    if ( !bSuccess )
        {
-               nErg = -1;
-               m_sErrorMessage = 
m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
+        nTryFormat = m_nDateFormatKey;
+        bSuccess = lcl_saveConvertToNumber( m_xFormatter, nTryFormat, sValue, 
fValue );
        }
+
+    if ( bSuccess )
+               nErg = buildNode_Date( fValue, _nType, pAppend, pLiteral, 
pCompare );
+    else
+               m_sErrorMessage = 
m_pContext->getErrorMessage(IParseContext::ERROR_INVALID_DATE_COMPARE);
+
        return nErg;
 }
 // 
-----------------------------------------------------------------------------




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to