5c7c8215157a4c60be8744a42959abc321a70304
[framework/web/wrt-commons.git] / modules / db / src / orm.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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  * @file        orm.cpp
18  * @author      Bartosz Janiak (b.janiak@samsung.com)
19  * @version     1.0
20  * @brief       Static definitions and function template specialziations of DPL-ORM.
21  */
22
23 #include <dpl/db/orm.h>
24
25 namespace DPL {
26 namespace DB {
27 namespace ORM {
28
29 namespace RelationTypes {
30 const char Equal[] = "=";
31 const char LessThan[] = "<";
32 const char And[] = "AND";
33 const char Or[] = "OR";
34 const char Is[] = "IS";
35 }
36
37 template<>
38 int GetColumnFromCommand<int>(ColumnIndex columnIndex,
39         DataCommand *command)
40 {
41     return command->GetColumnInteger(columnIndex);
42 }
43
44 template<>
45 DPL::String GetColumnFromCommand<DPL::String>(ColumnIndex columnIndex,
46         DataCommand *command)
47 {
48     return DPL::FromUTF8String(command->GetColumnString(columnIndex));
49 }
50
51 template<>
52 OptionalInteger GetColumnFromCommand<OptionalInteger>(ColumnIndex columnIndex,
53         DataCommand *command)
54 {
55     return command->GetColumnOptionalInteger(columnIndex);
56 }
57
58 template<>
59 OptionalString GetColumnFromCommand<OptionalString>(ColumnIndex columnIndex,
60         DataCommand *command)
61 {
62     return command->GetColumnOptionalString(columnIndex);
63 }
64
65 template<>
66 double GetColumnFromCommand<double>(ColumnIndex columnIndex,
67         DataCommand *command)
68 {
69     return command->GetColumnDouble(columnIndex);
70 }
71
72 void DataCommandUtils::BindArgument(DataCommand *command,
73         ArgumentIndex index,
74         int argument)
75 {
76     command->BindInteger(index, argument);
77 }
78
79 void DataCommandUtils::BindArgument(DataCommand *command,
80         ArgumentIndex index,
81         const OptionalInteger& argument)
82 {
83     command->BindInteger(index, argument);
84 }
85
86 void DataCommandUtils::BindArgument(DataCommand *command,
87         ArgumentIndex index,
88         const DPL::String& argument)
89 {
90     command->BindString(index, argument);
91 }
92
93 void DataCommandUtils::BindArgument(DataCommand *command,
94         ArgumentIndex index,
95         const OptionalString& argument)
96 {
97     command->BindString(index, argument);
98 }
99
100 }
101 }
102 }