Skip to content

Commit 1a478d6

Browse files
committed
Add a demo for RAW
1 parent aa7a437 commit 1a478d6

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

examples/demo.sql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,7 @@ END LOOP;
106106
END;
107107
/
108108
SHOW ERRORS
109+
110+
-- For raw1.js
111+
DROP TABLE myraw;
112+
CREATE TABLE myraw (r RAW(64));

examples/demodrop.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,5 @@ DROP TABLE mylobs;
4242
DROP TYPE dorow;
4343

4444
DROP FUNCTION mydofetch;
45+
46+
DROP TABLE myraw;

examples/raw1.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. */
2+
3+
/******************************************************************************
4+
*
5+
* You may not use the identified files except in compliance with the Apache
6+
* License, Version 2.0 (the "License.")
7+
*
8+
* You may obtain a copy of the License at
9+
* http://www.apache.org/licenses/LICENSE-2.0.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
*
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*
18+
* NAME
19+
* raw1.js
20+
*
21+
* DESCRIPTION
22+
* Shows using a Buffer to insert and select a RAW.
23+
* Use demo.sql to create the dependencies or do:
24+
*
25+
* DROP TABLE myraw;
26+
* CREATE TABLE myraw (r RAW(64));
27+
*
28+
*****************************************************************************/
29+
30+
var async = require('async');
31+
var oracledb = require('oracledb');
32+
var dbConfig = require('./dbconfig.js');
33+
34+
var buf = new Buffer([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x4f, 0x72, 0x61, 0x63, 0x6c, 0x65, 0x21], 'hex');
35+
36+
var insertRaw = function (conn, cb) {
37+
conn.execute(
38+
"INSERT INTO myraw VALUES (:r)",
39+
{ r : { val: buf, type: oracledb.BUFFER, dir:oracledb.BIND_IN }},
40+
function(err, result) {
41+
if (err) {
42+
return cb(err, conn);
43+
} else {
44+
console.log(result.rowsAffected + " row(s) inserted.");
45+
return cb(null, conn);
46+
}
47+
});
48+
};
49+
50+
var queryRaw = function (conn, cb) {
51+
conn.execute(
52+
"SELECT r FROM myraw",
53+
function (err, result) {
54+
if (err) {
55+
return cb(err, conn);
56+
} else {
57+
var buf = result.rows[0];
58+
console.log("Buffer queried:");
59+
console.log(buf);
60+
console.log(buf.toString('utf8'));
61+
return cb(null, conn);
62+
}
63+
});
64+
};
65+
66+
// Insert and query the RAW data
67+
async.waterfall(
68+
[
69+
function(cb) {
70+
oracledb.getConnection(dbConfig, cb);
71+
},
72+
insertRaw,
73+
queryRaw
74+
],
75+
function (err, conn) {
76+
if (err) { console.error("In waterfall error cb: ==>", err, "<=="); }
77+
conn.release(function (err) { if (err) console.error(err.message); });
78+
});
79+

0 commit comments

Comments
 (0)