forked from cms-tsg-fog/RateMon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql_query_tool.py
More file actions
37 lines (26 loc) · 1.28 KB
/
sql_query_tool.py
File metadata and controls
37 lines (26 loc) · 1.28 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
# Imports
import cx_Oracle
import socket
# For the parsing
import re
class DBQueryTool:
def __init__(self) :
# Connect to the Database
hostname = socket.gethostname()
if hostname.find('lxplus') > -1: self.dsn_ = 'cms_omds_adg' #offline
else: self.dsn_ = 'cms_omds_lb' #online
orcl = cx_Oracle.connect(user='cms_hlt_r',password='convertMe!',dsn=self.dsn_)
orcl = cx_Oracle.connect(user='cms_trg_r',password='X3lmdvu4',dsn=self.dsn_)
# Create a DB cursor
self.curs = orcl.cursor()
def test_query(self):
# query="""SELECT MAX(A.RUNNUMBER), MAX(B.LIVELUMISECTION) FROM CMS_RUNINFO.RUNNUMBERTBL A, CMS_RUNTIME_LOGGER.LUMI_SECTIONS B WHERE B.RUNNUMBER=A.RUNNUMBER AND B.LUMISECTION > 0 """
query="""SELECT LAST(B.LUMISECTION) FROM CMS_RUNINFO.RUNNUMBERTBL A, CMS_RUNTIME_LOGGER.LUMI_SECTIONS B WHERE B.RUNNUMBER=A.RUNNUMBER AND B.LUMISECTION > 0 """
# query="""SELECT column_name FROM all_tab_cols WHERE table_name = 'LUMI_SECTIONS' AND owner = 'CMS_RUNTIME_LOGGER'"""
self.curs.execute(query)
print self.curs.fetchall()
# print self.curs.fetchone()
## ----------- End of class ------------ ##
if __name__ == "__main__":
query_tool = DBQueryTool()
query_tool.test_query()