Skip to content

Commit

Permalink
Add tests for schema name containing special characters
Browse files Browse the repository at this point in the history
  • Loading branch information
sehrope committed Oct 14, 2014
1 parent e708385 commit 169c6df
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions org/postgresql/test/jdbc4/jdbc41/SchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ protected void setUp() throws Exception
Statement stmt = _conn.createStatement();
stmt.execute("CREATE SCHEMA schema1");
stmt.execute("CREATE SCHEMA schema2");
stmt.execute("CREATE SCHEMA \"schema 3\"");
stmt.execute("CREATE SCHEMA \"schema \"\"4\"");
stmt.execute("CREATE SCHEMA \"schema '5\"");
stmt.execute("CREATE SCHEMA \"UpperCase\"");
TestUtil.createTable(_conn, "schema1.table1", "id integer");
TestUtil.createTable(_conn, "schema2.table2", "id integer");
TestUtil.createTable(_conn, "\"UpperCase\".table3", "id integer");
}

protected void tearDown() throws SQLException
Expand All @@ -41,6 +46,10 @@ protected void tearDown() throws SQLException
Statement stmt = _conn.createStatement();
stmt.execute("DROP SCHEMA schema1 CASCADE");
stmt.execute("DROP SCHEMA schema2 CASCADE");
stmt.execute("DROP SCHEMA \"schema 3\" CASCADE");
stmt.execute("DROP SCHEMA \"schema \"\"4\" CASCADE");
stmt.execute("DROP SCHEMA \"schema '5\" CASCADE");
stmt.execute("DROP SCHEMA \"UpperCase\" CASCADE");
TestUtil.closeDB(_conn);
}

Expand All @@ -53,6 +62,14 @@ public void testGetSetSchema() throws SQLException
assertEquals("schema1", _conn.getSchema());
_conn.setSchema("schema2");
assertEquals("schema2", _conn.getSchema());
_conn.setSchema("schema 3");
assertEquals("\"schema 3\"", _conn.getSchema());
_conn.setSchema("schema \"4");
assertEquals("\"schema \"\"4\"", _conn.getSchema());
_conn.setSchema("schema '5");
assertEquals("\"schema '5\"", _conn.getSchema());
_conn.setSchema("UpperCase");
assertEquals("\"UpperCase\"", _conn.getSchema());
}

/**
Expand Down Expand Up @@ -92,6 +109,19 @@ public void testUsingSchema() throws SQLException
{
// expected
}

_conn.setSchema("UpperCase");
stmt.executeQuery(TestUtil.selectSQL("table3", "*"));
stmt.executeQuery(TestUtil.selectSQL("schema1.table1", "*"));
try
{
stmt.executeQuery(TestUtil.selectSQL("table1", "*"));
fail("Objects of schema1 should not be visible without prefix");
}
catch (SQLException e)
{
// expected
}
}
catch (SQLException e)
{
Expand Down

0 comments on commit 169c6df

Please sign in to comment.