2010-10-12 15:53:47 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-21 22:06:52 +00:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
2006-09-17 04:02:42 +00:00
|
|
|
|
2007-11-21 14:22:00 +00:00
|
|
|
|
2010-10-14 22:33:33 +01:00
|
|
|
#include <sal/macros.h>
|
2010-04-20 15:55:51 +02:00
|
|
|
#include "svx/ParseContext.hxx"
|
2007-11-21 14:22:00 +00:00
|
|
|
#include "stringlistresource.hxx"
|
2010-04-20 15:55:51 +02:00
|
|
|
#include "svx/fmresids.hrc"
|
2007-11-21 14:22:00 +00:00
|
|
|
|
2007-06-27 17:09:44 +00:00
|
|
|
#include <svx/dialmgr.hxx>
|
2007-11-21 14:22:00 +00:00
|
|
|
|
2009-10-16 00:05:16 +02:00
|
|
|
#include <unotools/syslocale.hxx>
|
2002-09-27 13:05:46 +00:00
|
|
|
#include <vcl/svapp.hxx>
|
2007-11-21 14:22:00 +00:00
|
|
|
#include <tools/debug.hxx>
|
2010-10-16 03:18:35 -05:00
|
|
|
#include <osl/mutex.hxx>
|
2002-09-27 10:26:33 +00:00
|
|
|
|
|
|
|
using namespace svxform;
|
|
|
|
using namespace ::connectivity;
|
|
|
|
//==========================================================================
|
|
|
|
//= OSystemParseContext
|
|
|
|
//==========================================================================
|
2006-10-12 11:44:00 +00:00
|
|
|
DBG_NAME(OSystemParseContext)
|
2002-09-27 10:26:33 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
OSystemParseContext::OSystemParseContext() : IParseContext()
|
|
|
|
{
|
|
|
|
DBG_CTOR(OSystemParseContext,NULL);
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2007-11-21 14:22:00 +00:00
|
|
|
|
|
|
|
::svx::StringListResource aKeywords( SVX_RES( RID_RSC_SQL_INTERNATIONAL ) );
|
|
|
|
aKeywords.get( m_aLocalizedKeywords );
|
2002-09-27 10:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
OSystemParseContext::~OSystemParseContext()
|
|
|
|
{
|
|
|
|
DBG_DTOR(OSystemParseContext,NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
::com::sun::star::lang::Locale OSystemParseContext::getPreferredLocale( ) const
|
|
|
|
{
|
2012-11-23 23:06:10 +01:00
|
|
|
return SvtSysLocale().GetLanguageTag().getLocale();
|
2002-09-27 10:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-04-07 12:06:47 +02:00
|
|
|
OUString OSystemParseContext::getErrorMessage(ErrorCode _eCode) const
|
2002-09-27 10:26:33 +00:00
|
|
|
{
|
2013-09-04 14:50:08 +02:00
|
|
|
OUString aMsg;
|
2010-10-13 02:47:36 -05:00
|
|
|
SolarMutexGuard aGuard;
|
2002-09-27 10:26:33 +00:00
|
|
|
switch (_eCode)
|
|
|
|
{
|
2012-04-29 23:36:57 +01:00
|
|
|
case ERROR_GENERAL: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ERROR); break;
|
|
|
|
case ERROR_VALUE_NO_LIKE: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_VALUE_NO_LIKE); break;
|
|
|
|
case ERROR_FIELD_NO_LIKE: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_FIELD_NO_LIKE); break;
|
|
|
|
case ERROR_INVALID_COMPARE: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_CRIT_NO_COMPARE); break;
|
|
|
|
case ERROR_INVALID_INT_COMPARE: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_INT_NO_VALID); break;
|
|
|
|
case ERROR_INVALID_DATE_COMPARE: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_ACCESS_DAT_NO_VALID); break;
|
|
|
|
case ERROR_INVALID_REAL_COMPARE: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_REAL_NO_VALID); break;
|
|
|
|
case ERROR_INVALID_TABLE: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE); break;
|
|
|
|
case ERROR_INVALID_TABLE_OR_QUERY: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_OR_QUERY); break;
|
|
|
|
case ERROR_INVALID_COLUMN: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_COLUMN); break;
|
|
|
|
case ERROR_INVALID_TABLE_EXIST: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_TABLE_EXISTS); break;
|
|
|
|
case ERROR_INVALID_QUERY_EXIST: aMsg = SVX_RESSTR(RID_STR_SVT_SQL_SYNTAX_QUERY_EXISTS); break;
|
2006-06-19 14:51:02 +00:00
|
|
|
case ERROR_NONE: break;
|
2002-09-27 10:26:33 +00:00
|
|
|
}
|
|
|
|
return aMsg;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2013-04-07 12:06:47 +02:00
|
|
|
OString OSystemParseContext::getIntlKeywordAscii(InternationalKeyCode _eKey) const
|
2002-09-27 10:26:33 +00:00
|
|
|
{
|
2007-11-21 14:22:00 +00:00
|
|
|
size_t nIndex = 0;
|
|
|
|
switch ( _eKey )
|
2002-09-27 10:26:33 +00:00
|
|
|
{
|
2007-11-21 14:22:00 +00:00
|
|
|
case KEY_LIKE: nIndex = 0; break;
|
|
|
|
case KEY_NOT: nIndex = 1; break;
|
|
|
|
case KEY_NULL: nIndex = 2; break;
|
|
|
|
case KEY_TRUE: nIndex = 3; break;
|
|
|
|
case KEY_FALSE: nIndex = 4; break;
|
|
|
|
case KEY_IS: nIndex = 5; break;
|
|
|
|
case KEY_BETWEEN: nIndex = 6; break;
|
|
|
|
case KEY_OR: nIndex = 7; break;
|
|
|
|
case KEY_AND: nIndex = 8; break;
|
|
|
|
case KEY_AVG: nIndex = 9; break;
|
|
|
|
case KEY_COUNT: nIndex = 10; break;
|
|
|
|
case KEY_MAX: nIndex = 11; break;
|
|
|
|
case KEY_MIN: nIndex = 12; break;
|
|
|
|
case KEY_SUM: nIndex = 13; break;
|
2008-08-19 08:47:25 +00:00
|
|
|
case KEY_EVERY: nIndex = 14; break;
|
|
|
|
case KEY_ANY: nIndex = 15; break;
|
|
|
|
case KEY_SOME: nIndex = 16; break;
|
|
|
|
case KEY_STDDEV_POP: nIndex = 17; break;
|
|
|
|
case KEY_STDDEV_SAMP: nIndex = 18; break;
|
|
|
|
case KEY_VAR_SAMP: nIndex = 19; break;
|
|
|
|
case KEY_VAR_POP: nIndex = 20; break;
|
|
|
|
case KEY_COLLECT: nIndex = 21; break;
|
|
|
|
case KEY_FUSION: nIndex = 22; break;
|
|
|
|
case KEY_INTERSECTION: nIndex = 23; break;
|
2006-06-19 14:51:02 +00:00
|
|
|
case KEY_NONE:
|
2011-03-01 19:07:44 +01:00
|
|
|
OSL_FAIL( "OSystemParseContext::getIntlKeywordAscii: illegal argument!" );
|
2006-06-19 14:51:02 +00:00
|
|
|
break;
|
2002-09-27 10:26:33 +00:00
|
|
|
}
|
2007-11-21 14:22:00 +00:00
|
|
|
|
|
|
|
OSL_ENSURE( nIndex < m_aLocalizedKeywords.size(), "OSystemParseContext::getIntlKeywordAscii: invalid index!" );
|
|
|
|
|
2013-04-07 12:06:47 +02:00
|
|
|
OString sKeyword;
|
2007-11-21 14:22:00 +00:00
|
|
|
if ( nIndex < m_aLocalizedKeywords.size() )
|
2013-04-07 12:06:47 +02:00
|
|
|
sKeyword = OUStringToOString(m_aLocalizedKeywords[nIndex], RTL_TEXTENCODING_UTF8);
|
2007-11-21 14:22:00 +00:00
|
|
|
return sKeyword;
|
2002-09-27 10:26:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
2013-04-07 12:06:47 +02:00
|
|
|
IParseContext::InternationalKeyCode OSystemParseContext::getIntlKeyCode(const OString& rToken) const
|
2002-09-27 10:26:33 +00:00
|
|
|
{
|
2013-07-04 09:45:49 +09:00
|
|
|
static const IParseContext::InternationalKeyCode Intl_TokenID[] =
|
2002-09-27 10:26:33 +00:00
|
|
|
{
|
|
|
|
KEY_LIKE, KEY_NOT, KEY_NULL, KEY_TRUE,
|
|
|
|
KEY_FALSE, KEY_IS, KEY_BETWEEN, KEY_OR,
|
|
|
|
KEY_AND, KEY_AVG, KEY_COUNT, KEY_MAX,
|
2008-08-19 08:47:25 +00:00
|
|
|
KEY_MIN, KEY_SUM, KEY_EVERY,
|
|
|
|
KEY_ANY, KEY_SOME, KEY_STDDEV_POP,
|
|
|
|
KEY_STDDEV_SAMP, KEY_VAR_SAMP, KEY_VAR_POP,
|
|
|
|
KEY_COLLECT, KEY_FUSION, KEY_INTERSECTION
|
2002-09-27 10:26:33 +00:00
|
|
|
};
|
|
|
|
|
2012-05-29 17:23:51 +01:00
|
|
|
sal_uInt32 nCount = sizeof Intl_TokenID / sizeof Intl_TokenID[0];
|
2002-09-27 10:26:33 +00:00
|
|
|
for (sal_uInt32 i = 0; i < nCount; i++)
|
|
|
|
{
|
2013-04-07 12:06:47 +02:00
|
|
|
OString aKey = getIntlKeywordAscii(Intl_TokenID[i]);
|
2002-09-27 10:26:33 +00:00
|
|
|
if (rToken.equalsIgnoreAsciiCase(aKey))
|
|
|
|
return Intl_TokenID[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return KEY_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// =============================================================================
|
|
|
|
// =============================================================================
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
::osl::Mutex& getSafteyMutex()
|
|
|
|
{
|
|
|
|
static ::osl::Mutex s_aSafety;
|
|
|
|
return s_aSafety;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
oslInterlockedCount& getCounter()
|
|
|
|
{
|
|
|
|
static oslInterlockedCount s_nCounter;
|
|
|
|
return s_nCounter;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
OSystemParseContext* getSharedContext(OSystemParseContext* _pContext = NULL,sal_Bool _bSet = sal_False)
|
|
|
|
{
|
|
|
|
static OSystemParseContext* s_pSharedContext = NULL;
|
2007-05-10 09:05:21 +00:00
|
|
|
if ( _pContext && !s_pSharedContext )
|
|
|
|
{
|
2002-09-27 10:26:33 +00:00
|
|
|
s_pSharedContext = _pContext;
|
2007-05-10 09:05:21 +00:00
|
|
|
return s_pSharedContext;
|
|
|
|
}
|
|
|
|
if ( _bSet )
|
|
|
|
{
|
|
|
|
OSystemParseContext* pReturn = _pContext ? _pContext : s_pSharedContext;
|
|
|
|
s_pSharedContext = _pContext;
|
|
|
|
return pReturn;
|
|
|
|
}
|
2002-09-27 10:26:33 +00:00
|
|
|
return s_pSharedContext;
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
OParseContextClient::OParseContextClient()
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( getSafteyMutex() );
|
2012-09-22 01:51:12 -05:00
|
|
|
if ( 1 == osl_atomic_increment( &getCounter() ) )
|
2002-09-27 10:26:33 +00:00
|
|
|
{ // first instance
|
|
|
|
getSharedContext( new OSystemParseContext );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
OParseContextClient::~OParseContextClient()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
::osl::MutexGuard aGuard( getSafteyMutex() );
|
2012-09-22 01:51:12 -05:00
|
|
|
if ( 0 == osl_atomic_decrement( &getCounter() ) )
|
2002-09-27 10:26:33 +00:00
|
|
|
delete getSharedContext(NULL,sal_True);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
const OSystemParseContext* OParseContextClient::getParseContext() const
|
|
|
|
{
|
|
|
|
return getSharedContext();
|
|
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-10-12 15:53:47 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|