From 153a3c02382d033e735910fd916eee54b5f5d129 Mon Sep 17 00:00:00 2001 From: qin86 Date: Mon, 13 Jun 2022 02:48:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=89=E5=B9=B3HW=20ecpg=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interfaces/ecpg/ecpglib/connect.cpp | 10 ++++---- .../interfaces/ecpg/ecpglib/descriptor.cpp | 4 ++-- src/common/interfaces/ecpg/ecpglib/misc.cpp | 12 +++++----- .../interfaces/ecpg/ecpglib/prepare.cpp | 4 ++-- src/common/interfaces/ecpg/preproc/Makefile | 8 ++++++- .../interfaces/ecpg/preproc/check_rules.pl | 7 ++++-- .../interfaces/ecpg/preproc/descriptor.cpp | 2 +- .../interfaces/ecpg/preproc/ecpg.trailer | 8 +++---- .../interfaces/ecpg/preproc/ecpg_keywords.cpp | 24 +++++++++++++++---- src/common/interfaces/ecpg/preproc/parse.pl | 14 ++--------- src/common/interfaces/ecpg/preproc/parser.cpp | 8 +++---- src/common/interfaces/ecpg/preproc/pgc.l | 10 ++++---- .../interfaces/ecpg/preproc/variable.cpp | 2 +- src/common/interfaces/ecpg/test/Makefile | 8 +------ .../interfaces/ecpg/test/connect/test1.pgc | 14 +++++------ .../interfaces/ecpg/test/connect/test5.pgc | 16 ++++++------- .../ecpg/test/expected/preproc-whenever.cpp | 2 +- .../interfaces/ecpg/test/preproc/whenever.pgc | 2 +- src/test/regress/pg_regress.cpp | 23 ++++++++++++++++-- 19 files changed, 103 insertions(+), 75 deletions(-) diff --git a/src/common/interfaces/ecpg/ecpglib/connect.cpp b/src/common/interfaces/ecpg/ecpglib/connect.cpp index f4acad7d8..b674b8343 100644 --- a/src/common/interfaces/ecpg/ecpglib/connect.cpp +++ b/src/common/interfaces/ecpg/ecpglib/connect.cpp @@ -11,12 +11,12 @@ #include "sqlca.h" #ifdef ENABLE_THREAD_SAFETY -static THR_LOCAL pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER; -static THR_LOCAL pthread_key_t actual_connection_key; -static THR_LOCAL pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT; +static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_key_t actual_connection_key; +static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT; #endif -static THR_LOCAL struct connection* actual_connection = NULL; -static THR_LOCAL struct connection* all_connections = NULL; +static struct connection* actual_connection = NULL; +static struct connection* all_connections = NULL; #ifdef ENABLE_THREAD_SAFETY static void ecpg_actual_connection_init(void) diff --git a/src/common/interfaces/ecpg/ecpglib/descriptor.cpp b/src/common/interfaces/ecpg/ecpglib/descriptor.cpp index 2c073f353..a738bbeb5 100644 --- a/src/common/interfaces/ecpg/ecpglib/descriptor.cpp +++ b/src/common/interfaces/ecpg/ecpglib/descriptor.cpp @@ -20,8 +20,8 @@ static void descriptor_free(struct descriptor* desc); /* We manage descriptors separately for each thread. */ #ifdef ENABLE_THREAD_SAFETY -static THR_LOCAL pthread_key_t descriptor_key; -static THR_LOCAL pthread_once_t descriptor_once = PTHREAD_ONCE_INIT; +static pthread_key_t descriptor_key; +static pthread_once_t descriptor_once = PTHREAD_ONCE_INIT; static void descriptor_deallocate_all(struct descriptor* list); diff --git a/src/common/interfaces/ecpg/ecpglib/misc.cpp b/src/common/interfaces/ecpg/ecpglib/misc.cpp index 386a63e94..f6960f5d9 100644 --- a/src/common/interfaces/ecpg/ecpglib/misc.cpp +++ b/src/common/interfaces/ecpg/ecpglib/misc.cpp @@ -39,8 +39,8 @@ static struct sqlca_t sqlca_init = {{'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '}, {'0', '0', '0', '0', '0'}}; #ifdef ENABLE_THREAD_SAFETY -static THR_LOCAL pthread_key_t sqlca_key; -static THR_LOCAL pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT; +static pthread_key_t sqlca_key; +static pthread_once_t sqlca_key_once = PTHREAD_ONCE_INIT; #else static struct sqlca_t sqlca = {{'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '}, sizeof(struct sqlca_t), @@ -53,11 +53,11 @@ static struct sqlca_t sqlca = {{'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '}, #endif #ifdef ENABLE_THREAD_SAFETY -static THR_LOCAL pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER; -static THR_LOCAL pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t debug_init_mutex = PTHREAD_MUTEX_INITIALIZER; #endif -static THR_LOCAL int simple_debug = 0; -static THR_LOCAL FILE* debugstream = NULL; +static int simple_debug = 0; +static FILE* debugstream = NULL; void ecpg_init_sqlca(struct sqlca_t* sqlca) { diff --git a/src/common/interfaces/ecpg/ecpglib/prepare.cpp b/src/common/interfaces/ecpg/ecpglib/prepare.cpp index fa776d088..3d0df2731 100644 --- a/src/common/interfaces/ecpg/ecpglib/prepare.cpp +++ b/src/common/interfaces/ecpg/ecpglib/prepare.cpp @@ -21,10 +21,10 @@ typedef struct { const char* connection; /* connection for the statement */ } stmtCacheEntry; -static THR_LOCAL int nextStmtID = 1; +static int nextStmtID = 1; static const int stmtCacheNBuckets = 2039; /* # buckets - a prime # */ static const int stmtCacheEntPerBucket = 8; /* # entries/bucket */ -static THR_LOCAL stmtCacheEntry stmtCacheEntries[16384] = {{0, {0}, 0, 0, 0}}; +static stmtCacheEntry stmtCacheEntries[16384] = {{0, {0}, 0, 0, 0}}; static bool deallocate_one(int lineno, enum COMPAT_MODE c, struct connection* con, struct prepared_statement* prev, struct prepared_statement* thisPtr); diff --git a/src/common/interfaces/ecpg/preproc/Makefile b/src/common/interfaces/ecpg/preproc/Makefile index 4cea8baab..055daf0d1 100644 --- a/src/common/interfaces/ecpg/preproc/Makefile +++ b/src/common/interfaces/ecpg/preproc/Makefile @@ -64,9 +64,15 @@ endif pgc.cpp: pgc.l ifdef FLEX - $(FLEX) $(FLEXFLAGS) -o'$@' $< + $(FLEX) $(FLEXFLAGS) -o'$@' $< + @grep -rn "size_t yy_size_t" $@;if [ $$? == 0 ]; then sed -i 's/int yyl;/size_t yyl;/g' $@;\ + sed -i "s/i < _yybytes_len/(size_t)i < (size_t)_yybytes_len/g" $@;\ + sed -i "s/n < max_size/(size_t)n < (size_t)max_size/g" $@;fi; else @$(missing) flex $< $@ + @grep -rn "size_t yy_size_t" $@;if [ $$? == 0 ]; then sed -i 's/int yyl;/size_t yyl;/g' $@;\ + sed -i "s/i < _yybytes_len/(size_t)i < (size_t)_yybytes_len/g" $@;\ + sed -i "s/n < max_size/(size_t)n < (size_t)max_size/g" $@;fi; endif preproc.y: ../../../../common/backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type diff --git a/src/common/interfaces/ecpg/preproc/check_rules.pl b/src/common/interfaces/ecpg/preproc/check_rules.pl index 93dfdaea6..d549c653b 100644 --- a/src/common/interfaces/ecpg/preproc/check_rules.pl +++ b/src/common/interfaces/ecpg/preproc/check_rules.pl @@ -53,7 +53,8 @@ my $comment = 0; my $non_term_id = ''; my $cc = 0; -#读取gram.y文件,把该文件中的规则部分(即%%分割的第二部分),以模式为key存放到哈希变量%found中 +# Read the gram. Y file and store the rule part of the file (the second +# part of the %% split) in the hash variable %found open GRAM, $parser or die $!; while () { @@ -155,7 +156,9 @@ if ($verbose) my $ret = 0; $cc = 0; -#读取ecpg.addons文件,匹配ECPG:格式,匹配到的以空格分成三段,用第二段在哈希变量%found中查找,如果存在则检查通过,如果不存在则检查不通过 +# Read the ecpg. Addons file and match the ecpg: format, split the matching into three segments +# with Spaces, use the second segment to search the hash variable %found, if it exists, the check +# passes, if it does not exist, the check fails open ECPG, $filename or die $!; while () { diff --git a/src/common/interfaces/ecpg/preproc/descriptor.cpp b/src/common/interfaces/ecpg/preproc/descriptor.cpp index 59eaad7ac..a68dd2d01 100644 --- a/src/common/interfaces/ecpg/preproc/descriptor.cpp +++ b/src/common/interfaces/ecpg/preproc/descriptor.cpp @@ -15,7 +15,7 @@ * assignment handling function (descriptor) */ -static THR_LOCAL struct assignment* assignments; +static struct assignment* assignments; void push_assignment(char* var, enum ECPGdtype value) { diff --git a/src/common/interfaces/ecpg/preproc/ecpg.trailer b/src/common/interfaces/ecpg/preproc/ecpg.trailer index d31ce22ae..a6ad4a217 100644 --- a/src/common/interfaces/ecpg/preproc/ecpg.trailer +++ b/src/common/interfaces/ecpg/preproc/ecpg.trailer @@ -1453,13 +1453,13 @@ action : CONTINUE_P { $$.code = W_DO; $$.command = cat_str(4, $2, mm_strdup("("), $4, mm_strdup(")")); - $$.str = cat2_str(mm_strdup("ecpgcall"), mm_strdup($$.command)); + $$.str = cat2_str(mm_strdup("call"), mm_strdup($$.command)); } | SQL_CALL name { $$.code = W_DO; $$.command = cat2_str($2, mm_strdup("()")); - $$.str = cat2_str(mm_strdup("ecpgcall"), mm_strdup($$.command)); + $$.str = cat2_str(mm_strdup("call"), mm_strdup($$.command)); } ; @@ -1471,7 +1471,7 @@ ECPGKeywords: ECPGKeywords_vanames { $$ = $1; } ; ECPGKeywords_vanames: SQL_BREAK { $$ = mm_strdup("break"); } - | SQL_CALL { $$ = mm_strdup("ecpgcall"); } + | SQL_CALL { $$ = mm_strdup("call"); } | SQL_CARDINALITY { $$ = mm_strdup("cardinality"); } | SQL_COUNT { $$ = mm_strdup("count"); } | SQL_DATETIME_INTERVAL_CODE { $$ = mm_strdup("datetime_interval_code"); } @@ -1479,7 +1479,7 @@ ECPGKeywords_vanames: SQL_BREAK { $$ = mm_strdup("break"); } | SQL_FOUND { $$ = mm_strdup("found"); } | SQL_GO { $$ = mm_strdup("go"); } | SQL_GOTO { $$ = mm_strdup("goto"); } - | SQL_IDENTIFIED { $$ = mm_strdup("ecpgidentified"); } + | SQL_IDENTIFIED { $$ = mm_strdup("identified"); } | SQL_INDICATOR { $$ = mm_strdup("indicator"); } | SQL_KEY_MEMBER { $$ = mm_strdup("key_member"); } | SQL_LENGTH { $$ = mm_strdup("length"); } diff --git a/src/common/interfaces/ecpg/preproc/ecpg_keywords.cpp b/src/common/interfaces/ecpg/preproc/ecpg_keywords.cpp index 7db78e146..bc1d81ac2 100644 --- a/src/common/interfaces/ecpg/preproc/ecpg_keywords.cpp +++ b/src/common/interfaces/ecpg/preproc/ecpg_keywords.cpp @@ -37,19 +37,19 @@ static const ScanKeyword ECPGScanKeywords[] = { {"autocommit", SQL_AUTOCOMMIT, 0}, {"bool", SQL_BOOL, 0}, {"break", SQL_BREAK, 0}, + {"call", SQL_CALL, 0}, {"cardinality", SQL_CARDINALITY, 0}, {"count", SQL_COUNT, 0}, {"datetime_interval_code", SQL_DATETIME_INTERVAL_CODE, 0}, {"datetime_interval_precision", SQL_DATETIME_INTERVAL_PRECISION, 0}, {"describe", SQL_DESCRIBE, 0}, {"descriptor", SQL_DESCRIPTOR, 0}, - {"ecpgcall", SQL_CALL, 0}, - {"ecpgidentified", SQL_IDENTIFIED, 0}, {"found", SQL_FOUND, 0}, {"free", SQL_FREE, 0}, {"get", SQL_GET, 0}, {"go", SQL_GO, 0}, {"goto", SQL_GOTO, 0}, + {"identified", SQL_IDENTIFIED, 0}, {"indicator", SQL_INDICATOR, 0}, {"key_member", SQL_KEY_MEMBER, 0}, {"length", SQL_LENGTH, 0}, @@ -77,6 +77,22 @@ static const ScanKeyword ECPGScanKeywords[] = { {"whenever", SQL_WHENEVER, 0}, }; +static const ScanKeyword ECPGSQLKeywords[] = { + {"call", SQL_CALL, 0}, + {"identified", SQL_IDENTIFIED, 0}, +}; + +static bool ISECPGSQLKeyword(const char* text) +{ + const ScanKeyword* res = NULL; + bool is_ecpg_keyword = false; + + res = ScanKeywordLookup(text, ECPGSQLKeywords, lengthof(ECPGSQLKeywords)); + if (res) + is_ecpg_keyword = true; + return is_ecpg_keyword; +} + /* * ScanECPGKeywordLookup - see if a given word is a keyword * @@ -86,10 +102,10 @@ static const ScanKeyword ECPGScanKeywords[] = { const ScanKeyword* ScanECPGKeywordLookup(const char* text) { const ScanKeyword* res = NULL; - + /* First check SQL symbols defined by the backend. */ res = ScanKeywordLookup(text, SQLScanKeywords, NumSQLScanKeywords); - if (res) + if (res && !ISECPGSQLKeyword(text)) return res; /* Try ECPG-specific keywords. */ diff --git a/src/common/interfaces/ecpg/preproc/parse.pl b/src/common/interfaces/ecpg/preproc/parse.pl index 17103971f..d92195c3d 100644 --- a/src/common/interfaces/ecpg/preproc/parse.pl +++ b/src/common/interfaces/ecpg/preproc/parse.pl @@ -31,7 +31,6 @@ my ($stmt_mode, @fields); my ($line, $non_term_id); -# 哈希变量 key => values # some token have to be replaced by other symbols # either in the rule my %replace_token = ( @@ -52,10 +51,10 @@ my %replace_string = ( 'SUBPARTITION_FOR' => 'subpartition for', 'ADD_PARTITION' => 'add partition', 'DROP_PARTITION' => 'drop partition', - 'DROP_SUBPARTITION' => 'drop subpartition', 'REBUILD_PARTITION' => 'rebuild partition', 'MODIFY_PARTITION' => 'modify partition', - 'MODIFY_SUBPARTITION' => 'modify subpartition', + 'ADD_SUBPARTITION' => 'add subpartition', + 'DROP_SUBPARTITION' => 'drop subpartition', 'TYPECAST' => '::', 'DOT_DOT' => '..', 'COLON_EQUALS' => ':=',); @@ -137,9 +136,6 @@ dump_buffer('rules'); include_file('trailer', 'ecpg.trailer'); dump_buffer('trailer'); -# 以参数为文件读取即gram.y文件,读取gram.y文件中的types和tokens,分别以types、orig_tokens为key, -# 添加到哈希变量%buff中,并结合哈希变量%addons以rules为key把规则添加到哈希变量%buff中; -# 加载ecpg.tokens、ecpg.header、ecpg.type文件,分别以tokens、header、ecpgtype为key,添加到哈希变量%buff中 sub main { line: while (<>) @@ -435,7 +431,6 @@ sub main } } -# 读取第二个参数文件,以第一个参数为key,添加到哈希变量%buff中 # append a file onto a buffer. # Arguments: buffer_name, filename (without path) sub include_file @@ -474,7 +469,6 @@ sub include_addon if ($rec->{type} eq 'addon') { - # add_to_buffer('rules', $str)函数以'rules'为key,添加到哈希变量%buff中 dump_fields($stmt_mode, $fields, ''); } @@ -485,7 +479,6 @@ sub include_addon } -# 以第一个参数为key,第二个参数为values,写入哈希变量buff中 # include_addon does this same thing, but does not call this # sub... so if you change this, you need to fix include_addon too # Pass: buffer_name, string_to_append @@ -494,7 +487,6 @@ sub add_to_buffer push(@{ $buff{ $_[0] } }, "$_[1]\n"); } -#这个函数以参数为key打印出哈希变量%buff中参数的values,输出到preproc.y文件中 sub dump_buffer { my ($buffer) = @_; @@ -503,7 +495,6 @@ sub dump_buffer print @$ref; } - sub dump_fields { my ($mode, $flds, $ln) = @_; @@ -649,7 +640,6 @@ sub dump_line =cut -#读取文件ecpg.addons,并把ecpg.addons文件信息加入到哈希变量addons中 sub preload_addons { my $filename = $path . "/ecpg.addons"; diff --git a/src/common/interfaces/ecpg/preproc/parser.cpp b/src/common/interfaces/ecpg/preproc/parser.cpp index 53858c469..452c635f4 100644 --- a/src/common/interfaces/ecpg/preproc/parser.cpp +++ b/src/common/interfaces/ecpg/preproc/parser.cpp @@ -24,10 +24,10 @@ #include "extern.h" #include "preproc.hpp" -static THR_LOCAL bool have_lookahead; /* is lookahead info valid? */ -static THR_LOCAL int lookahead_token; /* one-token lookahead */ -static THR_LOCAL YYSTYPE lookahead_yylval; /* yylval for lookahead token */ -static THR_LOCAL YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */ +static bool have_lookahead; /* is lookahead info valid? */ +static int lookahead_token; /* one-token lookahead */ +static YYSTYPE lookahead_yylval; /* yylval for lookahead token */ +static YYLTYPE lookahead_yylloc; /* yylloc for lookahead token */ /* * Intermediate filter between parser and base lexer (base_yylex in scan.l). diff --git a/src/common/interfaces/ecpg/preproc/pgc.l b/src/common/interfaces/ecpg/preproc/pgc.l index 1d89cab4b..8ad517013 100644 --- a/src/common/interfaces/ecpg/preproc/pgc.l +++ b/src/common/interfaces/ecpg/preproc/pgc.l @@ -627,7 +627,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. * Note that slash-star or dash-dash at the first * character will match a prior rule, not this one. */ - unsigned int nchars = yyleng; + size_t nchars = yyleng; char *slashstar = strstr(yytext, "/*"); char *dashdash = strstr(yytext, "--"); @@ -666,7 +666,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. nchars--; /* else remove the +/-, and check again */ } - if (nchars < yyleng) + if (nchars < (size_t)yyleng) { /* Strip the unwanted chars from the token */ yyless(nchars); @@ -907,7 +907,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. } {identifier}{space}*";" { struct _defines *ptr, *ptr2 = NULL; - int i; + size_t i; /* * Skip the ";" and trailing whitespace. Note that yytext @@ -1095,7 +1095,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. else { struct _defines *defptr; - unsigned int i; + size_t i; /* * Skip the ";" and trailing whitespace. Note that yytext @@ -1183,7 +1183,7 @@ cppline {space}*#([^i][A-Za-z]*|{if}|{ifdef}|{ifndef}|{import})(.*\\{space})*. else { struct _yy_buffer *yb = yy_buffer; - int i; + size_t i; struct _defines *ptr; for (ptr = defines; ptr; ptr = ptr->next) diff --git a/src/common/interfaces/ecpg/preproc/variable.cpp b/src/common/interfaces/ecpg/preproc/variable.cpp index 43a7996d4..c2ca29478 100644 --- a/src/common/interfaces/ecpg/preproc/variable.cpp +++ b/src/common/interfaces/ecpg/preproc/variable.cpp @@ -4,7 +4,7 @@ #include "extern.h" -static THR_LOCAL struct variable* allvariables = NULL; +static struct variable* allvariables = NULL; struct variable* new_variable(const char* name, struct ECPGtype* type, int brace_level) { diff --git a/src/common/interfaces/ecpg/test/Makefile b/src/common/interfaces/ecpg/test/Makefile index ddf8b46c1..e83ae0a06 100644 --- a/src/common/interfaces/ecpg/test/Makefile +++ b/src/common/interfaces/ecpg/test/Makefile @@ -89,11 +89,5 @@ check: all $(MKDIR_P) ./log test -d $(HOME)/memchk/asan || mkdir -p $(HOME)/memchk/asan test -e $(HOME)/memchk/memleak_ignore || touch $(HOME)/memchk/memleak_ignore - ${pg_mem_check} && ./pg_regress $(REGRESS_OPTS) --top-builddir=$(top_builddir) --single_node -d 1 -c 0 -r 1 -p 57436 -b ./tmp_check -n $(pg_regress_locale_flags) $(THREAD) -w --keep_last_data=false --temp-config=$(srcdir)/make_connect.conf --schedule=$(srcdir)/ecpg_schedule --regconf=regress.conf + ${pg_mem_check} && ./pg_regress $(REGRESS_OPTS) --top-builddir=$(top_builddir) --single_node -d 1 -c 0 -r 1 -p 57436 -b ./tmp_check -n $(pg_regress_locale_flags) $(THREAD) -w --keep_last_data=false --temp-config=$(srcdir)/make_connect.conf --schedule=$(srcdir)/ecpg_schedule --regconf=regress.conf --ecpg -# the same options, but with --listen-on-tcp -checktcp: all - ./pg_regress $(REGRESS_OPTS) --top-builddir=$(top_builddir) --temp-install=./tmp_check $(pg_regress_locale_flags) $(THREAD) --schedule=$(srcdir)/ecpg_schedule_tcp --host=localhost - -installcheck: all - ./pg_regress $(REGRESS_OPTS) --psqldir='$(PSQLDIR)' --top-builddir=$(top_builddir) $(pg_regress_locale_flags) $(THREAD) --schedule=$(srcdir)/ecpg_schedule diff --git a/src/common/interfaces/ecpg/test/connect/test1.pgc b/src/common/interfaces/ecpg/test/connect/test1.pgc index d310c2043..e2667ca2c 100644 --- a/src/common/interfaces/ecpg/test/connect/test1.pgc +++ b/src/common/interfaces/ecpg/test/connect/test1.pgc @@ -23,19 +23,19 @@ exec sql end declare section; exec sql alter user connectuser ENCRYPTED PASSWORD "connectpw@1234"; exec sql disconnect; /* <-- "main" not specified */ - exec sql connect to connectdb@localhost as main user connectdb ecpgidentified by "connectpw@123" ; + exec sql connect to connectdb@localhost as main user connectdb identified by "connectpw@123" ; exec sql disconnect main; - exec sql connect to @localhost as main user connectdb ecpgidentified by "connectpw@123"; + exec sql connect to @localhost as main user connectdb identified by "connectpw@123"; exec sql disconnect main; /* exec sql connect to :@TEMP_PORT@ as main user connectdb; exec sql disconnect main; */ - exec sql connect to tcp:postgresql://localhost/connectdb user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to tcp:postgresql://localhost/connectdb user connectuser identified by "connectpw@123"; exec sql disconnect; - exec sql connect to tcp:postgresql://localhost/ user connectdb ecpgidentified by "connectpw@123"; + exec sql connect to tcp:postgresql://localhost/ user connectdb identified by "connectpw@123"; exec sql disconnect; strcpy(pw, "connectpw@123"); @@ -50,15 +50,15 @@ exec sql end declare section; exec sql disconnect; /* wrong db */ - exec sql connect to tcp:postgresql://localhost/nonexistant user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to tcp:postgresql://localhost/nonexistant user connectuser identified by "connectpw@123"; exec sql disconnect; /* wrong port */ - exec sql connect to tcp:postgresql://localhost:20/connectdb user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to tcp:postgresql://localhost:20/connectdb user connectuser identified by "connectpw@123"; /* no disconnect necessary */ /* wrong password */ - exec sql connect to unix:postgresql://localhost/connectdb user connectuser ecpgidentified by "wrongpw@123"; + exec sql connect to unix:postgresql://localhost/connectdb user connectuser identified by "wrongpw@123"; /* no disconnect necessary */ return (0); diff --git a/src/common/interfaces/ecpg/test/connect/test5.pgc b/src/common/interfaces/ecpg/test/connect/test5.pgc index 2cd7a5bf1..7a1260a15 100644 --- a/src/common/interfaces/ecpg/test/connect/test5.pgc +++ b/src/common/interfaces/ecpg/test/connect/test5.pgc @@ -38,28 +38,28 @@ exec sql end declare section; exec sql connect to 'connectdb' as main; exec sql disconnect main; - exec sql connect to as main user connectdb ecpgidentified by "connectpw@123"; + exec sql connect to as main user connectdb identified by "connectpw@123"; exec sql disconnect main; - exec sql connect to connectdb as main user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to connectdb as main user connectuser identified by "connectpw@123"; exec sql disconnect main; - exec sql connect to unix:postgresql://localhost/connectdb as main user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to unix:postgresql://localhost/connectdb as main user connectuser identified by "connectpw@123"; exec sql disconnect main; - exec sql connect to "unix:postgresql://localhost/connectdb" as main user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to "unix:postgresql://localhost/connectdb" as main user connectuser identified by "connectpw@123"; exec sql disconnect main; - exec sql connect to 'unix:postgresql://localhost/connectdb' as main user :user ecpgidentified by "connectpw@123"; + exec sql connect to 'unix:postgresql://localhost/connectdb' as main user :user identified by "connectpw@123"; exec sql disconnect main; - exec sql connect to unix:postgresql://localhost/connectdb?connect_timeout=14&client_encoding=latin1 as main user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to unix:postgresql://localhost/connectdb?connect_timeout=14&client_encoding=latin1 as main user connectuser identified by "connectpw@123"; exec sql disconnect main; - exec sql connect to "unix:postgresql://200.46.204.71/connectdb" as main user connectuser ecpgidentified by "connectpw@123"; + exec sql connect to "unix:postgresql://200.46.204.71/connectdb" as main user connectuser identified by "connectpw@123"; exec sql disconnect main; - exec sql connect to unix:postgresql://localhost/ as main user connectdb ecpgidentified by "connectpw@123"; + exec sql connect to unix:postgresql://localhost/ as main user connectdb identified by "connectpw@123"; exec sql disconnect main; /* connect twice */ diff --git a/src/common/interfaces/ecpg/test/expected/preproc-whenever.cpp b/src/common/interfaces/ecpg/test/expected/preproc-whenever.cpp index c06f0eaa8..ec73ac601 100644 --- a/src/common/interfaces/ecpg/test/expected/preproc-whenever.cpp +++ b/src/common/interfaces/ecpg/test/expected/preproc-whenever.cpp @@ -153,7 +153,7 @@ if (sqlca.sqlcode < 0) print ( "select" );} #line 44 "whenever.pgc" - /* exec sql whenever sqlerror ecpgcall print2 ( ) ; */ + /* exec sql whenever sqlerror call print2 ( ) ; */ #line 46 "whenever.pgc" { ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "select * from nonexistant", ECPGt_EOIT, diff --git a/src/common/interfaces/ecpg/test/preproc/whenever.pgc b/src/common/interfaces/ecpg/test/preproc/whenever.pgc index 8544ecb9c..9b3ae9e9e 100644 --- a/src/common/interfaces/ecpg/test/preproc/whenever.pgc +++ b/src/common/interfaces/ecpg/test/preproc/whenever.pgc @@ -43,7 +43,7 @@ int main(void) exec sql select * into :i from nonexistant; exec sql rollback; - exec sql whenever sqlerror ecpgcall print2(); + exec sql whenever sqlerror call print2(); exec sql select * into :i from nonexistant; exec sql rollback; diff --git a/src/test/regress/pg_regress.cpp b/src/test/regress/pg_regress.cpp index 087917d85..d61114a2c 100644 --- a/src/test/regress/pg_regress.cpp +++ b/src/test/regress/pg_regress.cpp @@ -459,6 +459,7 @@ static char* platform = "euleros2.0_sp2_x86_64"; /* client logic jdbc run regression tests */ static bool use_jdbc_client = false; +static bool use_ecpg = false; static bool to_create_jdbc_user = false; static bool is_skip_environment_cleanup = false; static char* client_logic_hook = "encryption"; @@ -5382,7 +5383,7 @@ static void create_database(const char* dbname) } } -static void create_role(const char* rolename, const _stringlist* granted_dbs) +static void create_role_ecpg(const char* rolename, const _stringlist* granted_dbs) { header(_("creating role \"%s\""), rolename); psql_command("postgres", "CREATE ROLE \"%s\" WITH LOGIN PASSWORD 'connectpw@123'", rolename); @@ -5391,6 +5392,15 @@ static void create_role(const char* rolename, const _stringlist* granted_dbs) } } +static void create_role(const char* rolename, const _stringlist* granted_dbs) +{ + header(_("creating role \"%s\""), rolename); + psql_command("postgres", "CREATE ROLE \"%s\" WITH LOGIN", rolename); + for (; granted_dbs != NULL; granted_dbs = granted_dbs->next) { + psql_command("postgres", "GRANT ALL ON DATABASE \"%s\" TO \"%s\"", granted_dbs->str, rolename); + } +} + static char* make_absolute_path(const char* in) { char* result = NULL; @@ -5466,6 +5476,7 @@ static void help(void) printf(_(" --psqldir=DIR use gsql in DIR (default: find in PATH)\n")); printf(_(" --enable-segment create table default with segment=on")); printf(_(" --jdbc enable jdbc regression test")); + printf(_(" --ecpg enable ecpg regression test")); printf(_("\n")); printf(_("The exit status is 0 if all tests passed, 1 if some tests failed, and 2\n")); printf(_("if the tests could not be run for some reason.\n")); @@ -6361,6 +6372,7 @@ int regression_main(int argc, char* argv[], init_function ifunc, test_function t {"client_logic_hook", required_argument, NULL, 59}, {"jdbc", no_argument, NULL, 60}, {"skip_environment_cleanup", no_argument, NULL, 61}, + {"ecpg", no_argument, NULL, 62}, {NULL, 0, NULL, 0} }; @@ -6642,6 +6654,10 @@ int regression_main(int argc, char* argv[], init_function ifunc, test_function t case 61: is_skip_environment_cleanup = true; break; + case 62: + printf("\n starting with ecpg\n"); + use_ecpg = true; + break; default: /* getopt_long already emitted a complaint */ fprintf(stderr, _("\nTry \"%s -h\" for more information.\n"), progname); @@ -7189,7 +7205,10 @@ int regression_main(int argc, char* argv[], init_function ifunc, test_function t create_jdbc_user(dblist); } for (ssl = extraroles; ssl; ssl = ssl->next) { - create_role(ssl->str, dblist); + if (use_ecpg) + create_role_ecpg(ssl->str, dblist); + else + create_role(ssl->str, dblist); } }