Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First, thanks for the pointers! Partial answer follows ....</p> <p>What I've got so far ... first some scaffolding:</p> <pre><code># Connect to our db through DBIx::Class my $schema = My::Schema-&gt;connect('dbi:SQLite:/home/me/accounts.db'); # See also BEGIN { $ENV{DBIC_TRACE} = 1 } $schema-&gt;storage-&gt;debug(1); # Create an instance of our subclassed (see below) # DBIx::Class::Storage::Statistics class my $stats = My::DBIx::Class::Storage::Statistics-&gt;new(); # Set the debugobj object on our schema's storage $schema-&gt;storage-&gt;debugobj($stats); </code></pre> <p>And the definition of My::DBIx::Class::Storage::Statistics being:</p> <pre><code>package My::DBIx::Class::Storage::Statistics; use base qw&lt;DBIx::Class::Storage::Statistics&gt;; use Data::Dumper qw&lt;Dumper&gt;; use SQL::Statement; use SQL::Parser; sub query_start { my ($self, $sql_query, @params) = @_; print "The original sql query is\n$sql_query\n\n"; my $parser = SQL::Parser-&gt;new(); my $stmt = SQL::Statement-&gt;new($sql_query, $parser); #printf "%s\n", $stmt-&gt;command; print "The parameters for this query are:"; print Dumper \@params; } </code></pre> <p>Which solves the problem about how to hook in to get the SQL query for me to "pretty-ify".</p> <p>Then I run a query:</p> <pre><code>my $rs = $schema-&gt;resultset('SomeTable')-&gt;search( { 'email' =&gt; $email, 'others.some_col' =&gt; 1, }, { join =&gt; 'others' } ); $rs-&gt;count; </code></pre> <p>However SQL::Parser barfs on the SQL generated by DBIx::Class:</p> <pre><code>The original sql query is SELECT COUNT( * ) FROM some_table me LEFT JOIN others other_table ON ( others.some_col_id = me.id ) WHERE ( others.some_col_id = ? AND email = ? ) SQL ERROR: Bad table or column name '(others' has chars not alphanumeric or underscore! SQL ERROR: No equijoin condition in WHERE or ON clause </code></pre> <p>So ... is there a better parser than SQL::Parser for the job?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload