📄 csunittest.java
字号:
/* * CSUnitTest.java * * Created on 8. September 2001, 07:54 */package net.sourceforge.jtds.test;import java.sql.*;import java.math.BigDecimal;import junit.framework.TestSuite;import java.io.*;import net.sourceforge.jtds.util.Logger;/** * * @author builder * @version 1.0 */public class CSUnitTest extends DatabaseTestCase { public CSUnitTest(String name) { super(name); if (output == null) try { output = new PrintStream(new FileOutputStream("nul")); } catch (FileNotFoundException ex) { throw new RuntimeException("could not create device nul"); } } static PrintStream output = null; public static void main(String args[]) { Logger.setActive(true); if (args.length > 0) { output = System.out; junit.framework.TestSuite s = new TestSuite(); for (int i = 0; i < args.length; i++) { s.addTest(new CSUnitTest(args[i])); } junit.textui.TestRunner.run(s); } else { junit.textui.TestRunner.run(CSUnitTest.class); } } public void testMaxRows0003() throws Exception { dropTable("#t0003"); Statement stmt = con.createStatement(); stmt.executeUpdate("create table #t0003 " + " (i integer not null) "); stmt.close(); PreparedStatement pstmt = con.prepareStatement( "insert into #t0003 values (?)"); final int rowsToAdd = 100; int count = 0; for (int i = 1; i <= rowsToAdd; i++) { pstmt.setInt(1, i); count += pstmt.executeUpdate(); } assertEquals("count: " + count + " rowsToAdd: " + rowsToAdd, rowsToAdd, count); pstmt.close(); pstmt = con.prepareStatement("select i from #t0003 order by i"); int rowLimit = 32; pstmt.setMaxRows(rowLimit); assertTrue(pstmt.getMaxRows() == rowLimit); ResultSet rs = pstmt.executeQuery(); count = 0; while (rs.next()) { count++; assertEquals(rs.getInt("i"), count); } pstmt.close(); assertEquals(rowLimit, count); } public void testGetAsciiStream0018() throws Exception { Statement stmt = con.createStatement(); ResultSet rs; String bigtext1 = "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + "abcdefghijklmnop" + ""; String bigimage1 = "0x" + "0123456789abcdef" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + "fedcba9876543210" + ""; dropTable("#t0018"); String sql = "create table #t0018 ( " + " mybinary binary(5) not null, " + " myvarbinary varbinary(4) not null, " + " mychar char(10) not null, " + " myvarchar varchar(8) not null, " + " mytext text not null, " + " myimage image not null, " + " mynullbinary binary(3) null, " + " mynullvarbinary varbinary(6) null, " + " mynullchar char(10) null, " + " mynullvarchar varchar(40) null, " + " mynulltext text null, " + " mynullimage image null) "; assertEquals(stmt.executeUpdate(sql), 0); // Insert a row without nulls via a Statement sql = "insert into #t0018( " + " mybinary, " + " myvarbinary, " + " mychar, " + " myvarchar, " + " mytext, " + " myimage, " + " mynullbinary, " + " mynullvarbinary, " + " mynullchar, " + " mynullvarchar, " + " mynulltext, " + " mynullimage " + ") " + "values( " + " 0xffeeddccbb, " + // mybinary " 0x78, " + // myvarbinary " 'Z', " + // mychar " '', " + // myvarchar " '" + bigtext1 + "', " + // mytext " " + bigimage1 + ", " + // myimage " null, " + // mynullbinary " null, " + // mynullvarbinary " null, " + // mynullchar " null, " + // mynullvarchar " null, " + // mynulltext " null " + // mynullimage ")"; assertEquals(stmt.executeUpdate(sql), 1); sql = "select * from #t0018"; rs = stmt.executeQuery(sql); if (!rs.next()) { fail("should get Result"); } else { output.println("Getting the results"); output.println("mybinary is " + rs.getObject("mybinary")); output.println("myvarbinary is " + rs.getObject("myvarbinary")); output.println("mychar is " + rs.getObject("mychar")); output.println("myvarchar is " + rs.getObject("myvarchar")); output.println("mytext is " + rs.getObject("mytext")); output.println("myimage is " + rs.getObject("myimage")); output.println("mynullbinary is " + rs.getObject("mynullbinary")); output.println("mynullvarbinary is " + rs.getObject("mynullvarbinary")); output.println("mynullchar is " + rs.getObject("mynullchar")); output.println("mynullvarchar is " + rs.getObject("mynullvarchar")); output.println("mynulltext is " + rs.getObject("mynulltext")); output.println("mynullimage is " + rs.getObject("mynullimage")); } stmt.close(); } public void testMoneyHandling0019() throws Exception { java.sql.Statement stmt; int i; BigDecimal money[] = { new BigDecimal("922337203685477.5807"), new BigDecimal("-922337203685477.5807"), new BigDecimal("1.0000"), new BigDecimal("0.0000"), new BigDecimal("-1.0000") }; BigDecimal smallmoney[] = { new BigDecimal("214748.3647"), new BigDecimal("-214748.3648"), new BigDecimal("1.0000"), new BigDecimal("0.0000"), new BigDecimal("-1.0000") }; if (smallmoney.length != money.length) { throw new SQLException("Must have same number of elements in " + "money and smallmoney"); } stmt = con.createStatement(); dropTable("#t0019"); stmt.executeUpdate("create table #t0019 ( " + " i integer primary key, " + " mymoney money not null, " + " mysmallmoney smallmoney not null) " + ""); for (i=0; i<money.length; i++) { stmt.executeUpdate("insert into #t0019 values (" + i + ", " + money[i] + ", " +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -