📄 csunittest.java
字号:
for (i=1; i<=meta.getColumnCount(); i++) { output.print(rs.getString(i) + "\t"); } output.println(""); } output.println("Done processing the result set"); } else { output.println("About to call getUpdateCount()"); updateCount = stmt.getUpdateCount(); output.println("Updated " + updateCount + " rows"); } output.println("About to call getMoreResults()"); isResultSet = stmt.getMoreResults(); done = !isResultSet && updateCount==-1; } while (!done); stmt.close(); assertTrue(passed); } static String longString(char ch) { int i; StringBuffer str255 = new StringBuffer(255); for (i=0; i<255; i++) { str255.append(ch); } return str255.toString(); } public void testExceptionByUpdate0033() throws Exception { boolean passed; Statement stmt = con.createStatement(); output.println("Starting test #t0033- make sure Statement.executeUpdate() throws exception"); try { passed = false; stmt.executeUpdate("I am sure this is an error"); } catch (SQLException e) { output.println("The exception is " + e.getMessage()); passed = true; } stmt.close(); assertTrue(passed); } public void testInsertConflict0049() throws Exception { try { dropTable("jTDS_t0049b"); // important: first drop this because of foreign key dropTable("jTDS_t0049a"); Statement stmt = con.createStatement(); String query = "create table jTDS_t0049a( " + " a integer identity(1,1) primary key, " + " b char not null)"; assertEquals(0, stmt.executeUpdate(query)); query = "create table jTDS_t0049b( " + " a integer not null, " + " c char not null, " + " foreign key (a) references jTDS_t0049a(a)) "; assertEquals(0, stmt.executeUpdate(query)); query = "insert into jTDS_t0049b (a, c) values (?, ?)"; java.sql.PreparedStatement pstmt = con.prepareStatement(query); try { pstmt.setInt(1, 1); pstmt.setString(2, "a"); pstmt.executeUpdate(); fail("Was expecting INSERT to fail"); } catch (SQLException e) { assertEquals("23000", e.getSQLState()); } pstmt.close(); assertEquals(1, stmt.executeUpdate("insert into jTDS_t0049a (b) values ('a')")); pstmt = con.prepareStatement(query); pstmt.setInt(1, 1); pstmt.setString(2, "a"); assertEquals(1, pstmt.executeUpdate()); stmt.close(); pstmt.close(); } finally { dropTable("jTDS_t0049b"); // important: first drop this because of foreign key dropTable("jTDS_t0049a"); } } public void testxx0050() throws Exception { try { Statement stmt = con.createStatement(); dropTable("jTDS_t0050b"); dropTable("jTDS_t0050a"); String query = "create table jTDS_t0050a( " + " a integer identity(1,1) primary key, " + " b char not null)"; assertEquals(0, stmt.executeUpdate(query)); query = "create table jTDS_t0050b( " + " a integer not null, " + " c char not null, " + " foreign key (a) references jTDS_t0050a(a)) "; assertEquals(0, stmt.executeUpdate(query)); query = "create procedure #p0050 (@a integer, @c char) as " + " insert into jTDS_t0050b (a, c) values (@a, @c)"; assertEquals(0, stmt.executeUpdate(query)); query = "exec #p0050 ?, ?"; java.sql.CallableStatement cstmt = con.prepareCall(query); try { cstmt.setInt(1, 1); cstmt.setString(2, "a"); cstmt.executeUpdate(); fail("Expecting INSERT to fail"); } catch (SQLException e) { assertEquals("23000", e.getSQLState()); } assertEquals(1, stmt.executeUpdate( "insert into jTDS_t0050a (b) values ('a')")); assertEquals(1, cstmt.executeUpdate()); stmt.close(); cstmt.close(); } finally { dropTable("jTDS_t0050b"); dropTable("jTDS_t0050a"); } } public void testxx0051() throws Exception { boolean passed = true; try { String types[] = {"TABLE"}; DatabaseMetaData dbMetaData = con.getMetaData( ); ResultSet rs = dbMetaData.getTables( null, "%", "t%", types); while (rs.next()) { output.println("Table " + rs.getString(3)); output.println(" catalog " + rs.getString(1)); output.println(" schema " + rs.getString(2)); output.println(" name " + rs.getString(3)); output.println(" type " + rs.getString(4)); output.println(" remarks " + rs.getString(5)); } } catch (java.sql.SQLException e) { passed = false; output.println("Exception caught. " + e.getMessage()); e.printStackTrace(); } assertTrue(passed); } public void testxx0055() throws Exception { boolean passed = true; int i; try { String expectedNames[] = { "TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "TABLE_TYPE", "REMARKS", "TYPE_CAT", "TYPE_SCHEM", "TYPE_NAME", "SELF_REFERENCING_COL_NAME", "REF_GENERATION" }; String types[] = {"TABLE"}; DatabaseMetaData dbMetaData = con.getMetaData(); ResultSet rs = dbMetaData.getTables( null, "%", "t%", types); ResultSetMetaData rsMetaData = rs.getMetaData(); if (rsMetaData.getColumnCount() != expectedNames.length) { passed = false; output.println("Bad column count. Should be " + expectedNames.length + ", was " + rsMetaData.getColumnCount()); } for (i=0; passed && i<expectedNames.length; i++) { if (! rsMetaData.getColumnName(i+1).equals(expectedNames[i])) { passed = false; output.println("Bad name for column " + (i+1) + ". " + "Was " + rsMetaData.getColumnName(i+1) + ", expected " + expectedNames[i]); } } } catch (java.sql.SQLException e) { passed = false; output.println("Exception caught. " + e.getMessage()); e.printStackTrace(); } assertTrue(passed); } public void testxx0052() throws Exception { boolean passed = true; // ugly, I know byte[] image = { (byte)0x47, (byte)0x49, (byte)0x46, (byte)0x38, (byte)0x39, (byte)0x61, (byte)0x0A, (byte)0x00, (byte)0x0A, (byte)0x00, (byte)0x80, (byte)0xFF, (byte)0x00, (byte)0xD7, (byte)0x3D, (byte)0x1B, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x2C, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x0A, (byte)0x00, (byte)0x0A, (byte)0x00, (byte)0x00, (byte)0x02, (byte)0x08, (byte)0x84, (byte)0x8F, (byte)0xA9, (byte)0xCB, (byte)0xED, (byte)0x0F, (byte)0x63, (byte)0x2B, (byte)0x00, (byte)0x3B, }; int i; int count; Statement stmt = con.createStatement(); dropTable("#t0052"); try { String sql = "create table #t0052 ( " + " myvarchar varchar(2000) not null, " + " myvarbinary varbinary(2000) not null) "; stmt.executeUpdate(sql); sql = "insert into #t0052 " + " (myvarchar, " + " myvarbinary) " + " values " + " (\'This is a test with german umlauts 漩黒', " + " 0x4749463839610A000A0080FF00D73D1B0000002C000000000A000A00000208848FA9CBED0F632B003B" + " )"; stmt.executeUpdate(sql); sql = "select * from #t0052"; ResultSet rs = stmt.executeQuery(sql); if (!rs.next()) { passed = false; } else { output.println("Testing getAsciiStream()"); InputStream in = rs.getAsciiStream("myvarchar"); String expect = "This is a test with german umlauts ???"; byte[] toRead = new byte[expect.length()]; count = in.read(toRead); if (count == expect.length()) { for (i=0; i<expect.length(); i++) { if (expect.charAt(i) != toRead[i]) { passed = false; output.println("Expected "+expect.charAt(i) + " but was " + toRead[i]); } } } else { passed = false; output.println("Premature end in " + "getAsciiStream(\"myvarchar\") " + count + " instead of " + expect.length()); } in.close(); in = rs.getAsciiStream(2); toRead = new byte[41]; count = in.read(toRead); if (count == 41) { for (i=0; i<41; i++) { if (toRead[i] != (toRead[i] & 0x7F)) { passed = false; output.println("Non ASCII characters in getAsciiStream"); break; } } } else { passed = false; output.println("Premature end in getAsciiStream(1) " +count+" instead of 41"); } in.close(); output.println("Testing getUnicodeStream()"); Reader reader = rs.getCharacterStream("myvarchar"); expect = "This is a test with german umlauts 漩
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -