forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPostgreSQLStatementImpl.cpp
More file actions
169 lines (121 loc) · 3 KB
/
PostgreSQLStatementImpl.cpp
File metadata and controls
169 lines (121 loc) · 3 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//
// PostgreSQLStatementImpl.cpp
//
// Library: Data/PostgreSQL
// Package: PostgreSQL
// Module: PostgreSQLStatementImpl
//
// Copyright (c) 2015, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/PostgreSQL/PostgreSQLStatementImpl.h"
namespace Poco {
namespace Data {
namespace PostgreSQL {
PostgreSQLStatementImpl::PostgreSQLStatementImpl(SessionImpl& aSessionImpl):
Poco::Data::StatementImpl(aSessionImpl),
_statementExecutor(aSessionImpl.handle()),
_pBinder(new Binder),
_pExtractor(new Extractor (_statementExecutor)),
_hasNext(NEXT_DONTKNOW)
{
}
PostgreSQLStatementImpl::~PostgreSQLStatementImpl()
{
}
std::size_t PostgreSQLStatementImpl::columnsReturned() const
{
return _statementExecutor.columnsReturned();
}
int PostgreSQLStatementImpl::affectedRowCount() const
{
return (int)_statementExecutor.getAffectedRowCount();
}
const MetaColumn& PostgreSQLStatementImpl::metaColumn(std::size_t aPosition) const
{
return _statementExecutor.metaColumn(aPosition);
}
bool PostgreSQLStatementImpl::hasNext()
{
if (NEXT_DONTKNOW == _hasNext)
{
if (columnsReturned() == 0)
{
return false;
}
if (_statementExecutor.fetch())
{
_hasNext = NEXT_TRUE;
return true;
}
_hasNext = NEXT_FALSE;
return false;
}
else if (NEXT_TRUE == _hasNext)
{
return true;
}
return false;
}
std::size_t PostgreSQLStatementImpl::next()
{
if (! hasNext())
{
throw StatementException("No data received");
}
Poco::Data::AbstractExtractionVec::iterator it= extractions().begin();
Poco::Data::AbstractExtractionVec::iterator itEnd = extractions().end();
std::size_t position = 0;
for (; it != itEnd; ++it)
{
(*it)->extract(position);
position += (*it)->numOfColumnsHandled();
}
_hasNext = NEXT_DONTKNOW;
return 1;
}
bool PostgreSQLStatementImpl::canBind() const
{
bool ret = false;
if ((_statementExecutor.state() >= StatementExecutor::STMT_COMPILED)
&& !bindings().empty())
{
ret = (*bindings().begin())->canBind();
}
return ret;
}
bool PostgreSQLStatementImpl::canCompile() const
{
return (_statementExecutor.state() < StatementExecutor::STMT_COMPILED);
}
void PostgreSQLStatementImpl::compileImpl()
{
_statementExecutor.prepare(toString());
}
void PostgreSQLStatementImpl::bindImpl()
{
Poco::Data::AbstractBindingVec& binds = bindings();
std::size_t position = 0;
Poco::Data::AbstractBindingVec::iterator it= binds.begin();
Poco::Data::AbstractBindingVec::iterator itEnd = binds.end();
for (; it != itEnd && (*it)->canBind(); ++it)
{
(*it)->bind(position);
position += (*it)->numOfColumnsHandled();
}
_pBinder->updateBindVectorToCurrentValues();
_statementExecutor.bindParams(_pBinder->bindVector());
_statementExecutor.execute();
_hasNext = NEXT_DONTKNOW;
}
Poco::Data::AbstractExtractor::Ptr PostgreSQLStatementImpl::extractor()
{
return _pExtractor;
}
Poco::Data::AbstractBinder::Ptr PostgreSQLStatementImpl::binder()
{
return _pBinder;
}
} } } // namespace Poco::Data::PostgreSQL