本文整理汇总了Python中ibm_db_dbi.connect方法的典型用法代码示例。如果您正苦于以下问题:Python ibm_db_dbi.connect方法的具体用法?Python ibm_db_dbi.connect怎么用?Python ibm_db_dbi.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ibm_db_dbi
的用法示例。
在下文中一共展示了ibm_db_dbi.connect方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_connection
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def get_connection(self):
if settings.DISABLE_REPORTING_DB:
raise SIMSProblem("Reporting database access has been disabled in this deployment.")
elif feature_disabled('sims'):
raise SIMSProblem("Reporting database access has been temporarily disabled due to server maintenance or load.")
try:
import ibm_db_dbi
except ImportError:
raise SIMSProblem("could not import DB2 module")
SIMSConn.DatabaseError = ibm_db_dbi.DatabaseError
SIMSConn.DB2Error = ibm_db_dbi.Error
try:
dbconn = ibm_db_dbi.connect(self.sims_db, self.sims_user, self.sims_passwd)
except ibm_db_dbi.Error:
raise #SIMSProblem("Could not communicate with reporting database.")
cursor = dbconn.cursor()
cursor.execute("SET SCHEMA "+self.schema)
return dbconn, cursor
示例2: SIMS_problem_handler
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def SIMS_problem_handler(func):
"""
Decorator to deal somewhat gracefully with any SIMS database problems.
Any decorated function may raise a SIMSProblem instance to indicate a
problem with the database connection.
Should be applied to any functions that use a SIMSConn object.
"""
def wrapped(*args, **kwargs):
# check for the types of errors we know might happen and return an error message in a SIMSProblem
try:
return func(*args, **kwargs)
except SIMSConn.DatabaseError as e:
raise SIMSProblem("could not connect to reporting database")
except SIMSConn.DB2Error as e:
raise SIMSProblem("problem with connection to reporting database")
wrapped.__name__ = func.__name__
return wrapped
示例3: connect
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def connect():
""" Connect to a DB2 database.
All subclasses of DB2_Query will use this database for queries.
"""
if settings.DISABLE_REPORTING_DB:
raise SIMSProblem("Reporting database access has been disabled in this deployment.")
sims_user = settings.SIMS_USER
sims_passwd = settings.SIMS_PASSWORD
sims_db_name = settings.SIMS_DB_NAME
sims_db_schema = settings.SIMS_DB_SCHEMA
import ibm_db_dbi
dbconn = ibm_db_dbi.connect(sims_db_name, sims_user, sims_passwd)
cursor = dbconn.cursor()
cursor.execute("SET SCHEMA "+sims_db_schema)
DB2_Query.db = dbconn
示例4: __init__
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def __init__(self, query_args={}):
if not self.db:
raise NotConnected("Please call DB2_Query.connect before creating any DB2 query objects.")
super(DB2_Query, self).__init__(self.db, DB2_Query.clean_input, DB2_Query.clean_output, query_args)
示例5: connect
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def connect(self):
self.initConnection()
try:
database = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % (self.db, self.hostname, self.port)
self.connector = ibm_db_dbi.connect(database, self.user, self.password)
except ibm_db_dbi.OperationalError, msg:
raise SqlmapConnectionException(msg)
示例6: query_ibm_db
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def query_ibm_db():
statement = request.forms.get('sql')
conn = dbi.connect()
cur = conn.cursor()
cur.execute(statement)
headers = [descr[0] for descr in cur.description]
return template('query', headers=headers, rows=cur)
示例7: query_ibm_db
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def query_ibm_db():
statement = request.form.get('sql')
conn = dbi.connect()
cur = conn.cursor()
cur.execute(statement)
headers = [descr[0] for descr in cur.description]
return render_template('query.html', headers=headers, rows=cur)
示例8: writeDataToExcel
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def writeDataToExcel(args, workbook, sheetName):
""" Write query output to Excel worksheet """
try:
conn = dbi.connect()
cur = conn.cursor()
cur.execute(args.c)
headers = [descr[0] for descr in cur.description]
format = workbook.add_format({'bold': args.b, 'italic': args.i})
worksheet = workbook.add_worksheet(sheetName)
worksheet.write_row('A1', headers, format)
for i, row in enumerate(cur, start=1):
worksheet.write_row(i, 0, row)
except Exception as err:
print('ERROR: ' + str(err))
示例9: connect
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def connect(self):
return ibm_db_dbi.connect("DSN=%s; HOSTNAME=%s; PORT=%s" % (self.database, self.host, self.port), user=self.username, password=self.password)
示例10: connect
# 需要导入模块: import ibm_db_dbi [as 别名]
# 或者: from ibm_db_dbi import connect [as 别名]
def connect(self):
self.initConnection()
try:
database = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % (self.db, self.hostname, self.port)
self.connector = ibm_db_dbi.connect(database, self.user, self.password)
except ibm_db_dbi.OperationalError, msg:
raise SqlmapConnectionException(getSafeExString(msg))