-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.js
110 lines (95 loc) · 3.92 KB
/
select.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var fs = require('fs');
var oracledb = require('oracledb');
// Get a non-pooled connection
oracledb.getConnection(
{
user : '',
password : '',
connectString : ''
},
function(err, connection)
{
if (err) {
console.error(err.message);
return;
}
console.log("argv: "+process.argv[2]);
//var templateId = 10534;
var templateId = +process.argv[2];
//fs.rmdirSync(''+templateId);
fs.mkdirSync(''+templateId);
connection.execute(
//"SELECT * FROM GLOBAL_NAME",[],
//The statement to execute
"select TEMPLATEID, SUBJECT, BODYHTML, BODYTEXT " +
"FROM SMTP_NTEMPLATES " +
"WHERE LANGUAGEID=1033 AND TEMPLATEID = :id",
// The "bind value" for the "bind variable" :id
[templateId],
// Optional execute options argument, such as the query result format
// or whether to get extra metadata
// { outFormat: oracledb.OBJECT, extendedMetaData: true },
{ fetchInfo: { "BODYHTML": { type: oracledb.STRING}, "BODYTEXT": { type: oracledb.STRING} } },
// The callback function handles the SQL execution results
function(err, result)
{
if (err) {
console.error(err.message);
doRelease(connection);
return;
}
//console.log(result.metaData); // [ { name: 'TEMPLATEID' }, { name: 'SUBJECT' } ]
// console.log(result.rows); // [ [ 5051, ' ... ' ] ]
var bodyhtml = result.rows[0][2];
var bodytxt = result.rows[0][3];
//console.log(bodyhtml);
fs.writeFileSync(''+templateId+'/'+templateId+'.html', bodyhtml);
fs.writeFileSync(''+templateId+'/'+templateId+'.txt', bodytxt);
//doRelease(connection);
}
);
connection.execute(
//"SELECT * FROM GLOBAL_NAME",[],
//The statement to execute
"select TEMPLATEID, SUBJECT, BODYHTML, BRANDID, BODYTEXT " +
"FROM SMTP_NTEMPLATES_BRANDED " +
"WHERE LANGUAGEID=1033 AND TEMPLATEID = :id",
// The "bind value" for the "bind variable" :id
[templateId],
// Optional execute options argument, such as the query result format
// or whether to get extra metadata
// { outFormat: oracledb.OBJECT, extendedMetaData: true },
{ fetchInfo: { "BODYHTML": { type: oracledb.STRING}, "BODYTEXT": { type: oracledb.STRING} } },
// The callback function handles the SQL execution results
function(err, result)
{
if (err) {
console.error(err.message);
doRelease(connection);
return;
}
console.log(result.metaData); // [ { name: 'TEMPLATEID' }, { name: 'SUBJECT' } ]
//console.log(result.rows); // [ [ 5051, ' ... ' ] ]
console.log(result.rows.length);
for(var i=0; i<result.rows.length; i++ ) {
var bodyhtml = result.rows[i][2];
var bodytxt = result.rows[i][4];
var brandId = result.rows[i][3];
console.log(brandId);
fs.writeFileSync(''+templateId+'/'+ templateId+'-'+brandId+ '.html', bodyhtml);
fs.writeFileSync(''+templateId+'/'+ templateId+'-'+brandId+ '.txt', bodytxt);
}
//doRelease(connection);
}
);
});
// Note: connections should always be released when not needed
function doRelease(connection)
{
connection.close(
function(err) {
if (err) {
console.error(err.message);
}
});
}