pgFormatter::Beautify(3pm) | User Contributed Perl Documentation | pgFormatter::Beautify(3pm) |
pgFormatter::Beautify - Library for pretty-printing SQL queries
Version 5.5
This module can be used to reformat given SQL query, optionally anonymizing parameters.
Output can be either plain text, or it can be HTML with appropriate styles so that it can be displayed on a web page.
Example usage:
my $beautifier = pgFormatter::Beautify->new(); $beautifier->query( 'select a,b,c from d where e = f' ); $beautifier->beautify(); my $nice_txt = $beautifier->content(); $beautifier->format('html'); $beautifier->beautify(); my $nice_html = $beautifier->content(); $beautifier->format('html'); $beautifier->anonymize(); $beautifier->beautify(); my $nice_anonymized_html = $beautifier->content(); $beautifier->format(); $beautifier->beautify(); $beautifier->wrap_lines() my $wrapped_txt = $beautifier->content();
Generic constructor - creates object, sets defaults, and reads config from given hash with options.
Takes options as hash. Following options are recognized:
For defaults, please check function set_defaults.
Accessor to query string. Both reads:
$object->query()
, and writes
$object->query( $something )
Accessor to content of results. Must be called after $object->beautify().
This can be either plain text or html following the format asked by the client with the $object->format() method.
Makes result html with styles set for highlighting.
Splits input SQL into tokens
Code lifted from SQL::Beautify
Beautify SQL.
After calling this function, $object->content() will contain nicely indented result.
Code lifted from SQL::Beautify
Add a token to the beautified string.
Code lifted from SQL::Beautify
Increase the indentation level.
Code lifted from SQL::Beautify
Decrease the indentation level.
Code lifted from SQL::Beautify
Return a string of spaces according to the current indentation level and the spaces setting for indenting.
Code lifted from SQL::Beautify
Add a line break, but make sure there are no empty lines.
Code lifted from SQL::Beautify
Have a look at the token that's coming up next.
Code lifted from SQL::Beautify
Get the next token, removing it from the list of remaining tokens.
Code lifted from SQL::Beautify
Check if a token is a known SQL keyword.
Code lifted from SQL::Beautify
Check if a token is a known SQL type
Check if a token is a SQL or C style comment
Check if a token is a known SQL function.
Code lifted from SQL::Beautify and rewritten to check one long regexp instead of a lot of small ones.
Add new keywords to highlight.
Code lifted from SQL::Beautify
Create compiled regexp from prefix, suffix and and a list of values to match.
Refresh compiled regexp for functions.
Add new functions to highlight.
Code lifted from SQL::Beautify
Add new rules.
Code lifted from SQL::Beautify
Find custom rule for a token.
Code lifted from SQL::Beautify
Applies defined rule.
Code lifted from SQL::Beautify
Check if a token is a constant.
Code lifted from SQL::Beautify
Check if a token is punctuation.
Code lifted from SQL::Beautify
Simply generate a random string, thanks to Perlmonks.
Returns original in certain cases which don't require anonymization, like timestamps, or intervals.
Anonymize litteral in SQL queries by replacing parameters with fake values
Sets defaults for newly created objects.
Currently defined defaults:
Set output format - possible values: 'text' and 'html'
Default is text output. Returns 0 in case or wrong format and use default.
Sets various dictionaries (lists of keywords, functions, symbols, and the like)
This was moved to separate function, so it can be put at the very end of module so it will be easier to read the rest of the code.
Internal function used to hide dynamic code in plpgsql to the parser. The original values are restored with function _restore_dynamic_code().
Internal function used to restore plpgsql dynamic code in plpgsql that was removed by the _remove_dynamic_code() method.
Internal function used to quote operator with multiple character to be tokenized as a single word. The original values are restored with function _restore_operator().
Internal function used to restore operator that was removed by the _quote_operator() method.
Internal function used to replace constant in a COMMENT statement to be tokenized as a single word. The original values are restored with function _restore_comment_stmt().
Internal function used to restore comment string that was removed by the _quote_comment_stmt() method.
Internal function used to remove comments in SQL code to simplify the work of the wrap_lines. Comments must be restored with the _restore_comments() method.
Internal function used to restore comments in SQL code that was removed by the _remove_comments() method.
Internal function used to wrap line at a certain length.
pgFormatter is an original work from Gilles Darold
Please report any bugs or feature requests to: https://github.com/darold/pgFormatter/issues
Copyright 2012-2023 Gilles Darold. All rights reserved.
pgFormatter is free software distributed under the PostgreSQL Licence.
A modified version of the SQL::Beautify Perl Module is embedded in pgFormatter with copyright (C) 2009 by Jonas Kramer and is published under the terms of the Artistic License 2.0.
2023-02-05 | perl v5.36.0 |