/
standard-into-type.cpp
149 lines (129 loc) · 4.06 KB
/
standard-into-type.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//
// Copyright (C) 2004-2006 Maciej Sobczak, Stephen Hutton, Rafal Bobrowski
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#define SOCI_FIREBIRD_SOURCE
#include "soci-firebird.h"
#include "common.h"
#include <soci.h>
using namespace soci;
using namespace soci::details;
using namespace soci::details::firebird;
void firebird_standard_into_type_backend::define_by_pos(
int & position, void * data, exchange_type type)
{
position_ = position-1;
data_ = data;
type_ = type;
++position;
statement_.intoType_ = eStandard;
statement_.intos_.push_back(static_cast<void*>(this));
XSQLVAR *var = statement_.sqldap_->sqlvar+position_;
buf_ = allocBuffer(var);
var->sqldata = buf_;
var->sqlind = &indISCHolder_;
}
void firebird_standard_into_type_backend::pre_fetch()
{
// nothing to do
}
void firebird_standard_into_type_backend::post_fetch(
bool gotData, bool calledFromFetch, indicator * ind)
{
if (calledFromFetch && (gotData == false))
{
// this is a normal end-of-rowset condition,
// no need to set anything (fetch() will return false)
return;
}
if (gotData)
{
if (i_null == statement_.inds_[position_][0] && NULL == ind)
{
throw soci_error("Null value fetched and no indicator defined.");
}
else if (NULL != ind)
{
*ind = statement_.inds_[position_][0];
}
}
}
void firebird_standard_into_type_backend::exchangeData()
{
XSQLVAR *var = statement_.sqldap_->sqlvar+position_;
switch (type_)
{
// simple cases
case x_char:
*reinterpret_cast<char*>(data_) = getTextParam(var)[0];
break;
case x_short:
{
short t = from_isc<short>(var);
*reinterpret_cast<short*>(data_) = t;
}
break;
case x_unsigned_long:
{
unsigned long t = from_isc<unsigned long>(var);
*reinterpret_cast<unsigned long*>(data_) = t;
}
break;
case x_integer:
{
int t = from_isc<int>(var);
*reinterpret_cast<int *>(data_) = t;
}
break;
case x_long_long:
{
long long t = from_isc<long long>(var);
*reinterpret_cast<long long *>(data_) = t;
}
break;
case x_double:
{
double t = from_isc<double>(var);
*reinterpret_cast<double*>(data_) = t;
}
break;
// cases that require adjustments and buffer management
case x_stdstring:
*(reinterpret_cast<std::string*>(data_)) = getTextParam(var);
break;
case x_stdtm:
tmDecode(var->sqltype,
buf_, static_cast<std::tm*>(data_));
// isc_decode_timestamp() used by tmDecode() incorrectly sets
// tm_isdst to 0 in the struct that it creates, see
// http://tracker.firebirdsql.org/browse/CORE-3877, work around it
// by pretending the DST is actually unknown.
static_cast<std::tm*>(data_)->tm_isdst = -1;
break;
// cases that require special handling
case x_blob:
{
blob *tmp = reinterpret_cast<blob*>(data_);
firebird_blob_backend *blob =
dynamic_cast<firebird_blob_backend*>(tmp->get_backend());
if (0 == blob)
{
throw soci_error("Can't get Firebid BLOB BackEnd");
}
blob->assign(*reinterpret_cast<ISC_QUAD*>(buf_));
}
break;
default:
throw soci_error("Into element used with non-supported type.");
} // switch
}
void firebird_standard_into_type_backend::clean_up()
{
if (buf_ != NULL)
{
delete [] buf_;
buf_ = NULL;
}
}