forked from msatyan/NodeFullStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleConnNode.js
More file actions
105 lines (88 loc) · 2.22 KB
/
SimpleConnNode.js
File metadata and controls
105 lines (88 loc) · 2.22 KB
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
// Copyright (c) 2018 Sathyanesh Krishnan. All rights reserved.
// Licensed under the Apache License, Version 2.0
var dbobj = require('ifxnjs');
var fs = require('fs');
function DirExec( conn, ErrIgn, sql )
{
try
{
var result = conn.querySync( sql );
console.log( sql );
}
catch (e)
{
console.log( "--- " + sql );
if( ErrIgn != 1 )
{
console.log(e);
console.log();
}
}
}
function DoSomeWork(err, conn)
{
if (err)
{
return console.log(err);
}
DirExec( conn, 1, "drop table t1" );
DirExec( conn, 0, "create table t1 ( c1 int, c2 char(20) ) " );
DirExec( conn, 0, "insert into t1 values( 1, 'val-1' )" );
DirExec( conn, 0, "insert into t1 values( 2, 'val-2' )" );
DirExec( conn, 0, "insert into t1 values( 3, 'val-3' )" );
DirExec( conn, 0, "insert into t1 values( 4, 'val-4' )" );
DirExec( conn, 0, "insert into t1 values( 5, 'val-5' )" );
console.log(" --- SELECT * FROM t1 ------ " );
// blocks until the query is completed and all data has been acquired
var rows = conn.querySync( "SELECT * FROM t1" );
console.log();
console.log(rows);
};
var MyAsynchronousTask = function (err, conn)
{
DoSomeWork(err, conn);
conn.close();
}
function ifxnjs_Open(ConStr)
{
console.log(" --- MyAsynchronousTask Starting....." );
dbobj.open( ConStr, MyAsynchronousTask );
console.log(" --- Check the sequence printed!" );
}
function ifxnjs_OpenSync(ConStr)
{
console.log(" --- Executing ifxnjs.openSync() ...." );
var conn;
try
{
conn = dbobj.openSync(ConStr);
}
catch(e)
{
console.log(e);
return;
}
DoSomeWork(0, conn);
try
{
conn.closeSync();
}
catch(e)
{
console.log(e);
}
console.log(" --- End ifxnjs.openSync()" );
}
function main_func()
{
// See the SampleConfig.json to create MyConfig.json
// Make sure the port used in connection is IDS SQLI port.
var MyConfig = JSON.parse(fs.readFileSync('MyConfig.json', 'utf8')); // do Synchronously read only
var ConnStr = MyConfig.AllConns.Conn1.ConnStr;
// ConnStr = "SERVER=ids0;DATABASE=db1;HOST=127.0.0.1;SERVICE=9088;UID=informix;PWD=xxxxx;";
//Synchronous Execution
ifxnjs_OpenSync(ConnStr);
//Asynchronous Execution
ifxnjs_Open(ConnStr);
}
main_func();