do_connect (sample/psql.rb)

    # File sample/psql.rb, line 455
    def do_connect(settings, new_dbname)
      dbname = settings.db.db

      if !new_dbname
        printf(STDERR, "\\connect must be followed by a database name\n");
      else
        olddb = settings.db

        begin
          printf("closing connection to database: %s\n", dbname);
          settings.db = PGconn.connect(olddb.host, olddb.port, "", "", new_dbname)
          printf("connecting to new database: %s\n", new_dbname)
          olddb.finish()
        rescue
          printf(STDERR, "%s\n", $!)
          printf("reconnecting to %s\n", dbname)
          settings.db = PGconn.connect(olddb.host, olddb.port,"", "", dbname)
        ensure
          settings.prompt = settings.db.db + PROMPT
        end
      end
    end