From: Arthur Axel "fREW" Schmidt Date: Sat, 23 Oct 2010 17:05:00 +0000 (+0000) Subject: Highlight transaction keywords X-Git-Tag: v1.70~25 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=820bb1f5b8926c8c8c4c34ed99c057abfb8fe105;p=dbsrgits%2FSQL-Abstract.git Highlight transaction keywords --- diff --git a/Changes b/Changes index 1423ac9..45f40be 100644 --- a/Changes +++ b/Changes @@ -1,6 +1,7 @@ Revision history for SQL::Abstract - Hide bulk inserts from DBIx::Class + - Highlight transaction keywords revision 1.69 2010-10-22 ---------------------------- diff --git a/examples/console.pl b/examples/console.pl index 48fd5ec..61e5dee 100644 --- a/examples/console.pl +++ b/examples/console.pl @@ -5,6 +5,7 @@ use SQL::Abstract::Tree; my $sqlat = SQL::Abstract::Tree->new({ profile => 'console' }); my @sql = ( + "BEGIN WORK", "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'", @@ -17,7 +18,11 @@ my @sql = ( "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", - + "COMMIT", + 'ROLLBACK', + 'SAVEPOINT station', + 'ROLLBACK TO SAVEPOINT station', + 'RELEASE SAVEPOINT station', ); print "\n\n'" . $sqlat->format($_) . "'\n" for @sql; diff --git a/lib/SQL/Abstract/Tree.pm b/lib/SQL/Abstract/Tree.pm index 43c5fb7..daf0ae9 100644 --- a/lib/SQL/Abstract/Tree.pm +++ b/lib/SQL/Abstract/Tree.pm @@ -76,6 +76,12 @@ my @expression_start_keywords = ( 'UNION', 'INTERSECT', 'EXCEPT', + 'BEGIN \s+ WORK', + 'COMMIT', + 'ROLLBACK \s+ TO \s+ SAVEPOINT', + 'ROLLBACK', + 'SAVEPOINT', + 'RELEASE \s+ SAVEPOINT', 'RETURNING', 'ROW_NUMBER \s* \( \s* \) \s+ OVER', ); @@ -175,6 +181,13 @@ my %profiles = ( ( placeholder_surround => [q(') . $c->('black on_magenta'), $c->('reset') . q(')], colormap => { + 'begin work' => [$c->('black on_white'), $c->('reset')], + commit => [$c->('black on_white'), $c->('reset')], + rollback => [$c->('black on_white'), $c->('reset')], + savepoint => [$c->('black on_white'), $c->('reset')], + 'rollback to savepoint' => [$c->('black on_white'), $c->('reset')], + 'release savepoint' => [$c->('black on_white'), $c->('reset')], + select => [$c->('red'), $c->('reset')], 'insert into' => [$c->('red'), $c->('reset')], update => [$c->('red'), $c->('reset')], @@ -239,6 +252,13 @@ my %profiles = ( first => ['', ''], limit => ['', ''], offset => ['', ''], + + 'begin work' => ['', ''], + commit => ['', ''], + rollback => ['', ''], + savepoint => ['', ''], + 'rollback to savepoint' => ['', ''], + 'release savepoint' => ['', ''], }, indentmap => { %indents }, },