Queries

If the query has no parameters do not specify the binding variables in the execute method:

connection.execute("SELECT 1 FROM DUAL", function (err, results) {
    results.getRows(function (err, rows) {
        if (err) {
        return;
        }
    results.close(function (err) {
        if (err) {
         }
        });
    });
});

connection.execute("SELECT 1 FROM DUAL")
    .then(results => {
        results.getRows()
            .then(rows => console.log(rows))
            .catch(e => console.log(e.stack))
})
.catch(e => console.log(e.stack())

Example with async/await:

(async () => {
    var connection = await driver.connect(config);
    try {
        var results = await connection.execute('SELECT 1 AS VALUE FROM DUAL');
        var rows = await results.getRows();
        console.log(rows);
} catch (e) {
    await connection.rollback();
    throw e;
} finally {
    await connection.close();
}
})().catch(e => console.log(e.stack));

If your query has parameters, supply the binding variables in the execute method:

...
connection.execute("SELECT * FROM MYTABLE WHERE id = ?", [ 54 ], (err, results) => {
    results.getRows(function (err, rows) {
    results.close(function (err) {
    ...
    });
  });
});
...

To supply special options, supply these as an object in the execute method.

Parameter Type Description

sql

String

is the SQL string to be executed by the database.

binds

Array

is an array of variables bound to a parameterized statement. Empty arrays are equivalent to omitting binds entirely.

options

Object

is an object (hash) of connection and statement options to use while executing the SQL string. The valid options are presented below, and their permissible values:

Value Type Description

autoCommit

boolean

indicates whether each statement is automatically committed when execute is called. Default value: true

readOnly

boolean

indicates whether to execute the statement in a read-only transaction
Default value: false

fetchSize

positive integer value

indicating the result set batch size when using result streaming
Default value: 1000

rowMode

ENUM

indicates whether to return results as objects or as an array of values.
Default value: RowMode.ROWS_AS_ARRAY)
Permissible values: RowMode.ROWS_AS_ARRAY, RowMode.ROWS_AS_OBJECT

isolationLevel

ENUM

indicates the desired transaction isolation level to use.
Default value: Isolation.CONSISTENT_READ
Permissible values: Isolation.CONSISTENT_READ, Isolation.READ_COMMITTED

callback

Function

an error-first callback whose second argument is a result set. Not required when using promises.

For example:

var { Driver, RowMode } = require('nuodb');
...
connection.execute("SELECT * FROM MYTABLE WHERE id = ?", [ 54 ], { rowMode: RowMode.ROWS_AS_OBJECT } (err, results) => {
results.getRows(function (err, rows) {
    results.close(function (err) {
    ...
    });
  });
});
...

Selecting from DUAL requires explicit column names. For example:

connection.execute('SELECT 1 AS VALUE FROM DUAL;', [], function (err, results) {
if (err) {
        }
console.log(results.rows);
results.close(function (err) {
if (err) {
    }
});