forked from ibmdb/python-ibmdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scalarsp_create.py
More file actions
70 lines (65 loc) · 2.47 KB
/
test_scalarsp_create.py
File metadata and controls
70 lines (65 loc) · 2.47 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
from __future__ import print_function
import unittest
import ibm_db
import config
from datetime import date, time, datetime
from testfunctions import IbmDbTestFunctions
class IbmDbTestCase(unittest.TestCase):
def test_scalarsp_create(self):
obj = IbmDbTestFunctions()
obj.assert_expectf(self.run_test_scalarsp_create)
def run_test_scalarsp_create(self):
conn = ibm_db.connect(config.database, config.user, config.password)
if not conn:
print("no connection")
return
scalar_types = [
("int_scalar", "INTEGER"),
("sint_scalar", "SMALLINT"),
("bint_scalar", "BIGINT"),
("float_scalar", "FLOAT"),
("double_scalar", "DOUBLE"),
("real_scalar", "REAL"),
("decfloat16_scalar", "DECFLOAT(16)"),
("decfloat34_scalar", "DECFLOAT(34)"),
("decimal_scalar", "DECIMAL(10,2)"),
("date_scalar", "DATE"),
("time_scalar", "TIME"),
("ts_scalar", "TIMESTAMP"),
]
for proc_name, base_type in scalar_types:
try:
ibm_db.exec_immediate(conn, f"DROP PROCEDURE {proc_name}")
except:
pass
if base_type in ["INTEGER", "SMALLINT", "BIGINT"]:
operation = "SET var2 = var1 + 1;"
elif base_type in ["FLOAT", "DOUBLE", "REAL"]:
operation = "SET var2 = var1 + 1.0;"
elif base_type in ["DECFLOAT(16)", "DECFLOAT(34)", "DECIMAL(10,2)"]:
operation = "SET var2 = var1 + Decimal(1.25);"
elif base_type == "DATE":
operation = "SET var2 = var1 + 1 DAY;"
elif base_type == "TIME":
operation = "SET var2 = var1 + 1 MINUTE;"
elif base_type == "TIMESTAMP":
operation = "SET var2 = var1 + 1 SECOND;"
else:
operation = "SET var2 = var1;"
ibm_db.exec_immediate(conn, f"""
CREATE PROCEDURE {proc_name}(IN var1 {base_type}, OUT var2 {base_type})
LANGUAGE SQL
BEGIN
{operation}
END
""")
print("Preparation complete: scalar stored procedures with safe operations created.")
#__END__
#__LUW_EXPECTED__
#Preparation complete: scalar stored procedures with safe operations created.
#__ZOS_EXPECTED__
#... same as LUW ...
#__SYSTEMI_EXPECTED__
#... same as LUW ...
#__IDS_EXPECTED__
#... same as LUW ...