<s> __author__ = '<STR_LIT>' <EOL> import MySQLdb <EOL> import MySQLdb . cursors <EOL> def create_conf ( ) : <EOL> conf = dict ( ) <EOL> conf [ '<STR_LIT:host>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT:port>' ] = <NUM_LIT> <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT:utf8>' <EOL> return conf <EOL> def get_dw_conf ( ) : <EOL> conf = create_conf ( ) <EOL> conf [ '<STR_LIT:host>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return conf <EOL> def get_slave_conf ( ) : <EOL> conf = create_conf ( ) <EOL> conf [ '<STR_LIT:host>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return conf <EOL> def get_local_conf ( ) : <EOL> conf = create_conf ( ) <EOL> conf [ '<STR_LIT:host>' ] = '<STR_LIT:127.0.0.1>' <EOL> conf [ '<STR_LIT:user>' ] = '<STR_LIT:root>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return conf <EOL> def get_test_conf ( ) : <EOL> conf = create_conf ( ) <EOL> conf [ '<STR_LIT:host>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return conf <EOL> def get_stable_conf ( ) : <EOL> conf = create_conf ( ) <EOL> conf [ '<STR_LIT:host>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT:user>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> conf [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return conf <EOL> class PDBC : <EOL> def __init__ ( self , conf ) : <EOL> self . conn = MySQLdb . connect ( host = conf [ '<STR_LIT:host>' ] , user = conf [ '<STR_LIT:user>' ] , passwd = conf [ '<STR_LIT>' ] , db = conf [ '<STR_LIT>' ] , <EOL> port = conf [ '<STR_LIT:port>' ] , charset = conf [ '<STR_LIT>' ] , cursorclass = MySQLdb . cursors . DictCursor ) <EOL> self . cur = self . conn . cursor ( ) <EOL> def __del__ ( self ) : <EOL> self . cur . close ( ) <EOL> self . conn . close ( ) <EOL> def get_data ( self , sql ) : <EOL> self . cur . execute ( sql ) <EOL> result = self . cur . fetchall ( ) <EOL> return result <EOL> def get_cursor ( self , sql ) : <EOL> self . cur . execute ( sql ) <EOL> return self . cur <EOL> def exec_data ( self , sql ) : <EOL> result = self . cur . execute ( sql ) <EOL> self . conn . commit ( ) <EOL> return result <EOL> def insert_data ( self , sql ) : <EOL> self . cur . execute ( sql ) <EOL> new_id = int ( self . cur . lastrowid ) <EOL> self . conn . commit ( ) <EOL> return new_id </s>
