@miatechnet/node-odbc 2.4.10-multiresult.1 → 2.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +178 -178
- package/LICENSE +23 -23
- package/README.md +1314 -1314
- package/binding.gyp +100 -100
- package/lib/Connection.js +521 -521
- package/lib/Cursor.js +92 -92
- package/lib/Pool.js +470 -470
- package/lib/Statement.js +207 -207
- package/lib/odbc.d.ts +210 -210
- package/lib/odbc.js +56 -56
- package/package.json +69 -69
- package/src/dynodbc.cpp +189 -189
- package/src/dynodbc.h +383 -383
- package/src/odbc.cpp +850 -850
- package/src/odbc.h +362 -362
- package/src/odbc_connection.cpp +4312 -4312
- package/src/odbc_connection.h +114 -114
- package/src/odbc_cursor.cpp +265 -265
- package/src/odbc_cursor.h +52 -52
- package/src/odbc_statement.cpp +610 -610
- package/src/odbc_statement.h +43 -43
- package/lib/bindings/napi-v8/odbc.node +0 -0
package/src/odbc_cursor.cpp
CHANGED
|
@@ -1,265 +1,265 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2021 IBM
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
6
|
-
copyright notice and this permission notice appear in all copies.
|
|
7
|
-
|
|
8
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
#include "odbc_cursor.h"
|
|
18
|
-
|
|
19
|
-
Napi::FunctionReference ODBCCursor::constructor;
|
|
20
|
-
|
|
21
|
-
Napi::Object ODBCCursor::Init(Napi::Env env, Napi::Object exports)
|
|
22
|
-
{
|
|
23
|
-
Napi::HandleScope scope(env);
|
|
24
|
-
|
|
25
|
-
Napi::Function constructorFunction = DefineClass(env, "ODBCCursor", {
|
|
26
|
-
InstanceMethod("fetch", &ODBCCursor::Fetch),
|
|
27
|
-
InstanceMethod("close", &ODBCCursor::Close),
|
|
28
|
-
|
|
29
|
-
InstanceAccessor("noData", &ODBCCursor::MoreResultsGetter, nullptr),
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// Attach the Database Constructor to the target object
|
|
33
|
-
constructor = Napi::Persistent(constructorFunction);
|
|
34
|
-
constructor.SuppressDestruct();
|
|
35
|
-
|
|
36
|
-
return exports;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
ODBCCursor::ODBCCursor(const Napi::CallbackInfo& info) : Napi::ObjectWrap<ODBCCursor>(info) {
|
|
41
|
-
this->data = info[0].As<Napi::External<StatementData>>().Data();
|
|
42
|
-
this->odbcConnection = info[1].As<Napi::External<ODBCConnection>>().Data();
|
|
43
|
-
if (info.Length() > 2 && info[2].IsArray()) {
|
|
44
|
-
this->napiParametersReference = Napi::Persistent(info[2].As<Napi::Array>());
|
|
45
|
-
} else {
|
|
46
|
-
this->napiParametersReference = Napi::Persistent(Napi::Array::New(Env()));
|
|
47
|
-
}
|
|
48
|
-
this->free_statement_on_close = info[3].As<Napi::Boolean>().Value();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
SQLRETURN ODBCCursor::Free() {
|
|
52
|
-
|
|
53
|
-
SQLRETURN return_code = SQL_SUCCESS;
|
|
54
|
-
|
|
55
|
-
if (this->free_statement_on_close && this->data)
|
|
56
|
-
{
|
|
57
|
-
if (
|
|
58
|
-
this->data->hstmt &&
|
|
59
|
-
this->data->hstmt != SQL_NULL_HANDLE
|
|
60
|
-
)
|
|
61
|
-
{
|
|
62
|
-
uv_mutex_lock(&ODBC::g_odbcMutex);
|
|
63
|
-
return_code =
|
|
64
|
-
SQLFreeHandle
|
|
65
|
-
(
|
|
66
|
-
SQL_HANDLE_STMT,
|
|
67
|
-
this->data->hstmt
|
|
68
|
-
);
|
|
69
|
-
this->data->hstmt = SQL_NULL_HANDLE;
|
|
70
|
-
uv_mutex_unlock(&ODBC::g_odbcMutex);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
napiParametersReference.Reset();
|
|
74
|
-
delete this->data;
|
|
75
|
-
this->data = NULL;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return return_code;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
ODBCCursor::~ODBCCursor()
|
|
82
|
-
{
|
|
83
|
-
this->Free();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
87
|
-
// FETCH ///////////////////////////////////////////////////////////////////
|
|
88
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
89
|
-
class FetchAsyncWorker : public ODBCAsyncWorker {
|
|
90
|
-
|
|
91
|
-
private:
|
|
92
|
-
ODBCCursor *cursor;
|
|
93
|
-
StatementData *data;
|
|
94
|
-
|
|
95
|
-
public:
|
|
96
|
-
FetchAsyncWorker
|
|
97
|
-
(
|
|
98
|
-
ODBCCursor *cursor,
|
|
99
|
-
Napi::Function &callback
|
|
100
|
-
)
|
|
101
|
-
:
|
|
102
|
-
ODBCAsyncWorker(callback),
|
|
103
|
-
cursor(cursor),
|
|
104
|
-
data(cursor->data)
|
|
105
|
-
{}
|
|
106
|
-
|
|
107
|
-
~FetchAsyncWorker() {}
|
|
108
|
-
|
|
109
|
-
void Execute() {
|
|
110
|
-
SQLRETURN return_code;
|
|
111
|
-
bool alloc_error = false;
|
|
112
|
-
|
|
113
|
-
return_code =
|
|
114
|
-
fetch_and_store
|
|
115
|
-
(
|
|
116
|
-
data,
|
|
117
|
-
true,
|
|
118
|
-
&alloc_error
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
if (alloc_error == true)
|
|
122
|
-
{
|
|
123
|
-
SetError("[odbc] Error allocating or reallocating memory when fetching data. No ODBC error information available.\0");
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
if (!SQL_SUCCEEDED(return_code) && return_code != SQL_NO_DATA) {
|
|
128
|
-
if (return_code == SQL_INVALID_HANDLE) {
|
|
129
|
-
SetError("[odbc] Error fetching results with SQLFetch: SQL_INVALID_HANDLE\0");
|
|
130
|
-
return;
|
|
131
|
-
} else {
|
|
132
|
-
this->errors = GetODBCErrors(SQL_HANDLE_STMT, data->hstmt);
|
|
133
|
-
}
|
|
134
|
-
SetError("[odbc] Error fetching results with SQLFetch\0");
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
void OnOK() {
|
|
140
|
-
|
|
141
|
-
Napi::Env env = Env();
|
|
142
|
-
Napi::HandleScope scope(env);
|
|
143
|
-
|
|
144
|
-
Napi::Array rows =
|
|
145
|
-
process_data_for_napi
|
|
146
|
-
(
|
|
147
|
-
env,
|
|
148
|
-
data,
|
|
149
|
-
cursor->napiParametersReference.Value()
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
std::vector<napi_value> callbackArguments
|
|
153
|
-
{
|
|
154
|
-
env.Null(),
|
|
155
|
-
rows
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
Callback().Call(callbackArguments);
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
Napi::Value ODBCCursor::Fetch(const Napi::CallbackInfo& info) {
|
|
163
|
-
|
|
164
|
-
Napi::Env env = info.Env();
|
|
165
|
-
Napi::HandleScope scope(env);
|
|
166
|
-
|
|
167
|
-
Napi::Function callback = info[0].As<Napi::Function>();
|
|
168
|
-
|
|
169
|
-
FetchAsyncWorker *worker = new FetchAsyncWorker(this, callback);
|
|
170
|
-
worker->Queue();
|
|
171
|
-
|
|
172
|
-
return env.Undefined();
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
176
|
-
// Close ///////////////////////////////////////////////////////////////////
|
|
177
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
178
|
-
class CursorCloseAsyncWorker : public ODBCAsyncWorker {
|
|
179
|
-
|
|
180
|
-
private:
|
|
181
|
-
ODBCCursor *odbcCursor;
|
|
182
|
-
StatementData *data;
|
|
183
|
-
|
|
184
|
-
public:
|
|
185
|
-
CursorCloseAsyncWorker
|
|
186
|
-
(
|
|
187
|
-
ODBCCursor *cursor,
|
|
188
|
-
Napi::Function &callback
|
|
189
|
-
)
|
|
190
|
-
:
|
|
191
|
-
ODBCAsyncWorker(callback),
|
|
192
|
-
odbcCursor(cursor),
|
|
193
|
-
data(cursor->data)
|
|
194
|
-
{}
|
|
195
|
-
|
|
196
|
-
~CursorCloseAsyncWorker() {}
|
|
197
|
-
|
|
198
|
-
void Execute() {
|
|
199
|
-
|
|
200
|
-
SQLRETURN return_code;
|
|
201
|
-
|
|
202
|
-
return_code =
|
|
203
|
-
SQLCloseCursor
|
|
204
|
-
(
|
|
205
|
-
data->hstmt // StatementHandle
|
|
206
|
-
);
|
|
207
|
-
|
|
208
|
-
if (!SQL_SUCCEEDED(return_code)) {
|
|
209
|
-
this->errors = GetODBCErrors(SQL_HANDLE_STMT, data->hstmt);
|
|
210
|
-
SetError("[odbc] Error closing the cursor!\0");
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (odbcCursor->free_statement_on_close)
|
|
215
|
-
{
|
|
216
|
-
return_code = odbcCursor->Free();
|
|
217
|
-
if (!SQL_SUCCEEDED(return_code)) {
|
|
218
|
-
this->errors = GetODBCErrors(SQL_HANDLE_STMT, data->hstmt);
|
|
219
|
-
SetError("[odbc] Error closing the Statement\0");
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
else
|
|
224
|
-
{
|
|
225
|
-
if (data != NULL)
|
|
226
|
-
{
|
|
227
|
-
data->deleteColumns();
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
void OnOK() {
|
|
233
|
-
|
|
234
|
-
Napi::Env env = Env();
|
|
235
|
-
Napi::HandleScope scope(env);
|
|
236
|
-
|
|
237
|
-
std::vector<napi_value> callbackArguments;
|
|
238
|
-
callbackArguments.push_back(env.Null());
|
|
239
|
-
Callback().Call(callbackArguments);
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
Napi::Value ODBCCursor::Close(const Napi::CallbackInfo& info) {
|
|
244
|
-
|
|
245
|
-
Napi::Env env = info.Env();
|
|
246
|
-
Napi::HandleScope scope(env);
|
|
247
|
-
|
|
248
|
-
Napi::Function callback = info[0].As<Napi::Function>();
|
|
249
|
-
|
|
250
|
-
CursorCloseAsyncWorker *worker = new CursorCloseAsyncWorker(this, callback);
|
|
251
|
-
worker->Queue();
|
|
252
|
-
|
|
253
|
-
return env.Undefined();
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Return true once SQL_NO_DATA has been returned from SQLFetch. Have to do it
|
|
257
|
-
// this way, as a "moreResults" would have to return true if called before the
|
|
258
|
-
// first call to SQLFetch, but there might actually not be any more results to
|
|
259
|
-
// retrieve.
|
|
260
|
-
Napi::Value ODBCCursor::MoreResultsGetter(const Napi::CallbackInfo& info) {
|
|
261
|
-
Napi::Env env = info.Env();
|
|
262
|
-
Napi::HandleScope scope(env);
|
|
263
|
-
|
|
264
|
-
return Napi::Boolean::New(env, data->result_set_end_reached);
|
|
265
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2021 IBM
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
6
|
+
copyright notice and this permission notice appear in all copies.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#include "odbc_cursor.h"
|
|
18
|
+
|
|
19
|
+
Napi::FunctionReference ODBCCursor::constructor;
|
|
20
|
+
|
|
21
|
+
Napi::Object ODBCCursor::Init(Napi::Env env, Napi::Object exports)
|
|
22
|
+
{
|
|
23
|
+
Napi::HandleScope scope(env);
|
|
24
|
+
|
|
25
|
+
Napi::Function constructorFunction = DefineClass(env, "ODBCCursor", {
|
|
26
|
+
InstanceMethod("fetch", &ODBCCursor::Fetch),
|
|
27
|
+
InstanceMethod("close", &ODBCCursor::Close),
|
|
28
|
+
|
|
29
|
+
InstanceAccessor("noData", &ODBCCursor::MoreResultsGetter, nullptr),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// Attach the Database Constructor to the target object
|
|
33
|
+
constructor = Napi::Persistent(constructorFunction);
|
|
34
|
+
constructor.SuppressDestruct();
|
|
35
|
+
|
|
36
|
+
return exports;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
ODBCCursor::ODBCCursor(const Napi::CallbackInfo& info) : Napi::ObjectWrap<ODBCCursor>(info) {
|
|
41
|
+
this->data = info[0].As<Napi::External<StatementData>>().Data();
|
|
42
|
+
this->odbcConnection = info[1].As<Napi::External<ODBCConnection>>().Data();
|
|
43
|
+
if (info.Length() > 2 && info[2].IsArray()) {
|
|
44
|
+
this->napiParametersReference = Napi::Persistent(info[2].As<Napi::Array>());
|
|
45
|
+
} else {
|
|
46
|
+
this->napiParametersReference = Napi::Persistent(Napi::Array::New(Env()));
|
|
47
|
+
}
|
|
48
|
+
this->free_statement_on_close = info[3].As<Napi::Boolean>().Value();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
SQLRETURN ODBCCursor::Free() {
|
|
52
|
+
|
|
53
|
+
SQLRETURN return_code = SQL_SUCCESS;
|
|
54
|
+
|
|
55
|
+
if (this->free_statement_on_close && this->data)
|
|
56
|
+
{
|
|
57
|
+
if (
|
|
58
|
+
this->data->hstmt &&
|
|
59
|
+
this->data->hstmt != SQL_NULL_HANDLE
|
|
60
|
+
)
|
|
61
|
+
{
|
|
62
|
+
uv_mutex_lock(&ODBC::g_odbcMutex);
|
|
63
|
+
return_code =
|
|
64
|
+
SQLFreeHandle
|
|
65
|
+
(
|
|
66
|
+
SQL_HANDLE_STMT,
|
|
67
|
+
this->data->hstmt
|
|
68
|
+
);
|
|
69
|
+
this->data->hstmt = SQL_NULL_HANDLE;
|
|
70
|
+
uv_mutex_unlock(&ODBC::g_odbcMutex);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
napiParametersReference.Reset();
|
|
74
|
+
delete this->data;
|
|
75
|
+
this->data = NULL;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return return_code;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
ODBCCursor::~ODBCCursor()
|
|
82
|
+
{
|
|
83
|
+
this->Free();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
87
|
+
// FETCH ///////////////////////////////////////////////////////////////////
|
|
88
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
89
|
+
class FetchAsyncWorker : public ODBCAsyncWorker {
|
|
90
|
+
|
|
91
|
+
private:
|
|
92
|
+
ODBCCursor *cursor;
|
|
93
|
+
StatementData *data;
|
|
94
|
+
|
|
95
|
+
public:
|
|
96
|
+
FetchAsyncWorker
|
|
97
|
+
(
|
|
98
|
+
ODBCCursor *cursor,
|
|
99
|
+
Napi::Function &callback
|
|
100
|
+
)
|
|
101
|
+
:
|
|
102
|
+
ODBCAsyncWorker(callback),
|
|
103
|
+
cursor(cursor),
|
|
104
|
+
data(cursor->data)
|
|
105
|
+
{}
|
|
106
|
+
|
|
107
|
+
~FetchAsyncWorker() {}
|
|
108
|
+
|
|
109
|
+
void Execute() {
|
|
110
|
+
SQLRETURN return_code;
|
|
111
|
+
bool alloc_error = false;
|
|
112
|
+
|
|
113
|
+
return_code =
|
|
114
|
+
fetch_and_store
|
|
115
|
+
(
|
|
116
|
+
data,
|
|
117
|
+
true,
|
|
118
|
+
&alloc_error
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
if (alloc_error == true)
|
|
122
|
+
{
|
|
123
|
+
SetError("[odbc] Error allocating or reallocating memory when fetching data. No ODBC error information available.\0");
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!SQL_SUCCEEDED(return_code) && return_code != SQL_NO_DATA) {
|
|
128
|
+
if (return_code == SQL_INVALID_HANDLE) {
|
|
129
|
+
SetError("[odbc] Error fetching results with SQLFetch: SQL_INVALID_HANDLE\0");
|
|
130
|
+
return;
|
|
131
|
+
} else {
|
|
132
|
+
this->errors = GetODBCErrors(SQL_HANDLE_STMT, data->hstmt);
|
|
133
|
+
}
|
|
134
|
+
SetError("[odbc] Error fetching results with SQLFetch\0");
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
void OnOK() {
|
|
140
|
+
|
|
141
|
+
Napi::Env env = Env();
|
|
142
|
+
Napi::HandleScope scope(env);
|
|
143
|
+
|
|
144
|
+
Napi::Array rows =
|
|
145
|
+
process_data_for_napi
|
|
146
|
+
(
|
|
147
|
+
env,
|
|
148
|
+
data,
|
|
149
|
+
cursor->napiParametersReference.Value()
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
std::vector<napi_value> callbackArguments
|
|
153
|
+
{
|
|
154
|
+
env.Null(),
|
|
155
|
+
rows
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
Callback().Call(callbackArguments);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
Napi::Value ODBCCursor::Fetch(const Napi::CallbackInfo& info) {
|
|
163
|
+
|
|
164
|
+
Napi::Env env = info.Env();
|
|
165
|
+
Napi::HandleScope scope(env);
|
|
166
|
+
|
|
167
|
+
Napi::Function callback = info[0].As<Napi::Function>();
|
|
168
|
+
|
|
169
|
+
FetchAsyncWorker *worker = new FetchAsyncWorker(this, callback);
|
|
170
|
+
worker->Queue();
|
|
171
|
+
|
|
172
|
+
return env.Undefined();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
176
|
+
// Close ///////////////////////////////////////////////////////////////////
|
|
177
|
+
////////////////////////////////////////////////////////////////////////////////
|
|
178
|
+
class CursorCloseAsyncWorker : public ODBCAsyncWorker {
|
|
179
|
+
|
|
180
|
+
private:
|
|
181
|
+
ODBCCursor *odbcCursor;
|
|
182
|
+
StatementData *data;
|
|
183
|
+
|
|
184
|
+
public:
|
|
185
|
+
CursorCloseAsyncWorker
|
|
186
|
+
(
|
|
187
|
+
ODBCCursor *cursor,
|
|
188
|
+
Napi::Function &callback
|
|
189
|
+
)
|
|
190
|
+
:
|
|
191
|
+
ODBCAsyncWorker(callback),
|
|
192
|
+
odbcCursor(cursor),
|
|
193
|
+
data(cursor->data)
|
|
194
|
+
{}
|
|
195
|
+
|
|
196
|
+
~CursorCloseAsyncWorker() {}
|
|
197
|
+
|
|
198
|
+
void Execute() {
|
|
199
|
+
|
|
200
|
+
SQLRETURN return_code;
|
|
201
|
+
|
|
202
|
+
return_code =
|
|
203
|
+
SQLCloseCursor
|
|
204
|
+
(
|
|
205
|
+
data->hstmt // StatementHandle
|
|
206
|
+
);
|
|
207
|
+
|
|
208
|
+
if (!SQL_SUCCEEDED(return_code)) {
|
|
209
|
+
this->errors = GetODBCErrors(SQL_HANDLE_STMT, data->hstmt);
|
|
210
|
+
SetError("[odbc] Error closing the cursor!\0");
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if (odbcCursor->free_statement_on_close)
|
|
215
|
+
{
|
|
216
|
+
return_code = odbcCursor->Free();
|
|
217
|
+
if (!SQL_SUCCEEDED(return_code)) {
|
|
218
|
+
this->errors = GetODBCErrors(SQL_HANDLE_STMT, data->hstmt);
|
|
219
|
+
SetError("[odbc] Error closing the Statement\0");
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
else
|
|
224
|
+
{
|
|
225
|
+
if (data != NULL)
|
|
226
|
+
{
|
|
227
|
+
data->deleteColumns();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
void OnOK() {
|
|
233
|
+
|
|
234
|
+
Napi::Env env = Env();
|
|
235
|
+
Napi::HandleScope scope(env);
|
|
236
|
+
|
|
237
|
+
std::vector<napi_value> callbackArguments;
|
|
238
|
+
callbackArguments.push_back(env.Null());
|
|
239
|
+
Callback().Call(callbackArguments);
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
Napi::Value ODBCCursor::Close(const Napi::CallbackInfo& info) {
|
|
244
|
+
|
|
245
|
+
Napi::Env env = info.Env();
|
|
246
|
+
Napi::HandleScope scope(env);
|
|
247
|
+
|
|
248
|
+
Napi::Function callback = info[0].As<Napi::Function>();
|
|
249
|
+
|
|
250
|
+
CursorCloseAsyncWorker *worker = new CursorCloseAsyncWorker(this, callback);
|
|
251
|
+
worker->Queue();
|
|
252
|
+
|
|
253
|
+
return env.Undefined();
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Return true once SQL_NO_DATA has been returned from SQLFetch. Have to do it
|
|
257
|
+
// this way, as a "moreResults" would have to return true if called before the
|
|
258
|
+
// first call to SQLFetch, but there might actually not be any more results to
|
|
259
|
+
// retrieve.
|
|
260
|
+
Napi::Value ODBCCursor::MoreResultsGetter(const Napi::CallbackInfo& info) {
|
|
261
|
+
Napi::Env env = info.Env();
|
|
262
|
+
Napi::HandleScope scope(env);
|
|
263
|
+
|
|
264
|
+
return Napi::Boolean::New(env, data->result_set_end_reached);
|
|
265
|
+
}
|
package/src/odbc_cursor.h
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2021 IBM
|
|
3
|
-
|
|
4
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
-
purpose with or without fee is hereby granted, provided that the above
|
|
6
|
-
copyright notice and this permission notice appear in all copies.
|
|
7
|
-
|
|
8
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
-
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
#ifndef _SRC_ODBC_CURSOR_H
|
|
18
|
-
#define _SRC_ODBC_CURSOR_H
|
|
19
|
-
|
|
20
|
-
#include <napi.h>
|
|
21
|
-
|
|
22
|
-
#include "odbc.h"
|
|
23
|
-
#include "odbc_connection.h"
|
|
24
|
-
#include "odbc_statement.h"
|
|
25
|
-
|
|
26
|
-
class ODBCCursor : public Napi::ObjectWrap<ODBCCursor>
|
|
27
|
-
{
|
|
28
|
-
friend class FetchAsyncWorker;
|
|
29
|
-
|
|
30
|
-
public:
|
|
31
|
-
static Napi::FunctionReference constructor;
|
|
32
|
-
|
|
33
|
-
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
|
34
|
-
|
|
35
|
-
ODBCConnection *odbcConnection;
|
|
36
|
-
StatementData *data;
|
|
37
|
-
Napi::Reference<Napi::Array> napiParametersReference;
|
|
38
|
-
bool free_statement_on_close;
|
|
39
|
-
|
|
40
|
-
SQLRETURN Free();
|
|
41
|
-
|
|
42
|
-
explicit ODBCCursor(const Napi::CallbackInfo& info);
|
|
43
|
-
~ODBCCursor();
|
|
44
|
-
|
|
45
|
-
Napi::Value Fetch(const Napi::CallbackInfo& info);
|
|
46
|
-
Napi::Value Close(const Napi::CallbackInfo& info);
|
|
47
|
-
|
|
48
|
-
// Property Getter/Setters
|
|
49
|
-
Napi::Value MoreResultsGetter(const Napi::CallbackInfo& info);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
#endif
|
|
1
|
+
/*
|
|
2
|
+
Copyright (c) 2021 IBM
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
6
|
+
copyright notice and this permission notice appear in all copies.
|
|
7
|
+
|
|
8
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
9
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
10
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
11
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
12
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
13
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
14
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#ifndef _SRC_ODBC_CURSOR_H
|
|
18
|
+
#define _SRC_ODBC_CURSOR_H
|
|
19
|
+
|
|
20
|
+
#include <napi.h>
|
|
21
|
+
|
|
22
|
+
#include "odbc.h"
|
|
23
|
+
#include "odbc_connection.h"
|
|
24
|
+
#include "odbc_statement.h"
|
|
25
|
+
|
|
26
|
+
class ODBCCursor : public Napi::ObjectWrap<ODBCCursor>
|
|
27
|
+
{
|
|
28
|
+
friend class FetchAsyncWorker;
|
|
29
|
+
|
|
30
|
+
public:
|
|
31
|
+
static Napi::FunctionReference constructor;
|
|
32
|
+
|
|
33
|
+
static Napi::Object Init(Napi::Env env, Napi::Object exports);
|
|
34
|
+
|
|
35
|
+
ODBCConnection *odbcConnection;
|
|
36
|
+
StatementData *data;
|
|
37
|
+
Napi::Reference<Napi::Array> napiParametersReference;
|
|
38
|
+
bool free_statement_on_close;
|
|
39
|
+
|
|
40
|
+
SQLRETURN Free();
|
|
41
|
+
|
|
42
|
+
explicit ODBCCursor(const Napi::CallbackInfo& info);
|
|
43
|
+
~ODBCCursor();
|
|
44
|
+
|
|
45
|
+
Napi::Value Fetch(const Napi::CallbackInfo& info);
|
|
46
|
+
Napi::Value Close(const Napi::CallbackInfo& info);
|
|
47
|
+
|
|
48
|
+
// Property Getter/Setters
|
|
49
|
+
Napi::Value MoreResultsGetter(const Napi::CallbackInfo& info);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
#endif
|