सबसे पहले, पॉइंटर्स के लिए धन्यवाद! आंशिक जवाब इस प्रकार है ....
मैं अब तक क्या मिल गया है ... पहले कुछ मचान:
# Connect to our db through DBIx::Class
my $schema = My::Schema->connect('dbi:SQLite:/home/me/accounts.db');
# See also BEGIN { $ENV{DBIC_TRACE} = 1 }
$schema->storage->debug(1);
# Create an instance of our subclassed (see below)
# DBIx::Class::Storage::Statistics class
my $stats = My::DBIx::Class::Storage::Statistics->new();
# Set the debugobj object on our schema's storage
$schema->storage->debugobj($stats);
और होने का मेरे :: DBIx :: कक्षा :: भंडारण :: सांख्यिकी परिभाषा :
package My::DBIx::Class::Storage::Statistics;
use base qw<DBIx::Class::Storage::Statistics>;
use Data::Dumper qw<Dumper>;
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->new();
my $stmt = SQL::Statement->new($sql_query, $parser);
#printf "%s\n", $stmt->command;
print "The parameters for this query are:";
print Dumper \@params;
}
कौन कैसे में हुक करने के लिए "बहुत-ify" मेरे लिए SQL क्वेरी प्राप्त करने के बारे समस्या का हल।
my $rs = $schema->resultset('SomeTable')->search(
{
'email' => $email,
'others.some_col' => 1,
},
{ join => 'others' }
);
$rs->count;
हालांकि एसक्यूएल :: पार्सर DBIx :: क्लास द्वारा उत्पन्न एसक्यूएल पर barfs:
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
तो ... वहाँ से एक बेहतर पार्सर है
तब मैं क्वेरी चलाने एसक्यूएल :: नौकरी के लिए पार्सर?
मैं दो मॉडलों को हल करने के लिए इस मॉड्यूल का उपयोग करता हूं, 1) प्रदर्शित क्वेरी को ट्रेस के माध्यम से एक विशिष्ट सबराउटिन से लिंक करें, और 2) सुंदर प्रिंट: https://gist.github.com/jar-o/25ba571709de15a83361 – jar