-
Notifications
You must be signed in to change notification settings - Fork 13
/
FakeResultSetEsc.ts
86 lines (74 loc) · 2.85 KB
/
FakeResultSetEsc.ts
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
// Copyright 2023 by Teradata Corporation. All rights reserved.
// This sample program demonstrates the behavior of the fake_result_sets escape function.
// @ts-ignore
import { TeradataConnection, TeradataCursor } from "teradatasql";
type Row = any[] | null;
type Rows = any[];
const con: TeradataConnection = new TeradataConnection();
con.connect({ host: "whomooz", user: "guest", password: "please" });
const cur: TeradataCursor = con.cursor();
cur.execute("create volatile table voltab1 (c1 integer, c2 varchar(100)) on commit preserve rows");
cur.execute("insert into voltab1 values (1, 'abc')");
cur.execute("insert into voltab1 values (2, 'def')");
cur.execute("create volatile table voltab2 (c1 integer, c2 varchar(100)) on commit preserve rows");
cur.execute("insert into voltab2 values (3, 'ghi')");
cur.execute("insert into voltab2 values (4, 'jkl')");
cur.execute("insert into voltab2 values (5, 'mno')");
cur.execute("create volatile table voltab3 (c1 integer, c2 varchar(100)) on commit preserve rows");
cur.execute("insert into voltab3 values (6, 'pqr')");
cur.execute("insert into voltab3 values (7, 'stu')");
cur.execute("insert into voltab3 values (8, 'vwx')");
cur.execute("insert into voltab3 values (9, 'yz')");
cur.execute("{fn teradata_fake_result_sets}select * from voltab1 order by 1");
console.log("=== Two result sets produced by a single-statement SQL request that returns one result set ===");
console.log(" --- Fake result set ---");
let row: Row = cur.fetchone();
if (row) {
for (let i: number = 0; i < row.length; i++) {
if (cur.description) {
console.log(`Column ${i + 1} ${cur.description[i][0].padEnd(15)} = ${row[i]}`);
}
}
}
cur.nextset();
console.log(" --- Real result set ---");
let rows: Rows = cur.fetchall();
for (const row of rows) {
console.log(row);
}
console.log();
cur.execute("{fn teradata_fake_result_sets}select * from voltab2 order by 1 ; select * from voltab3 order by 1");
console.log("=== Four result sets produced by a multi-statement SQL request that returns two result sets ===");
console.log(" --- Fake result set ---");
row = cur.fetchone();
if (row) {
for (let i: number = 0; i < row.length; i++) {
if (cur.description) {
console.log(`Column ${i + 1} ${cur.description[i][0].padEnd(15)} = ${row[i]}`);
}
}
}
cur.nextset();
console.log(" --- Real result set ---");
rows = cur.fetchall();
for (const row of rows) {
console.log(row);
}
cur.nextset();
console.log(" --- Fake result set ---");
row = cur.fetchone();
if (row) {
for (let i: number = 0; i < row.length; i++) {
if (cur.description) {
console.log(`Column ${i + 1} ${cur.description[i][0].padEnd(15)} = ${row[i]}`);
}
}
}
cur.nextset();
console.log(" --- Real result set ---");
rows = cur.fetchall();
for (const row of rows) {
console.log(row);
}
cur.close();
con.close();