forked from pocoproject/poco
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMySQLStatementImpl.cpp
More file actions
162 lines (121 loc) · 2.83 KB
/
MySQLStatementImpl.cpp
File metadata and controls
162 lines (121 loc) · 2.83 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
//
// MySQLException.cpp
//
// $Id: //poco/1.4/Data/MySQL/src/MySQLStatementImpl.cpp#1 $
//
// Library: Data
// Package: MySQL
// Module: MySQLStatementImpl
//
// Copyright (c) 2008, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// SPDX-License-Identifier: BSL-1.0
//
#include "Poco/Data/MySQL/MySQLStatementImpl.h"
namespace Poco {
namespace Data {
namespace MySQL {
MySQLStatementImpl::MySQLStatementImpl(SessionImpl& h) :
Poco::Data::StatementImpl(h),
_stmt(h.handle()),
_pBinder(new Binder),
_pExtractor(new Extractor(_stmt, _metadata)),
_hasNext(NEXT_DONTKNOW)
{
}
MySQLStatementImpl::~MySQLStatementImpl()
{
}
std::size_t MySQLStatementImpl::columnsReturned() const
{
return _metadata.columnsReturned();
}
int MySQLStatementImpl::affectedRowCount() const
{
return _stmt.getAffectedRowCount();
}
const MetaColumn& MySQLStatementImpl::metaColumn(std::size_t pos) const
{
return _metadata.metaColumn(pos);
}
bool MySQLStatementImpl::hasNext()
{
if (_hasNext == NEXT_DONTKNOW)
{
if (_metadata.columnsReturned() == 0)
{
return false;
}
if (_stmt.fetch())
{
_hasNext = NEXT_TRUE;
return true;
}
_hasNext = NEXT_FALSE;
return false;
}
else if (_hasNext == NEXT_TRUE)
{
return true;
}
return false;
}
std::size_t MySQLStatementImpl::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 pos = 0;
for (; it != itEnd; ++it)
{
(*it)->extract(pos);
pos += (*it)->numOfColumnsHandled();
}
_hasNext = NEXT_DONTKNOW;
return 1;
}
bool MySQLStatementImpl::canBind() const
{
bool ret = false;
if ((_stmt.state() >= StatementExecutor::STMT_COMPILED) && !bindings().empty())
ret = (*bindings().begin())->canBind();
return ret;
}
bool MySQLStatementImpl::canCompile() const
{
return (_stmt.state() < StatementExecutor::STMT_COMPILED);
}
void MySQLStatementImpl::compileImpl()
{
_metadata.reset();
_stmt.prepare(toString());
_metadata.init(_stmt);
if (_metadata.columnsReturned() > 0)
_stmt.bindResult(_metadata.row());
}
void MySQLStatementImpl::bindImpl()
{
Poco::Data::AbstractBindingVec& binds = bindings();
std::size_t pos = 0;
Poco::Data::AbstractBindingVec::iterator it = binds.begin();
Poco::Data::AbstractBindingVec::iterator itEnd = binds.end();
for (; it != itEnd && (*it)->canBind(); ++it)
{
(*it)->bind(pos);
pos += (*it)->numOfColumnsHandled();
}
_stmt.bindParams(_pBinder->getBindArray(), _pBinder->size());
_stmt.execute();
_hasNext = NEXT_DONTKNOW;
}
Poco::Data::AbstractExtractor::Ptr MySQLStatementImpl::extractor()
{
return _pExtractor;
}
Poco::Data::AbstractBinder::Ptr MySQLStatementImpl::binder()
{
return _pBinder;
}
} } } // namespace Poco::Data::MySQL