Created
September 16, 2015 22:23
-
-
Save bjouhier/3c7c5c108fc90286719f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var oracledb = require('oracledb'); | |
var ez = require('ez-streams'); | |
var cnx = oracledb.getConnection({ | |
user: "scott", | |
password: "oracle", | |
connectString: "localhost/ORCL", | |
}, _); | |
try { | |
cnx.execute("drop table clobs", _); | |
console.error("old table dropped"); | |
} catch (err) { | |
if (!/^ORA-00942/.test(err.message)) throw err; | |
} | |
console.error("creating clobs table"); | |
cnx.execute("create table clobs (id integer, text clob)", _); | |
function insertClob(_, id, text) { | |
console.error("inserting clob id=" + id + ", text=" + text); | |
var result = cnx.execute("insert into clobs (id, text) values (:id, empty_clob()) returning text into :text", { | |
id: id, | |
text: { | |
type: oracledb.CLOB, | |
dir: oracledb.BIND_OUT | |
} | |
}, { | |
autoCommit: false | |
}, _); | |
if (result.rowsAffected != 1 || result.outBinds.text.length != 1) { | |
throw new Error('Error getting a LOB locator'); | |
} | |
var lob = result.outBinds.text[0]; | |
ez.devices.string.reader(text).pipe(_, ez.devices.node.writer(lob)); | |
} | |
insertClob(_, 1, "hello world"); | |
insertClob(_, 2, "how are you doing today?"); | |
insertClob(_, 3, "fine, thank you"); | |
console.error("committing inserted rows"); | |
cnx.execute("commit", _); | |
console.error("selecting all rows from clobs table"); | |
var rs = cnx.execute("select id, text from clobs", [], { | |
resultSet: true, | |
}, _).resultSet; | |
while (true) { | |
console.error("before rs.getRow(_)"); | |
var row = rs.getRow(_); | |
console.error("after rs.getRow(_) row=" + !!row); | |
if (!row) break; | |
console.error(row[0] + ": " + ez.devices.node.reader(row[1]).readAll(_)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is a repro for oracle/node-oracledb#210
It is written with
streamline.js
andez-streams
because I write all my code with these tools. So you have to install these with NPM first, and run with_node
instead ofnode
(and keep the._js
extension too):With the bugfix that I submitted (checkout the
sage
branch on my fork), I get:Without the fix I get:
Notes: