Enhanced placeholder/argument check algorithm

This commit is contained in:
Dave Morriss 2025-05-07 17:21:29 +01:00
parent 586c8e537e
commit bf8f6db45c
3 changed files with 18 additions and 14 deletions

View File

@ -21,7 +21,7 @@
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
# VERSION: 0.0.4
# CREATED: 2015-07-11 15:53:01
# REVISION: 2025-05-06 21:12:08
# REVISION: 2025-05-07 17:20:00
#
#===============================================================================
@ -136,8 +136,10 @@ else {
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
#
# Count placeholders in the query and the arguments provided
# Count placeholders in the query and the arguments provided. First remove all
# comments which may contain '?' characters, then count any that are left.
#
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
$pcount = grep {/\?/} split( '', $query );
$acount = scalar(@dbargs);

View File

@ -20,7 +20,7 @@
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
# VERSION: 0.0.3
# CREATED: 2021-06-18 13:24:49
# REVISION: 2025-05-07 09:50:34
# REVISION: 2025-05-07 17:20:07
#
#===============================================================================
@ -132,8 +132,10 @@ else {
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
#
# Count placeholders in the query and the arguments provided
# Count placeholders in the query and the arguments provided. First remove all
# comments which may contain '?' characters, then count any that are left.
#
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
$pcount = grep {/\?/} split( '', $query );
$acount = scalar(@dbargs);
@ -212,9 +214,9 @@ catch ($e) {
}
#
# Prepare for JSON, forcing object key sorting (expensive)
# Prepare for JSON, forcing object key sorting (expensive), and prettification
#
$json = JSON->new->utf8->canonical;
$json = JSON->new->utf8->canonical->pretty;
#
# Grab everything as an arrayref of hashrefs
@ -391,7 +393,7 @@ This documentation refers to query2json version 0.0.3
=head1 USAGE
query2json [-help] [-documentation|-man] [-debug=N] [-config=FILE]
[-query=FILE] [-output=FILE] [-[no]header] [QUERY]
[-query=FILE] [-output=FILE] [QUERY]
=head1 OPTIONS
@ -461,11 +463,6 @@ these placeholders can be passed to the script through the B<-dbarg=ARG>
option. The option can be repeated as many times as required and the order of
B<ARG> values is preserved.
=item B<-[no-]header>
This option allows a header to be added to the CSV output with the names of
the database columns in CSV format. By default this is not produced.
=back
=head1 DESCRIPTION

View File

@ -28,7 +28,7 @@
# AUTHOR: Dave Morriss (djm), Dave.Morriss@gmail.com
# VERSION: 0.0.8
# CREATED: 2021-06-18 13:24:49
# REVISION: 2025-05-06 16:39:25
# REVISION: 2025-05-07 17:19:15
#
#===============================================================================
@ -164,11 +164,16 @@ else {
_debug( $DEBUG >= 3, '$query: ' . Dumper(\$query) );
#
# Count placeholders in the query and the arguments provided
# Count placeholders in the query and the arguments provided. First remove all
# comments which may contain '?' characters, then count any that are left.
#
$query = join("\n", grep {!/^--/} split( "\n", $query ) );
$pcount = grep {/\?/} split( '', $query );
$acount = scalar(@dbargs);
#
# Check the placeholder and argument counts are the same
#
if ( $pcount ne $acount) {
say STDERR "Query placeholder vs argument mismatch";
say STDERR "Placeholders = $pcount, Arguments = $acount";