30 void set(
const void * i_value,
DbValue & o_dbVal);
33 const type_info &
valueType(
void)
const {
return typeOf; };
37 const type_info & typeOf;
40 function<void(
const void * i_value,
DbValue & o_dbVal)> doSetValue;
43 template<
typename TValue>
static void setValue(
const void * i_value,
DbValue & o_dbVal)
45 TValue val = *
static_cast<const TValue *
>(i_value);
55 template<
typename TValue>
56 int FormatHandler(
const void * i_value,
size_t i_size,
char * io_buffer,
const char * i_format)
58 TValue val = *
static_cast<const TValue *
>(i_value);
59 return snprintf(io_buffer, i_size, i_format, val);
63 template<
typename TValue>
66 TValue val = *
static_cast<const TValue *
>(i_value);
69 return snprintf(io_buffer, i_size, i_format, val);
72 strncpy(io_buffer,
"NULL", i_size);
73 io_buffer[i_size - 1] =
'\0';
74 return (
int)strnlen(io_buffer, i_size);
78 extern int BoolFormatHandler(
const void * i_value,
size_t i_size,
char * io_buffer);
84 extern int StrFormatHandler(
const void * i_value,
size_t i_size,
char * io_buffer);
89 inline const char * nullValueString =
"null";
94 template<const
size_t valueLen>
104 ValueFormatterBase(
const type_info & i_type,
bool i_isSqlFormat =
false,
const char * i_doubleFormat =
"") :
106 doFormatValue(nullptr)
108 if (typeOf ==
typeid(
char)) {
109 doFormatValue = bind(FormatHandler<char>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hhd");
111 if (typeOf ==
typeid(
unsigned char)) {
112 doFormatValue = bind(FormatHandler<unsigned char>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hhu");
114 if (typeOf ==
typeid(
short)) {
115 doFormatValue = bind(FormatHandler<short>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hd");
117 if (typeOf ==
typeid(
unsigned short)) {
118 doFormatValue = bind(FormatHandler<unsigned short>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hu");
120 if (typeOf ==
typeid(
int)) {
121 doFormatValue = bind(FormatHandler<int>, placeholders::_1, placeholders::_2, placeholders::_3,
"%d");
123 if (typeOf ==
typeid(
unsigned int)) {
124 doFormatValue = bind(FormatHandler<unsigned int>, placeholders::_1, placeholders::_2, placeholders::_3,
"%u");
126 if (typeOf ==
typeid(
long)) {
127 doFormatValue = bind(FormatHandler<long>, placeholders::_1, placeholders::_2, placeholders::_3,
"%ld");
129 if (typeOf ==
typeid(
unsigned long)) {
130 doFormatValue = bind(FormatHandler<unsigned long>, placeholders::_1, placeholders::_2, placeholders::_3,
"%lu");
132 if (typeOf ==
typeid(
long long)) {
133 doFormatValue = bind(FormatHandler<long long>, placeholders::_1, placeholders::_2, placeholders::_3,
"%lld");
135 if (typeOf ==
typeid(
unsigned long long)) {
136 doFormatValue = bind(FormatHandler<unsigned long long>, placeholders::_1, placeholders::_2, placeholders::_3,
"%llu");
138 if (typeOf ==
typeid(int8_t)) {
139 doFormatValue = bind(FormatHandler<int8_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hhd");
141 if (typeOf ==
typeid(uint8_t)) {
142 doFormatValue = bind(FormatHandler<uint8_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hhu");
144 if (typeOf ==
typeid(int16_t)) {
145 doFormatValue = bind(FormatHandler<int16_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hd");
147 if (typeOf ==
typeid(uint16_t)) {
148 doFormatValue = bind(FormatHandler<uint16_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%hu");
150 if (typeOf ==
typeid(int32_t)) {
151 doFormatValue = bind(FormatHandler<int32_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%d");
153 if (typeOf ==
typeid(uint32_t)) {
154 doFormatValue = bind(FormatHandler<uint32_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%u");
156 if (typeOf ==
typeid(int64_t)) {
157 doFormatValue = bind(FormatHandler<int64_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%lld");
159 if (typeOf ==
typeid(uint64_t)) {
160 doFormatValue = bind(FormatHandler<uint64_t>, placeholders::_1, placeholders::_2, placeholders::_3,
"%llu");
163 if (!i_isSqlFormat) {
165 if (typeOf ==
typeid(
bool)) {
168 if (typeOf ==
typeid(
float)) {
169 doFormatValue = bind(
170 FormatHandler<float>,
171 placeholders::_1, placeholders::_2, placeholders::_3,
172 ((i_doubleFormat !=
nullptr && i_doubleFormat[0] !=
'\0') ? i_doubleFormat :
"%.15g")
175 if (typeOf ==
typeid(
double)) {
176 doFormatValue = bind(
177 FormatHandler<double>,
178 placeholders::_1, placeholders::_2, placeholders::_3,
179 ((i_doubleFormat !=
nullptr && i_doubleFormat[0] !=
'\0') ? i_doubleFormat :
"%.15g")
182 if (typeOf ==
typeid(
long double)) {
183 doFormatValue = bind(
184 FormatHandler<long double>,
185 placeholders::_1, placeholders::_2, placeholders::_3,
186 ((i_doubleFormat !=
nullptr && i_doubleFormat[0] !=
'\0') ? i_doubleFormat :
"%.15g")
189 if (typeOf ==
typeid(
string)) {
195 if (typeOf ==
typeid(
bool)) {
198 if (typeOf ==
typeid(
float)) {
199 doFormatValue = bind(
200 FloatSqlFormatHandler<float>,
201 placeholders::_1, placeholders::_2, placeholders::_3,
202 ((i_doubleFormat !=
nullptr && i_doubleFormat[0] !=
'\0') ? i_doubleFormat :
"%.15g")
205 if (typeOf ==
typeid(
double)) {
206 doFormatValue = bind(
207 FloatSqlFormatHandler<double>,
208 placeholders::_1, placeholders::_2, placeholders::_3,
209 ((i_doubleFormat !=
nullptr && i_doubleFormat[0] !=
'\0') ? i_doubleFormat :
"%.15g")
212 if (typeOf ==
typeid(
long double)) {
213 doFormatValue = bind(
214 FloatSqlFormatHandler<long double>,
215 placeholders::_1, placeholders::_2, placeholders::_3,
216 ((i_doubleFormat !=
nullptr && i_doubleFormat[0] !=
'\0') ? i_doubleFormat :
"%.15g")
219 if (typeOf ==
typeid(
string)) {
224 if (doFormatValue ==
nullptr)
225 throw DbException(
"invalid value type to convert to string");
244 const char *
formatValue(
const void * i_value,
bool i_isNull =
false)
override
246 if (i_isNull || i_value ==
nullptr)
return nullValueString;
248 doFormatValue(i_value, valueLen, valueStr);
254 const type_info & typeOf;
257 char valueStr[valueLen + 1] =
"";
260 function<int(
const void * i_value,
size_t i_size,
char * io_buffer)> doFormatValue;
267 typedef ValueFormatterBase<OM_STR_DB_MAX> ValueFormatter;
275 ValueArray(
const type_info & i_type,
size_t i_size);
284 const type_info &
typeOf(
void)
const {
return valueType; }
287 const size_t sizeOf(
void)
const {
return valueCount; }
290 void *
ptr(
void)
const {
return valueArr; }
293 const type_info & valueType;
294 const size_t valueCount;
298 template<
typename TVal> TVal * newValueArray(
size_t i_size)
300 TVal * pData =
new TVal[i_size];
301 fill(
static_cast<TVal *
>(pData), &(
static_cast<TVal *
>(pData))[i_size], numeric_limits<TVal>::quiet_NaN());
332 ValueRow(
int i_idCount,
const type_info & i_type);
345 int size(
void)
const override {
return idCount + 1; }
346 const type_info *
const *
columnTypes(
void)
const override {
return typeVec.data(); }
349 void set(
IRowBase * i_row,
int i_column,
const void * i_value)
const override;
356 const type_info & typeOf;
358 vector<const type_info *> typeVec;
361 function<void(
const void * i_value,
DbValue & o_dbVal)> doSetValue;
364 template<
typename TValue>
static void setValueColumn(
const void * i_value,
DbValue & o_dbVal)
366 TValue val = *
static_cast<const TValue *
>(i_value);
380 ValueRowDigester(
int i_idCount,
const type_info & i_type,
MD5 * io_md5,
const char * i_doubleFormat =
"");
390 const type_info & typeOf;
396 unique_ptr<IValueFormatter> fmtValue;
compute MD5 hash
Definition: md5.h:38
set DbValue by casting a pointer to the value
Definition: dbValue.h:21
void set(const void *i_value, DbValue &o_dbVal)
set DbValue by casting a pointer to the value
Definition: dbValue.cpp:115
DbValueSetter(const type_info &i_type)
create DbValue setter.
Definition: dbValue.cpp:83
const type_info & valueType(void) const
return value type
Definition: dbValue.h:33
row factory and setter interface to select row from database
Definition: dbCommon.h:45
public interafce for row processing during select, ie: select and append to row list
Definition: dbCommon.h:181
Row adapter to select row from value table (parameter, accumulator or expression)
Definition: dbValue.h:338
IRowBase * createRow(void) const override
create new row (tuple, struct or array) initialized with default field values
Definition: dbValue.h:344
const type_info *const * columnTypes(void) const override
array[rowSize] of type_info for each column, used to convert from db-type to target type
Definition: dbValue.h:346
int size(void) const override
return row size: number of columns
Definition: dbValue.h:345
void set(IRowBase *i_row, int i_column, const void *i_value) const override
IRowAdapter interface implementation: set column value.
Definition: dbValue.cpp:229
ValueRowAdapter(int i_idCount, const type_info &i_type)
new row adapter for value table row, use std::string type for VARCHAR input parameters
Definition: dbValue.cpp:189
row processor to calculate digest of value table row (parameter, accumulator or expression)
Definition: dbValue.h:377
void processRow(IRowBaseUptr &i_row) override
IRowProcessor implementation: append row to digest.
Definition: dbValue.cpp:265
ValueRowDigester(int i_idCount, const type_info &i_type, MD5 *io_md5, const char *i_doubleFormat="")
new row digester for value table row, use std::string type for VARCHAR input parameters
Definition: dbValue.cpp:256
OpenM++ data library: public interface for db common structures.
OpenM++ common helper utilities.
openM++ namespace
Definition: log.h:32
const char * trueValueString
NULL value as string.
Definition: dbValue.h:90
int BoolSqlFormatHandler(const void *i_value, size_t i_size, char *io_buffer)
convert bool value to SQL constant: return "1" or "0"
Definition: dbValue.cpp:54
int StrSqlFormatHandler(const void *i_value, size_t i_size, char *io_buffer)
convert string value into SQL constant: return 'quoted source value'
Definition: dbValue.cpp:72
OpenmException< 4000, dbUnknownErrorMessage > DbException
db-exception
Definition: dbCommon.h:41
std::unique_ptr< IRowBase > IRowBaseUptr
unique pointer to db row
Definition: omHelper.h:236
ValueFormatterBase< OM_CODE_DB_MAX > ShortFormatter
parameter, accumulator or expression value formatter
Definition: dbValue.h:268
int FormatHandler(const void *i_value, size_t i_size, char *io_buffer, const char *i_format)
convert value to string using snprintf: integer and float values.
Definition: dbValue.h:56
int BoolFormatHandler(const void *i_value, size_t i_size, char *io_buffer)
convert bool value to string: return "true" or "false"
Definition: dbValue.cpp:44
const char * falseValueString
true boolean value as string
Definition: dbValue.h:91
int FloatSqlFormatHandler(const void *i_value, size_t i_size, char *io_buffer, const char *i_format)
convert value to string using snprintf: integer and float values.
Definition: dbValue.h:64
int StrFormatHandler(const void *i_value, size_t i_size, char *io_buffer)
convert value to string: make a copy of source string
Definition: dbValue.cpp:64
db-row abstract base
Definition: omHelper.h:231
microdata csv value formatter: long strings are not supported
Definition: dbValue.h:272
ValueArray(const type_info &i_type, size_t i_size)
create new array of values or array of string
Definition: dbValue.cpp:124
const size_t sizeOf(void) const
array size: value count
Definition: dbValue.h:287
void cleanup(void) noexcept
cleanup resources: free memory
Definition: dbValue.cpp:156
const type_info & typeOf(void) const
type of value
Definition: dbValue.h:284
void * ptr(void) const
return pointer to array
Definition: dbValue.h:290
~ValueArray(void) noexcept
cleanup resources: free memory
Definition: dbValue.h:278
value table row: parameter, accumulators or expression tables
Definition: dbValue.h:312
DbValue dbVal
value if type is numeric: integer, double, boolean etc.
Definition: dbValue.h:326
int idCount
key size: dimension count, acc_id, sub_id, expr_id
Definition: dbValue.h:314
const type_info & typeOf
value type, use std::string type for VARCHAR input parameters
Definition: dbValue.h:323
unique_ptr< int32_t[]> idArr
key columns: dimemnsions id and acc_id, sub_id, expr_id
Definition: dbValue.h:317
bool isNotNull
if true then value is NOT NULL
Definition: dbValue.h:320
ValueRow(int i_idCount, const type_info &i_type)
create empty row of value table
Definition: dbValue.cpp:171
string strVal
value if type is string
Definition: dbValue.h:329
union to pass value to database methods
Definition: dbCommon.h:73