<s> """<STR_LIT>""" <EOL> import psycopg2 as dbapi <EOL> from psycopg2 . extensions import UNICODE <EOL> from kalapy . db . engines . relational import RelationalDatabase , QueryBuilder <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> dbapi . extensions . register_type ( UNICODE ) <EOL> DatabaseError = dbapi . DatabaseError <EOL> IntegrityError = dbapi . IntegrityError <EOL> class Database ( RelationalDatabase ) : <EOL> data_types = { <EOL> "<STR_LIT:key>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:text>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:float>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> def __init__ ( self , name , host = None , port = None , user = None , password = None ) : <EOL> super ( Database , self ) . __init__ ( name , host , port , user , password ) <EOL> self . connection = None <EOL> def connect ( self ) : <EOL> if self . connection is not None : <EOL> return self <EOL> conn_string = '<STR_LIT>' % self . name <EOL> if self . user : <EOL> conn_string = '<STR_LIT>' % ( conn_string , self . user ) <EOL> if self . password : <EOL> conn_string = '<STR_LIT>' % ( conn_string , self . password ) <EOL> if self . host : <EOL> conn_string = '<STR_LIT>' % ( conn_string , self . host ) <EOL> if self . port : <EOL> conn_string = '<STR_LIT>' % ( conn_string , self . port ) <EOL> self . connection = dbapi . connect ( conn_string ) <EOL> self . connection . set_isolation_level ( <NUM_LIT:1> ) <EOL> return self <EOL> def exists_table ( self , model ) : <EOL> cursor = self . cursor ( ) <EOL> cursor . execute ( """<STR_LIT>""" , ( model . _meta . table , ) ) <EOL> return bool ( cursor . fetchone ( ) ) <EOL> def lastrowid ( self , cursor , model ) : <EOL> cursor . execute ( '<STR_LIT>' % model . _meta . table ) <EOL> return cursor . fetchone ( ) [ <NUM_LIT:0> ] <EOL> def query_builder ( self , qset ) : <EOL> return QueryBuilder ( qset ) <EOL> class QueryBuilder ( QueryBuilder ) : <EOL> def handle_like ( self , name , value ) : <EOL> return '<STR_LIT>' % ( name ) </s>
