mirror of
https://github.com/postgres/postgres.git
synced 2025-08-28 18:48:04 +03:00
Pre-beta mechanical code beautification.
Run pgindent, pgperltidy, and reformat-dat-files. This set of diffs is a bit larger than typical. We've updated to pg_bsd_indent 2.1.2, which properly indents variable declarations that have multi-line initialization expressions (the continuation lines are now indented one tab stop). We've also updated to perltidy version 20230309 and changed some of its settings, which reduces its desire to add whitespace to lines to make assignments etc. line up. Going forward, that should make for fewer random-seeming changes to existing code. Discussion: https://postgr.es/m/20230428092545.qfb3y5wcu4cm75ur@alvherre.pgsql
This commit is contained in:
@@ -521,7 +521,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
case ECPGt_bytea:
|
||||
{
|
||||
struct ECPGgeneric_bytea *variable =
|
||||
(struct ECPGgeneric_bytea *) (var + offset * act_tuple);
|
||||
(struct ECPGgeneric_bytea *) (var + offset * act_tuple);
|
||||
long dst_size,
|
||||
src_size,
|
||||
dec_size;
|
||||
@@ -690,7 +690,7 @@ ecpg_get_data(const PGresult *results, int act_tuple, int act_field, int lineno,
|
||||
case ECPGt_varchar:
|
||||
{
|
||||
struct ECPGgeneric_varchar *variable =
|
||||
(struct ECPGgeneric_varchar *) (var + offset * act_tuple);
|
||||
(struct ECPGgeneric_varchar *) (var + offset * act_tuple);
|
||||
|
||||
variable->len = size;
|
||||
if (varcharsize == 0)
|
||||
|
@@ -210,7 +210,7 @@ get_char_item(int lineno, void *var, enum ECPGttype vartype, char *value, int va
|
||||
case ECPGt_varchar:
|
||||
{
|
||||
struct ECPGgeneric_varchar *variable =
|
||||
(struct ECPGgeneric_varchar *) var;
|
||||
(struct ECPGgeneric_varchar *) var;
|
||||
|
||||
if (varcharsize == 0)
|
||||
memcpy(variable->arr, value, strlen(value));
|
||||
@@ -597,7 +597,7 @@ set_desc_attr(struct descriptor_item *desc_item, struct variable *var,
|
||||
else
|
||||
{
|
||||
struct ECPGgeneric_bytea *variable =
|
||||
(struct ECPGgeneric_bytea *) (var->value);
|
||||
(struct ECPGgeneric_bytea *) (var->value);
|
||||
|
||||
desc_item->is_binary = true;
|
||||
desc_item->data_len = variable->len;
|
||||
|
@@ -820,7 +820,7 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
|
||||
case ECPGt_bytea:
|
||||
{
|
||||
struct ECPGgeneric_bytea *variable =
|
||||
(struct ECPGgeneric_bytea *) (var->value);
|
||||
(struct ECPGgeneric_bytea *) (var->value);
|
||||
|
||||
if (!(mallocedval = (char *) ecpg_alloc(variable->len, lineno)))
|
||||
return false;
|
||||
@@ -833,7 +833,7 @@ ecpg_store_input(const int lineno, const bool force_indicator, const struct vari
|
||||
case ECPGt_varchar:
|
||||
{
|
||||
struct ECPGgeneric_varchar *variable =
|
||||
(struct ECPGgeneric_varchar *) (var->value);
|
||||
(struct ECPGgeneric_varchar *) (var->value);
|
||||
|
||||
if (!(newcopy = (char *) ecpg_alloc(variable->len + 1, lineno)))
|
||||
return false;
|
||||
|
@@ -36,10 +36,10 @@ extern "C"
|
||||
#endif
|
||||
|
||||
extern interval * PGTYPESinterval_new(void);
|
||||
extern void PGTYPESinterval_free(interval *intvl);
|
||||
extern void PGTYPESinterval_free(interval * intvl);
|
||||
extern interval * PGTYPESinterval_from_asc(char *str, char **endptr);
|
||||
extern char *PGTYPESinterval_to_asc(interval *span);
|
||||
extern int PGTYPESinterval_copy(interval *intvlsrc, interval *intvldest);
|
||||
extern char *PGTYPESinterval_to_asc(interval * span);
|
||||
extern int PGTYPESinterval_copy(interval * intvlsrc, interval * intvldest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -315,7 +315,7 @@ int DecodeInterval(char **field, int *ftype, int nf, int *dtype, struct tm *tm
|
||||
int DecodeTime(char *str, int *tmask, struct tm *tm, fsec_t *fsec);
|
||||
void EncodeDateTime(struct tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str, bool EuroDates);
|
||||
void EncodeInterval(struct tm *tm, fsec_t fsec, int style, char *str);
|
||||
int tm2timestamp(struct tm *tm, fsec_t fsec, int *tzp, timestamp *result);
|
||||
int tm2timestamp(struct tm *tm, fsec_t fsec, int *tzp, timestamp * result);
|
||||
int DecodeUnits(int field, char *lowtoken, int *val);
|
||||
bool CheckDateTokenTables(void);
|
||||
void EncodeDateOnly(struct tm *tm, int style, char *str, bool EuroDates);
|
||||
|
@@ -780,17 +780,17 @@ EncodeInterval(struct /* pg_ */ tm *tm, fsec_t fsec, int style, char *str)
|
||||
case INTSTYLE_SQL_STANDARD:
|
||||
{
|
||||
bool has_negative = year < 0 || mon < 0 ||
|
||||
mday < 0 || hour < 0 ||
|
||||
min < 0 || sec < 0 || fsec < 0;
|
||||
mday < 0 || hour < 0 ||
|
||||
min < 0 || sec < 0 || fsec < 0;
|
||||
bool has_positive = year > 0 || mon > 0 ||
|
||||
mday > 0 || hour > 0 ||
|
||||
min > 0 || sec > 0 || fsec > 0;
|
||||
mday > 0 || hour > 0 ||
|
||||
min > 0 || sec > 0 || fsec > 0;
|
||||
bool has_year_month = year != 0 || mon != 0;
|
||||
bool has_day_time = mday != 0 || hour != 0 ||
|
||||
min != 0 || sec != 0 || fsec != 0;
|
||||
min != 0 || sec != 0 || fsec != 0;
|
||||
bool has_day = mday != 0;
|
||||
bool sql_standard_value = !(has_negative && has_positive) &&
|
||||
!(has_year_month && has_day_time);
|
||||
!(has_year_month && has_day_time);
|
||||
|
||||
/*
|
||||
* SQL Standard wants only 1 "<sign>" preceding the whole
|
||||
|
@@ -346,8 +346,8 @@ dttofmtasc_replace(timestamp * ts, date dDate, int dow, struct tm *tm,
|
||||
break;
|
||||
|
||||
/*
|
||||
* The preferred date and time representation for
|
||||
* the current locale.
|
||||
* The preferred date and time representation for the
|
||||
* current locale.
|
||||
*/
|
||||
case 'c':
|
||||
/* XXX */
|
||||
|
@@ -20,16 +20,16 @@ use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
|
||||
my $srcdir = '.';
|
||||
my $parser = '../../../backend/parser/gram.y';
|
||||
my $stamp = '';
|
||||
my $srcdir = '.';
|
||||
my $parser = '../../../backend/parser/gram.y';
|
||||
my $stamp = '';
|
||||
my $verbose = 0;
|
||||
|
||||
GetOptions(
|
||||
'srcdir=s' => \$srcdir,
|
||||
'parser=s' => \$parser,
|
||||
'stamp=s' => \$stamp,
|
||||
'verbose' => \$verbose,) or die "wrong arguments";
|
||||
'stamp=s' => \$stamp,
|
||||
'verbose' => \$verbose,) or die "wrong arguments";
|
||||
|
||||
my $filename = "$srcdir/ecpg.addons";
|
||||
if ($verbose)
|
||||
@@ -51,14 +51,14 @@ my %replace_line = (
|
||||
'PrepareStmtPREPAREnameprep_type_clauseASPreparableStmt' =>
|
||||
'PREPARE prepared_name prep_type_clause AS PreparableStmt');
|
||||
|
||||
my $block = '';
|
||||
my $yaccmode = 0;
|
||||
my $in_rule = 0;
|
||||
my $block = '';
|
||||
my $yaccmode = 0;
|
||||
my $in_rule = 0;
|
||||
my $brace_indent = 0;
|
||||
my (@arr, %found);
|
||||
my $comment = 0;
|
||||
my $comment = 0;
|
||||
my $non_term_id = '';
|
||||
my $cc = 0;
|
||||
my $cc = 0;
|
||||
|
||||
open my $parser_fh, '<', $parser or die $!;
|
||||
while (<$parser_fh>)
|
||||
@@ -140,13 +140,14 @@ while (<$parser_fh>)
|
||||
$block = '';
|
||||
$in_rule = 0 if $arr[$fieldIndexer] eq ';';
|
||||
}
|
||||
elsif (($arr[$fieldIndexer] =~ '[A-Za-z0-9]+:')
|
||||
|| ( $fieldIndexer + 1 < $n
|
||||
&& $arr[ $fieldIndexer + 1 ] eq ':'))
|
||||
elsif (
|
||||
($arr[$fieldIndexer] =~ '[A-Za-z0-9]+:')
|
||||
|| ( $fieldIndexer + 1 < $n
|
||||
&& $arr[ $fieldIndexer + 1 ] eq ':'))
|
||||
{
|
||||
die "unterminated rule at grammar line $.\n"
|
||||
if $in_rule;
|
||||
$in_rule = 1;
|
||||
$in_rule = 1;
|
||||
$non_term_id = $arr[$fieldIndexer];
|
||||
$non_term_id =~ tr/://d;
|
||||
}
|
||||
|
@@ -16,9 +16,9 @@ use strict;
|
||||
use warnings;
|
||||
use Getopt::Long;
|
||||
|
||||
my $srcdir = '.';
|
||||
my $srcdir = '.';
|
||||
my $outfile = '';
|
||||
my $parser = '';
|
||||
my $parser = '';
|
||||
|
||||
GetOptions(
|
||||
'srcdir=s' => \$srcdir,
|
||||
@@ -29,13 +29,13 @@ GetOptions(
|
||||
open(my $parserfh, '<', $parser) or die "could not open parser file $parser";
|
||||
open(my $outfh, '>', $outfile) or die "could not open output file $outfile";
|
||||
|
||||
my $copymode = 0;
|
||||
my $brace_indent = 0;
|
||||
my $yaccmode = 0;
|
||||
my $in_rule = 0;
|
||||
my $header_included = 0;
|
||||
my $copymode = 0;
|
||||
my $brace_indent = 0;
|
||||
my $yaccmode = 0;
|
||||
my $in_rule = 0;
|
||||
my $header_included = 0;
|
||||
my $feature_not_supported = 0;
|
||||
my $tokenmode = 0;
|
||||
my $tokenmode = 0;
|
||||
|
||||
my (%buff, $infield, $comment, %tokens, %addons);
|
||||
my ($stmt_mode, @fields);
|
||||
@@ -50,67 +50,67 @@ my %replace_token = (
|
||||
'FCONST' => 'ecpg_fconst',
|
||||
'Sconst' => 'ecpg_sconst',
|
||||
'XCONST' => 'ecpg_xconst',
|
||||
'IDENT' => 'ecpg_ident',
|
||||
'PARAM' => 'ecpg_param',);
|
||||
'IDENT' => 'ecpg_ident',
|
||||
'PARAM' => 'ecpg_param',);
|
||||
|
||||
# or in the block
|
||||
my %replace_string = (
|
||||
'FORMAT_LA' => 'format',
|
||||
'NOT_LA' => 'not',
|
||||
'NULLS_LA' => 'nulls',
|
||||
'WITH_LA' => 'with',
|
||||
'WITHOUT_LA' => 'without',
|
||||
'TYPECAST' => '::',
|
||||
'DOT_DOT' => '..',
|
||||
'COLON_EQUALS' => ':=',
|
||||
'FORMAT_LA' => 'format',
|
||||
'NOT_LA' => 'not',
|
||||
'NULLS_LA' => 'nulls',
|
||||
'WITH_LA' => 'with',
|
||||
'WITHOUT_LA' => 'without',
|
||||
'TYPECAST' => '::',
|
||||
'DOT_DOT' => '..',
|
||||
'COLON_EQUALS' => ':=',
|
||||
'EQUALS_GREATER' => '=>',
|
||||
'LESS_EQUALS' => '<=',
|
||||
'LESS_EQUALS' => '<=',
|
||||
'GREATER_EQUALS' => '>=',
|
||||
'NOT_EQUALS' => '<>',);
|
||||
'NOT_EQUALS' => '<>',);
|
||||
|
||||
# specific replace_types for specific non-terminals - never include the ':'
|
||||
# ECPG-only replace_types are defined in ecpg-replace_types
|
||||
my %replace_types = (
|
||||
'PrepareStmt' => '<prep>',
|
||||
'ExecuteStmt' => '<exec>',
|
||||
'PrepareStmt' => '<prep>',
|
||||
'ExecuteStmt' => '<exec>',
|
||||
'opt_array_bounds' => '<index>',
|
||||
|
||||
# "ignore" means: do not create type and rules for this non-term-id
|
||||
'parse_toplevel' => 'ignore',
|
||||
'stmtmulti' => 'ignore',
|
||||
'CreateAsStmt' => 'ignore',
|
||||
'DeallocateStmt' => 'ignore',
|
||||
'ColId' => 'ignore',
|
||||
'type_function_name' => 'ignore',
|
||||
'ColLabel' => 'ignore',
|
||||
'Sconst' => 'ignore',
|
||||
'parse_toplevel' => 'ignore',
|
||||
'stmtmulti' => 'ignore',
|
||||
'CreateAsStmt' => 'ignore',
|
||||
'DeallocateStmt' => 'ignore',
|
||||
'ColId' => 'ignore',
|
||||
'type_function_name' => 'ignore',
|
||||
'ColLabel' => 'ignore',
|
||||
'Sconst' => 'ignore',
|
||||
'opt_distinct_clause' => 'ignore',
|
||||
'PLpgSQL_Expr' => 'ignore',
|
||||
'PLAssignStmt' => 'ignore',
|
||||
'plassign_target' => 'ignore',
|
||||
'plassign_equals' => 'ignore',);
|
||||
'PLpgSQL_Expr' => 'ignore',
|
||||
'PLAssignStmt' => 'ignore',
|
||||
'plassign_target' => 'ignore',
|
||||
'plassign_equals' => 'ignore',);
|
||||
|
||||
# these replace_line commands excise certain keywords from the core keyword
|
||||
# lists. Be sure to account for these in ColLabel and related productions.
|
||||
my %replace_line = (
|
||||
'unreserved_keywordCONNECTION' => 'ignore',
|
||||
'unreserved_keywordCURRENT_P' => 'ignore',
|
||||
'unreserved_keywordDAY_P' => 'ignore',
|
||||
'unreserved_keywordHOUR_P' => 'ignore',
|
||||
'unreserved_keywordINPUT_P' => 'ignore',
|
||||
'unreserved_keywordMINUTE_P' => 'ignore',
|
||||
'unreserved_keywordMONTH_P' => 'ignore',
|
||||
'unreserved_keywordSECOND_P' => 'ignore',
|
||||
'unreserved_keywordYEAR_P' => 'ignore',
|
||||
'col_name_keywordCHAR_P' => 'ignore',
|
||||
'col_name_keywordINT_P' => 'ignore',
|
||||
'col_name_keywordVALUES' => 'ignore',
|
||||
'reserved_keywordTO' => 'ignore',
|
||||
'reserved_keywordUNION' => 'ignore',
|
||||
'unreserved_keywordCURRENT_P' => 'ignore',
|
||||
'unreserved_keywordDAY_P' => 'ignore',
|
||||
'unreserved_keywordHOUR_P' => 'ignore',
|
||||
'unreserved_keywordINPUT_P' => 'ignore',
|
||||
'unreserved_keywordMINUTE_P' => 'ignore',
|
||||
'unreserved_keywordMONTH_P' => 'ignore',
|
||||
'unreserved_keywordSECOND_P' => 'ignore',
|
||||
'unreserved_keywordYEAR_P' => 'ignore',
|
||||
'col_name_keywordCHAR_P' => 'ignore',
|
||||
'col_name_keywordINT_P' => 'ignore',
|
||||
'col_name_keywordVALUES' => 'ignore',
|
||||
'reserved_keywordTO' => 'ignore',
|
||||
'reserved_keywordUNION' => 'ignore',
|
||||
|
||||
# some other production rules have to be ignored or replaced
|
||||
'fetch_argsFORWARDopt_from_incursor_name' => 'ignore',
|
||||
'fetch_argsBACKWARDopt_from_incursor_name' => 'ignore',
|
||||
'fetch_argsFORWARDopt_from_incursor_name' => 'ignore',
|
||||
'fetch_argsBACKWARDopt_from_incursor_name' => 'ignore',
|
||||
"opt_array_boundsopt_array_bounds'['Iconst']'" => 'ignore',
|
||||
'VariableShowStmtSHOWvar_name' => 'SHOW var_name ecpg_into',
|
||||
'VariableShowStmtSHOWTIMEZONE' => 'SHOW TIME ZONE ecpg_into',
|
||||
@@ -139,7 +139,7 @@ dump_buffer('tokens');
|
||||
dump_buffer('types');
|
||||
dump_buffer('ecpgtype');
|
||||
dump_buffer('orig_tokens');
|
||||
print $outfh '%%', "\n";
|
||||
print $outfh '%%', "\n";
|
||||
print $outfh 'prog: statements;', "\n";
|
||||
dump_buffer('rules');
|
||||
include_file('trailer', 'ecpg.trailer');
|
||||
@@ -177,7 +177,7 @@ sub main
|
||||
if (/^%%/)
|
||||
{
|
||||
$tokenmode = 2;
|
||||
$copymode = 1;
|
||||
$copymode = 1;
|
||||
$yaccmode++;
|
||||
$infield = 0;
|
||||
}
|
||||
@@ -212,14 +212,14 @@ sub main
|
||||
}
|
||||
elsif ($arr[0] eq '%type' && $header_included == 0)
|
||||
{
|
||||
include_file('header', 'ecpg.header');
|
||||
include_file('header', 'ecpg.header');
|
||||
include_file('ecpgtype', 'ecpg.type');
|
||||
$header_included = 1;
|
||||
}
|
||||
|
||||
if ($tokenmode == 1)
|
||||
{
|
||||
my $str = '';
|
||||
my $str = '';
|
||||
my $prior = '';
|
||||
for my $a (@arr)
|
||||
{
|
||||
@@ -320,9 +320,9 @@ sub main
|
||||
{
|
||||
$copymode = 1;
|
||||
}
|
||||
@fields = ();
|
||||
@fields = ();
|
||||
$infield = 0;
|
||||
$line = '';
|
||||
$line = '';
|
||||
$in_rule = 0;
|
||||
next;
|
||||
}
|
||||
@@ -365,7 +365,7 @@ sub main
|
||||
elsif ($replace_types{$non_term_id} eq 'ignore')
|
||||
{
|
||||
$copymode = 0;
|
||||
$line = '';
|
||||
$line = '';
|
||||
next line;
|
||||
}
|
||||
$line = $line . ' ' . $arr[$fieldIndexer];
|
||||
@@ -390,7 +390,7 @@ sub main
|
||||
$stmt_mode = 0;
|
||||
}
|
||||
my $tstr =
|
||||
'%type '
|
||||
'%type '
|
||||
. $replace_types{$non_term_id} . ' '
|
||||
. $non_term_id;
|
||||
add_to_buffer('types', $tstr);
|
||||
@@ -399,8 +399,8 @@ sub main
|
||||
{
|
||||
add_to_buffer('rules', $line);
|
||||
}
|
||||
$line = '';
|
||||
@fields = ();
|
||||
$line = '';
|
||||
@fields = ();
|
||||
$infield = 1;
|
||||
die "unterminated rule at grammar line $.\n"
|
||||
if $in_rule;
|
||||
@@ -699,11 +699,11 @@ sub preload_addons
|
||||
{
|
||||
push(@{ $x->{lines} }, @code);
|
||||
}
|
||||
@code = ();
|
||||
@code = ();
|
||||
@needsRules = ();
|
||||
}
|
||||
$record = {};
|
||||
$record->{type} = $2;
|
||||
$record = {};
|
||||
$record->{type} = $2;
|
||||
$record->{lines} = [];
|
||||
if (exists $addons{$1}) { die "Ga! there are dups!\n"; }
|
||||
$addons{$1} = $record;
|
||||
|
@@ -78,7 +78,7 @@ ECPGmake_struct_member(const char *name, struct ECPGtype *type, struct ECPGstruc
|
||||
{
|
||||
struct ECPGstruct_member *ptr,
|
||||
*ne =
|
||||
(struct ECPGstruct_member *) mm_alloc(sizeof(struct ECPGstruct_member));
|
||||
(struct ECPGstruct_member *) mm_alloc(sizeof(struct ECPGstruct_member));
|
||||
|
||||
ne->name = mm_strdup(name);
|
||||
ne->type = type;
|
||||
|
@@ -1051,9 +1051,9 @@ libpq_prng_init(PGconn *conn)
|
||||
gettimeofday(&tval, NULL);
|
||||
|
||||
rseed = ((uintptr_t) conn) ^
|
||||
((uint64) getpid()) ^
|
||||
((uint64) tval.tv_usec) ^
|
||||
((uint64) tval.tv_sec);
|
||||
((uint64) getpid()) ^
|
||||
((uint64) tval.tv_usec) ^
|
||||
((uint64) tval.tv_sec);
|
||||
|
||||
pg_prng_seed(&conn->prng_state, rseed);
|
||||
}
|
||||
|
@@ -1448,7 +1448,7 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
|
||||
if (conn->pipelineStatus != PQ_PIPELINE_OFF)
|
||||
{
|
||||
libpq_append_conn_error(conn, "%s not allowed in pipeline mode",
|
||||
"PQsendQuery");
|
||||
"PQsendQuery");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1516,7 +1516,7 @@ PQsendQueryParams(PGconn *conn,
|
||||
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
|
||||
{
|
||||
libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
|
||||
PQ_QUERY_PARAM_MAX_LIMIT);
|
||||
PQ_QUERY_PARAM_MAX_LIMIT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1562,7 +1562,7 @@ PQsendPrepare(PGconn *conn,
|
||||
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
|
||||
{
|
||||
libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
|
||||
PQ_QUERY_PARAM_MAX_LIMIT);
|
||||
PQ_QUERY_PARAM_MAX_LIMIT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1656,7 +1656,7 @@ PQsendQueryPrepared(PGconn *conn,
|
||||
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
|
||||
{
|
||||
libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
|
||||
PQ_QUERY_PARAM_MAX_LIMIT);
|
||||
PQ_QUERY_PARAM_MAX_LIMIT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -2103,10 +2103,9 @@ PQgetResult(PGconn *conn)
|
||||
|
||||
/*
|
||||
* We're about to return the NULL that terminates the round of
|
||||
* results from the current query; prepare to send the results
|
||||
* of the next query, if any, when we're called next. If there's
|
||||
* no next element in the command queue, this gets us in IDLE
|
||||
* state.
|
||||
* results from the current query; prepare to send the results of
|
||||
* the next query, if any, when we're called next. If there's no
|
||||
* next element in the command queue, this gets us in IDLE state.
|
||||
*/
|
||||
pqPipelineProcessQueue(conn);
|
||||
res = NULL; /* query is complete */
|
||||
@@ -3051,6 +3050,7 @@ pqPipelineProcessQueue(PGconn *conn)
|
||||
return;
|
||||
|
||||
case PGASYNC_IDLE:
|
||||
|
||||
/*
|
||||
* If we're in IDLE mode and there's some command in the queue,
|
||||
* get us into PIPELINE_IDLE mode and process normally. Otherwise
|
||||
|
@@ -142,7 +142,7 @@ lo_truncate(PGconn *conn, int fd, size_t len)
|
||||
if (conn->lobjfuncs->fn_lo_truncate == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_truncate");
|
||||
"lo_truncate");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ lo_truncate64(PGconn *conn, int fd, pg_int64 len)
|
||||
if (conn->lobjfuncs->fn_lo_truncate64 == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_truncate64");
|
||||
"lo_truncate64");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -395,7 +395,7 @@ lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence)
|
||||
if (conn->lobjfuncs->fn_lo_lseek64 == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_lseek64");
|
||||
"lo_lseek64");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ lo_create(PGconn *conn, Oid lobjId)
|
||||
if (conn->lobjfuncs->fn_lo_create == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_create");
|
||||
"lo_create");
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
@@ -558,7 +558,7 @@ lo_tell64(PGconn *conn, int fd)
|
||||
if (conn->lobjfuncs->fn_lo_tell64 == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_tell64");
|
||||
"lo_tell64");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -667,7 +667,7 @@ lo_import_internal(PGconn *conn, const char *filename, Oid oid)
|
||||
if (fd < 0)
|
||||
{ /* error */
|
||||
libpq_append_conn_error(conn, "could not open file \"%s\": %s",
|
||||
filename, strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
filename, strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
@@ -723,8 +723,8 @@ lo_import_internal(PGconn *conn, const char *filename, Oid oid)
|
||||
/* deliberately overwrite any error from lo_close */
|
||||
pqClearConnErrorState(conn);
|
||||
libpq_append_conn_error(conn, "could not read from file \"%s\": %s",
|
||||
filename,
|
||||
strerror_r(save_errno, sebuf, sizeof(sebuf)));
|
||||
filename,
|
||||
strerror_r(save_errno, sebuf, sizeof(sebuf)));
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
@@ -778,8 +778,8 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
|
||||
/* deliberately overwrite any error from lo_close */
|
||||
pqClearConnErrorState(conn);
|
||||
libpq_append_conn_error(conn, "could not open file \"%s\": %s",
|
||||
filename,
|
||||
strerror_r(save_errno, sebuf, sizeof(sebuf)));
|
||||
filename,
|
||||
strerror_r(save_errno, sebuf, sizeof(sebuf)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -799,8 +799,8 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
|
||||
/* deliberately overwrite any error from lo_close */
|
||||
pqClearConnErrorState(conn);
|
||||
libpq_append_conn_error(conn, "could not write to file \"%s\": %s",
|
||||
filename,
|
||||
strerror_r(save_errno, sebuf, sizeof(sebuf)));
|
||||
filename,
|
||||
strerror_r(save_errno, sebuf, sizeof(sebuf)));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -822,7 +822,7 @@ lo_export(PGconn *conn, Oid lobjId, const char *filename)
|
||||
if (close(fd) != 0 && result >= 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "could not write to file \"%s\": %s",
|
||||
filename, strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
filename, strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
result = -1;
|
||||
}
|
||||
|
||||
@@ -954,56 +954,56 @@ lo_initialize(PGconn *conn)
|
||||
if (lobjfuncs->fn_lo_open == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_open");
|
||||
"lo_open");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
if (lobjfuncs->fn_lo_close == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_close");
|
||||
"lo_close");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
if (lobjfuncs->fn_lo_creat == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_creat");
|
||||
"lo_creat");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
if (lobjfuncs->fn_lo_unlink == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_unlink");
|
||||
"lo_unlink");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
if (lobjfuncs->fn_lo_lseek == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_lseek");
|
||||
"lo_lseek");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
if (lobjfuncs->fn_lo_tell == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lo_tell");
|
||||
"lo_tell");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
if (lobjfuncs->fn_lo_read == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"loread");
|
||||
"loread");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
if (lobjfuncs->fn_lo_write == 0)
|
||||
{
|
||||
libpq_append_conn_error(conn, "cannot determine OID of function %s",
|
||||
"lowrite");
|
||||
"lowrite");
|
||||
free(lobjfuncs);
|
||||
return -1;
|
||||
}
|
||||
|
@@ -749,8 +749,8 @@ retry4:
|
||||
*/
|
||||
definitelyEOF:
|
||||
libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
|
||||
/* Come here if lower-level code already set a suitable errorMessage */
|
||||
definitelyFailed:
|
||||
@@ -1067,7 +1067,7 @@ pqSocketCheck(PGconn *conn, int forRead, int forWrite, time_t end_time)
|
||||
char sebuf[PG_STRERROR_R_BUFLEN];
|
||||
|
||||
libpq_append_conn_error(conn, "%s() failed: %s", "select",
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
SOCK_STRERROR(SOCK_ERRNO, sebuf, sizeof(sebuf)));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -1280,7 +1280,7 @@ libpq_ngettext(const char *msgid, const char *msgid_plural, unsigned long n)
|
||||
* newline.
|
||||
*/
|
||||
void
|
||||
libpq_append_error(PQExpBuffer errorMessage, const char *fmt, ...)
|
||||
libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...)
|
||||
{
|
||||
int save_errno = errno;
|
||||
bool done;
|
||||
@@ -1309,7 +1309,7 @@ libpq_append_error(PQExpBuffer errorMessage, const char *fmt, ...)
|
||||
* format should not end with a newline.
|
||||
*/
|
||||
void
|
||||
libpq_append_conn_error(PGconn *conn, const char *fmt, ...)
|
||||
libpq_append_conn_error(PGconn *conn, const char *fmt,...)
|
||||
{
|
||||
int save_errno = errno;
|
||||
bool done;
|
||||
|
@@ -124,7 +124,7 @@ PQprint(FILE *fout, const PGresult *res, const PQprintOpt *po)
|
||||
{
|
||||
int len;
|
||||
const char *s = (j < numFieldName && po->fieldName[j][0]) ?
|
||||
po->fieldName[j] : PQfname(res, j);
|
||||
po->fieldName[j] : PQfname(res, j);
|
||||
|
||||
fieldNames[j] = s;
|
||||
len = s ? strlen(s) : 0;
|
||||
|
@@ -466,7 +466,7 @@ static void
|
||||
handleSyncLoss(PGconn *conn, char id, int msgLength)
|
||||
{
|
||||
libpq_append_conn_error(conn, "lost synchronization with server: got message type \"%c\", length %d",
|
||||
id, msgLength);
|
||||
id, msgLength);
|
||||
/* build an error result holding the error message */
|
||||
pqSaveErrorResult(conn);
|
||||
conn->asyncStatus = PGASYNC_READY; /* drop out of PQgetResult wait loop */
|
||||
|
@@ -226,7 +226,7 @@ pq_verify_peer_name_matches_certificate_ip(PGconn *conn,
|
||||
* wrong given the subject matter.
|
||||
*/
|
||||
libpq_append_conn_error(conn, "certificate contains IP address with invalid length %zu",
|
||||
iplen);
|
||||
iplen);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ pq_verify_peer_name_matches_certificate_ip(PGconn *conn,
|
||||
if (!addrstr)
|
||||
{
|
||||
libpq_append_conn_error(conn, "could not convert certificate's IP address to string: %s",
|
||||
strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ pq_verify_peer_name_matches_certificate(PGconn *conn)
|
||||
else if (names_examined == 1)
|
||||
{
|
||||
libpq_append_conn_error(conn, "server certificate for \"%s\" does not match host name \"%s\"",
|
||||
first_name, host);
|
||||
first_name, host);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -213,8 +213,8 @@ pg_GSS_write(PGconn *conn, const void *ptr, size_t len)
|
||||
if (output.length > PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32))
|
||||
{
|
||||
libpq_append_conn_error(conn, "client tried to send oversize GSSAPI packet (%zu > %zu)",
|
||||
(size_t) output.length,
|
||||
PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32));
|
||||
(size_t) output.length,
|
||||
PQ_GSS_SEND_BUFFER_SIZE - sizeof(uint32));
|
||||
errno = EIO; /* for lack of a better idea */
|
||||
goto cleanup;
|
||||
}
|
||||
@@ -349,8 +349,8 @@ pg_GSS_read(PGconn *conn, void *ptr, size_t len)
|
||||
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
|
||||
{
|
||||
libpq_append_conn_error(conn, "oversize GSSAPI packet sent by the server (%zu > %zu)",
|
||||
(size_t) input.length,
|
||||
PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32));
|
||||
(size_t) input.length,
|
||||
PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32));
|
||||
errno = EIO; /* for lack of a better idea */
|
||||
return -1;
|
||||
}
|
||||
@@ -591,8 +591,8 @@ pqsecure_open_gss(PGconn *conn)
|
||||
if (input.length > PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32))
|
||||
{
|
||||
libpq_append_conn_error(conn, "oversize GSSAPI packet sent by the server (%zu > %zu)",
|
||||
(size_t) input.length,
|
||||
PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32));
|
||||
(size_t) input.length,
|
||||
PQ_GSS_RECV_BUFFER_SIZE - sizeof(uint32));
|
||||
return PGRES_POLLING_FAILED;
|
||||
}
|
||||
|
||||
|
@@ -213,12 +213,12 @@ rloop:
|
||||
if (result_errno == EPIPE ||
|
||||
result_errno == ECONNRESET)
|
||||
libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
else
|
||||
libpq_append_conn_error(conn, "SSL SYSCALL error: %s",
|
||||
SOCK_STRERROR(result_errno,
|
||||
sebuf, sizeof(sebuf)));
|
||||
SOCK_STRERROR(result_errno,
|
||||
sebuf, sizeof(sebuf)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -313,12 +313,12 @@ pgtls_write(PGconn *conn, const void *ptr, size_t len)
|
||||
result_errno = SOCK_ERRNO;
|
||||
if (result_errno == EPIPE || result_errno == ECONNRESET)
|
||||
libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
else
|
||||
libpq_append_conn_error(conn, "SSL SYSCALL error: %s",
|
||||
SOCK_STRERROR(result_errno,
|
||||
sebuf, sizeof(sebuf)));
|
||||
SOCK_STRERROR(result_errno,
|
||||
sebuf, sizeof(sebuf)));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -415,7 +415,7 @@ pgtls_get_peer_certificate_hash(PGconn *conn, size_t *len)
|
||||
if (algo_type == NULL)
|
||||
{
|
||||
libpq_append_conn_error(conn, "could not find digest for NID %s",
|
||||
OBJ_nid2sn(algo_nid));
|
||||
OBJ_nid2sn(algo_nid));
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
@@ -1000,7 +1000,7 @@ initialize_SSL(PGconn *conn)
|
||||
if (ssl_min_ver == -1)
|
||||
{
|
||||
libpq_append_conn_error(conn, "invalid value \"%s\" for minimum SSL protocol version",
|
||||
conn->ssl_min_protocol_version);
|
||||
conn->ssl_min_protocol_version);
|
||||
SSL_CTX_free(SSL_context);
|
||||
return -1;
|
||||
}
|
||||
@@ -1026,7 +1026,7 @@ initialize_SSL(PGconn *conn)
|
||||
if (ssl_max_ver == -1)
|
||||
{
|
||||
libpq_append_conn_error(conn, "invalid value \"%s\" for maximum SSL protocol version",
|
||||
conn->ssl_max_protocol_version);
|
||||
conn->ssl_max_protocol_version);
|
||||
SSL_CTX_free(SSL_context);
|
||||
return -1;
|
||||
}
|
||||
@@ -1091,7 +1091,7 @@ initialize_SSL(PGconn *conn)
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "could not read root certificate file \"%s\": %s",
|
||||
fnbuf, err);
|
||||
fnbuf, err);
|
||||
SSLerrfree(err);
|
||||
SSL_CTX_free(SSL_context);
|
||||
return -1;
|
||||
@@ -1161,7 +1161,7 @@ initialize_SSL(PGconn *conn)
|
||||
else
|
||||
fnbuf[0] = '\0';
|
||||
|
||||
if (conn->sslcertmode[0] == 'd') /* disable */
|
||||
if (conn->sslcertmode[0] == 'd') /* disable */
|
||||
{
|
||||
/* don't send a client cert even if we have one */
|
||||
have_cert = false;
|
||||
@@ -1181,7 +1181,7 @@ initialize_SSL(PGconn *conn)
|
||||
if (errno != ENOENT && errno != ENOTDIR)
|
||||
{
|
||||
libpq_append_conn_error(conn, "could not open certificate file \"%s\": %s",
|
||||
fnbuf, strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
fnbuf, strerror_r(errno, sebuf, sizeof(sebuf)));
|
||||
SSL_CTX_free(SSL_context);
|
||||
return -1;
|
||||
}
|
||||
@@ -1199,7 +1199,7 @@ initialize_SSL(PGconn *conn)
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "could not read certificate file \"%s\": %s",
|
||||
fnbuf, err);
|
||||
fnbuf, err);
|
||||
SSLerrfree(err);
|
||||
SSL_CTX_free(SSL_context);
|
||||
return -1;
|
||||
@@ -1298,7 +1298,7 @@ initialize_SSL(PGconn *conn)
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "could not load SSL engine \"%s\": %s",
|
||||
engine_str, err);
|
||||
engine_str, err);
|
||||
SSLerrfree(err);
|
||||
free(engine_str);
|
||||
return -1;
|
||||
@@ -1309,7 +1309,7 @@ initialize_SSL(PGconn *conn)
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "could not initialize SSL engine \"%s\": %s",
|
||||
engine_str, err);
|
||||
engine_str, err);
|
||||
SSLerrfree(err);
|
||||
ENGINE_free(conn->engine);
|
||||
conn->engine = NULL;
|
||||
@@ -1324,7 +1324,7 @@ initialize_SSL(PGconn *conn)
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "could not read private SSL key \"%s\" from engine \"%s\": %s",
|
||||
engine_colon, engine_str, err);
|
||||
engine_colon, engine_str, err);
|
||||
SSLerrfree(err);
|
||||
ENGINE_finish(conn->engine);
|
||||
ENGINE_free(conn->engine);
|
||||
@@ -1337,7 +1337,7 @@ initialize_SSL(PGconn *conn)
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "could not load private SSL key \"%s\" from engine \"%s\": %s",
|
||||
engine_colon, engine_str, err);
|
||||
engine_colon, engine_str, err);
|
||||
SSLerrfree(err);
|
||||
ENGINE_finish(conn->engine);
|
||||
ENGINE_free(conn->engine);
|
||||
@@ -1374,10 +1374,10 @@ initialize_SSL(PGconn *conn)
|
||||
{
|
||||
if (errno == ENOENT)
|
||||
libpq_append_conn_error(conn, "certificate present, but not private key file \"%s\"",
|
||||
fnbuf);
|
||||
fnbuf);
|
||||
else
|
||||
libpq_append_conn_error(conn, "could not stat private key file \"%s\": %m",
|
||||
fnbuf);
|
||||
fnbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1385,7 +1385,7 @@ initialize_SSL(PGconn *conn)
|
||||
if (!S_ISREG(buf.st_mode))
|
||||
{
|
||||
libpq_append_conn_error(conn, "private key file \"%s\" is not a regular file",
|
||||
fnbuf);
|
||||
fnbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1442,7 +1442,7 @@ initialize_SSL(PGconn *conn)
|
||||
if (SSL_use_PrivateKey_file(conn->ssl, fnbuf, SSL_FILETYPE_ASN1) != 1)
|
||||
{
|
||||
libpq_append_conn_error(conn, "could not load private key file \"%s\": %s",
|
||||
fnbuf, err);
|
||||
fnbuf, err);
|
||||
SSLerrfree(err);
|
||||
return -1;
|
||||
}
|
||||
@@ -1458,7 +1458,7 @@ initialize_SSL(PGconn *conn)
|
||||
char *err = SSLerrmessage(ERR_get_error());
|
||||
|
||||
libpq_append_conn_error(conn, "certificate does not match private key file \"%s\": %s",
|
||||
fnbuf, err);
|
||||
fnbuf, err);
|
||||
SSLerrfree(err);
|
||||
return -1;
|
||||
}
|
||||
@@ -1520,8 +1520,8 @@ open_client_SSL(PGconn *conn)
|
||||
* it means that verification failed due to a missing
|
||||
* system CA pool without it being a protocol error. We
|
||||
* inspect the sslrootcert setting to ensure that the user
|
||||
* was using the system CA pool. For other errors, log them
|
||||
* using the normal SYSCALL logging.
|
||||
* was using the system CA pool. For other errors, log
|
||||
* them using the normal SYSCALL logging.
|
||||
*/
|
||||
if (!save_errno && vcode == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY &&
|
||||
strcmp(conn->sslrootcert, "system") == 0)
|
||||
@@ -1529,7 +1529,7 @@ open_client_SSL(PGconn *conn)
|
||||
X509_verify_cert_error_string(vcode));
|
||||
else if (r == -1)
|
||||
libpq_append_conn_error(conn, "SSL SYSCALL error: %s",
|
||||
SOCK_STRERROR(save_errno, sebuf, sizeof(sebuf)));
|
||||
SOCK_STRERROR(save_errno, sebuf, sizeof(sebuf)));
|
||||
else
|
||||
libpq_append_conn_error(conn, "SSL SYSCALL error: EOF detected");
|
||||
pgtls_close(conn);
|
||||
@@ -1571,12 +1571,12 @@ open_client_SSL(PGconn *conn)
|
||||
case SSL_R_VERSION_TOO_LOW:
|
||||
#endif
|
||||
libpq_append_conn_error(conn, "This may indicate that the server does not support any SSL protocol version between %s and %s.",
|
||||
conn->ssl_min_protocol_version ?
|
||||
conn->ssl_min_protocol_version :
|
||||
MIN_OPENSSL_TLS_VERSION,
|
||||
conn->ssl_max_protocol_version ?
|
||||
conn->ssl_max_protocol_version :
|
||||
MAX_OPENSSL_TLS_VERSION);
|
||||
conn->ssl_min_protocol_version ?
|
||||
conn->ssl_min_protocol_version :
|
||||
MIN_OPENSSL_TLS_VERSION,
|
||||
conn->ssl_max_protocol_version ?
|
||||
conn->ssl_max_protocol_version :
|
||||
MAX_OPENSSL_TLS_VERSION);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@@ -255,14 +255,14 @@ pqsecure_raw_read(PGconn *conn, void *ptr, size_t len)
|
||||
case EPIPE:
|
||||
case ECONNRESET:
|
||||
libpq_append_conn_error(conn, "server closed the connection unexpectedly\n"
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
"\tThis probably means the server terminated abnormally\n"
|
||||
"\tbefore or while processing the request.");
|
||||
break;
|
||||
|
||||
default:
|
||||
libpq_append_conn_error(conn, "could not receive data from server: %s",
|
||||
SOCK_STRERROR(result_errno,
|
||||
sebuf, sizeof(sebuf)));
|
||||
SOCK_STRERROR(result_errno,
|
||||
sebuf, sizeof(sebuf)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -919,8 +919,8 @@ extern char *libpq_ngettext(const char *msgid, const char *msgid_plural, unsigne
|
||||
*/
|
||||
#undef _
|
||||
|
||||
extern void libpq_append_error(PQExpBuffer errorMessage, const char *fmt, ...) pg_attribute_printf(2, 3);
|
||||
extern void libpq_append_conn_error(PGconn *conn, const char *fmt, ...) pg_attribute_printf(2, 3);
|
||||
extern void libpq_append_error(PQExpBuffer errorMessage, const char *fmt,...) pg_attribute_printf(2, 3);
|
||||
extern void libpq_append_conn_error(PGconn *conn, const char *fmt,...) pg_attribute_printf(2, 3);
|
||||
|
||||
/*
|
||||
* These macros are needed to let error-handling code be portable between
|
||||
|
@@ -40,13 +40,13 @@ my @tests = (
|
||||
q{user='uri-user' host='host' (inet)},
|
||||
q{},
|
||||
],
|
||||
[ q{postgresql://uri-user@}, q{user='uri-user' (local)}, q{}, ],
|
||||
[ q{postgresql://uri-user@}, q{user='uri-user' (local)}, q{}, ],
|
||||
[ q{postgresql://host:12345/}, q{host='host' port='12345' (inet)}, q{}, ],
|
||||
[ q{postgresql://host:12345}, q{host='host' port='12345' (inet)}, q{}, ],
|
||||
[ q{postgresql://host/db}, q{dbname='db' host='host' (inet)}, q{}, ],
|
||||
[ q{postgresql://host/}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgresql://host}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgresql://}, q{(local)}, q{}, ],
|
||||
[ q{postgresql://host:12345}, q{host='host' port='12345' (inet)}, q{}, ],
|
||||
[ q{postgresql://host/db}, q{dbname='db' host='host' (inet)}, q{}, ],
|
||||
[ q{postgresql://host/}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgresql://host}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgresql://}, q{(local)}, q{}, ],
|
||||
[
|
||||
q{postgresql://?hostaddr=127.0.0.1}, q{hostaddr='127.0.0.1' (inet)},
|
||||
q{},
|
||||
@@ -101,10 +101,10 @@ my @tests = (
|
||||
q{postgresql://[200z:db8::1234]/}, q{host='200z:db8::1234' (inet)},
|
||||
q{},
|
||||
],
|
||||
[ q{postgresql://[::1]}, q{host='::1' (inet)}, q{}, ],
|
||||
[ q{postgres://}, q{(local)}, q{}, ],
|
||||
[ q{postgres:///}, q{(local)}, q{}, ],
|
||||
[ q{postgres:///db}, q{dbname='db' (local)}, q{}, ],
|
||||
[ q{postgresql://[::1]}, q{host='::1' (inet)}, q{}, ],
|
||||
[ q{postgres://}, q{(local)}, q{}, ],
|
||||
[ q{postgres:///}, q{(local)}, q{}, ],
|
||||
[ q{postgres:///db}, q{dbname='db' (local)}, q{}, ],
|
||||
[
|
||||
q{postgres://uri-user@/db}, q{user='uri-user' dbname='db' (local)},
|
||||
q{},
|
||||
@@ -174,8 +174,8 @@ my @tests = (
|
||||
q{postgresql://%}, q{},
|
||||
q{libpq_uri_regress: invalid percent-encoded token: "%"},
|
||||
],
|
||||
[ q{postgres://@host}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgres://host:/}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgres://@host}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgres://host:/}, q{host='host' (inet)}, q{}, ],
|
||||
[ q{postgres://:12345/}, q{port='12345' (local)}, q{}, ],
|
||||
[
|
||||
q{postgres://otheruser@?host=/no/such/directory},
|
||||
@@ -230,8 +230,7 @@ my @tests = (
|
||||
[
|
||||
q{postgresql://host?sslmode=verify-full},
|
||||
q{host='host' (inet)},
|
||||
q{},
|
||||
PGSSLROOTCERT => "system",
|
||||
q{}, PGSSLROOTCERT => "system",
|
||||
]);
|
||||
|
||||
# test to run for each of the above test definitions
|
||||
|
@@ -34,7 +34,8 @@ $node1->connect_fails(
|
||||
expected_stderr => qr/invalid load_balance_hosts value: "doesnotexist"/);
|
||||
|
||||
# load_balance_hosts=disable should always choose the first one.
|
||||
$node1->connect_ok("host=$hostlist port=$portlist load_balance_hosts=disable",
|
||||
$node1->connect_ok(
|
||||
"host=$hostlist port=$portlist load_balance_hosts=disable",
|
||||
"load_balance_hosts=disable connects to the first node",
|
||||
sql => "SELECT 'connect1'",
|
||||
log_like => [qr/statement: SELECT 'connect1'/]);
|
||||
@@ -42,17 +43,23 @@ $node1->connect_ok("host=$hostlist port=$portlist load_balance_hosts=disable",
|
||||
# Statistically the following loop with load_balance_hosts=random will almost
|
||||
# certainly connect at least once to each of the nodes. The chance of that not
|
||||
# happening is so small that it's negligible: (2/3)^50 = 1.56832855e-9
|
||||
foreach my $i (1 .. 50) {
|
||||
$node1->connect_ok("host=$hostlist port=$portlist load_balance_hosts=random",
|
||||
foreach my $i (1 .. 50)
|
||||
{
|
||||
$node1->connect_ok(
|
||||
"host=$hostlist port=$portlist load_balance_hosts=random",
|
||||
"repeated connections with random load balancing",
|
||||
sql => "SELECT 'connect2'");
|
||||
}
|
||||
|
||||
my $node1_occurences = () = $node1->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node2_occurences = () = $node2->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node3_occurences = () = $node3->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node1_occurences = () =
|
||||
$node1->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node2_occurences = () =
|
||||
$node2->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node3_occurences = () =
|
||||
$node3->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
|
||||
my $total_occurences = $node1_occurences + $node2_occurences + $node3_occurences;
|
||||
my $total_occurences =
|
||||
$node1_occurences + $node2_occurences + $node3_occurences;
|
||||
|
||||
ok($node1_occurences > 1, "received at least one connection on node1");
|
||||
ok($node2_occurences > 1, "received at least one connection on node2");
|
||||
@@ -64,15 +71,18 @@ $node2->stop();
|
||||
|
||||
# load_balance_hosts=disable should continue trying hosts until it finds a
|
||||
# working one.
|
||||
$node3->connect_ok("host=$hostlist port=$portlist load_balance_hosts=disable",
|
||||
$node3->connect_ok(
|
||||
"host=$hostlist port=$portlist load_balance_hosts=disable",
|
||||
"load_balance_hosts=disable continues until it connects to the a working node",
|
||||
sql => "SELECT 'connect3'",
|
||||
log_like => [qr/statement: SELECT 'connect3'/]);
|
||||
|
||||
# Also with load_balance_hosts=random we continue to the next nodes if previous
|
||||
# ones are down. Connect a few times to make sure it's not just lucky.
|
||||
foreach my $i (1 .. 5) {
|
||||
$node3->connect_ok("host=$hostlist port=$portlist load_balance_hosts=random",
|
||||
foreach my $i (1 .. 5)
|
||||
{
|
||||
$node3->connect_ok(
|
||||
"host=$hostlist port=$portlist load_balance_hosts=random",
|
||||
"load_balance_hosts=random continues until it connects to the a working node",
|
||||
sql => "SELECT 'connect4'",
|
||||
log_like => [qr/statement: SELECT 'connect4'/]);
|
||||
|
@@ -34,15 +34,18 @@ if ($ENV{PG_TEST_EXTRA} !~ /\bload_balance\b/)
|
||||
# load balancing method is tested.
|
||||
|
||||
# Cluster setup which is shared for testing both load balancing methods
|
||||
my $can_bind_to_127_0_0_2 = $Config{osname} eq 'linux' || $PostgreSQL::Test::Utils::windows_os;
|
||||
my $can_bind_to_127_0_0_2 =
|
||||
$Config{osname} eq 'linux' || $PostgreSQL::Test::Utils::windows_os;
|
||||
|
||||
# Checks for the requirements for testing load balancing method 2
|
||||
if (!$can_bind_to_127_0_0_2) {
|
||||
if (!$can_bind_to_127_0_0_2)
|
||||
{
|
||||
plan skip_all => 'load_balance test only supported on Linux and Windows';
|
||||
}
|
||||
|
||||
my $hosts_path;
|
||||
if ($windows_os) {
|
||||
if ($windows_os)
|
||||
{
|
||||
$hosts_path = 'c:\Windows\System32\Drivers\etc\hosts';
|
||||
}
|
||||
else
|
||||
@@ -52,18 +55,22 @@ else
|
||||
|
||||
my $hosts_content = PostgreSQL::Test::Utils::slurp_file($hosts_path);
|
||||
|
||||
my $hosts_count = () = $hosts_content =~ /127\.0\.0\.[1-3] pg-loadbalancetest/g;
|
||||
if ($hosts_count != 3) {
|
||||
my $hosts_count = () =
|
||||
$hosts_content =~ /127\.0\.0\.[1-3] pg-loadbalancetest/g;
|
||||
if ($hosts_count != 3)
|
||||
{
|
||||
# Host file is not prepared for this test
|
||||
plan skip_all => "hosts file was not prepared for DNS load balance test"
|
||||
plan skip_all => "hosts file was not prepared for DNS load balance test";
|
||||
}
|
||||
|
||||
$PostgreSQL::Test::Cluster::use_tcp = 1;
|
||||
$PostgreSQL::Test::Cluster::test_pghost = '127.0.0.1';
|
||||
my $port = PostgreSQL::Test::Cluster::get_free_port();
|
||||
my $node1 = PostgreSQL::Test::Cluster->new('node1', port => $port);
|
||||
my $node2 = PostgreSQL::Test::Cluster->new('node2', port => $port, own_host => 1);
|
||||
my $node3 = PostgreSQL::Test::Cluster->new('node3', port => $port, own_host => 1);
|
||||
my $node2 =
|
||||
PostgreSQL::Test::Cluster->new('node2', port => $port, own_host => 1);
|
||||
my $node3 =
|
||||
PostgreSQL::Test::Cluster->new('node3', port => $port, own_host => 1);
|
||||
|
||||
# Create a data directory with initdb
|
||||
$node1->init();
|
||||
@@ -76,7 +83,8 @@ $node2->start();
|
||||
$node3->start();
|
||||
|
||||
# load_balance_hosts=disable should always choose the first one.
|
||||
$node1->connect_ok("host=pg-loadbalancetest port=$port load_balance_hosts=disable",
|
||||
$node1->connect_ok(
|
||||
"host=pg-loadbalancetest port=$port load_balance_hosts=disable",
|
||||
"load_balance_hosts=disable connects to the first node",
|
||||
sql => "SELECT 'connect1'",
|
||||
log_like => [qr/statement: SELECT 'connect1'/]);
|
||||
@@ -85,17 +93,23 @@ $node1->connect_ok("host=pg-loadbalancetest port=$port load_balance_hosts=disabl
|
||||
# Statistically the following loop with load_balance_hosts=random will almost
|
||||
# certainly connect at least once to each of the nodes. The chance of that not
|
||||
# happening is so small that it's negligible: (2/3)^50 = 1.56832855e-9
|
||||
foreach my $i (1 .. 50) {
|
||||
$node1->connect_ok("host=pg-loadbalancetest port=$port load_balance_hosts=random",
|
||||
foreach my $i (1 .. 50)
|
||||
{
|
||||
$node1->connect_ok(
|
||||
"host=pg-loadbalancetest port=$port load_balance_hosts=random",
|
||||
"repeated connections with random load balancing",
|
||||
sql => "SELECT 'connect2'");
|
||||
}
|
||||
|
||||
my $node1_occurences = () = $node1->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node2_occurences = () = $node2->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node3_occurences = () = $node3->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node1_occurences = () =
|
||||
$node1->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node2_occurences = () =
|
||||
$node2->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
my $node3_occurences = () =
|
||||
$node3->log_content() =~ /statement: SELECT 'connect2'/g;
|
||||
|
||||
my $total_occurences = $node1_occurences + $node2_occurences + $node3_occurences;
|
||||
my $total_occurences =
|
||||
$node1_occurences + $node2_occurences + $node3_occurences;
|
||||
|
||||
ok($node1_occurences > 1, "received at least one connection on node1");
|
||||
ok($node2_occurences > 1, "received at least one connection on node2");
|
||||
@@ -107,15 +121,18 @@ $node2->stop();
|
||||
|
||||
# load_balance_hosts=disable should continue trying hosts until it finds a
|
||||
# working one.
|
||||
$node3->connect_ok("host=pg-loadbalancetest port=$port load_balance_hosts=disable",
|
||||
$node3->connect_ok(
|
||||
"host=pg-loadbalancetest port=$port load_balance_hosts=disable",
|
||||
"load_balance_hosts=disable continues until it connects to the a working node",
|
||||
sql => "SELECT 'connect3'",
|
||||
log_like => [qr/statement: SELECT 'connect3'/]);
|
||||
|
||||
# Also with load_balance_hosts=random we continue to the next nodes if previous
|
||||
# ones are down. Connect a few times to make sure it's not just lucky.
|
||||
foreach my $i (1 .. 5) {
|
||||
$node3->connect_ok("host=pg-loadbalancetest port=$port load_balance_hosts=random",
|
||||
foreach my $i (1 .. 5)
|
||||
{
|
||||
$node3->connect_ok(
|
||||
"host=pg-loadbalancetest port=$port load_balance_hosts=random",
|
||||
"load_balance_hosts=random continues until it connects to the a working node",
|
||||
sql => "SELECT 'connect4'",
|
||||
log_like => [qr/statement: SELECT 'connect4'/]);
|
||||
|
Reference in New Issue
Block a user