forked from jesslilly/db2.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
120 lines (108 loc) · 4.58 KB
/
test.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
111
112
113
114
115
116
117
118
119
120
var db2;
try {
db2 = require('db2');
} catch (exception) {
db2 = require('./db2');
}
var connection = db2.connect("olapTest");
connection.execute("SELECT * FROM requests", function () {
//*
console.log("Got %d arguments:", arguments.length);
for (var i = 0; i < arguments.length; i++) {
console.log(" %d: %s", i, JSON.stringify(arguments[i]));
}
// */
});
//*
//connection.execute("SELECT * FROM requests FETCH FIRST 10 ROWS ONLY", function (error, result) {if (error) {return console.log(error);} console.log(require('util').inspect(result));});
var testCreate = function () {
var run = false;
try {
connection.execute("CREATE TABLE sliff (sloff CLOB)", function (error, row) {
if (error) {
throw error;
}
if (row) {
throw new Error("CREATE TABLE cannot produce a row result");
}
run = true;
});
if (!run) {
throw new Error("the CREATE TABLE callback needs to be run");
}
connection.execute("INSERT INTO sliff VALUES (?)", 'sloff', function (error, row) {
if (error) {
throw error;
}
if (row) {
throw new Error('row must be null');
}
});
connection.execute("SELECT * FROM sliff", function (error, row) {
if (error) {
throw error;
}
if (row && row.SLOFF.toString() !== 'sloff') {
throw new Error('row.SLOFF: ' + JSON.stringify(row.SLOFF.toString()) + ' !== "sloff"');
}
});
} catch (exception) {
if (exception.nativeError === -601) { // object already exists
connection.execute("DROP TABLE sliff");
testCreate();
} else {
console.error("%s: %s", exception, JSON.stringify(exception));
throw exception;
}
}
};
testCreate();
testCreate = function () {
try {
connection.execute("CREATE TABLE argumentBinding (cString VARCHAR(255))", function (error, row) {
if (error) {
throw error;
}
if (row !== null) {
throw new Error("row must be null: " + JSON.stringify(row));
}
});
// FIXME: write a test case for inserting too long data
connection.execute("INSERT INTO argumentBinding VALUES (?)", 'test argument', function (error, row) {
if (error) {
throw error;
}
if (row) {
throw new Error('row must be null');
}
});
connection.execute("SELECT * FROM argumentBinding", function (error, row) {
if (error) {
throw error;
}
if (row && row.CSTRING.toString() !== 'test argument') {
throw new Error('row.CSTRING: ' + JSON.stringify(row.CSTRING.toString()) + ' !== "sloff"');
}
});
} catch (exception) {
if (exception.nativeError === -601) { // object already exists
connection.execute("DROP TABLE argumentBinding");
return testCreate();
}
throw exception;
}
};
testCreate();
connection.execute("SELECT httpMethod FROM requests");
connection.execute("SELECT count(httpMethod) FROM requests GROUP BY httpMethod");
connection.execute("SELECT httpMethod, count(httpMethod) FROM requests GROUP BY httpMethod");
connection.execute("SELECT httpMethod, count(*) FROM requests GROUP BY httpMethod");
connection.execute("SELECT httpMethod, count(*) AS count FROM requests GROUP BY GROUPING SETS ((httpMethod, httpURL))");
connection.execute("SELECT httpMethod, statusCode, count(*) AS count FROM requests GROUP BY GROUPING SETS ((httpMethod, statusCode))");
connection.execute("SELECT httpMethod, statusCode, count(*) AS count FROM requests GROUP BY GROUPING SETS ((httpMethod, statusCode), (httpMethod))");
connection.execute("SELECT httpMethod, statusCode, count(*) AS count FROM requests GROUP BY GROUPING SETS ((httpMethod, statusCode), (httpMethod)) ORDER BY httpMethod");
connection.execute("SELECT httpMethod, statusCode, count(*) AS count FROM requests GROUP BY GROUPING SETS ((httpMethod, httpURL, statusCode), (httpMethod, httpURL), (httpMethod)) ORDER BY httpMethod");
connection.execute("SELECT httpMethod, httpURL, statusCode, count(*) AS count FROM requests GROUP BY GROUPING SETS ((httpMethod, httpURL, statusCode), (httpMethod, httpURL), (httpMethod)) ORDER BY httpMethod");
connection.execute("SELECT httpMethod, httpURL, statusCode, sum(bodySize) AS data FROM requests GROUP BY GROUPING SETS ((httpMethod, httpURL, statusCode), (httpMethod, httpURL), (httpMethod)) ORDER BY httpMethod");
// */
// vim:set sw=4 et: