[Bast-commits] r9692 - in SQL-Abstract/1.x/trunk: . examples lib lib/DBIx lib/DBIx/Class lib/DBIx/Class/Storage

frew at dev.catalyst.perl.org frew at dev.catalyst.perl.org
Mon Sep 6 23:29:38 GMT 2010


Author: frew
Date: 2010-09-07 00:29:38 +0100 (Tue, 07 Sep 2010)
New Revision: 9692

Added:
   SQL-Abstract/1.x/trunk/examples/
   SQL-Abstract/1.x/trunk/examples/console.pl
   SQL-Abstract/1.x/trunk/lib/DBIx/
   SQL-Abstract/1.x/trunk/lib/DBIx/Class/
   SQL-Abstract/1.x/trunk/lib/DBIx/Class/Storage/
   SQL-Abstract/1.x/trunk/lib/DBIx/Class/Storage/PrettyPrinter.pm
Modified:
   SQL-Abstract/1.x/trunk/Makefile.PL
Log:
add examples and DBIC::Storage::PrettyPrinter

Modified: SQL-Abstract/1.x/trunk/Makefile.PL
===================================================================
--- SQL-Abstract/1.x/trunk/Makefile.PL	2010-09-06 23:26:04 UTC (rev 9691)
+++ SQL-Abstract/1.x/trunk/Makefile.PL	2010-09-06 23:29:38 UTC (rev 9692)
@@ -18,6 +18,9 @@
 test_requires "Test::Warn"      => 0;
 test_requires "Storable"        => 0;   # for cloning in tests
 
+no_index package => 'DBIx::Class::Storage::PrettyPrinter';
+no_index directory => 'examples';
+
 tests_recursive 't';
 
 WriteAll();

Added: SQL-Abstract/1.x/trunk/examples/console.pl
===================================================================
--- SQL-Abstract/1.x/trunk/examples/console.pl	                        (rev 0)
+++ SQL-Abstract/1.x/trunk/examples/console.pl	2010-09-06 23:29:38 UTC (rev 9692)
@@ -0,0 +1,20 @@
+#!/sur/bin/env perl
+
+use SQL::Abstract::Tree;
+
+my $sqlat = SQL::Abstract::Tree->new({ profile => 'console' });
+
+my @sql = (
+   "SELECT a, b, c FROM foo WHERE foo.a =1 and foo.b LIKE 'station'",
+   "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'",
+   "SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'",
+   "UPDATE session SET expires = ?  WHERE (id = ?)",
+   "INSERT INTO Request (creation_date, is_private, owner_id, request) VALUES (? , ? , ? , ?)",
+   "SELECT [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype] FROM [users_roles] [me] JOIN [roles] [role] ON [role].[id] = [me].[role_id] JOIN [roles_permissions] [role_permissions] ON [role_permissions].[role_id] = [role].[id] JOIN [permissions] [permission] ON [permission].[id] = [role_permissions].[permission_id] JOIN [permissionscreens] [permission_screens] ON [permission_screens].[permission_id] = [permission].[id] JOIN [screens] [screen] ON [screen].[id] = [permission_screens].[screen_id] WHERE ( [me].[user_id] = ? ) GROUP BY [screen].[id], [screen].[name], [screen].[section_id], [screen].[xtype]",
+   "SELECT [status], [supplier_id], [ship_to_supplier_id], [request_by_user_id], [is_printed], [creation_date], [id], [date], [fob_state], [is_confirmed], [is_outside_process], [ship_via], [special_instructions], [when_shipped] FROM ( SELECT [status], [supplier_id], [ship_to_supplier_id], [request_by_user_id], [is_printed], [creation_date], [id], [date], [fob_state], [is_confirmed], [is_outside_process], [ship_via], [special_instructions], [when_shipped], ROW_NUMBER() OVER(  ORDER BY [me].[id] DESC ) AS [rno__row__index] FROM ( SELECT [me].[status], [me].[supplier_id], [me].[ship_to_supplier_id], [me].[request_by_user_id], [me].[is_printed], [me].[creation_date], [me].[id], [me].[date], [me].[fob_state], [me].[is_confirmed], [me].[is_outside_process], [me].[ship_via], [me].[special_instructions], [me].[when_shipped] FROM [PurchaseOrders] [me] WHERE ( [me].[status] = ? ) ) [me] ) [me] WHERE [rno__row__index] BETWEEN 1 AND 25",
+   "SELECT me.id, me.name, me.creator_id, group_users.group_id, group_users.user_id, user.id, user.first_name, user.last_name, user.nickname, user.email, user.password, user.is_active, user.logins FROM Group me LEFT JOIN GroupUser group_users ON group_users.group_id = me.id LEFT JOIN User user ON user.id = group_users.user_id WHERE (me.creator_id = ?) ORDER BY name, group_users.group_id",
+
+);
+
+print "\n\n" . $sqlat->format($_) . "\n" for @sql;
+

Added: SQL-Abstract/1.x/trunk/lib/DBIx/Class/Storage/PrettyPrinter.pm
===================================================================
--- SQL-Abstract/1.x/trunk/lib/DBIx/Class/Storage/PrettyPrinter.pm	                        (rev 0)
+++ SQL-Abstract/1.x/trunk/lib/DBIx/Class/Storage/PrettyPrinter.pm	2010-09-06 23:29:38 UTC (rev 9692)
@@ -0,0 +1,29 @@
+package DBIx::Class::Storage::PrettyPrinter;
+
+use base 'DBIx::Class::Storage::Statistics';
+
+use SQL::Abstract::Tree;
+
+__PACKAGE__->mk_group_accessors( simple => '_sqlat' );
+
+sub new {
+	my $class = shift;
+
+	my $sqlat = SQL::Abstract::Tree->new(shift @_);
+	my $self = $class->next::method(@_);
+
+	$self->_sqlat($sqlat);
+
+	return $self
+}
+
+sub query_start {
+  my $self = shift;
+  my $string = shift;
+
+  my $formatted = $self->_sqlat->format($string);
+
+  $self->next::method($formatted, @_);
+}
+
+1;




More information about the Bast-commits mailing list