Skip to content

Commit 31bd3f2

Browse files
committed
sqltools: avoid copy_from, psycopg 2.9 broke it
1 parent d50ebd0 commit 31bd3f2

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

skytools/basetypes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ def fetchall(self) -> Sequence[DictRow]: raise NotImplementedError
3838
def fetchone(self) -> DictRow: raise NotImplementedError
3939
def __enter__(self) -> "Cursor": raise NotImplementedError
4040
def __exit__(self, typ: Type, value: Any, traceback: Any) -> Any: raise NotImplementedError
41-
def copy_from(self, buf: IO[str], hdr: str) -> None: raise NotImplementedError
42-
def copy_expert(self, sql: str, f: Union[IO[str], io.TextIOBase]) -> None: raise NotImplementedError
41+
def copy_expert(self, sql: str, f: Union[IO[str], io.TextIOBase], size: int = 8192) -> None: raise NotImplementedError
4342

4443

4544
class Connection(Protocol):

skytools/sqltools.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ def magic_insert(curs: Cursor, tablename: str,
341341
curs.execute(buf.getvalue())
342342
else:
343343
buf.seek(0)
344-
hdr = "%s (%s)" % (qtablename, ",".join(qfields))
345-
curs.copy_from(buf, hdr)
344+
sql = "COPY %s (%s) FROM STDIN" % (qtablename, ",".join(qfields))
345+
curs.copy_expert(sql, buf)
346346
return None
347347

348348

@@ -401,9 +401,10 @@ def flush(self) -> None:
401401

402402
self.buf.seek(0)
403403
if self.sql_from:
404-
self.dstcurs.copy_expert(self.sql_from, self.buf)
404+
sql = self.sql_from
405405
else:
406-
self.dstcurs.copy_from(self.buf, self.tablename or "missing_table_name")
406+
sql = "COPY %s FROM STDIN" % (self.tablename or "missing_table_name",)
407+
self.dstcurs.copy_expert(sql, self.buf)
407408
self.buf.seek(0)
408409
self.buf.truncate()
409410

0 commit comments

Comments
 (0)