-
Notifications
You must be signed in to change notification settings - Fork 0
/
tst.js
101 lines (81 loc) · 2.96 KB
/
tst.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
var oracledb = require('oracledb');
var fs = require('fs');
var path = require('path');
var async = require('async');
const util = require('util');
var dateFormat = require('dateformat');
var fileArray=[];
oracledb.getConnection(
{
user : "SCOTT",
password : "SCOTT",
connectString : "192.168.1.103/orcl"
},
function(err, connection)
{
if (err) {
console.error("ERROR: "+err.message);
return;
}
var runQuery = function (sql,callback) {
connection.execute(sql.trim(),
function (err, result) {
if (err) {
console.log(err);
}
console.log("Query run:" + sql.trim());
console.log("Result:" + result.rows);
callback();
});
}
//var fileArray = ['C:/Users/vinisman/IdeaProjects/StroyBusiness_SRC/sql/Module1/Module1.sql','C:/Users/vinisman/IdeaProjects/StroyBusiness_SRC/sql/script1.sql'];
var readFile = function (file,callbackDone){
console.log("file=" + file);
var content = fs.readFileSync(file);
var filecontent = content.toString().split(";");
filecontent = filecontent.filter(function(n){ return n != '' });
console.log("filecontent=[" + filecontent +"]");
async.eachSeries(filecontent,runQuery,function (err) {
console.log('Done');callbackDone();});
}
var SqlFileList = function(directoryName)
{
var files = fs.readdirSync(directoryName);
files.forEach(function(file)
{
var FilePath=directoryName + path.sep + file;
var f = fs.statSync(FilePath);
if (f.isDirectory())
{
SqlFileList(FilePath)
}
else
{
// console.log("File: " + FilePath);
var ts = fs.statSync(FilePath);
var tm = dateFormat(ts.mtime, "dd-mm-yyyy H:MM:ss");
// console.log("Time: " + tm);
fileArray.push({
path: FilePath,
mtime: tm
});
fs.writeFileSync('test.json', JSON.stringify(fileArray, null, 4));
// fileArray.push(FilePath);
// readFile(FilePath,function(){});
}
}
)
}
SqlFileList(__dirname +path.sep+"sql");
console.log(fileArray);
/*
async.eachSeries(fileArray,readFile, function (err) {
if (err) {
console.error(err.message);
return;
}
connection.close();
console.log('Connection closed');
})
*/
});