Closed cheslyn closed 5 years ago
It works for me with node-oracledb 4.0.1:
var oracledb = require('oracledb');
oracledb.maxRows = 1000;
var dbConfig = require('./dbconfig.js');
oracledb.getConnection(
{
user : dbConfig.user,
password : dbConfig.password,
connectString : dbConfig.connectString
},
function(err, connection) {
if (err) {
console.error(err.message);
return;
}
connection.execute(
`select 1 from all_objects where rownum <= 2000 `,
[],
{ maxRows: 1000 },
function(err, result) {
if (err) {
console.error(err.message);
doRelease(connection);
return;
}
//console.log(result.metaData);
console.log("Number of rows ", result.rows.length);
doRelease(connection);
});
});
// Note: connections should always be released when not needed
function doRelease(connection) {
connection.close(
function(err) {
if (err) {
console.error(err.message);
}
});
}
Gives:
Number of rows 1000
Check your WHERE clause and argument usage.
If your problem is really with strongloop, then check with them.
Other comments: you may find the async/await style of programming easier to use. And with recent DBs, you can use the improved OFFSET / FETCH NEXT SQL syntax to limit rows.
@cjbj Thanks for responding to this thread , appreciate the same.
But the problem is your test case returns a rowcount of only 1 row in the resultset which will work fine. I ran your script on my env and do get the same output "Number of rows 1000"
Here is what you need to do, tweak 2 lines
`select rownum,object_name from all_objects where rownum <= 1000 `,
console.log(result.rows);
Run the script now and maybe redirect the output to a .txt file you will see that it just returns the first 100 rows and the output file ends with .. 900 more items Which breaks the rest of my post processing code.
[ 99, 'SQL_VERSION$' ],
[ 100, 'I_SQL_VERSION$_VERSION#' ],
... 900 more items ]
So it is not an issue with the Where clause or argument usage, the return dataset always truncates to 100 rows.
That's just how console.log()
works. Compare it with:
for (const row of result.rows)
console.log(row);
Aside from the output display choices you have, as a suggestion if you're dealing with a lot of rows, then you may want to use a ResultSet.
Awesome , I am able to resolve the main problem. However could you please point me to documentation on how to format the result set ? or possibly give a solution to it if that is easier .
Code
const rs = result.resultSet;
let row;
let i = 1;
while ((row = await rs.getRow())) {
console.log(row );
}
Returns data in this format
[ 1, 'CON$MIG' ]
[ 2, 'UNDO$' ]
[ 3, 'C_COBJ#' ]
[ 4, 'PROXY_ROLE_DATA$' ]
[ 5, 'I_CDEF2' ]
What would it take to add a "," at the end of each array/row and encapsulate it in 2 main Sq brackets ? i.e. as returned by the non result-set data format. eg
[
[ 1, 'CON$MIG' ],
[ 2, 'UNDO$' ],
[ 3, 'C_COBJ#' ],
[ 4, 'PROXY_ROLE_DATA$' ],
[ 5, 'I_CDEF2' ]
]
Try commands like console.log('[');
Database ver : 12.1.0.2.0 node ver : v10.15.1
Problem The output always defaults to 100 rows and the formed output is truncated to something like this
I have gone through this thread , but looks like it was not resolved https://github.com/strongloop/loopback-connector-oracle/issues/101
Note : I have the following 2 settings in my .js file
Sample of the file