DBIx-Custom icon indicating copy to clipboard operation
DBIx-Custom copied to clipboard

Wierd space bugs in Some MySQL version

Open yuki-kimoto opened this issue 2 years ago • 0 comments

I find Wierd space bugs in Some MySQL version. I memo it.

The following fix the bugs.

sub execute {
  my $self = shift;
  my $sql = shift;
  
  # Options
  my $param;
  $param = shift if @_ % 2;
  $param ||= {};
  my %opt = @_;
  
  # Append
  $sql .= $opt{append} if defined $opt{append};
  
  # Parse named place holder
  my $safe_char = $self->{safety_character};
  my $place_holder_re = $safe_char eq 'a-zA-Z0-9_'
    ? qr/(.*?[^\\]):([$safe_char\.]+)(?:\{(.*?)\})?(.*)/so
    : qr/(.*?[^\\]):([$safe_char\.]+)(?:\{(.*?)\})?(.*)/s;
  my $source_sql = $sql;
  $source_sql =~ s/([0-9]):/$1\\:/g;
  my $parsed_sql = '';
  my $columns;
  while ($source_sql =~ /$place_holder_re/) {
    push @$columns, $2;
    ($parsed_sql, $source_sql) = defined $3 ?
      ($parsed_sql . "$1$2 $3 ?", "$4") : ($parsed_sql . "$1?", "$4");
  }
  
  $parsed_sql .= $source_sql;
  $parsed_sql =~ s/\\:/:/g if index($parsed_sql, "\\:") != -1;

yuki-kimoto avatar Dec 15 '21 07:12 yuki-kimoto