0

次のコードでnode-oracleモジュールを使用しています(node-oracleドキュメントから):

var oracle = require("oracle");

oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
  if(err){ console.log("Connect err:" + err); }
  if(connection){ console.log("Connection:" + connection); }

  // selecting rows
connection.execute("SELECT nickname FROM users WHERE nickname = :1", ['luc'], function(err, results) {
  console.log("execution");
  console.log("RESULTS:" + results);
  console.log("Err:" + err);
});

connection.setAutoCommit(true);

connection.commit(function(err) {
  console.log("commiting");
  // transaction committed
});

connection.rollback(function(err) {
  console.log("rollback");
  // transaction rolledback
});

connection.close(); // call this when you are done with the connection
});

これにより、さまざまなエラーメッセージが表示されます。

$ node test_node_oracle.js 
Connection:[object Connection]
rollback
commiting
execution
RESULTS:undefined
Err:Error: ORA-24324: service handle not initialized

時々それはまた与える:

$ node test_node_oracle.js 
Connection:[object Connection]
Segmentation fault

またはまた:

$ node test_node_oracle.js 
Connection:[object Connection]
commiting
rollback
execution
RESULTS:undefined
Err:Error: ORA-32102: invalid OCI handle

ただし、sqlplusアクセスは正常に機能します。

$ sqlplus USER / PASS@192.168.1.120 / orcl

SQL * Plus:リリース11.2.0.3.02012年3月12日月曜日15:18:18の本番

Copyright(c)1982、2011、Oracle。全著作権所有。

接続先:Oracle Database 11g Enterprise Editionリリース11.2.0.1.0-パーティショニング、OLAP、データマイニング、および実際のアプリケーションテストオプションを使用した本番環境

SQL>

4

1 に答える 1

2
connection.close(); // call this when you are done with the connection

node.js(event-loop)ではすべてのステートメントが非ブロッキングであるため、これはすぐに呼び出されると思います。commitおそらく、and内の適切なコールバックでラップする必要がありrollbackます。connectionまた、すべてのコードをコールバック内にラップする必要があります

oracle.connect({ "hostname": "192.168.1.120/orcl", "user": "USER", "password": "PASS" }, function(err, connection) {
// wrap all your code inside of this.
}
于 2012-03-12T19:16:43.080 に答える