Hi Thomas and Noel,

The attached patch implements the GRANT SCHEMA feature, which is present in
the roadmap priority 2 features. I'll try to contribute with some of those
features. Besides, let me know if you think there's some feature more
interesting at moment, maybe I can help.

Regards,

Fred

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/fred/Dropbox/h2-trunk/trunk/h2/src/main/org/h2/command
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: Parser.java
--- Parser.java Base (BASE)
+++ Parser.java Modificado Localmente (Baseado em LOCAL)
@@ -4252,12 +4252,20 @@
         }
         if (tableClauseExpected) {
             if (readIf("ON")) {
+                if (readIf("SCHEMA")){
+                    Schema schema = database.getSchema(currentToken);
+                    for (Table table: schema.getAllTablesAndViews()){
+                        command.addTable(table);
+                    }
+                    read();
+                }else{
                 do {
                     Table table = readTableOrView();
                     command.addTable(table);
                 } while (readIf(","));
             }
         }
+        }
         if (operationType == CommandInterface.GRANT) {
             read("TO");
         } else {
# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: /home/fred/Dropbox/h2-trunk/trunk/h2/src/test
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: org/h2/test/db/TestRights.java
--- org/h2/test/db/TestRights.java Base (BASE)
+++ org/h2/test/db/TestRights.java Modificado Localmente (Baseado em LOCAL)
@@ -36,6 +36,8 @@
     public void test() throws SQLException {
         testLinkedTableMeta();
         testGrantMore();
+        testGrantSchema();
+        testRevokeSchema();
         testOpenNonAdminWithMode();
         testDisallowedTables();
         testDropOwnUser();
@@ -111,6 +113,106 @@
         conn.close();
     }
 
+    private void testGrantSchema() throws SQLException {
+        deleteDb("rights");
+        Connection conn = getConnection("rights");
+        stat = conn.createStatement();
+        stat.execute("create role new_role");
+        stat.execute("create table test1(id int)");
+        stat.execute("create table test2(id int)");
+        stat.execute("create table test3(id int)");
+        stat.execute("grant select on schema public to new_role");
+        ResultSet rs = stat.executeQuery(
+                "select * from information_schema.table_privileges order by table_name, privilege_type");
+        assertTrue(rs.next());
+        assertEquals("TEST1", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST2", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST3", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertFalse(rs.next());
+        stat.execute("grant insert on schema public to new_role");
+        rs = stat.executeQuery(
+                "select * from information_schema.table_privileges order by table_name, privilege_type");
+        assertTrue(rs.next());
+        assertEquals("TEST1", rs.getString("table_name"));
+        assertEquals("INSERT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST1", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST2", rs.getString("table_name"));
+        assertEquals("INSERT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST2", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST3", rs.getString("table_name"));
+        assertEquals("INSERT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST3", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));       
+        assertFalse(rs.next());
+        stat.execute("drop table test1");
+        stat.execute("drop table test2");
+        stat.execute("drop table test3");
+        stat.execute("drop role new_role");
+        conn.close();
+    }
+    
+    private void testRevokeSchema() throws SQLException {
+        deleteDb("rights");
+        Connection conn = getConnection("rights");
+        stat = conn.createStatement();
+        stat.execute("create role new_role");
+        stat.execute("create table test1(id int)");
+        stat.execute("create table test2(id int)");
+        stat.execute("create table test3(id int)");
+        stat.execute("grant insert,select on schema public to new_role");
+        ResultSet rs = stat.executeQuery(
+                "select * from information_schema.table_privileges order by table_name, privilege_type");
+        assertTrue(rs.next());
+        assertEquals("TEST1", rs.getString("table_name"));
+        assertEquals("INSERT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST1", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST2", rs.getString("table_name"));
+        assertEquals("INSERT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST2", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST3", rs.getString("table_name"));
+        assertEquals("INSERT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST3", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));       
+        assertFalse(rs.next());
+        stat.execute("revoke insert on schema public from new_role");
+        rs = stat.executeQuery(
+                "select * from information_schema.table_privileges order by table_name, privilege_type");
+        assertTrue(rs.next());
+        assertEquals("TEST1", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST2", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));
+        assertTrue(rs.next());
+        assertEquals("TEST3", rs.getString("table_name"));
+        assertEquals("SELECT", rs.getString("privilege_type"));       
+        assertFalse(rs.next());
+        stat.execute("drop table test1");
+        stat.execute("drop table test2");
+        stat.execute("drop table test3");
+        stat.execute("drop role new_role");
+        conn.close();
+    }
+
     private void testOpenNonAdminWithMode() throws SQLException {
         if (config.memory) {
             return;

Reply via email to