📄 testschemaparse.java
字号:
execSQL( pref + "ALTER TABLE constrainedtbl ADD CONSTRAINT con2 CHECK (i6 > 4)", expect); execSQL( "ALTER " + pref + "TABLE constrainedtbl ADD CONSTRAINT con3 CHECK (i6 > 4)", expect); execSQL("ALTER TABLE constrainedtbl " + pref + "ADD CONSTRAINT con4 CHECK (i6 > 4)", expect); execSQL( "ALTER TABLE constrainedtbl ADD CONSTRAINT con1 CHECK (i6 > 4)", true); // setup execSQL( "ALTER TABLE constrainedtbl ADD CONSTRAINT con2 CHECK (i6 > 4)", true); // setup execSQL( "ALTER TABLE constrainedtbl ADD CONSTRAINT con3 CHECK (i6 > 4)", true); // setup execSQL( "ALTER TABLE constrainedtbl ADD CONSTRAINT con4 CHECK (i6 > 4)", true); // setup execSQL("ALTER TABLE constrainedtbl ADD " + pref + "CONSTRAINT con5 CHECK (i6 > 4)", expect); execSQL("ALTER TABLE constrainedtbl ADD CONSTRAINT con6 " + pref + "CHECK (i6 > 4)", expect); execSQL("ALTER TABLE constrainedtbl DROP CONSTRAINT ucons", true); // reset execSQL( pref + "ALTER TABLE constrainedtbl ADD CONSTRAINT ucons UNIQUE (i6)", expect); execSQL("ALTER TABLE constrainedtbl DROP CONSTRAINT ucons", true); // reset execSQL( "ALTER " + pref + "TABLE constrainedtbl ADD CONSTRAINT ucons UNIQUE (i6)", expect); execSQL("ALTER TABLE constrainedtbl DROP CONSTRAINT ucons", true); // reset execSQL("ALTER TABLE constrainedtbl " + pref + "ADD CONSTRAINT ucons UNIQUE (i6)", expect); execSQL("ALTER TABLE constrainedtbl DROP CONSTRAINT ucons", true); // reset execSQL("ALTER TABLE constrainedtbl ADD " + pref + "CONSTRAINT ucons UNIQUE (i6)", expect); execSQL("ALTER TABLE constrainedtbl DROP CONSTRAINT ucons", true); // reset execSQL("ALTER TABLE constrainedtbl ADD CONSTRAINT ucons " + pref + "UNIQUE (i6)", expect); execSQL("ALTER TABLE constrainedtbl ADD CONSTRAINT ucons UNIQUE (i6)", true); // reset execSQL(pref + "ALTER TABLE playtbl RENAME TO renamedtbl", expect); execSQL("ALTER TABLE renamedtbl RENAME TO playtbl", true); // reset execSQL("ALTER " + pref + "TABLE playtbl RENAME TO renamedtbl", expect); execSQL("ALTER TABLE renamedtbl RENAME TO playtbl", true); // reset execSQL("ALTER TABLE playtbl " + pref + "RENAME TO renamedtbl", expect); execSQL("ALTER TABLE renamedtbl RENAME TO playtbl", true); // reset execSQL("ALTER TABLE playtbl RENAME " + pref + "TO renamedtbl", expect); execSQL(pref + "ALTER TABLE constrainedtbl DROP CONSTRAINT con1", expect); execSQL("ALTER " + pref + "TABLE constrainedtbl DROP CONSTRAINT con2", expect); execSQL("ALTER TABLE constrainedtbl " + pref + "DROP CONSTRAINT con3", expect); execSQL("ALTER TABLE constrainedtbl DROP " + pref + "CONSTRAINT con4", expect); execSQL("ALTER TABLE foreigntbl DROP CONSTRAINT tstfk", true); // reset execSQL(pref + "ALTER TABLE foreigntbl ADD CONSTRAINT tstfk FOREIGN KEY " + "(i7) REFERENCES primarytbl (i8)", expect); execSQL("ALTER TABLE foreigntbl DROP CONSTRAINT tstfk", true); // reset execSQL("ALTER " + pref + "TABLE foreigntbl ADD CONSTRAINT tstfk FOREIGN KEY " + "(i7) REFERENCES primarytbl (i8)", expect); execSQL("ALTER TABLE foreigntbl DROP CONSTRAINT tstfk", true); // reset execSQL("ALTER TABLE foreigntbl " + pref + "ADD CONSTRAINT tstfk FOREIGN KEY " + "(i7) REFERENCES primarytbl (i8)", expect); execSQL("ALTER TABLE foreigntbl DROP CONSTRAINT tstfk", true); // reset execSQL("ALTER TABLE foreigntbl ADD " + pref + "CONSTRAINT tstfk FOREIGN KEY " + "(i7) REFERENCES primarytbl (i8)", expect); execSQL("ALTER TABLE foreigntbl DROP CONSTRAINT tstfk", true); // reset execSQL("ALTER TABLE foreigntbl ADD CONSTRAINT tstfk " + pref + "FOREIGN KEY " + "(i7) REFERENCES primarytbl (i8)", expect); execSQL("ALTER TABLE foreigntbl DROP CONSTRAINT tstfk", true); // reset execSQL("ALTER TABLE foreigntbl ADD CONSTRAINT tstfk FOREIGN " + pref + "KEY " + "(i7) REFERENCES primarytbl (i8)", expect); execSQL("ALTER TABLE foreigntbl DROP CONSTRAINT tstfk", true); // reset execSQL("ALTER TABLE foreigntbl ADD CONSTRAINT tstfk FOREIGN KEY " + "(i7) " + pref + "REFERENCES primarytbl (i8)", expect); /* // KEEP THESE TEST CASES AT THE BOTTOM!!!! Can wreck all following // tests in current method, even when this test succeeds. // Can only run one successful SHUTDOWN command in one test case. execSQL(pref + "SHUTDOWN", SQL_ABORT); execSQL(pref + "SHUTDOWN IMMEDIATELY", SQL_ABORT); */ shutdownTested = true; /* Failing execSQL(pref + "SHUTDOWN BADARG", SQL_ABORT); execSQL("Bad SHUTDOWN command did shut down database", "SET LOGSIZE " + pref + "5", 0); */ execSQL("SHUTDOWN IMMEDIATELY", 0); } public void testThreePartNames() throws Exception { execSQL("SELECT public.tsttbl.i FROM public.beta.tsttbl\n" + "WHERE public.tsttbl.i = 1", SQL_ABORT); } /** * This method seems to be obsolete. */ public void testBasicQueries() throws Exception { String prefix = "public."; assertEquals(2, queryRowCount("SELECT i FROM " + prefix + "tsttbl")); assertEquals(1, queryRowCount("SELECT vc FROM " + prefix + "tsttbl WHERE i = 1")); assertEquals(1, queryRowCount("SELECT vc FROM " + prefix + "tsttbl WHERE i = (\n" + " SELECT i2 FROM " + prefix + "joinedtbl\n" + ")")); }/** @todo fredt - need to define additional identifiers to use for all cases of expect */ private static final int SQL_ABORT = -1234; private static final int SQL_INITIAL = -1233; private static final int SQL_FAIL = -1; private void execSQL(String s, boolean ignoreError) throws SQLException { try { statement.execute(s); statement.getUpdateCount(); } catch (SQLException se) { if (!ignoreError) { throw se; }//else System.err.println("FAILURE of (" + s + ')'); } } private void execSQL(String m, String s, int expect) { int retval = SQL_INITIAL; try { statement.execute(s); retval = statement.getUpdateCount(); } catch (SQLException se) { retval = SQL_ABORT; } assertEquals(m, expect, retval); }/** @todo fredt - this method body seems to be incorrect */ private void execSQL(String s, int expect) { execSQL(s, s, expect); } private int queryRowCount(String query) throws SQLException { int count = 0; if (!statement.execute(query)) { return count; } ResultSet rs = statement.getResultSet(); try { while (rs.next()) { count++; } } finally { rs.close(); } return count; } private int tableRowCount(String tableName) throws SQLException { String query = "SELECT count(*) FROM " + tableName; if (!statement.execute(query)) { return 0; } ResultSet rs = statement.getResultSet(); try { if (!rs.next()) { throw new SQLException("0 rows returned by (" + query + ')'); } int count = rs.getInt(1); if (rs.next()) { throw new SQLException("> 1 row returned by (" + query + ')'); } return count; } finally { rs.close(); } //throw new Exception("Failed to get rowcount for " + tableName); } public TestSchemaParse() { super(); } public TestSchemaParse(String s) { super(s); } public static void main(String[] sa) { if (sa.length > 0 && sa[0].startsWith("-g")) { junit.swingui.TestRunner.run(TestSchemaParse.class); } else { junit.textui.TestRunner runner = new junit.textui.TestRunner(); System.exit( runner.run( runner.getTest( TestSchemaParse.class.getName())).wasSuccessful() ? 0 : 1); } } public static junit.framework.Test suite() { junit.framework.TestSuite newSuite = new junit.framework.TestSuite(); newSuite.addTest(new TestSchemaParse("testSanityCheck")); newSuite.addTest(new TestSchemaParse("testTwoPartKeywords")); newSuite.addTest(new TestSchemaParse("testThreePartKeywords")); newSuite.addTest(new TestSchemaParse("testThreePartNames")); newSuite.addTest(new TestSchemaParse("testBasicQueries")); newSuite.addTest(new TestSchemaParse("test2pTables")); newSuite.addTest(new TestSchemaParse("test2pViews")); newSuite.addTest(new TestSchemaParse("test2pSequences")); newSuite.addTest(new TestSchemaParse("test2pIndexes")); newSuite.addTest(new TestSchemaParse("test2pAliases")); newSuite.addTest(new TestSchemaParse("test2pConstraints")); newSuite.addTest(new TestSchemaParse("test2pTriggers")); return newSuite; } ; public void fire(int i, String name, String table, Object[] row1, Object[] row2) {} public static String capitalize(String inString) { return inString.toUpperCase(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -