6e7196fa4a6c83602a4fc52f17d26890155b4425
[platform/framework/native/appfw.git] / inc / FIoSqlStatementBuilder.h
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        FIoSqlStatementBuilder.h
19  * @brief       This is the header file for the %SqlStatementBuilder class.
20  *
21  * This header file contains the declarations of the %SqlStatementBuilder class.
22  */
23
24 #ifndef _FIO_SQL_STATEMENT_BUILDER_H_
25 #define _FIO_SQL_STATEMENT_BUILDER_H_
26
27 #include <FOspConfig.h>
28
29 namespace Tizen { namespace Base
30 {
31 class String;
32 namespace Collection
33 {
34 class IList;
35 class IMap;
36 }
37 }}
38
39 namespace Tizen { namespace Io
40 {
41
42 /**
43  * @class       SqlStatementBuilder
44  * @brief       This class provides methods for building SQL statement.
45  *
46  * @since       2.0
47  *
48  * @final       This class is not intended for extension.
49  *
50  * The %SqlStatementBuilder class provides methods for building SQL statement.
51  */
52 class _OSP_EXPORT_ SqlStatementBuilder
53         : public Tizen::Base::Object
54 {
55
56 public:
57         /**
58         * Creates SQL SELECT statement.
59         *
60         * @since                2.0
61         *
62         * @return               A created SQL SELECT statement, @n
63         *                               else an empty string in case of failure
64         * @param[in]    table                           A table name to query from
65         * @param[in]    pColumnList                     A list of column names to query @n
66         *                                                                       The type of objects contained in the specified @c pColumnList must be
67         *                                                                       Tizen::Base::String class.
68         *                                                                       If it is @c null, all columns are returned in result set.
69         * @param[in]    pWhere                          A filter to select desired rows to query @n
70         *                                                                       It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
71         *                                                                       column1 = 'stringValue' AND column2 = numericValue.
72         * @param[in]    pOrder                          Sorting order of rows to query @n
73         *                                                                       It is an SQL 'ORDER BY' clause excluding the 'ORDER BY' itself.
74         * @param[in]    pLimit                          Limitation of the number of rows to query @n
75         *                                                                       It is the SQL 'LIMIT' clause excluding the 'LIMIT' itself.
76         * @param[in]    pGroup                          A filter to select a column grouping rows to query @n
77         *                                                                       It is the SQL 'GROUP BY' clause excluding the 'GROUP BY' itself.
78         * @param[in]    pHaving                         A filter for the group @n
79         *                                                                       It is the SQL 'HAVING' clause excluding the 'HAVING' itself.
80         * @exception    E_SUCCESS                       The method is successful.
81         * @exception    E_INVALID_ARG           Either of the following conditions has occurred:
82         *                                                                       - The specified @c pColumnList is empty.
83         *                                                                       - The specified @c pOrder is @c null and @c pLimit is not @c null.
84         *                                                                       - The specified @c pGroup is @c null and @c pHaving is not @c null.
85         * @exception    E_SYSTEM                        A system error has occurred.
86         * @remarks      The specific error code can be accessed using the GetLastResult() method.
87         * @remarks              If the value specified in the @c pWhere is string, the value must be wrapped in
88         *                               single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.
89         *                               For more information on the SQL statement, see SQLite SQL documents.
90         */
91         static Tizen::Base::String CreateSelectStatement(const Tizen::Base::String& table, const Tizen::Base::Collection::IList* pColumnList,
92                         const Tizen::Base::String* pWhere, const Tizen::Base::String* pOrder = null, const Tizen::Base::String* pLimit = null,
93                         const Tizen::Base::String* pGroup = null, const Tizen::Base::String* pHaving = null);
94
95         /**
96         * Creates SQL INSERT statement.
97         *
98         * @since                2.0
99         *
100         * @return               A created SQL INSERT statement, @n
101         *                               else an empty string in case of failure @n
102         * @param[in]    table                           A table name to insert
103         * @param[in]    insertMap                       Column-value pairs to insert @n
104         *                                                                       The type of objects contained in the specified @c insertMap must be
105         *                                                                       Tizen::Base::String class.
106         * @exception    E_SUCCESS                       The method is successful.
107         * @exception    E_INVALID_ARG           The specified @c insertMap is empty.
108         * @exception    E_SYSTEM                        A system error has occurred.
109         * @remarks      The specific error code can be accessed using the GetLastResult() method.
110         * @remarks              If the value specified in the @c insertMap is string, the value must be wrapped in
111         *                               single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.
112         *                               For more information on the SQL statement, see SQLite SQL documents.
113         */
114         static Tizen::Base::String CreateInsertStatement(const Tizen::Base::String& table, const Tizen::Base::Collection::IMap& insertMap);
115
116         /**
117         * Creates SQL UPDATE statement.
118         *
119         * @since                2.0
120         *
121         * @return               A created SQL UPDATE statement, @n
122         *                               else an empty string in case of failure @n
123         * @param[in]    table                           A table name to update
124         * @param[in]    updateMap                       Column-value pairs to update @n
125         *                                                                       The type of objects contained in the specified @c updateMap must be
126         *                                                                       Tizen::Base::String class.
127         * @param[in]    pWhere                          A filter to select desired rows to update @n
128         *                                                                       It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
129         *                                                                       column1 = 'stringValue' AND column2 = numericValue.
130         * @exception    E_SUCCESS                       The method is successful.
131         * @exception    E_INVALID_ARG           The specified @c updateMap is empty.
132         * @exception    E_SYSTEM                        A system error has occurred.
133         * @remarks      The specific error code can be accessed using the GetLastResult() method.
134         * @remarks              If the value specified in the @c pWhere or @c updateMap is string, the value must be wrapped in
135         *                               single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.
136         *                               For more information on the SQL statement, see SQLITE SQL documents.
137         */
138         static Tizen::Base::String CreateUpdateStatement(const Tizen::Base::String& table, const Tizen::Base::Collection::IMap& updateMap,
139                         const Tizen::Base::String* pWhere);
140
141         /**
142         * Creates SQL DELETE statement.
143         *
144         * @since                2.0
145         *
146         * @return               A created SQL DELETE statement, @n
147         *                               else an empty string in case of failure @n
148         * @param[in]    table                           A table name to query
149         * @param[in]    pWhere                          A filter to select desired rows to delete @n
150         *                                                                       It is an SQL 'WHERE' clause excluding the 'WHERE' itself such as
151         *                                                                       column1 = 'stringValue' AND column2 = numericValue.
152         *                                                                       If it is @c null, all rows are deleted.
153         * @exception    E_SUCCESS                       The method is successful.
154         * @exception    E_INVALID_ARG           A specified parameter is invalid.
155         * @exception    E_SYSTEM                        A system error has occurred.
156         * @remarks      The specific error code can be accessed using the GetLastResult() method.
157         * @remarks              If the value specified in the @c pWhere is string, the value must be wrapped in
158         *                               single quotes. Otherwise it is not needed to wrap the numeric value in single quotes.
159         *                               For more information on the SQL statement, see SQLITE SQL documents.
160         */
161         static Tizen::Base::String CreateDeleteStatement(const Tizen::Base::String& table, const Tizen::Base::String* pWhere);
162
163 private:
164         /**
165         * This default constructor is intentionally declared as private because this class cannot be constructed.
166         *
167         * @since        2.0
168         */
169         SqlStatementBuilder(void);
170
171         /**
172         * This destructor is intentionally declared as private because this class cannot be constructed.
173         *
174         * @since        2.0
175         */
176         virtual ~SqlStatementBuilder(void);
177
178         /**
179         * The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
180         *
181         * @since        2.0
182         * @remarks      This constructor is hidden.
183         */
184         SqlStatementBuilder(const SqlStatementBuilder& rhs);
185
186         /**
187         * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
188         *
189         * @since        2.0
190         * @remarks      This operator is hidden.
191         */
192         SqlStatementBuilder& operator =(const SqlStatementBuilder& rhs);
193
194         class _SqlStatementBuilderImpl* __pSqlStatementBuilderImpl;
195
196 }; // SqlStatementBuilder
197
198 }} // Tizen::Io
199
200 #endif // _FIO_SQL_STATEMENT_BUILDER_H_
201