From 9711e9c064475af3f37e34786cf0529c7fdc331f Mon Sep 17 00:00:00 2001 From: Nikolay Novik Date: Sat, 28 Oct 2023 14:36:42 -0400 Subject: [PATCH] Implement setinputsizes. (#453) --- CHANGES.txt | 8 ++++++++ aioodbc/cursor.py | 18 +++++++++++++++--- tests/test_cursor.py | 6 +++++- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index d5050f9..05c8daa 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,13 @@ Changes ------- +0.4.1 (2023-10-28) +^^^^^^^^^^^^^^^^^^ +* Implemented cursor setinputsizes. +* Implemented cursor fetchval. +* Added more type annotations. +* Added autocommit setter for cusror. + + 0.4.0 (2023-03-16) ^^^^^^^^^^^^^^^^^^ * Fixed compatibility with python 3.9+. diff --git a/aioodbc/cursor.py b/aioodbc/cursor.py index 9ab82b9..52c5881 100644 --- a/aioodbc/cursor.py +++ b/aioodbc/cursor.py @@ -145,9 +145,21 @@ def executemany(self, sql, *params): def callproc(self, procname, args=()): raise NotImplementedError - async def setinputsizes(self, *args, **kwargs): - """Does nothing, required by DB API.""" - return None + async def setinputsizes(self, sizes=None) -> None: + """Explicitly declare the types and sizes of the parameters in a query. + Set to None to clear any previously registered input sizes. + + :param sizes: A list of tuples, one tuple for each query parameter, + where each tuple contains: + 1. the column datatype + 2. the column size (char length or decimal precision) + 3. the decimal scale. + + For example: + [(pyodbc.SQL_WVARCHAR, 50, 0), (pyodbc.SQL_DECIMAL, 18, 4)] + """ + # sizes: Optional[Iterable[Tuple[int, int, int]]] + await self._run_operation(self._impl.setinputsizes, sizes) async def setoutputsize(self, *args, **kwargs): """Does nothing, required by DB API.""" diff --git a/tests/test_cursor.py b/tests/test_cursor.py index 9e2535d..e653de7 100644 --- a/tests/test_cursor.py +++ b/tests/test_cursor.py @@ -56,7 +56,11 @@ async def test_cursor(conn): assert cur.arraysize == 1 assert cur.rowcount == -1 - r = await cur.setinputsizes() + r = await cur.setinputsizes( + [ + (pyodbc.SQL_WVARCHAR, 50, 0), + ] + ) assert r is None await cur.setoutputsize()