From d33fd8b8089607e7c22e2ae2fe096be50d8bfc03 Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Tue, 29 Aug 2023 23:20:01 +0200 Subject: [PATCH 1/6] Remove duplicate options --- setup.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/setup.py b/setup.py index 89e07f9..e4025ed 100755 --- a/setup.py +++ b/setup.py @@ -107,8 +107,6 @@ class build_pg_ext(build_ext): ('strict', None, "count all compiler warnings as errors"), ('direct-access', None, "enable direct access functions"), ('no-direct-access', None, "disable direct access functions"), - ('direct-access', None, "enable direct access functions"), - ('no-direct-access', None, "disable direct access functions"), ('large-objects', None, "enable large object support"), ('no-large-objects', None, "disable large object support"), ('default-vars', None, "enable default variables use"), From 828417d4c7fe6108ca357da497f672f233aa5cac Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Wed, 30 Aug 2023 00:41:55 +0200 Subject: [PATCH 2/6] Remove trailing space from error message --- pgdb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgdb.py b/pgdb.py index d2d06f4..d9b7aab 100644 --- a/pgdb.py +++ b/pgdb.py @@ -1142,7 +1142,7 @@ def executemany(self, operation, seq_of_parameters): except Error as err: # noinspection PyTypeChecker raise _db_error( - "Error in '%s': '%s' " % (sql, err), InterfaceError) + "Error in '%s': '%s'" % (sql, err), InterfaceError) except Exception as err: raise _op_error("Internal error in '%s': %s" % (sql, err)) # then initialize result raw count and description From 607ee83a1da2590de05d2c9d5f876ac390fc21b3 Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Sun, 3 Sep 2023 10:24:14 +0200 Subject: [PATCH 3/6] Fix typo --- pg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pg.py b/pg.py index 181892a..3db2e04 100644 --- a/pg.py +++ b/pg.py @@ -1970,7 +1970,7 @@ def set_parameter(self, parameter, value=None, local=False): if param == 'all': if value is not None: raise ValueError( - 'A value must ot be specified' + 'A value must not be specified' " when parameter is 'all'") params = {'all': None} break From 62594ff589d61e6777bbb34ba8155659df25b242 Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Sun, 3 Sep 2023 10:26:09 +0200 Subject: [PATCH 4/6] Remove unused regexps --- pg.py | 3 --- pgdb.py | 17 ++++++++--------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/pg.py b/pg.py index 3db2e04..7217701 100644 --- a/pg.py +++ b/pg.py @@ -1359,9 +1359,6 @@ def typecast(self, value, typ): return cast(value) -_re_fieldname = regex('^[A-Za-z][_a-zA-Z0-9]*$') - - # The result rows for database operations are returned as named tuples # by default. Since creating namedtuple classes is a somewhat expensive # operation, we cache up to 1024 of these classes by default. diff --git a/pgdb.py b/pgdb.py index d9b7aab..07b7f73 100644 --- a/pgdb.py +++ b/pgdb.py @@ -64,7 +64,7 @@ connection.close() # close the connection """ -from __future__ import print_function, division +from __future__ import division, print_function try: from _pg import * @@ -116,19 +116,22 @@ 'get_typecast', 'set_typecast', 'reset_typecast', 'version', '__version__'] -from datetime import date, time, datetime, timedelta, tzinfo -from time import localtime +from datetime import date, datetime, time, timedelta, tzinfo from decimal import Decimal as StdDecimal +from math import isinf, isnan +from time import localtime from uuid import UUID as Uuid -from math import isnan, isinf + try: # noinspection PyCompatibility from collections.abc import Iterable except ImportError: # Python < 3.3 from collections import Iterable + from collections import namedtuple from functools import partial +from json import dumps as jsonencode +from json import loads as jsondecode from re import compile as regex -from json import loads as jsondecode, dumps as jsonencode Decimal = StdDecimal @@ -900,10 +903,6 @@ def _op_error(msg): # *** Row Tuples *** - -_re_fieldname = regex('^[A-Za-z][_a-zA-Z0-9]*$') - - # The result rows for database operations are returned as named tuples # by default. Since creating namedtuple classes is a somewhat expensive # operation, we cache up to 1024 of these classes by default. From 4222457a297ad4b214997c41c7abc93c9adaa88a Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Sun, 3 Sep 2023 11:16:25 +0200 Subject: [PATCH 5/6] Quote parameter in docstring --- pg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pg.py b/pg.py index 7217701..92f247c 100644 --- a/pg.py +++ b/pg.py @@ -2634,7 +2634,7 @@ def truncate(self, table, restart=False, cascade=False, only=False): If restart is set to True, sequences owned by columns of the truncated table(s) are automatically restarted. If cascade is set to True, it also truncates all tables that have foreign-key references to any of - the named tables. If the parameter only is not set to True, all the + the named tables. If the parameter 'only' is not set to True, all the descendant tables (if any) will also be truncated. Optionally, a '*' can be specified after the table name to explicitly indicate that descendant tables are included. From 50c8e42e095a17645c3b6f4495980a968831e4f3 Mon Sep 17 00:00:00 2001 From: Christoph Zwerschke Date: Sun, 3 Sep 2023 11:21:19 +0200 Subject: [PATCH 6/6] Improve docstring --- pg.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pg.py b/pg.py index 92f247c..a785739 100644 --- a/pg.py +++ b/pg.py @@ -2691,16 +2691,18 @@ def get_as_list(self, table, what=None, where=None, The parameter 'what' can restrict the query to only return a subset of the table columns. It can be a string, list or a tuple. + The parameter 'where' can restrict the query to only return a subset of the table rows. It can be a string, list or a tuple - of SQL expressions that all need to be fulfilled. The parameter - 'order' specifies the ordering of the rows. It can also be a - other string, list or a tuple. If no ordering is specified, - the result will be ordered by the primary key(s) or all columns - if no primary key exists. You can set 'order' to False if you - don't care about the ordering. The parameters 'limit' and 'offset' - can be integers specifying the maximum number of rows returned - and a number of rows skipped over. + of SQL expressions that all need to be fulfilled. + + The parameter 'order' specifies the ordering of the rows. It can + also be a string, list or a tuple. If no ordering is specified, + the result will be ordered by the primary key(s) or all columns if + no primary key exists. You can set 'order' to False if you don't + care about the ordering. The parameters 'limit' and 'offset' can be + integers specifying the maximum number of rows returned and a number + of rows skipped over. If you set the 'scalar' option to True, then instead of the named tuples you will get the first items of these tuples.