Skip to content

Commit fa2bbf0

Browse files
committed
db2 test case
1 parent 66b7e39 commit fa2bbf0

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/dat/db2action.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,35 @@
11
import ibm_db
22

33
def main(args):
4+
#Connect to the DB2 database
5+
conn = ibm_db.connect("DATABASE=TEST;HOSTNAME=172.17.0.1;PORT=50000;PROTOCOL=TCPIP;UID=DB2INST1;PWD=db2inst1-pwd;", "", "")
6+
cmd = "DELETE FROM TESTTABLE WHERE name='Angela'"
7+
result = ibm_db.exec_immediate(conn, cmd)
8+
#output of the above can succeed or fail. Either is fine.
9+
10+
# Insert into TestTable
11+
cmd = "INSERT INTO TESTTABLE (NAME, AGE, LOCATION) VALUES ('Angela', 27, 'Texas')"
12+
result = ibm_db.exec_immediate(conn, cmd)
13+
if not result:
14+
return {"err":"error :"+cmd}
15+
16+
# Select from TestTable (the row just inserted)
17+
cmd = "SELECT * FROM TESTTABLE WHERE name='Angela'"
18+
result = ibm_db.exec_immediate(conn, cmd)
19+
if not result:
20+
return {"err":"error :"+cmd}
21+
else:
22+
ibm_db.fetch_both(result,0)
23+
value = ibm_db.result(result,"NAME")
24+
# Make sure the row was correctly inserted
25+
if value != 'Angela' :
26+
return {"err":"Expected name 'Angela', but instead found: "+ value}
27+
28+
# Delete the row from TestTable
29+
cmd = "DELETE FROM TESTTABLE WHERE name='Angela'"
30+
result = ibm_db.exec_immediate(conn, cmd)
31+
if not result:
32+
return {"err":"error :"+cmd}
33+
34+
# If no detected errors occurred so far; return Success status
435
return {"message":"Successfully called db2 action"}

tests/dat/setup.sql

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
CREATE DATABASE TEST AUTOMATIC STORAGE YES USING CODESET UTF-8 TERRITORY US PAGESIZE 4096;
2+
CONNECT TO TEST;
3+
4+
CREATE TABLE TESTTABLE (
5+
NAME VARCHAR(20) NOT NULL,
6+
AGE INTEGER NOT NULL,
7+
LOCATION VARCHAR(20)
8+
);

0 commit comments

Comments
 (0)