Python ibm_db_dbi.connect() Examples

The following are 15 code examples of ibm_db_dbi.connect(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ibm_db_dbi , or try the search function .
Example #1
Source File: queries.py    From coursys with GNU General Public License v3.0 7 votes vote down vote up
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 
Example #2
Source File: queries.py    From coursys with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #3
Source File: db2_query.py    From coursys with GNU General Public License v3.0 6 votes vote down vote up
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 
Example #4
Source File: db2_query.py    From coursys with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #5
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
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) 
Example #6
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
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) 
Example #7
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
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) 
Example #8
Source File: connector.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
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) 
Example #9
Source File: sample.py    From python-for-IBM-i-examples with MIT License 5 votes vote down vote up
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) 
Example #10
Source File: sample.py    From python-for-IBM-i-examples with MIT License 5 votes vote down vote up
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) 
Example #11
Source File: dbtoxlsx.py    From python-for-IBM-i-examples with MIT License 5 votes vote down vote up
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)) 
Example #12
Source File: connector.py    From POC-EXP with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #13
Source File: db2.py    From asm3 with GNU General Public License v3.0 5 votes vote down vote up
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) 
Example #14
Source File: connector.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
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) 
Example #15
Source File: connector.py    From EasY_HaCk with Apache License 2.0 5 votes vote down vote up
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))