Commit Graph

61 Commits

Author SHA1 Message Date
Tom Lane 7f380c59f8 Reduce size of backend scanner's tables.
Previously, the core scanner's yy_transition[] array had 37045 elements.
Since that number is larger than INT16_MAX, Flex generated the array to
contain 32-bit integers.  By reimplementing some of the bulkier scanner
rules, this patch reduces the array to 20495 elements.  The much smaller
total length, combined with the consequent use of 16-bit integers for
the array elements reduces the binary size by over 200kB.  This was
accomplished in two ways:

1. Consolidate handling of quote continuations into a new start condition,
rather than duplicating that logic for five different string types.

2. Treat Unicode strings and identifiers followed by a UESCAPE sequence
as three separate tokens, rather than one.  The logic to de-escape
Unicode strings is moved to the filter code in parser.c, which already
had the ability to provide special processing for token sequences.
While we could have implemented the conversion in the grammar, that
approach was rejected for performance and maintainability reasons.

Performance in microbenchmarks of raw parsing seems equal or slightly
faster in most cases, and it's reasonable to expect that in real-world
usage (with more competition for the CPU cache) there will be a larger
win.  The exception is UESCAPE sequences; lexing those is about 10%
slower, primarily because the scanner now has to be called three times
rather than one.  This seems acceptable since that feature is very
rarely used.

The psql and epcg lexers are likewise modified, primarily because we
want to keep them all in sync.  Since those lexers don't use the
space-hogging -CF option, the space savings is much less, but it's
still good for perhaps 10kB apiece.

While at it, merge the ecpg lexer's handling of C-style comments used
in SQL and in C.  Those have different rules regarding nested comments,
but since we already have the ability to keep track of the previous
start condition, we can use that to handle both cases within a single
start condition.  This matches the core scanner more closely.

John Naylor

Discussion: https://postgr.es/m/CACPNZCvaoa3EgVWm5yZhcSTX6RAtaLgniCPcBVOCwm8h3xpWkw@mail.gmail.com
2020-01-13 15:04:31 -05:00
Peter Eisentraut effa40281b Remove HAVE_LONG_LONG_INT
The presence of long long int is now implied in the requirement for
C99 and the configure check for the same.

We keep the define hard-coded in ecpg_config.h for backward
compatibility with ecpg-using user code.

Discussion: https://www.postgresql.org/message-id/flat/5cdd6a2b-b2c7-c6f6-344c-a406d5c1a254%402ndquadrant.com
2019-11-07 13:30:04 +01:00
Tom Lane 96b6c82c9d Revert "Add DECLARE STATEMENT support to ECPG."
This reverts commit bd7c95f0c1,
along with assorted follow-on fixes.  There are some questions
about the definition and implementation of that statement, and
we don't have time to resolve them before v13 release.  Rather
than ship the feature and then have backwards-compatibility
concerns constraining any redesign, let's remove it for now
and try again later.

Discussion: https://postgr.es/m/TY2PR01MB2443EC8286995378AEB7D9F8F5B10@TY2PR01MB2443.jpnprd01.prod.outlook.com
2019-09-20 12:47:37 -04:00
Peter Eisentraut c5bc7050af Message style fixes 2019-09-06 22:54:02 +02:00
Peter Eisentraut d5ab9df777 Remove unnecessary casts from size_t to int
We can use the %zu format specifier directly, no need to cast to int.
2019-07-04 17:02:13 +02:00
Michael Meskes e81f0e3113 Sync ECPG's CREATE TABLE AS statement with backend's.
Author: Higuchi-san ("Higuchi, Daisuke" <higuchi.daisuke@jp.fujitsu.com>)
2019-02-18 11:57:34 +01:00
Michael Meskes 050710b369 Add bytea datatype to ECPG.
So far ECPG programs had to treat binary data for bytea column as 'char' type.
But this meant converting from/to escaped format with PQunescapeBytea/
PQescapeBytea() and therefore forcing users to add unnecessary code and cost
for the conversion in runtime. By adding a dedicated datatype for bytea most of
this special handling is no longer needed.

Author: Matsumura-san ("Matsumura, Ryo" <matsumura.ryo@jp.fujitsu.com>)

Discussion: https://postgr.es/m/flat/03040DFF97E6E54E88D3BFEE5F5480F737A141F9@G01JPEXMBYT04
2019-02-18 10:20:31 +01:00
Michael Meskes bd7c95f0c1 Add DECLARE STATEMENT support to ECPG.
DECLARE STATEMENT is a statement that lets users declare an identifier
pointing at a connection.  This identifier will be used in other embedded
dynamic SQL statement such as PREPARE, EXECUTE, DECLARE CURSOR and so on.
When connecting to a non-default connection, the AT clause can be used in
a DECLARE STATEMENT once and is no longer needed in every dynamic SQL
statement.  This makes ECPG applications easier and more efficient.  Moreover,
writing code without designating connection explicitly improves portability.

Authors: Ideriha-san ("Ideriha, Takeshi" <ideriha.takeshi@jp.fujitsu.com>)
         Kuroda-san ("Kuroda, Hayato" <kuroda.hayato@jp.fujitsu.com>)

Discussion: https://postgr.es/m4E72940DA2BF16479384A86D54D0988A565669DF@G01JPEXMBKW04
2019-02-16 11:05:54 +01:00
Michael Meskes 7ea38f045d Change error handling of out of scope variables in ecpg.
The function called can result in an out of memory error that subsequently was
disregarded. Instead it should set the appropriate SQL error variables and be
checked by whatever whenever statement is defined.
2019-01-30 14:35:52 +01:00
Peter Eisentraut e4128ee767 SQL procedures
This adds a new object type "procedure" that is similar to a function
but does not have a return type and is invoked by the new CALL statement
instead of SELECT or similar.  This implementation is aligned with the
SQL standard and compatible with or similar to other SQL implementations.

This commit adds new commands CALL, CREATE/ALTER/DROP PROCEDURE, as well
as ALTER/DROP ROUTINE that can refer to either a function or a
procedure (or an aggregate function, as an extension to SQL).  There is
also support for procedures in various utility commands such as COMMENT
and GRANT, as well as support in pg_dump and psql.  Support for defining
procedures is available in all the languages supplied by the core
distribution.

While this commit is mainly syntax sugar around existing functionality,
future features will rely on having procedures as a separate object
type.

Reviewed-by: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>
2017-11-30 11:03:20 -05:00
Michael Meskes d22e9d5305 Implement DO CONTINUE action for ECPG WHENEVER statement.
Author: Vinayak Pokale
Reviewed-By: Masahiko Sawada
2017-08-25 15:17:29 +02:00
Michael Meskes ea0ca75d5d Changed ecpg parser to allow RETURNING clauses without attached C variables. 2017-08-14 11:29:34 +02:00
Heikki Linnakangas 181bdb90ba Fix typos in comments.
Backpatch to all supported versions, where applicable, to make backpatching
of future fixes go more smoothly.

Josh Soref

Discussion: https://www.postgresql.org/message-id/CACZqfqCf+5qRztLPgmmosr-B0Ye4srWzzw_mo4c_8_B_mtjmJQ@mail.gmail.com
2017-02-06 11:33:58 +02:00
Tom Lane 92fb649837 Use "%option prefix" to set API names in ecpg's lexer.
Clean up some technical debt left behind by commit 72b1e3a21: instead of
quickly hacking the name of base_yylex() with a #define, set it properly
with "%option prefix".  This causes the names of pgc.l's other exported
symbols to change as well, so run around and modify the outside references
to them as needed.  Similarly, make pgc.l's external references to
base_yylval use that variable's true name instead of a macro.

The reason for doing this now is that the quick-hack solution will fail
with future versions of flex, as reported by Дилян Палаузов.
Hence, back-patch into 9.6 where the previous commit appeared, since
it's likely people will build 9.6 with newer flex versions during
its lifetime.

Discussion: https://postgr.es/m/d845c1af-e18d-6651-178f-9f08cdf37e10@aegee.org
2016-12-11 14:54:25 -05:00
Tom Lane 72b1e3a21f Build backend/parser/scan.l and interfaces/ecpg/preproc/pgc.l standalone.
Now that we know about the %top{} trick, we can revert to building flex
lexers as separate .o files.  This is worth doing for a couple of reasons
besides sheer cleanliness.  We can narrow the scope of the -Wno-error flag
that's forced on scan.c.  Also, since these grammar and lexer files are
so large, splitting them into separate build targets should have some
advantages in build speed, particularly in parallel or ccache'd builds.

We have quite a few other .l files that could be changed likewise, but the
above arguments don't apply to them, so the benefit of fixing them seems
pretty minimal.  Leave the rest for some other day.
2016-03-19 12:07:24 -04:00
Michael Meskes d07fea542f Fix order of arguments in ecpg generated typedef command. 2015-10-16 17:29:05 +02:00
Peter Eisentraut cac7658205 Add transforms feature
This provides a mechanism for specifying conversions between SQL data
types and procedural languages.  As examples, there are transforms
for hstore and ltree for PL/Perl and PL/Python.

reviews by Pavel Stěhule and Andres Freund
2015-04-26 10:33:14 -04:00
Peter Eisentraut e12d7320ca Fix spurious tab character 2014-05-21 08:00:39 -04:00
Michael Meskes 51867a0f9b ECPG: Fix searching for quoted cursor names case-sensitively.
Patch by Böszörményi Zoltán <zb@cybertec.at>
2013-11-27 11:02:13 +01:00
Michael Meskes b46fa32100 ECPG: Make the preprocessor emit ';' if the variable type for a list of
variables is varchar. This fixes this test case:

int main(void)
{
    exec sql begin declare section;
    varchar a[50], b[50];
    exec sql end declare section;

    return 0;
}

Since varchars are internally turned into custom structs and
the type name is emitted for these variable declarations,
the preprocessed code previously had:

struct varchar_1  { ... }  a _,_  struct varchar_2  { ... }  b ;

The comma in the generated C file was a syntax error.

There are no regression test changes since it's not exercised.

Patch by Boszormenyi Zoltan <zb@cybertec.at>
2013-11-26 17:42:32 +01:00
Michael Meskes ef8b3b00b5 Fix ecpg parsing of sizeof().
The last fix used the wrong non-terminal to define valid types.
2013-11-25 15:11:39 +01:00
Michael Meskes 08d1b22b3b Allow C array definitions to use sizeof().
When parsing C variable definitions ecpg should allow sizeof() operators as array dimensions.
2013-11-24 12:51:21 +01:00
Peter Eisentraut b21de4e7b3 ecpg: Split off mmfatal() from mmerror()
This allows decorating mmfatal() with noreturn compiler hints, leading
to better diagnostics.
2013-11-19 21:56:54 -05:00
Peter Eisentraut 14a85031b1 ecpg: Consistently use mm_strdup()
mm_strdup() is provided to check errors from strdup(), but some places
were failing to use it.
2013-06-29 22:14:56 -04:00
Robert Haas 5d4b60f2f2 Lots of doc corrections.
Josh Kupershmidt
2012-04-23 22:43:09 -04:00
Michael Meskes 9a4880a0dd Do not use the variable name when defining a varchar structure in ecpg.
With a unique counter being added anyway, there is no need anymore to have the variable name listed, too.
2012-02-13 15:49:50 +01:00
Peter Eisentraut 654e1f96b0 Clean up whitespace and indentation in parser and scanner files
These are not touched by pgindent, so clean them up a bit manually.
2011-11-01 21:51:30 +02:00
Peter Eisentraut 030a2831a8 Move parse2.pl to parse.pl
We have a SCM, so we don't need to keep old versions of files around.
2011-06-14 07:34:00 +03:00
Michael Meskes 32fce70564 Added new version of ecpg's parser generator script. This one was written by
Andy Colson <andy@squeakycode.net>.
2011-03-03 13:43:50 +01:00
Michael Meskes 1066dbfb85 There is no need to have to identical functions in ecpg thus removing one of them. 2011-01-09 12:47:43 +01:00
Michael Meskes 833a2b57bc In ecpg's parser removed a fixed length limit for constants defining an array dimension. 2011-01-08 23:04:50 +01:00
Peter Eisentraut fc946c39ae Remove useless whitespace at end of lines 2010-11-23 22:34:55 +02:00
Michael Meskes 35d5d962e1 Some cleanup in ecpg code:
Use bool as type for booleans instead of int.
Do not implicitely cast size_t to int.
Make the compiler stop complaining about unused variables by adding an empty statement.
2010-11-02 18:12:01 +01:00
Magnus Hagander 9f2e211386 Remove cvs keywords from all files. 2010-09-20 22:08:53 +02:00
Michael Meskes 81624db39a Cursor names in the backend are not case-sensitve. This change makes sure that
ecpg also does not regard cursor names as case-sensitive.

Thanks to Zoltan Boszormenyi for the patch.
2010-09-10 10:13:20 +00:00
Michael Meskes 29259531c7 Replace self written 'long long int' configure test by standard 'AC_TYPE_LONG_LONG_INT' macro call. 2010-05-25 17:28:20 +00:00
Michael Meskes 15ab0e9a60 Ecpg now accepts "long long" datatypes even if "long" is 64bit wide. This used to cover the equally long "long long" type. This patch closes bug #5464. 2010-05-20 22:10:46 +00:00
Michael Meskes e01c6ce712 Give a more precise error message if a variable is re-used as cursor name in ecpg. 2010-03-31 08:45:18 +00:00
Michael Meskes b4d298ac23 ECPG's parser now accepts and handles variables as arguments for the FREE command.
Informix allows variables as argument to the embedded SQL command FREE. Given
that we only allow freeing cursors via FREE for compatibility reasons only we
should do the same.
2010-03-21 11:56:45 +00:00
Michael Meskes 1dff2a0f25 Fixed ecpg parser to allow more than one C preprocessor command inside a declare section. 2010-03-20 18:53:00 +00:00
Michael Meskes 600be01e89 ecpg now adds a unique counter to its varchar struct definitions to make these definitions unique, too. It used to use the linenumber but in the rare case of two definitions in one line this was not unique. 2010-03-09 11:09:46 +00:00
Michael Meskes 83fa037b73 Changed ECPG outofscope handling to always print out statements in the same order
so regression testing is possible,

by Zoltan Boszormenyi
2010-01-29 16:28:13 +00:00
Michael Meskes aa6ac35221 Applied patch by Boszormenyi Zoltan <zb@cybertec.at> to add out-of-scope cursor support to native mode. 2010-01-26 09:07:32 +00:00
Michael Meskes bf69b535c0 Applied patch by Boszormenyi Zoltan <zb@cybertec.at> to add DESCRIBE [OUTPUT] statement to ecpg. 2010-01-15 10:44:39 +00:00
Michael Meskes 6d4a351fcb Applied patch by Boszormenyi Zoltan <zb@cybertec.at> to add sqlda support to
ecpg in both native and compatiblity mode.
2010-01-05 16:38:23 +00:00
Michael Meskes a160c421a5 Added dynamic cursor names to ecpg. Almost the whole patch was done by
Boszormenyi Zoltan, with only a minor tweak or two from me.
2009-11-26 15:06:47 +00:00
Tom Lane e6c63bf660 Refactor ecpg grammar so that it uses the core grammar's unreserved_keyword
list, minus a few specific words that have to be treated specially.  This
replaces a hard-wired list of keywords that would have needed manual
maintenance, and was not getting it.  The 8.4 coding was already missing
these words, causing ecpg to incorrectly treat them as reserved words:
CALLED, CATALOG, DEFINER, ENUM, FOLLOWING, INVOKER, OPTIONS, PARTITION,
PRECEDING, RANGE, SECURITY, SERVER, UNBOUNDED, WRAPPER.  In HEAD we were
additionally missing COMMENTS, FUNCTIONS, SEQUENCES, TABLES.
Per gripe from Bosco Rama.
2009-11-21 05:44:05 +00:00
Alvaro Herrera e9984c47e9 Change "name" nonterminal in cursor-related productions to cursor_name.
This is a preparatory patch for allowing a dynamic cursor name be used in the
ECPG grammar.

Author: Zoltan Boszormenyi
2009-11-11 20:31:26 +00:00
Tom Lane 593f4b854a Don't treat NEW and OLD as reserved words anymore. For the purposes of rules
it works just as well to have them be ordinary identifiers, and this gets rid
of a number of ugly special cases.  Plus we aren't interfering with non-rule
usage of these names.

catversion bump because the names change internally in stored rules.
2009-11-05 23:24:27 +00:00
Tom Lane 9048b73184 Implement the DO statement to support execution of PL code without having
to create a function for it.

Procedural languages now have an additional entry point, namely a function
to execute an inline code block.  This seemed a better design than trying
to hide the transient-ness of the code from the PL.  As of this patch, only
plpgsql has an inline handler, but probably people will soon write handlers
for the other standard PLs.

In passing, remove the long-dead LANCOMPILER option of CREATE LANGUAGE.

Petr Jelinek
2009-09-22 23:43:43 +00:00