1*caf5cd79SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*caf5cd79SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*caf5cd79SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*caf5cd79SAndrew Rist * distributed with this work for additional information 6*caf5cd79SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*caf5cd79SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*caf5cd79SAndrew Rist * "License"); you may not use this file except in compliance 9*caf5cd79SAndrew Rist * with the License. You may obtain a copy of the License at 10*caf5cd79SAndrew Rist * 11*caf5cd79SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*caf5cd79SAndrew Rist * 13*caf5cd79SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*caf5cd79SAndrew Rist * software distributed under the License is distributed on an 15*caf5cd79SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*caf5cd79SAndrew Rist * KIND, either express or implied. See the License for the 17*caf5cd79SAndrew Rist * specific language governing permissions and limitations 18*caf5cd79SAndrew Rist * under the License. 19*caf5cd79SAndrew Rist * 20*caf5cd79SAndrew Rist *************************************************************/ 21*caf5cd79SAndrew Rist 22*caf5cd79SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef CONNECTIVITY_PREDICATEINPUT_HXX 25cdf0e10cSrcweir #define CONNECTIVITY_PREDICATEINPUT_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29cdf0e10cSrcweir #include <com/sun/star/sdbc/XConnection.hpp> 30cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp> 31cdf0e10cSrcweir #include <com/sun/star/i18n/XLocaleData.hpp> 32cdf0e10cSrcweir #include <connectivity/sqlparse.hxx> 33cdf0e10cSrcweir #include "connectivity/dbtoolsdllapi.hxx" 34cdf0e10cSrcweir 35cdf0e10cSrcweir //......................................................................... 36cdf0e10cSrcweir namespace dbtools 37cdf0e10cSrcweir { 38cdf0e10cSrcweir //......................................................................... 39cdf0e10cSrcweir 40cdf0e10cSrcweir //===================================================================== 41cdf0e10cSrcweir //= OPredicateInputController 42cdf0e10cSrcweir //===================================================================== 43cdf0e10cSrcweir /** A class which allows input of an SQL predicate for a row set column 44cdf0e10cSrcweir into a edit field. 45cdf0e10cSrcweir */ 46cdf0e10cSrcweir class OOO_DLLPUBLIC_DBTOOLS OPredicateInputController 47cdf0e10cSrcweir { 48cdf0e10cSrcweir private: 49cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > 50cdf0e10cSrcweir m_xORB; 51cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > 52cdf0e10cSrcweir m_xConnection; 53cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter > 54cdf0e10cSrcweir m_xFormatter; 55cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::i18n::XLocaleData > 56cdf0e10cSrcweir m_xLocaleData; 57cdf0e10cSrcweir 58cdf0e10cSrcweir ::connectivity::OSQLParser 59cdf0e10cSrcweir m_aParser; 60cdf0e10cSrcweir 61cdf0e10cSrcweir public: 62cdf0e10cSrcweir OPredicateInputController( 63cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, 64cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection >& _rxConnection, 65cdf0e10cSrcweir const ::connectivity::IParseContext* _pParseContext = NULL 66cdf0e10cSrcweir ); 67cdf0e10cSrcweir 68cdf0e10cSrcweir /** transforms a "raw" predicate value (usually obtained from a user input) into a valid predicate for the given column 69cdf0e10cSrcweir @param _rPredicateValue 70cdf0e10cSrcweir The text to normalize. 71cdf0e10cSrcweir @param _rxField 72cdf0e10cSrcweir The field for which the text should be a predicate value. 73cdf0e10cSrcweir @param _pErrorMessage 74cdf0e10cSrcweir If not <NULL/>, and a parsing error occurs, the error message will be copied to the string the argument 75cdf0e10cSrcweir points to. 76cdf0e10cSrcweir */ 77cdf0e10cSrcweir sal_Bool normalizePredicateString( 78cdf0e10cSrcweir ::rtl::OUString& _rPredicateValue, 79cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxField, 80cdf0e10cSrcweir ::rtl::OUString* _pErrorMessage = NULL 81cdf0e10cSrcweir ) const; 82cdf0e10cSrcweir 83cdf0e10cSrcweir /** get's a value of the predicate which can be used in a WHERE clause. 84cdf0e10cSrcweir @param _rPredicateValue 85cdf0e10cSrcweir the value which has been normalized using normalizePredicateString 86cdf0e10cSrcweir @param _rxField 87cdf0e10cSrcweir is the field for which a predicate is to be entered 88cdf0e10cSrcweir @param _bForStatementUse 89cdf0e10cSrcweir If <TRUE/>, the returned value can be used in an SQL statement. If <FALSE/>, it can be used 90cdf0e10cSrcweir for instance for setting parameter values. 91cdf0e10cSrcweir @param _pErrorMessage 92cdf0e10cSrcweir If not <NULL/>, and a parsing error occurs, the error message will be copied to the string the argument 93cdf0e10cSrcweir points to. 94cdf0e10cSrcweir @see normalizePredicateString 95cdf0e10cSrcweir */ 96cdf0e10cSrcweir ::rtl::OUString getPredicateValue( 97cdf0e10cSrcweir const ::rtl::OUString& _rPredicateValue, 98cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _rxField, 99cdf0e10cSrcweir sal_Bool _bForStatementUse, 100cdf0e10cSrcweir ::rtl::OUString* _pErrorMessage = NULL 101cdf0e10cSrcweir ) const; 102cdf0e10cSrcweir 103cdf0e10cSrcweir ::rtl::OUString getPredicateValue( 104cdf0e10cSrcweir const ::rtl::OUString& _sField 105cdf0e10cSrcweir , const ::rtl::OUString& _rPredicateValue 106cdf0e10cSrcweir , sal_Bool _bForStatementUse 107cdf0e10cSrcweir , ::rtl::OUString* _pErrorMessage = NULL) const; 108cdf0e10cSrcweir 109cdf0e10cSrcweir private: 110cdf0e10cSrcweir ::connectivity::OSQLParseNode* implPredicateTree( 111cdf0e10cSrcweir ::rtl::OUString& _rErrorMessage, 112cdf0e10cSrcweir const ::rtl::OUString& _rStatement, 113cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > & _rxField 114cdf0e10cSrcweir ) const; 115cdf0e10cSrcweir 116cdf0e10cSrcweir sal_Bool getSeparatorChars( 117cdf0e10cSrcweir const ::com::sun::star::lang::Locale& _rLocale, 118cdf0e10cSrcweir sal_Unicode& _rDecSep, 119cdf0e10cSrcweir sal_Unicode& _rThdSep 120cdf0e10cSrcweir ) const; 121cdf0e10cSrcweir 122cdf0e10cSrcweir ::rtl::OUString implParseNode(::connectivity::OSQLParseNode* pParseNode,sal_Bool _bForStatementUse) const; 123cdf0e10cSrcweir }; 124cdf0e10cSrcweir 125cdf0e10cSrcweir //......................................................................... 126cdf0e10cSrcweir } // namespace dbtools 127cdf0e10cSrcweir //......................................................................... 128cdf0e10cSrcweir 129cdf0e10cSrcweir #endif // CONNECTIVITY_PREDICATEINPUT_HXX 130cdf0e10cSrcweir 131