diff --git a/docs/conf.py b/docs/conf.py index ee15e15..11a0a60 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -47,7 +47,7 @@ # General information about the project. project = 'pglast' -copyright = '2017-2023 Lele Gaifax' +copyright = '2017-2024 Lele Gaifax' author = 'Lele Gaifax' # The version info for the project you're documenting, acts as replacement for diff --git a/docs/parsenodes.rst b/docs/parsenodes.rst index 6375613..988bfc7 100644 --- a/docs/parsenodes.rst +++ b/docs/parsenodes.rst @@ -974,7 +974,3 @@ __ https://github.com/pganalyze/libpg_query/blob/1ec3894/src/postgres/include/no .. data:: CURSOR_OPT_PARALLEL_OK See `here for details `__. - -.. data:: FETCH_ALL - - See `here for details `__. diff --git a/pglast/enums/parsenodes.py b/pglast/enums/parsenodes.py index 91f82f6..e9484a9 100644 --- a/pglast/enums/parsenodes.py +++ b/pglast/enums/parsenodes.py @@ -480,5 +480,3 @@ class WCOKind(IntEnum): CURSOR_OPT_CUSTOM_PLAN = 0x0400 CURSOR_OPT_PARALLEL_OK = 0x0800 - -FETCH_ALL = 9223372036854775807 diff --git a/pglast/printers/dml.py b/pglast/printers/dml.py index 18d4af9..2c3bdfa 100644 --- a/pglast/printers/dml.py +++ b/pglast/printers/dml.py @@ -3,10 +3,11 @@ # :Created: sab 05 ago 2017 16:34:08 CEST # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lele Gaifax +# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Lele Gaifax # from .. import ast, enums +from ..parser import LONG_MAX from . import IntEnumPrinter, get_string_value, node_printer @@ -638,29 +639,29 @@ class FetchDirectionPrinter(IntEnumPrinter): enum = enums.FetchDirection def FETCH_FORWARD(self, node, output): - if node.howMany == enums.FETCH_ALL: - output.write('ALL ') - elif node.howMany != 1: - output.write(f'FORWARD {node.howMany} ') + if node.howMany == 1: + output.write('NEXT') + else: + output.write('FORWARD') + output.swrite('ALL' if node.howMany == LONG_MAX else str(node.howMany)) def FETCH_BACKWARD(self, node, output): - if node.howMany == enums.FETCH_ALL: - output.write('BACKWARD ALL ') - elif node.howMany != 1: - output.write(f'BACKWARD {node.howMany} ') + if node.howMany == 1: + output.write('PRIOR') else: - output.write('PRIOR ') + output.write('BACKWARD') + output.swrite('ALL' if node.howMany == LONG_MAX else str(node.howMany)) def FETCH_ABSOLUTE(self, node, output): if node.howMany == 1: - output.write('FIRST ') + output.write('FIRST') elif node.howMany == -1: - output.write('LAST ') + output.write('LAST') else: - output.write(f'ABSOLUTE {node.howMany} ') + output.write(f'ABSOLUTE {node.howMany}') def FETCH_RELATIVE(self, node, output): - output.write(f'RELATIVE {node.howMany} ') + output.write(f'RELATIVE {node.howMany}') fetch_direction_printer = FetchDirectionPrinter() @@ -670,6 +671,7 @@ def FETCH_RELATIVE(self, node, output): def fetch_stmt(node, output): output.write('MOVE ' if node.ismove else 'FETCH ') fetch_direction_printer(node.direction, node, output) + output.write(' IN ' if node.ismove else ' FROM ') output.print_name(node.portalname) diff --git a/tests/test_printers_prettification/dml/fetch.sql b/tests/test_printers_prettification/dml/fetch.sql new file mode 100644 index 0000000..3d3ee3a --- /dev/null +++ b/tests/test_printers_prettification/dml/fetch.sql @@ -0,0 +1,35 @@ +fetch all foo += +FETCH FORWARD ALL FROM foo + +fetch next in foo += +FETCH NEXT FROM foo + +fetch forward 1 from foo += +FETCH NEXT FROM foo + +fetch 1 from foo += +FETCH NEXT FROM foo + +fetch backward 1 from foo += +FETCH PRIOR FROM foo + +fetch prior in foo += +FETCH PRIOR FROM foo + +fetch absolute 1 foo += +FETCH FIRST FROM foo + +fetch absolute -1 foo += +FETCH LAST FROM foo + +fetch absolute 42 foo += +FETCH ABSOLUTE 42 FROM foo diff --git a/tests/test_printers_prettification/dml/move.sql b/tests/test_printers_prettification/dml/move.sql new file mode 100644 index 0000000..3034c7b --- /dev/null +++ b/tests/test_printers_prettification/dml/move.sql @@ -0,0 +1,35 @@ +move all foo += +MOVE FORWARD ALL IN foo + +move next in foo += +MOVE NEXT IN foo + +move forward 1 from foo += +MOVE NEXT IN foo + +move 1 from foo += +MOVE NEXT IN foo + +move backward 1 from foo += +MOVE PRIOR IN foo + +move prior in foo += +MOVE PRIOR IN foo + +move absolute 1 foo += +MOVE FIRST IN foo + +move absolute -1 foo += +MOVE LAST IN foo + +move absolute 42 foo += +MOVE ABSOLUTE 42 IN foo diff --git a/tools/extract_enums.py b/tools/extract_enums.py index 72eef39..32614f7 100644 --- a/tools/extract_enums.py +++ b/tools/extract_enums.py @@ -3,7 +3,7 @@ # :Created: gio 03 ago 2017 14:54:39 CEST # :Author: Lele Gaifax # :License: GNU General Public License version 3 or later -# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 2023 Lele Gaifax +# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024 Lele Gaifax # from datetime import date @@ -13,12 +13,6 @@ from pycparser import c_ast, c_parser -try: - from pglast.parser import LONG_MAX -except ModuleNotFoundError: - # bootstrap - from sys import maxsize as LONG_MAX - CYEARS = f'2017-{date.today().year}' @@ -147,10 +141,6 @@ def extract_defines(source): line) if m is not None: yield m.group(1), m.group(2) - else: - m = match(r"#define\s+([a-zA-Z_]+)\s+LONG_MAX", line) - if m is not None: - yield m.group(1), LONG_MAX def emit_constant(value): @@ -221,7 +211,7 @@ def write_enum_doc(name, enum, output, toc, url, mod_name): if name in toc: output.write('\n Corresponds to the `%s enum <%s#L%d>`__.\n' % (name, url, toc[name])) - for index, item in enumerate(enum.values.enumerators): + for item in enum.values.enumerators: output.write('\n .. data:: %s\n' % item.name)