#NEWLINE# def connect( self ) : #NEWLINE# #INDENT# "Connect to the database\n\n        If we're not already connected we first connect to the admin\n        database and see if the given database exists.  If it doesn't,\n        we create and then connect to it.\n        " #NEWLINE# if ( not conn . conn ) : #NEWLINE# #INDENT# conn = pgconnect ( ADMIN_DB , self . user , self . host , self . port ) #NEWLINE# curs = pgexecute ( conn , ( "SELECT 1 FROM pg_database WHERE datname = '%s'" % self . name ) ) #NEWLINE# row = curs . fetchone ( ) #NEWLINE# if ( not row ) : #NEWLINE# #INDENT# curs . close ( ) #NEWLINE# curs = pgexecute_auto ( conn , ( CREATE_DDL % self . name ) ) #NEWLINE# curs . close ( ) #NEWLINE# #UNINDENT# conn . close ( ) #NEWLINE# self . conn = pgconnect ( self . name , self . user , self . host , self . port ) #NEWLINE# curs = pgexecute ( self . conn , 'SHOW server_version_num' ) #NEWLINE# self . _version = int ( curs . fetchone ( ) [ 0 ] )