Re: problem with copy_expert on cursor

Поиск
Список
Период
Сортировка
От Daniele Varrazzo
Тема Re: problem with copy_expert on cursor
Дата
Msg-id AANLkTin_AUSkU80cah-2xM9LOrxe=6ihJQd1CR=UgCC6@mail.gmail.com
обсуждение исходный текст
Ответ на problem with copy_expert on cursor  ("Eric Snow" <esnow@verio.net>)
Список psycopg
On Wed, Mar 2, 2011 at 9:20 PM, Eric Snow <esnow@verio.net> wrote:
> What would cause the following error when I call copy_expert on a
> DictCursor?
>
>    SystemError: 'null argument to internal routine'
>
> The sql I pass in is the copy, in a string.  The file is a
> cStringIO.StringO object.  I am using a custom row factory on the
> DictCursor.  So there are a number of things that could be the source of
> the error.  However, I am not familiar enough with psycopg to dig this
> out.
>
> Incidently, the problem is actually when I am using skytools for
> replication, and not actually in any code I have written.  I am using
> psycopg2 2.3.2.  Thanks.

Hi Eric,

the description of the problem is not very clear, e.g. I've not
understood if the problem happened in a COPY FROM STDIN or in COPY TO
STDOUT. I've tried to reproduce the problem but without success, both
in 2.3.2 and in 2.4.0.

To try and reproduce the problem I've added the test below to
tests/test_copy.py. Can you modify the test until you are able to make
it crash?

In order to run the test suite, create a database called
"psycopg2_test". Then, from the psycopg directory, execute "make",
then "make check". If you need to specify host/username/password to
connect to the database, set the env variables PSYCOPG2_TESTDB_HOST
and so on.

Thank you.

-- Daniele

    def test_copy_strange_cursor(self):
        from psycopg2.extras import DictCursor
        f = StringIO()
        for i, c in enumerate(string.ascii_letters):
            f.write("%s\t%s\n" % (i, c))

        f.seek(0)

        curs = self.conn.cursor(cursor_factory=DictCursor)
        curs.copy_expert('COPY tcopy FROM STDIN', f)
        curs.close()

        curs = self.conn.cursor()
        curs.execute("select * from tcopy order by id;")
        self.assertEqual(curs.fetchall(),
            list(enumerate(string.ascii_letters)))

        f1 = StringIO()
        curs = self.conn.cursor(cursor_factory=DictCursor)
        curs.copy_expert('COPY tcopy TO STDOUT', f1)
        curs.close()

        f.seek(0)
        f1.seek(0)
        self.assertEqual(f1.read(), f.read())

В списке psycopg по дате отправления:

Предыдущее
От: "Eric Snow"
Дата:
Сообщение: Re: problem with copy_expert on cursor
Следующее
От: Daniele Varrazzo
Дата:
Сообщение: Re: problem with copy_expert on cursor