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