Skip to content

Commit 5f636f4

Browse files
committed
Rewrite to avoid extra getRows() call at EOF
1 parent be0d5aa commit 5f636f4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

examples/resultset2.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
1+
/* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. */
22

33
/******************************************************************************
44
*
@@ -65,26 +65,29 @@ oracledb.getConnection(
6565
doRelease(connection);
6666
return;
6767
}
68-
console.log(result);
68+
// console.log(result);
6969
fetchRowsFromRS(connection, result.resultSet, numRows);
7070
});
7171
});
7272

7373
function fetchRowsFromRS(connection, resultSet, numRows)
7474
{
75-
resultSet.getRows( // get numRows rows
76-
numRows,
75+
resultSet.getRows(
76+
numRows, // get this many rows
7777
function (err, rows)
7878
{
7979
if (err) {
80-
console.log(err);
81-
doClose(connection, resultSet); // always close the result set
82-
} else if (rows.length === 0) { // no rows, or no more rows
80+
console.error(err);
8381
doClose(connection, resultSet); // always close the result set
8482
} else if (rows.length > 0) {
8583
console.log("fetchRowsFromRS(): Got " + rows.length + " rows");
8684
console.log(rows);
87-
fetchRowsFromRS(connection, resultSet, numRows);
85+
if (rows.length === numRows) // might be more rows
86+
fetchRowsFromRS(connection, resultSet, numRows);
87+
else
88+
doClose(connection, resultSet); // always close the result set
89+
} else { // no rows
90+
doClose(connection, resultSet); // always close the result set
8891
}
8992
});
9093
}

0 commit comments

Comments
 (0)