From a2ca0b33a40433f9bd5bb4ff4e2741aa75038b15 Mon Sep 17 00:00:00 2001 From: Rob Terhaar Date: Wed, 1 Aug 2012 04:39:20 -0300 Subject: [PATCH] Update mysql2pgsql/lib/postgres_file_writer.py added a first_row variable, so that a newline is added to the front of each row, but not the first. This is required because the \. needs to be on the same line as the last line of the copy from stdin block of data when importing blobs. --- mysql2pgsql/lib/postgres_file_writer.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mysql2pgsql/lib/postgres_file_writer.py b/mysql2pgsql/lib/postgres_file_writer.py index e7d8563..c01ede0 100644 --- a/mysql2pgsql/lib/postgres_file_writer.py +++ b/mysql2pgsql/lib/postgres_file_writer.py @@ -115,6 +115,11 @@ def write_contents(self, table, reader): f_write = self.f.write verbose = self.verbose # end variable optimiztions + + # this is so the \. char after copy from stdin + # does not end on a empty line. + first_row = True + first_char = "" f_write(""" -- @@ -134,9 +139,14 @@ def write_contents(self, table, reader): row = list(row) pr(table, row) try: - f_write(u'%s\n' % (u'\t'.join(row))) + f_write(u'%s%s' % (first_char, u'\t'.join(row))) except UnicodeDecodeError: - f_write(u'%s\n' % (u'\t'.join(r.decode('utf-8') for r in row))) + f_write(u'%s%s' % (first_char, u'\t'.join(r.decode('utf-8') for r in row))) + + if first_row: + first_row = False + first_char = "\n" + if verbose: if (i % 20000) == 0: now = tt()