Skip to content

Add support for COPY IN #135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2017
Merged

Add support for COPY IN #135

merged 1 commit into from
May 11, 2017

Conversation

elprans
Copy link
Member

@elprans elprans commented May 10, 2017

This commit adds two new Connection methods: copy_to_table() and
copy_records_to_table() that allow copying data to the specified
table either in text or, in the latter case, record form.

Related-To #123.
Closes #21.

@elprans elprans requested a review from 1st1 May 10, 2017 21:28
@elprans elprans self-assigned this May 10, 2017
object mview
Py_buffer *pybuf

mview = PyMemoryView_GetContiguous(data, cpython.PyBUF_SIMPLE, b'C')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to close mview after you use it?

raise RuntimeError(
'no encoder for OID {}'.format(codec.oid))

while True:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this block can be simplified if we remove while True.

break

elif reader is not None:
iterator = reader.__aiter__()
Copy link
Member

@1st1 1st1 May 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try:
   aiter = reader.__aiter__
except AttributeError:
   raise TypeError('reader is not an asynchronous iterator')
else:
   iterator = aiter()

except asyncio.TimeoutError:
self._write_copy_fail_msg('TimeoutError')
self._on_timeout(self.waiter)
await waiter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of await waiter do this:

try:
  await waiter
except TimeoutError:
  raise
else:
  raise RuntimeError('TimoutError was not raised')

'invalid result waiter state on cancellation'))
else:
self.cancel_waiter.set_result(None)
self.cancel_waiter.set_result(None)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you intentionally remove that code? If so the comment above it needs to be adjusted.

raise RuntimeError('failure in source')

with self.assertRaisesRegexp(RuntimeError, 'failure in source'):
await self.con.copy_to_table('copytab', source=_Source())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add self.assertEqual(await self.con.fetchval('select 1'), 1) to all tests that test failures to make sure that the protocol is fully recovered?

@elprans elprans force-pushed the copy_in branch 3 times, most recently from b310291 to 445775c Compare May 11, 2017 14:53
This commit adds two new Connection methods: copy_to_table() and
copy_records_to_table() that allow copying data to the specified
table either in text or, in the latter case, record form.

Closes #123.
Closes #21.
@elprans elprans merged commit 10d95d4 into master May 11, 2017
@elprans elprans deleted the copy_in branch May 11, 2017 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants