mardi 30 juin 2015

NodeJs + OracleDB + load sql file

The problem is simple, I cant load an sql file using the oracledb connector. It seems it doesn´t supoport more than one sentence.

Any idea how to load an sql file?

var oracledb = require('oracledb');
var fs = require('fs');

fs.readFile("test.sql", function(err, data) {
    if (err) {
        throw err;
    }

    connect(data.toString());
});

function connect(sql) {
    oracledb.getConnection({
            user: "****",
            password: "***",
            connectString: "****"
        },
        function(err, connection) {
            if (err) {
                console.error(err.message);
                return;
            }
            connection.execute(
                sql, [],
                function(err, result) {
                    if (err) {
                        console.error(err.message);
                        doRelease(connection);
                        return;
                    }
                    console.log(result.metaData);
                    console.log(result.rows);
                    doRelease(connection);
                });
        });
}

function doRelease(connection) {
    connection.release(
        function(err) {
            if (err) {
                console.error(err.message);
            }
        });
}

It throws an error:

ORA-00911: invalid character

The sql is here:

select * from DEFECTO;
select * from ESQUEMA;

Aucun commentaire:

Enregistrer un commentaire