sptk2 logo
SPTK Home Page
QueryParameter.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <array>
30#include <sptk5/db/QueryParameterBinding.h>
31
32namespace sptk {
33
34class QueryParameterList;
35
42class SP_EXPORT QueryParameter
43 : public Variant
44{
45 friend class Query;
46
47 friend class QueryParameterList;
48
49public:
53 void bindAdd(uint32_t bindIndex);
54
58 uint32_t bindCount() const;
59
63 uint32_t bindIndex(uint32_t ind);
64
71 {
72 return m_timeData.data();
73 }
74
79 {
80 return m_callbackLength;
81 }
82
88 explicit QueryParameter(const char* name, bool isOutput = false);
89
93 ~QueryParameter() override = default;
94
98 String name() const;
99
103 void setOutput();
104
109
114 {
115 setInteger(v);
116 return *this;
117 }
118
123 {
124 setInteger(v);
125 return *this;
126 }
127
131 QueryParameter& operator=(int32_t v) override
132 {
133 setInteger(v);
134 return *this;
135 }
136
140 QueryParameter& operator=(int64_t v) override
141 {
142 setInt64(v);
143 return *this;
144 }
145
149 QueryParameter& operator=(double v) override
150 {
151 setFloat(v);
152 return *this;
153 }
154
158 QueryParameter& operator=(const char* s) override
159 {
160 setString(s, 0);
161 return *this;
162 }
163
167 QueryParameter& operator=(const std::string& s)
168 {
169 setString(s.c_str(), s.length());
170 return *this;
171 }
172
177 {
178 setDateTime(dt);
179 return *this;
180 }
181
185 QueryParameter& operator=(const uint8_t* value) override
186 {
187 setImagePtr(value);
188 return *this;
189 }
190
195 QueryParameter& operator=(const Buffer& buffer) override
196 {
197 setBuffer(buffer.data(), buffer.bytes());
198 return *this;
199 }
200
208 virtual void setString(const char* value)
209 {
210 setString(value, 0);
211 }
212
221 virtual void setString(const char* value, size_t maxlen);
222
230 void setString(const String& value) override
231 {
232 setString(value.c_str(), (uint32_t) value.length());
233 }
234
238 bool isOutput() const
239 {
240 return m_binding.m_output;
241 }
242
248 {
249 return m_binding;
250 }
251
252 void reallocateBuffer(const char* value, size_t maxlen, size_t valueLength);
253
254private:
255 QueryParameterBinding m_binding;
256 String m_name;
257 std::vector<uint32_t> m_bindParamIndexes;
258 std::array<uint8_t, 80> m_timeData {};
259 long m_callbackLength {0};
260 QueryParameterList* m_paramList {nullptr};
261};
262
263using SQueryParameter = std::shared_ptr<QueryParameter>;
264
268} // namespace sptk
size_t bytes() const
Definition: BufferStorage.h:213
uint8_t * data()
Definition: BufferStorage.h:106
Definition: Buffer.h:51
Definition: DateTime.h:86
Definition: QueryParameterBinding.h:49
Definition: QueryParameterList.h:57
Definition: QueryParameter.h:44
String name() const
QueryParameter & operator=(const uint8_t *value) override
Definition: QueryParameter.h:185
QueryParameter & operator=(DateTime dt) override
Definition: QueryParameter.h:176
QueryParameter & operator=(const std::string &s)
Definition: QueryParameter.h:167
uint8_t * conversionBuffer()
Definition: QueryParameter.h:70
void setString(const String &value) override
Definition: QueryParameter.h:230
QueryParameter & operator=(const Variant &param)
~QueryParameter() override=default
QueryParameter & operator=(int16_t v)
Definition: QueryParameter.h:113
QueryParameter & operator=(const Buffer &buffer) override
Definition: QueryParameter.h:195
uint32_t bindCount() const
void bindAdd(uint32_t bindIndex)
virtual void setString(const char *value)
Definition: QueryParameter.h:208
virtual void setString(const char *value, size_t maxlen)
QueryParameterBinding & binding()
Definition: QueryParameter.h:247
QueryParameter & operator=(double v) override
Definition: QueryParameter.h:149
uint32_t bindIndex(uint32_t ind)
QueryParameter & operator=(uint16_t v)
Definition: QueryParameter.h:122
QueryParameter & operator=(int32_t v) override
Definition: QueryParameter.h:131
bool isOutput() const
Definition: QueryParameter.h:238
QueryParameter(const char *name, bool isOutput=false)
QueryParameter & operator=(int64_t v) override
Definition: QueryParameter.h:140
QueryParameter & operator=(const char *s) override
Definition: QueryParameter.h:158
long & callbackLength()
Definition: QueryParameter.h:78
Definition: Query.h:239
Definition: String.h:49
Definition: Variant.h:372

Fri Oct 14 2022 09:58:31: SPTK 5.4.1