7 use SQL::Abstract::Tree;
9 my $sqlat = SQL::Abstract::Tree->new;
11 cmp_deeply($sqlat->parse("SELECT a, b.*, * FROM foo WHERE foo.a =1 and foo.b LIKE 'station'"), [
97 ], 'simple statement parsed correctly');
99 cmp_deeply($sqlat->parse( "SELECT * FROM (SELECT * FROM foobar) WHERE foo.a =1 and foo.b LIKE 'station'"), [
191 ], 'subquery statement parsed correctly');
193 cmp_deeply($sqlat->parse("SELECT * FROM lolz WHERE ( foo.a =1 ) and foo.b LIKE 'station'"), [
267 ], 'simple statement with parens in where parsed correctly');
269 cmp_deeply($sqlat->parse( "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]"), [
303 "[screen].[section_id]"
386 "[roles_permissions]"
408 "[role_permissions].[role_id]"
457 "[role_permissions].[permission_id]"
472 "[permissionscreens]"
478 "[permission_screens]"
494 "[permission_screens].[permission_id]"
543 "[permission_screens].[screen_id]"
600 "[screen].[section_id]"
613 ], 'real life statement 1 parsed correctly');
615 cmp_deeply($sqlat->parse("SELECT x, y FROM foo WHERE x IN (?, ?, ?, ?)"), [
701 ], 'Lists parsed correctly');
703 # test for recursion warnings on huge selectors
705 my $sql = sprintf 'SELECT %s FROM foo', join (', ', map { qq|"$_"| } 'aa' .. 'zz' );
706 my $tree = $sqlat->parse($sql);
715 map { [ "LITERAL", [ qq|"$_"| ] ] } ('aa' .. 'zz')
731 ], 'long list parsed correctly');
733 is( $sqlat->unparse($tree), $sql, 'roundtrip ok');
734 } [], 'no recursion warnings on insane SQL';