acdbcca85c3073afdc61cbc6491d5db3ab204408
[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 #include <stddef.h>
23 #include <dpl/db/orm.h>
24
25
26 namespace DPL {
27 namespace DB {
28 namespace ORM {
29
30 namespace RelationTypes {
31 const char Equal[] = "=";
32 const char LessThan[] = "<";
33 const char And[] = "AND";
34 const char Or[] = "OR";
35 const char Is[] = "IS";
36 const char In[] = "IN";
37 }
38
39 template<>
40 int GetColumnFromCommand<int>(ColumnIndex columnIndex,
41         DataCommand *command)
42 {
43     return command->GetColumnInteger(columnIndex);
44 }
45
46 template<>
47 DPL::String GetColumnFromCommand<DPL::String>(ColumnIndex columnIndex,
48         DataCommand *command)
49 {
50     return DPL::FromUTF8String(command->GetColumnString(columnIndex));
51 }
52
53 template<>
54 OptionalInteger GetColumnFromCommand<OptionalInteger>(ColumnIndex columnIndex,
55         DataCommand *command)
56 {
57     return command->GetColumnOptionalInteger(columnIndex);
58 }
59
60 template<>
61 OptionalString GetColumnFromCommand<OptionalString>(ColumnIndex columnIndex,
62         DataCommand *command)
63 {
64     return command->GetColumnOptionalString(columnIndex);
65 }
66
67 template<>
68 double GetColumnFromCommand<double>(ColumnIndex columnIndex,
69         DataCommand *command)
70 {
71     return command->GetColumnDouble(columnIndex);
72 }
73
74 void DataCommandUtils::BindArgument(DataCommand *command,
75         ArgumentIndex index,
76         int argument)
77 {
78     command->BindInteger(index, argument);
79 }
80
81 void DataCommandUtils::BindArgument(DataCommand *command,
82         ArgumentIndex index,
83         const OptionalInteger& argument)
84 {
85     command->BindInteger(index, argument);
86 }
87
88 void DataCommandUtils::BindArgument(DataCommand *command,
89         ArgumentIndex index,
90         const DPL::String& argument)
91 {
92     command->BindString(index, argument);
93 }
94
95 void DataCommandUtils::BindArgument(DataCommand *command,
96         ArgumentIndex index,
97         const OptionalString& argument)
98 {
99     command->BindString(index, argument);
100 }
101
102 }
103 }
104 }