Mercurial > code
comparison C++/Driver.cpp @ 184:4c746050969a
Add support for request (PostgreSQL done)
Task: #199
author | David Demelier <markand@malikania.fr> |
---|---|
date | Mon, 11 Nov 2013 18:05:47 +0100 |
parents | f0cca031bcce |
children | cc1e5fe1ee2c |
comparison
equal
deleted
inserted
replaced
183:73146c7c763f | 184:4c746050969a |
---|---|
105 | 105 |
106 return getString(row, column); | 106 return getString(row, column); |
107 } | 107 } |
108 | 108 |
109 /* -------------------------------------------------------- | 109 /* -------------------------------------------------------- |
110 * Request class | |
111 * -------------------------------------------------------- */ | |
112 | |
113 Request::Request(const std::string &command) | |
114 : m_pos(0) | |
115 , m_params(0) | |
116 , m_command(command) | |
117 { | |
118 int i = -1; | |
119 | |
120 while ((i = command.find('#', i + 1)) != std::string::npos) | |
121 ++ m_params; | |
122 } | |
123 | |
124 Request::~Request() | |
125 { | |
126 } | |
127 | |
128 void Request::assertCorrect() | |
129 { | |
130 if (m_params <= 0) | |
131 throw std::runtime_error("no more arguments to set"); | |
132 } | |
133 | |
134 void Request::setValue(const std::string &value) | |
135 { | |
136 assertCorrect(); | |
137 | |
138 m_pos = m_command.find('#', m_pos); | |
139 m_command.replace(m_pos, 1, value); | |
140 m_pos += value.length(); | |
141 m_params --; | |
142 } | |
143 | |
144 template <> | |
145 void Request::bind(bool value) | |
146 { | |
147 setValue(bindBoolean(value)); | |
148 } | |
149 | |
150 template <> | |
151 void Request::bind(Date value) | |
152 { | |
153 setValue(bindDate(value)); | |
154 } | |
155 | |
156 template <> | |
157 void Request::bind(double value) | |
158 { | |
159 setValue(bindDouble(value)); | |
160 } | |
161 | |
162 template <> | |
163 void Request::bind(int value) | |
164 { | |
165 setValue(bindInt(value)); | |
166 } | |
167 | |
168 template <> | |
169 void Request::bind(std::string value) | |
170 { | |
171 setValue(bindString(value)); | |
172 } | |
173 | |
174 template <> | |
175 void Request::bind(const char *value) | |
176 { | |
177 setValue(bindString(value)); | |
178 } | |
179 | |
180 Request::operator std::string() | |
181 { | |
182 return m_command; | |
183 } | |
184 | |
185 /* -------------------------------------------------------- | |
110 * Driver class | 186 * Driver class |
111 * -------------------------------------------------------- */ | 187 * -------------------------------------------------------- */ |
112 | 188 |
113 Driver::Driver() | 189 Driver::Driver() |
114 { | 190 { |
120 | 196 |
121 const std::string &Driver::getError() const | 197 const std::string &Driver::getError() const |
122 { | 198 { |
123 return m_error; | 199 return m_error; |
124 } | 200 } |
201 | |
202 Query::Ptr Driver::query(Request::Ptr request) | |
203 { | |
204 return query(static_cast<std::string>(*request)); | |
205 } |