Sophie

Sophie

distrib > Fedora > 13 > i386 > by-pkgid > 2704cc0d30108833fb531964661e7486 > files > 51

mysql-connector-python3-0.3.2-2.fc13.noarch.rpm

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, os

import mysql.connector

"""

Example using MySQL Connector/Python showing:
* using warnings

"""

def main(config):
    config['get_warnings'] = True
    db = mysql.connector.Connect(**config)
    cursor = db.cursor()
    
    stmt_select = "SELECT 'abc'+1"
    
    print("Remove all sql modes..")
    cursor.execute("SET sql_mode = ''") # Make sure we don't have strict on
    
    print("Execute '%s'" % stmt_select)
    cursor.execute(stmt_select)
    cursor.fetchall()
    
    warnings = cursor.fetchwarnings()
    if warnings:
        print(warnings)
    else:
        print("We should have got warnings.")
        raise Exception("Got no warnings")

    db.close()

if __name__ == '__main__':
    #
    # Configure MySQL login and database to use in config.py
    #
    import config
    config = config.Config.dbinfo().copy()
    main(config)