ODBC Driver for QuickBooks Online

Build 20.0.7587

Parameterized Statements

The following code example shows how to bind parameters to create parameterized statements.

Single-Use Statements

The query method accepts an additional array parameter for binding query parameters to values.

db.open("...", (err) => {
     db.query(
        "SELECT Id, GivenName FROM Customers WHERE GivenName = ?",
        ["Cook, Brian"],
        (err, rows, moreRows) => {
        for (var i = 0; i < rows.length; i++) {
            console.log("Id = " + rows["Id"]);
            console.log("GivenName = " + rows["GivenName"]);
        }

        if (!moreRows) {
            console.log("All rows have been processed");
        }
    });
});

Reusable Statements

The prepare method creates prepared ODBCStatement objects, which can be re-used across multiple execute and executeNonQuery calls.

When you execute an ODBCStatement, your callback receives an ODBCResult object which is used to fetch results. It can be used to fetch all results at once into an array, or it can fetch rows one at a time.

db.open("...", (err) => {
    db.prepare(
        "SELECT Id, GivenName FROM Customers WHERE GivenName = ?",
        (err, stmt) => {
        function printData(result, done) {
            result.fetch((err, row) => {
                if (row === null) done();

                console.log("Id = " + row["Id"]);
                console.log("GivenName = " + row["GivenName"]);
                printData(result);
            }
        }

        stmt.executeQuery("Cook, Brian 1", (err, result) => {
            printData(result, () => {
                stmt.executeQuery("Cook, Brian 2", (err, result) => {
                    printData(result);
                });
            });
        });
    });
});

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587