- Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathResultSet.cpp
146 lines (107 loc) · 3.53 KB
/
ResultSet.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
/*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
*
* Software distributed under the License is distributed AS IS,
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
* See the License for the specific language governing rights
* and limitations under the License.
*
* The Original Code was created by Adriano dos Santos Fernandes
* for the Firebird Open Source RDBMS project.
*
* Copyright (c) 2008 Adriano dos Santos Fernandes <adrianosf@uol.com.br>
* and all contributors signed below.
*
* All Rights Reserved.
* Contributor(s): ______________________________________.
*/
#include"../jrd/ResultSet.h"
#include"../jrd/PreparedStatement.h"
#include"../jrd/align.h"
#include"../jrd/jrd.h"
#include"../jrd/req.h"
#include"../dsql/dsql.h"
#include"firebird/impl/sqlda_pub.h"
#include"../dsql/dsql_proto.h"
#include"../jrd/mov_proto.h"
usingnamespaceFirebird;
namespaceJrd {
ResultSet::ResultSet(thread_db* tdbb, PreparedStatement* aStmt, jrd_tra* aTransaction)
: stmt(aStmt),
transaction(aTransaction),
firstFetchDone(false)
{
stmt->open(tdbb, transaction);
stmt->resultSet = this;
}
ResultSet::~ResultSet()
{
if (!stmt)
return;
thread_db* tdbb = JRD_get_thread_data();
stmt->resultSet = NULL;
if (stmt->dsqlRequest->getDsqlStatement()->getType() != DsqlStatement::TYPE_EXEC_PROCEDURE)
DSQL_free_statement(tdbb, stmt->dsqlRequest, DSQL_close);
}
boolResultSet::fetch(thread_db* tdbb)
{
if (stmt->dsqlRequest->getDsqlStatement()->getType() == DsqlStatement::TYPE_EXEC_PROCEDURE &&
firstFetchDone)
{
returnfalse;
}
memset(stmt->outMessage.begin(), 0, stmt->outMessage.getCount());
if (!stmt->dsqlRequest->fetch(tdbb, stmt->outMessage.begin()))
returnfalse;
if (stmt->builder)
stmt->builder->moveFromResultSet(tdbb, this);
firstFetchDone = true;
returntrue;
}
boolResultSet::isNull(unsigned param) const
{
fb_assert(param > 0);
const dsc* desc = &stmt->outValues[(param - 1) * 2 + 1];
fb_assert(desc->dsc_dtype == dtype_short);
return *reinterpret_cast<SSHORT*>(desc->dsc_address) != 0;
}
dsc& ResultSet::getDesc(unsigned param)
{
fb_assert(param > 0);
return stmt->outValues[(param - 1) * 2];
}
Firebird::string ResultSet::getString(thread_db* tdbb, unsigned param)
{
fb_assert(param > 0);
Request* request = stmt->getDsqlRequest()->getRequest();
// Setup tdbb info necessary for blobs.
AutoSetRestore2<Request*, thread_db> autoRequest(
tdbb, &thread_db::getRequest, &thread_db::setRequest, request);
AutoSetRestore<jrd_tra*> autoRequestTrans(&request->req_transaction,
tdbb->getTransaction());
returnMOV_make_string2(tdbb, &getDesc(param), CS_NONE);
}
MetaName ResultSet::getMetaName(thread_db* tdbb, unsigned param)
{
returngetString(tdbb, param);
}
Firebird::MetaString ResultSet::getMetaString(thread_db* tdbb, unsigned param)
{
returngetString(tdbb, param);
}
voidResultSet::moveDesc(thread_db* tdbb, unsigned param, dsc& desc)
{
fb_assert(param > 0);
Request* request = stmt->getDsqlRequest()->getRequest();
// Setup tdbb info necessary for blobs.
AutoSetRestore2<Request*, thread_db> autoRequest(
tdbb, &thread_db::getRequest, &thread_db::setRequest, request);
AutoSetRestore<jrd_tra*> autoRequestTrans(&request->req_transaction,
tdbb->getTransaction());
MOV_move(tdbb, &getDesc(param), &desc);
}
} // namespace