ifx_db
Version:
IBM Informix bindings for node
59 lines (51 loc) • 1.98 kB
JavaScript
/* Test program to access Informix sample database */
/*require the ibm_db module*/
var common = require("./common")
, assert = require("assert")
, ifxdb = require("../");
var testTable = 'BIGINTTEST';
var testValues = [10205152031467301, 10205152031467303];
/*Connect to the database server
param 1: The DSN string which has the details of database name to connect to, user id, password, hostname, portnumber
param 2: The Callback function to execute when connection attempt to the specified database is completed
*/
ifxdb.open(common.connectionString, function(err, conn)
{
if(err) {
console.error("error: ", err.message);
assert.equal(err.message, null);
} else {
console.log('Connection to Informix machine successful');
try {
conn.querySync("create table " + testTable + " (COLINT BIGINT)");
} catch (e) {};
for(var i=0;i<testValues.length;i++) {
conn.querySync("insert into " + testTable + " values (" + testValues[i] + ")");
}
/*
On successful connection issue the SQL query by calling the query() function on Database
param 1: The SQL query to be issued
param 2: The callback function to execute when the database server responds
*/
conn.query("SELECT * FROM " + testTable, function(err, nodetest, moreResultSets) {
console.log("COLINT\tTESTVALUE");
console.log("-----------------------------------");
for (var i=0;i<nodetest.length;i++)
{
console.log(parseInt(nodetest[i].COLINT)+'\t'+testValues[i]);
if(nodetest[i].COLINT != testValues[i]) {
//throw error
}
}
console.log("-----------------------------------");
conn.querySync("drop table " + testTable);
/*
Close the connection to the database
param 1: The callback function to execute on completion of close function.
*/
conn.close(function(){
console.log("Connection Closed");
});
});
}
});