Skip to content

Commit d112fda

Browse files
committed
Adjusted code to use the new API for getting SODA collection names using ODPI-C latest version
1 parent 561d63e commit d112fda

File tree

4 files changed

+17
-28
lines changed

4 files changed

+17
-28
lines changed

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"odpi/src/dpiSodaDoc.c",
5454
"odpi/src/dpiSodaDocCursor.c",
5555
"odpi/src/dpiStmt.c",
56+
"odpi/src/dpiStringList.c",
5657
"odpi/src/dpiSubscr.c",
5758
"odpi/src/dpiUtils.c",
5859
"odpi/src/dpiVar.c"

src/njsBaton.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ void njsBaton_free(njsBaton *baton, napi_env env)
223223
free(baton->lob);
224224
baton->lob = NULL;
225225
}
226-
NJS_FREE_AND_CLEAR(baton->sodaCollNames);
226+
if (baton->sodaCollNames) {
227+
dpiContext_freeStringList(baton->globals->context,
228+
baton->sodaCollNames);
229+
NJS_FREE_AND_CLEAR(baton->sodaCollNames);
230+
}
227231
if (!baton->jsBufferRef) {
228232
NJS_FREE_AND_CLEAR(baton->bufferPtr);
229233
}

src/njsModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ struct njsBaton {
332332
const char **bindNames;
333333
uint32_t *bindNameLengths;
334334
dpiSodaOperOptions *sodaOperOptions;
335-
dpiSodaCollNames *sodaCollNames;
335+
dpiStringList *sodaCollNames;
336336
njsLobBuffer *lob;
337337

338338
// ODPI-C handles (requires release)

src/njsSodaDatabase.c

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2018, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2018, 2023, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -216,7 +216,7 @@ static void njsSodaDatabase_finalize(napi_env env, void *finalizeData,
216216
//-----------------------------------------------------------------------------
217217
NJS_NAPI_METHOD_IMPL_ASYNC(njsSodaDatabase_getCollectionNames, 1, NULL)
218218
{
219-
baton->sodaCollNames = calloc(1, sizeof(dpiSodaCollNames));
219+
baton->sodaCollNames = calloc(1, sizeof(dpiStringList));
220220
if (!baton->sodaCollNames)
221221
return njsUtils_throwInsufficientMemory(env);
222222
if (!njsUtils_getNamedPropertyString(env, args[0], "startsWith",
@@ -241,9 +241,7 @@ static bool njsSodaDatabase_getCollectionNamesAsync(njsBaton *baton)
241241
if (dpiSodaDb_getCollectionNames(db->handle, baton->startsWith,
242242
(uint32_t) baton->startsWithLength, (uint32_t) baton->limit,
243243
DPI_SODA_FLAGS_DEFAULT, baton->sodaCollNames) < 0) {
244-
njsBaton_setErrorDPI(baton);
245-
dpiSodaDb_freeCollectionNames(db->handle, baton->sodaCollNames);
246-
return false;
244+
return njsBaton_setErrorDPI(baton);
247245
}
248246
return true;
249247
}
@@ -256,34 +254,20 @@ static bool njsSodaDatabase_getCollectionNamesAsync(njsBaton *baton)
256254
static bool njsSodaDatabase_getCollectionNamesPostAsync(njsBaton *baton,
257255
napi_env env, napi_value *result)
258256
{
259-
njsSodaDatabase *db = (njsSodaDatabase*) baton->callingInstance;
260257
napi_value value;
261-
bool ok = true;
262258
uint32_t i;
263259

264260
// create array for the collection names
265-
if (napi_create_array_with_length(env, baton->sodaCollNames->numNames,
266-
result) != napi_ok)
267-
ok = false;
261+
NJS_CHECK_NAPI(env, napi_create_array_with_length(env,
262+
baton->sodaCollNames->numStrings, result))
268263

269264
// populate it with the collection names
270-
for (i = 0; ok && i < baton->sodaCollNames->numNames; i++) {
271-
272-
// create string for collection name at that index
273-
if (napi_create_string_utf8(env, baton->sodaCollNames->names[i],
274-
baton->sodaCollNames->nameLengths[i], &value) != napi_ok) {
275-
ok = false;
276-
break;
277-
}
278-
279-
// add it to the array
280-
if (napi_set_element(env, *result, i, value) != napi_ok)
281-
ok = false;
282-
265+
for (i = 0; i < baton->sodaCollNames->numStrings; i++) {
266+
NJS_CHECK_NAPI(env, napi_create_string_utf8(env,
267+
baton->sodaCollNames->strings[i],
268+
baton->sodaCollNames->stringLengths[i], &value))
269+
NJS_CHECK_NAPI(env, napi_set_element(env, *result, i, value))
283270
}
284-
dpiSodaDb_freeCollectionNames(db->handle, baton->sodaCollNames);
285-
if (!ok)
286-
return false;
287271

288272
return true;
289273
}

0 commit comments

Comments
 (0)