Skip to content

Commit

Permalink
Merge from v5
Browse files Browse the repository at this point in the history
  • Loading branch information
lelit committed Jan 10, 2024
2 parents 3abef0c + 4007f24 commit 19f92e3
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 33 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions docs/parsenodes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/pganalyze/libpg_query/blob/1ec3894/src/postgres/include/nodes/parsenodes.h#L3122>`__.

.. data:: FETCH_ALL

See `here for details <https://github.com/pganalyze/libpg_query/blob/1ec3894/src/postgres/include/nodes/parsenodes.h#L3157>`__.
2 changes: 0 additions & 2 deletions pglast/enums/parsenodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,5 +480,3 @@ class WCOKind(IntEnum):
CURSOR_OPT_CUSTOM_PLAN = 0x0400

CURSOR_OPT_PARALLEL_OK = 0x0800

FETCH_ALL = 9223372036854775807
30 changes: 16 additions & 14 deletions pglast/printers/dml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
# :Created: sab 05 ago 2017 16:34:08 CEST
# :Author: Lele Gaifax <lele@metapensiero.it>
# :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


Expand Down Expand Up @@ -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()
Expand All @@ -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)


Expand Down
35 changes: 35 additions & 0 deletions tests/test_printers_prettification/dml/fetch.sql
Original file line number Diff line number Diff line change
@@ -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
35 changes: 35 additions & 0 deletions tests/test_printers_prettification/dml/move.sql
Original file line number Diff line number Diff line change
@@ -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
14 changes: 2 additions & 12 deletions tools/extract_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# :Created: gio 03 ago 2017 14:54:39 CEST
# :Author: Lele Gaifax <lele@metapensiero.it>
# :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
Expand All @@ -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}'

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down

0 comments on commit 19f92e3

Please sign in to comment.