Method: Sequel::JDBC::Postgres::DatabaseMethods#copy_table

Defined in:
lib/sequel/adapters/jdbc/postgresql.rb

#copy_table(table, opts = OPTS) ⇒ Object

See Sequel::Postgres::Adapter#copy_table

[View source]

75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/sequel/adapters/jdbc/postgresql.rb', line 75

def copy_table(table, opts=OPTS)
  synchronize(opts[:server]) do |conn|
    copy_manager = Java::OrgPostgresqlCopy::CopyManager.new(conn)
    copier = copy_manager.copy_out(copy_table_sql(table, opts))
    begin
      if defined?(yield)
        while buf = copier.readFromCopy
          yield(String.from_java_bytes(buf))
        end
        nil
      else
        b = String.new
        while buf = copier.readFromCopy
          b << String.from_java_bytes(buf)
        end
        b
      end
    rescue => e
      raise_error(e, :disconnect=>true)
    ensure
      if buf && !e
        raise DatabaseDisconnectError, "disconnecting as a partial COPY may leave the connection in an unusable state"
      end
    end
  end
end