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//-----------------------------------------------------------------------------
217217NJS_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)
256254static 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