@ -365,6 +365,7 @@ static const char *get_simple_binary_op_name(OpExpr *expr);
static bool isSimpleNode ( Node * node , Node * parentNode , int prettyFlags ) ;
static bool isSimpleNode ( Node * node , Node * parentNode , int prettyFlags ) ;
static void appendContextKeyword ( deparse_context * context , const char * str ,
static void appendContextKeyword ( deparse_context * context , const char * str ,
int indentBefore , int indentAfter , int indentPlus ) ;
int indentBefore , int indentAfter , int indentPlus ) ;
static void removeStringInfoSpaces ( StringInfo str ) ;
static void get_rule_expr ( Node * node , deparse_context * context ,
static void get_rule_expr ( Node * node , deparse_context * context ,
bool showimplicit ) ;
bool showimplicit ) ;
static void get_oper_expr ( OpExpr * expr , deparse_context * context ) ;
static void get_oper_expr ( OpExpr * expr , deparse_context * context ) ;
@ -4479,21 +4480,23 @@ get_target_list(List *targetList, deparse_context *context,
/* Consider line-wrapping if enabled */
/* Consider line-wrapping if enabled */
if ( PRETTY_INDENT ( context ) & & context - > wrapColumn > = 0 )
if ( PRETTY_INDENT ( context ) & & context - > wrapColumn > = 0 )
{
{
int leading_nl_pos = - 1 ;
int leading_nl_pos ;
char * trailing_nl ;
int pos ;
/* Does the new field start with whitespace plus a new line? */
/* Does the new field start with a new line? */
for ( pos = 0 ; pos < targetbuf . len ; pos + + )
if ( targetbuf . len > 0 & & targetbuf . data [ 0 ] = = ' \n ' )
{
leading_nl_pos = 0 ;
if ( targetbuf . data [ pos ] = = ' \n ' )
else
leading_nl_pos = - 1 ;
/* If so, we shouldn't add anything */
if ( leading_nl_pos > = 0 )
{
{
leading_nl_pos = pos ;
/* instead, remove any trailing spaces currently in buf */
break ;
removeStringInfoSpaces ( buf ) ;
}
if ( targetbuf . data [ pos ] ! = ' ' )
break ;
}
}
else
{
char * trailing_nl ;
/* Locate the start of the current line in the output buffer */
/* Locate the start of the current line in the output buffer */
trailing_nl = strrchr ( buf - > data , ' \n ' ) ;
trailing_nl = strrchr ( buf - > data , ' \n ' ) ;
@ -4503,18 +4506,16 @@ get_target_list(List *targetList, deparse_context *context,
trailing_nl + + ;
trailing_nl + + ;
/*
/*
* If the field we ' re adding is the first in the list , or it
* Add a newline , plus some indentation , if the new field is
* already has a leading newline , don ' t add anything . Otherwise ,
* not the first and either the new field would cause an
* add a newline , plus some indentation , if either the new field
* overflow or the last field used more than one line .
* would cause an overflow or the last field used more than one
* line .
*/
*/
if ( colno > 1 & &
if ( colno > 1 & &
leading_nl_pos = = - 1 & &
( ( strlen ( trailing_nl ) + targetbuf . len > context - > wrapColumn ) | |
( ( strlen ( trailing_nl ) + strlen ( targetbuf . data ) > context - > wrapColumn ) | |
last_was_multiline ) )
last_was_multiline ) )
appendContextKeyword ( context , " " , - PRETTYINDENT_STD ,
appendContextKeyword ( context , " " , - PRETTYINDENT_STD ,
PRETTYINDENT_STD , PRETTYINDENT_VAR ) ;
PRETTYINDENT_STD , PRETTYINDENT_VAR ) ;
}
/* Remember this field's multiline status for next iteration */
/* Remember this field's multiline status for next iteration */
last_was_multiline =
last_was_multiline =
@ -6236,23 +6237,42 @@ static void
appendContextKeyword ( deparse_context * context , const char * str ,
appendContextKeyword ( deparse_context * context , const char * str ,
int indentBefore , int indentAfter , int indentPlus )
int indentBefore , int indentAfter , int indentPlus )
{
{
StringInfo buf = context - > buf ;
if ( PRETTY_INDENT ( context ) )
if ( PRETTY_INDENT ( context ) )
{
{
context - > indentLevel + = indentBefore ;
context - > indentLevel + = indentBefore ;
appendStringInfoChar ( context - > buf , ' \n ' ) ;
/* remove any trailing spaces currently in the buffer ... */
appendStringInfoSpaces ( context - > buf ,
removeStringInfoSpaces ( buf ) ;
/* ... then add a newline and some spaces */
appendStringInfoChar ( buf , ' \n ' ) ;
appendStringInfoSpaces ( buf ,
Max ( context - > indentLevel , 0 ) + indentPlus ) ;
Max ( context - > indentLevel , 0 ) + indentPlus ) ;
appendStringInfoString ( context - > buf , str ) ;
appendStringInfoString ( buf , str ) ;
context - > indentLevel + = indentAfter ;
context - > indentLevel + = indentAfter ;
if ( context - > indentLevel < 0 )
if ( context - > indentLevel < 0 )
context - > indentLevel = 0 ;
context - > indentLevel = 0 ;
}
}
else
else
appendStringInfoString ( context - > buf , str ) ;
appendStringInfoString ( buf , str ) ;
}
}
/*
* removeStringInfoSpaces - delete trailing spaces from a buffer .
*
* Possibly this should move to stringinfo . c at some point .
*/
static void
removeStringInfoSpaces ( StringInfo str )
{
while ( str - > len > 0 & & str - > data [ str - > len - 1 ] = = ' ' )
str - > data [ - - ( str - > len ) ] = ' \0 ' ;
}
/*
/*
* get_rule_expr_paren - deparse expr using get_rule_expr ,
* get_rule_expr_paren - deparse expr using get_rule_expr ,
* embracing the string with parentheses if necessary for prettyPrint .
* embracing the string with parentheses if necessary for prettyPrint .
@ -7941,6 +7961,15 @@ get_from_clause(Query *query, const char *prefix, deparse_context *context)
/* Consider line-wrapping if enabled */
/* Consider line-wrapping if enabled */
if ( PRETTY_INDENT ( context ) & & context - > wrapColumn > = 0 )
if ( PRETTY_INDENT ( context ) & & context - > wrapColumn > = 0 )
{
/* Does the new item start with a new line? */
if ( itembuf . len > 0 & & itembuf . data [ 0 ] = = ' \n ' )
{
/* If so, we shouldn't add anything */
/* instead, remove any trailing spaces currently in buf */
removeStringInfoSpaces ( buf ) ;
}
else
{
{
char * trailing_nl ;
char * trailing_nl ;
@ -7952,12 +7981,14 @@ get_from_clause(Query *query, const char *prefix, deparse_context *context)
trailing_nl + + ;
trailing_nl + + ;
/*
/*
* Add a newline , plus some indentation , if the new item would
* Add a newline , plus some indentation , if the new item
* cause an overflow .
* would cause an overflow .
*/
*/
if ( strlen ( trailing_nl ) + strlen ( itembuf . data ) > context - > wrapColumn )
if ( strlen ( trailing_nl ) + itembuf . len > context - > wrapColumn )
appendContextKeyword ( context , " " , - PRETTYINDENT_STD ,
appendContextKeyword ( context , " " , - PRETTYINDENT_STD ,
PRETTYINDENT_STD , PRETTYINDENT_VAR ) ;
PRETTYINDENT_STD ,
PRETTYINDENT_VAR ) ;
}
}
}
/* Add the new item */
/* Add the new item */