use of org.h2.test.utils.AssertThrows in project h2database by h2database.
the class TestSynonymForTable method testCreateForUnknownTable.
private void testCreateForUnknownTable() throws SQLException {
Connection conn = getConnection("synonym");
Statement stat = conn.createStatement();
assertThrows(JdbcSQLException.class, stat).execute("CREATE SYNONYM someSynonym FOR nonexistingTable");
conn.close();
}
use of org.h2.test.utils.AssertThrows in project h2database by h2database.
the class TestSynonymForTable method testCreateOrReplaceExistingTable.
private void testCreateOrReplaceExistingTable() throws SQLException {
Connection conn = getConnection("synonym");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE IF NOT EXISTS backingtable(id INT PRIMARY KEY)");
assertThrows(JdbcSQLException.class, stat).execute("CREATE OR REPLACE SYNONYM backingtable FOR backingtable");
conn.close();
}
use of org.h2.test.utils.AssertThrows in project h2database by h2database.
the class TestSynonymForTable method testDropTable.
private void testDropTable() throws SQLException {
Connection conn = getConnection("synonym");
createTableWithSynonym(conn);
Statement stat = conn.createStatement();
stat.execute("DROP TABLE backingtable");
// Backing table does not exist anymore.
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
// Synonym should be dropped as well
ResultSet synonyms = conn.createStatement().executeQuery("SELECT * FROM INFORMATION_SCHEMA.SYNONYMS WHERE SYNONYM_NAME='TESTSYNONYM'");
assertFalse(synonyms.next());
conn.close();
// Reopening should work with dropped synonym
Connection conn2 = getConnection("synonym");
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
conn2.close();
}
use of org.h2.test.utils.AssertThrows in project h2database by h2database.
the class TestSynonymForTable method testDropSynonym.
private void testDropSynonym() throws SQLException {
Connection conn = getConnection("synonym");
createTableWithSynonym(conn);
Statement stat = conn.createStatement();
stat.execute("DROP SYNONYM testsynonym");
// Synonym does not exist anymore.
assertThrows(JdbcSQLException.class, stat).execute("SELECT id FROM testsynonym");
// Dropping with "if exists" should succeed even if the synonym does not exist anymore.
stat.execute("DROP SYNONYM IF EXISTS testsynonym");
// Without "if exists" the command should fail if the synonym does not exist.
assertThrows(JdbcSQLException.class, stat).execute("DROP SYNONYM testsynonym");
conn.close();
}
use of org.h2.test.utils.AssertThrows in project h2database by h2database.
the class TestView method testParameterizedView.
private void testParameterizedView() throws SQLException {
deleteDb("view");
Connection conn = getConnection("view");
Statement stat = conn.createStatement();
stat.execute("CREATE TABLE Test(id INT AUTO_INCREMENT NOT NULL, " + "f1 VARCHAR NOT NULL, f2 VARCHAR NOT NULL)");
stat.execute("INSERT INTO Test(f1, f2) VALUES ('value1','value2')");
stat.execute("INSERT INTO Test(f1, f2) VALUES ('value1','value3')");
PreparedStatement ps = conn.prepareStatement("CREATE VIEW Test_View AS SELECT f2 FROM Test WHERE f1=?");
ps.setString(1, "value1");
assertThrows(ErrorCode.FEATURE_NOT_SUPPORTED_1, ps).executeUpdate();
// ResultSet rs;
// rs = stat.executeQuery("SELECT * FROM Test_View");
// assertTrue(rs.next());
// assertFalse(rs.next());
// rs = stat.executeQuery("select VIEW_DEFINITION " +
// "from information_schema.views " +
// "where TABLE_NAME='TEST_VIEW'");
// rs.next();
// assertEquals("...", rs.getString(1));
conn.close();
}
Aggregations