-
Notifications
You must be signed in to change notification settings - Fork 195
/
test_197_StatisticsIndexes.py
137 lines (127 loc) · 3.98 KB
/
test_197_StatisticsIndexes.py
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#
# Licensed Materials - Property of IBM
#
# (c) Copyright IBM Corp. 2007-2008
#
# NOTE: IDS requires that you pass the schema name (cannot pass None)
from __future__ import print_function
import sys
import unittest
import ibm_db
import config
from testfunctions import IbmDbTestFunctions
class IbmDbTestCase(unittest.TestCase):
def test_197_StatisticsIndexes(self):
obj = IbmDbTestFunctions()
obj.assert_expect(self.run_test_197)
def run_test_197(self):
conn = ibm_db.connect(config.database, config.user, config.password)
server = ibm_db.server_info( conn )
if conn:
try:
rc = ibm_db.exec_immediate(conn, "DROP TABLE index_test")
except:
pass
rc = ibm_db.exec_immediate(conn, "CREATE TABLE index_test (id INTEGER, data VARCHAR(50))")
rc = ibm_db.exec_immediate(conn, "CREATE UNIQUE INDEX index1 ON index_test (id)")
print("Test first index table:")
if (server.DBMS_NAME[0:3] == 'IDS'):
result = ibm_db.statistics(conn,None,config.user,"index_test",True)
elif ( sys.platform == 'zos'):
result = ibm_db.statistics(conn,None,config.user,"INDEX_TEST",True)
else:
result = ibm_db.statistics(conn,None,None,"INDEX_TEST",True)
row = ibm_db.fetch_tuple(result)
## skipping table info row. statistics returns informtation about table itself for informix ###
if (server.DBMS_NAME[0:3] == 'IDS'):
row = ibm_db.fetch_tuple(result)
print(row[2]) # TABLE_NAME
print(row[3]) # NON_UNIQUE
print(row[5]) # INDEX_NAME
print(row[8]) # COLUMN_NAME
try:
rc = ibm_db.exec_immediate(conn, "DROP TABLE index_test2")
except:
pass
rc = ibm_db.exec_immediate(conn, "CREATE TABLE index_test2 (id INTEGER, data VARCHAR(50))")
rc = ibm_db.exec_immediate(conn, "CREATE INDEX index2 ON index_test2 (data)")
print("Test second index table:")
if (server.DBMS_NAME[0:3] == 'IDS'):
result = ibm_db.statistics(conn,None,config.user,"index_test2",True)
elif ( sys.platform == 'zos'):
result = ibm_db.statistics(conn,None,config.user,"INDEX_TEST2",True)
else:
result = ibm_db.statistics(conn,None,None,"INDEX_TEST2",True)
row = ibm_db.fetch_tuple(result)
### skipping table info row. statistics returns informtation about table itself for informix ###
if (server.DBMS_NAME[0:3] == 'IDS'):
row = ibm_db.fetch_tuple(result)
print(row[2]) # TABLE_NAME
print(row[3]) # NON_UNIQUE
print(row[5]) # INDEX_NAME
print(row[8]) # COLUMN_NAME
print("Test non-existent table:")
if (server.DBMS_NAME[0:3] == 'IDS'):
result = ibm_db.statistics(conn,None,config.user,"non_existent_table",True)
else:
result = ibm_db.statistics(conn,None,None,"NON_EXISTENT_TABLE",True)
row = ibm_db.fetch_tuple(result)
if row:
print("Non-Empty")
else:
print("Empty")
else:
print('no connection: ' + ibm_db.conn_errormsg())
#__END__
#__LUW_EXPECTED__
#Test first index table:
#INDEX_TEST
#0
#INDEX1
#ID
#Test second index table:
#INDEX_TEST2
#1
#INDEX2
#DATA
#Test non-existent table:
#Empty
#__ZOS_EXPECTED__
#Test first index table:
#INDEX_TEST
#0
#INDEX1
#ID
#Test second index table:
#INDEX_TEST2
#1
#INDEX2
#DATA
#Test non-existent table:
#Empty
#__SYSTEMI_EXPECTED__
#Test first index table:
#INDEX_TEST
#0
#INDEX1
#ID
#Test second index table:
#INDEX_TEST2
#1
#INDEX2
#DATA
#Test non-existent table:
#Empty
#__IDS_EXPECTED__
#Test first index table:
#index_test
#0
#index1
#id
#Test second index table:
#index_test2
#1
#index2
#data
#Test non-existent table:
#Empty