[Dbix-class] Get generated SQL

Mark Lawrence nomad at null.net
Wed Mar 12 16:59:13 GMT 2008


On Wed Mar 12, 2008 at 04:20:16PM +0000, Matt Lawrence wrote:
> Mark Lawrence wrote:
> >On Wed Mar 12, 2008 at 03:37:33PM +0000, Matt Lawrence wrote:
> >  
> >>Mark Lawrence wrote:
> >>    
> >>>On Wed Mar 12, 2008 at 12:30:14PM +0000, Matt Lawrence wrote:
> 
> >>>>I guess I could add a failsafe to trap unprintable values still present 
> >>>>after quote() and replace them with dummy values as in your previous 
> >>>>example.
> >>>>
> >>>>  # Store quoted versions of the values
> >>>>  my @bind_vals = map {
> >>>>      $_ = $storage->dbh->quote($_->[1], shift @$datatypes);
> >>>>      $_ = $storage->dbh->quote('*BINARY DATA*') if /[^[:print:]\n\t]/;
> >>>>      $_;
> >>>>  } @$bind;
> >>>>
> >>>>   
> >>>>        
> >>>You don't need to care about newlines or tabs (in fact if you
> >>>specifically search for that you might not find what you are looking
> >>>for), you just want to know if it contains non-printable data:
> >>>
> >>>  $_ = $storage->dbh->quote('*BINARY DATA*') if /[^[:print:]]/;
> >>> 
> >>>      
> >>Newlines and tabs won't mess up terminals and they are not matched by 
> >>[:print:].
> >>    
> >
> >Take another look at what you are doing above. In plain english you are
> >looking for an unprintable character followed by a newline followed by a
> >tab. What happens if your data is "???ABC\n\t" where ??? are the
> >unprintable characters? Ie, the data is not terminated by non-printables.
> >That won't match your regex. And the newline and tab are anyway not
> >being replaced in that statement - you are setting the whole string to
> >'*BINARY DATA*' (which btw probably doesn't need to be quoted by DBI).
> >  
> Nope, the \n\t was inside the (negated) character class. It matches if 
> the string contains any character which is not printable, a newline or a 
> tab.

Sorry, my bad. However I'm still wondering why you want to replace text
that contains newlines or tabs by the string BINARY DATA. They are
certainly printable. The type of queries that I typically want to debug
are well and truly already longer than a single line anyway.

> I take your point about the quoting, there's no point trying to make 
> something keep it being valid SQL
> 
> How about this:
> 
>  my @bind_vals = map {
>      my $data_type = shift @$datatypes;
>      $_[1] =~ /[^[:print:]\n\t]/ ? '*BINARY DATA*' : 
>      $storage->dbh->quote($_[1], $data_type)
>  } @$bind;

[disclaimer: I am not a contributor to CDBI and don't know the standards]
but how about this for clarity:

  my @bind_vals = map {
      my $data_type = shift @$datatypes;
      $_[1] =~ /[^[:print:]]/
          ? '*BINARY DATA*'
          : $storage->dbh->quote($_[1], $data_type)
  } @$bind;

Mark.
-- 
Mark Lawrence



More information about the DBIx-Class mailing list