<s> from cafe . engine . clients . base import BaseClient <EOL> from cafe . common . reporting import cclogging <EOL> class SQLClientException ( Exception ) : <EOL> pass <EOL> class BaseSQLClient ( BaseClient ) : <EOL> """<STR_LIT>""" <EOL> _log = cclogging . getLogger ( __name__ ) <EOL> _driver = None <EOL> _connection = None <EOL> def connect ( self , data_source_name = None , user = None , password = None , <EOL> host = None , database = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _driver is None : <EOL> message = '<STR_LIT>' <EOL> self . _log . critical ( message ) <EOL> raise SQLClientException ( message ) <EOL> try : <EOL> self . _connection = self . _driver . connect ( <EOL> data_source_name , user , password , host , database ) <EOL> except AttributeError as detail : <EOL> message = "<STR_LIT>" <EOL> self . _log . exception ( detail ) <EOL> self . _log . critical ( message ) <EOL> raise detail <EOL> def execute ( self , operation , parameters = None , cursor = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _connection is None : <EOL> message = '<STR_LIT>' <EOL> self . _log . critical ( message ) <EOL> raise SQLClientException ( message ) <EOL> if cursor is None : <EOL> cursor = self . _connection . cursor ( ) <EOL> cursor . execute ( operation , parameters ) <EOL> return cursor <EOL> def execute_many ( self , operation , seq_of_parameters = None , cursor = None ) : <EOL> """<STR_LIT>""" <EOL> if self . _connection is None : <EOL> message = '<STR_LIT>' <EOL> self . _log . critical ( message ) <EOL> raise SQLClientException ( message ) <EOL> if cursor is None : <EOL> cursor = self . _connection . cursor ( ) <EOL> cursor . executemany ( operation , seq_of_parameters ) <EOL> return cursor <EOL> def close ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _connection is not None : <EOL> self . _connection . close ( ) <EOL> self . _connection = None </s>
