Skip to content

Instantly share code, notes, and snippets.

@changjie-lin
Last active February 19, 2016 06:11
Show Gist options
  • Save changjie-lin/071619377e6b877e75f6 to your computer and use it in GitHub Desktop.
Save changjie-lin/071619377e6b877e75f6 to your computer and use it in GitHub Desktop.
standalone case for pull request 329
/*
-- Test Date with milliseconds
CREATE TABLE testtab(id NUMBER, content DATE);
* */
var async = require('async');
var oracledb = require('oracledb');
var dbConfig = require('./dbconfig.js');
var doconnect = function(cb) {
oracledb.getConnection(dbConfig, cb);
};
var dorelease = function(conn) {
conn.release(function (err) {
if (err)
console.error(err.message);
});
};
var doinsert = function(conn, cb) {
var bindvar = new Date(Date.UTC(2003, 09, 23, 11, 50, 30, 123));
console.log('Insert date: ', bindvar.getTime());
conn.execute(
"INSERT INTO testtab(id, content) VALUES(:i, :c)",
{ i: 1, c: bindvar },
{ autoCommit: true },
function(err) {
if(err)
return cb(err, conn);
else
return cb(null, conn);
}
);
}
var doselect = function(conn, cb) {
conn.execute(
"SELECT content FROM testtab WHERE id = 1",
function(err, result) {
if (err)
return cb(err, conn);
else {
console.log('select from DB:', result.rows[0][0].getTime());
cb(null, conn);
}
}
);
}
async.waterfall(
[
doconnect,
doinsert,
doselect
],
function (err, conn) {
if (err) { console.error("In waterfall error cb: ==>", err, "<=="); }
if (conn)
dorelease(conn);
});
@changjie-lin
Copy link
Author

-- Output:
Insert date: 1066909830123
select from DB: 1066967430000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment