exports.callProceduresSync = function(schema, procedure, array){ var rows; try{ db2client.openSync(connString); rows = db2client.querySync("call "+schema+"."+procedure+"("+"?".concat(Array(array.length).join(",?"))+")", array); } catch (err){ throw err; }finally{ return rows; } }
exports.selectDataFromTableSync = function(tableName, colName, options){ var rows; try{ db2client.openSync(connString); var colStrList = "*"; var conditions = ""; if(colName) colStrList = generateCol(colName); if(options) conditions = generateConditions(options); rows = db2client.querySync("select "+colStrList+" from "+ tableName+conditions); }catch (e){ throw e; }finally{ return rows; } }
app.get('/samples/:id', function(req, res) { db.query("select meta from Samples where sample_id = ?", [req.params.id], function(err, rows, moreResultSets) { res.header("Content-Type", "text/xml"); res.send(rows[0].meta); util.debug(util.inspect(rows)); }); });
db2client.query("select "+colStrList+" from "+ tableName+conditions, function (err, rows) { if(err){ cb(err, undefined); } else { db2client.close(function () { cb(null, rows); }); } })
db2client.query("call "+schema+"."+procedure+"("+"?".concat(Array(array.length).join(",?"))+")", array, function (err, rows) { if(err){ cb(err, undefined); } else { db2client.close(function () { cb(null, rows); }); } })
db.query(sql, function(err, rows, rs){ //console.log(rows); var i=0; for (i=0; i<rows.length; i++) { console.log([ i, rows[i]["foo"], rows[i]["bar"] ].join(", ")); } db.close(function(){ console.log("close."); }); });
exports.callProcedures = function(schema, procedure, array, cb){ db2client.open(connString , function(err){ if(err){ cb(err, undefined); } else { db2client.query("call "+schema+"."+procedure+"("+"?".concat(Array(array.length).join(",?"))+")", array, function (err, rows) { if(err){ cb(err, undefined); } else { db2client.close(function () { cb(null, rows); }); } }) } }) }
db.open(cs, function(err){ var sql = "select foo, bar from HOGE order by foo"; db.query(sql, function(err, rows, rs){ //console.log(rows); var i=0; for (i=0; i<rows.length; i++) { console.log([ i, rows[i]["foo"], rows[i]["bar"] ].join(", ")); } db.close(function(){ console.log("close."); }); }); });
db2client.open(connString , function(err){ if(err){ cb(err, undefined); } else { var colStrList = "*"; var conditions = ""; if(colName) colStrList = generateCol(colName); if(options) conditions = generateConditions(options); db2client.query("select "+colStrList+" from "+ tableName+conditions, function (err, rows) { if(err){ cb(err, undefined); } else { db2client.close(function () { cb(null, rows); }); } }) } })
// a simple async service wrapper around a command line tool that does something with some data from a database // // basically, allows asynchronously run a config.executable_name for some xml data that is retrieved from // database using an integer id, get a "handle" in response and then to get result of the run using that // "handle" passed to a separate http get var express = require('express'); var util = require('util'); var odbc = require("odbc"); var uuid = require('node-uuid'); var db = new odbc.Database(); var fs = require('fs'); var spawn = require('child_process').spawn; var config = require('./config'); db.open(config.connection_string, function(err) { if (err) { console.log(err); process.exit(1); } }); var app = express(); app.get('/samples/:id', function(req, res) { db.query("select meta from Samples where sample_id = ?", [req.params.id], function(err, rows, moreResultSets) { res.header("Content-Type", "text/xml"); res.send(rows[0].meta);