mysql2pgsql/lib/postgres_file_writer.py
def write_contents(self, table, reader):
        """Write the data contents of `table` to the output file.

        :Parameters:
          - `table`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader.Table` object that represents the table to read/write.
          - `reader`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader` object that allows reading from the data source.

        Returns None
        """
        # start variable optimiztions
        pr = self.process_row
        f_write = self.f.write
        verbose = self.verbose
        # end variable optimiztions

        f_write("""
--
-- Data for Name: %(table_name)s; Type: TABLE DATA;
--

COPY "%(table_name)s" (%(column_names)s) FROM stdin;
""" % {
                'table_name': table.name,
                'column_names': ', '.join(('"%s"' % col['name']) for col in table.columns)})
        if verbose:
            tt = time.time
            start_time = tt()
            prev_val_len = 0
            prev_row_count = 0
        for i, row in enumerate(reader.read(table), 1):
            row = list(row)
            pr(table, row)
            try:
                f_write(u'%s\n' % (u'\t'.join(row)))
            except UnicodeDecodeError:
                f_write(u'%s\n' % (u'\t'.join(r.decode('utf-8') for r in row)))
            if verbose:
                if (i % 20000) == 0:
                    now = tt()
                    elapsed = now - start_time
                    val = '%.2f rows/sec [%s] ' % ((i - prev_row_count) / elapsed, i)
                    print_row_progress('%s%s' % (("\b" * prev_val_len), val))
                    prev_val_len = len(val) + 3
                    start_time = now
                    prev_row_count = i

        f_write("\\.\n\n")
        if verbose:
            print('')
def write_contents(self, table, reader):
        """Write the data contents of `table` to the output file.

        :Parameters:
          - `table`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader.Table` object that represents the table to read/write.
          - `reader`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader` object that allows reading from the data source.

        Returns None
        """
        # start variable optimiztions
        pr = self.process_row
        f_write = self.f.write
        verbose = self.verbose
        # end variable optimiztions

        f_write("""
--
-- Data for Name: %(table_name)s; Type: TABLE DATA;
--

COPY "%(table_name)s" (%(column_names)s) FROM stdin;
""" % {
                'table_name': table.name,
                'column_names': ', '.join(('"%s"' % col['name']) for col in table.columns)})
        if verbose:
            tt = time.time
            start_time = tt()
            prev_val_len = 0
            prev_row_count = 0
        for i, row in enumerate(reader.read(table), 1):
            row = list(row)
            pr(table, row)
            try:
                f_write(u'%s\n' % (u'\t'.join(row)))
            except UnicodeDecodeError:
                f_write(u'%s\n' % (u'\t'.join(r.decode('utf-8') for r in row)))
            if verbose:
                if (i % 20000) == 0:
                    now = tt()
                    elapsed = now - start_time
                    val = '%.2f rows/sec [%s] ' % ((i - prev_row_count) / elapsed, i)
                    print_row_progress('%s%s' % (("\b" * prev_val_len), val))
                    prev_val_len = len(val) + 3
                    start_time = now
                    prev_row_count = i

        f_write("\\.\n\n")
        if verbose:
            print('')
Write the data contents of `table` to the output file.

        :Parameters:
          - `table`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader.Table` object that represents the table to read/write.
          - `reader`: an instance of a :py:class:`mysql2pgsql.lib.mysql_reader.MysqlReader` object that allows reading from the data source.

        Returns None