-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In the PG headers FETCH_ALL is a synonym of LONG_MAX, and the latter value depends on the actual architecture so cannot be precomputed and hardcoded in the extracted enums. Given that it's used in a single place, instead of doing fancy gymnic to compute it lazily, take the straight path and directly use the LONG_MAX symbol exposed in the parser module, that correspond to its homonym C value. This fixes issue #142. While there, tweak the FetchStmt printer to emit slightly nicer representation.
Showing
6 changed files
with
89 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
.. :Project: pglast -- DO NOT EDIT: generated automatically | ||
.. :Author: Lele Gaifax <[email protected]> | ||
.. :License: GNU General Public License version 3 or later | ||
.. :Copyright: © 2017-2023 Lele Gaifax | ||
.. :Copyright: © 2017-2024 Lele Gaifax | ||
.. | ||
============================================================================== | ||
|
@@ -985,7 +985,3 @@ __ https://github.com/pganalyze/libpg_query/blob/db39825/src/postgres/include/no | |
.. data:: CURSOR_OPT_PARALLEL_OK | ||
|
||
See `here for details <https://github.com/pganalyze/libpg_query/blob/db39825/src/postgres/include/nodes/parsenodes.h#L2892>`__. | ||
|
||
.. data:: FETCH_ALL | ||
|
||
See `here for details <https://github.com/pganalyze/libpg_query/blob/db39825/src/postgres/include/nodes/parsenodes.h#L2927>`__. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
# :Project: pglast -- DO NOT EDIT: automatically extracted from parsenodes.h @ 15-4.2.4-0-gdb39825 | ||
# :Author: Lele Gaifax <[email protected]> | ||
# :License: GNU General Public License version 3 or later | ||
# :Copyright: © 2017-2023 Lele Gaifax | ||
# :Copyright: © 2017-2024 Lele Gaifax | ||
# | ||
|
||
from enum import Enum, IntEnum, IntFlag, auto | ||
|
@@ -486,5 +486,3 @@ class WCOKind(IntEnum): | |
CURSOR_OPT_CUSTOM_PLAN = 0x0400 | ||
|
||
CURSOR_OPT_PARALLEL_OK = 0x0800 | ||
|
||
FETCH_ALL = 9223372036854775807 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,11 @@ | |
# :Created: sab 05 ago 2017 16:34:08 CEST | ||
# :Author: Lele Gaifax <[email protected]> | ||
# :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 | ||
|
||
|
||
|
@@ -634,29 +635,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() | ||
|
@@ -666,6 +667,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) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# :Created: gio 03 ago 2017 14:54:39 CEST | ||
# :Author: Lele Gaifax <[email protected]> | ||
# :License: GNU General Public License version 3 or later | ||
# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022 Lele Gaifax | ||
# :Copyright: © 2017, 2018, 2019, 2020, 2021, 2022, 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 | ||
|
||
|
||
PY_HEADER = """\ | ||
# -*- coding: utf-8 -*- | ||
|
@@ -144,10 +138,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): | ||
|