📄 timestamptest.java
字号:
/* { "char(1000)",
"'123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890'",
"123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890" },
*/
// { "char(1000)", "'1234567890'", "1234567890" },
// { "image", "0x0a0a0b", new byte[] { 0x0a, 0x0a, 0x0b } },
};
}
public void testOutputParams() throws Exception {
Statement stmt = con.createStatement();
dropProcedure("#jtds_outputTest");
Object[][] datatypes = getDatatypes();
for (int i = 0; i < datatypes.length; i++) {
String valueToAssign;
boolean bImage = datatypes[i][0].equals("image");
if (bImage) {
valueToAssign = "";
} else {
valueToAssign = " = " + datatypes[i][1];
}
String sql = "create procedure #jtds_outputTest "
+ "@a1 " + datatypes[i][0] + " = null out "
+ "as select @a1" + valueToAssign;
stmt.executeUpdate(sql);
for (int pass = 0; (pass < 2 && !bImage) || pass < 1; pass++) {
CallableStatement cstmt = con.prepareCall("{call #jtds_outputTest(?)}");
int jtype = getType(datatypes[i][2]);
if (pass == 1)
cstmt.setObject(1, null, jtype, 10);
if (jtype == java.sql.Types.NUMERIC || jtype == java.sql.Types.DECIMAL) {
cstmt.registerOutParameter(1, jtype, 10);
if (pass == 0) {
cstmt.setObject(1, datatypes[i][2], jtype, 10);
}
} else if (jtype == java.sql.Types.VARCHAR) {
cstmt.registerOutParameter(1, jtype, 255);
if (pass == 0) {
cstmt.setObject(1, datatypes[i][2]);
}
} else {
cstmt.registerOutParameter(1, jtype);
if (pass == 0) {
cstmt.setObject(1, datatypes[i][2]);
}
}
assertEquals(bImage, cstmt.execute());
while (cstmt.getMoreResults() || cstmt.getUpdateCount() != -1) ;
if (jtype == java.sql.Types.VARBINARY) {
assertTrue(compareBytes(cstmt.getBytes(1), (byte[]) datatypes[i][2]) == 0);
} else if (datatypes[i][2] instanceof Number) {
Number n = (Number) cstmt.getObject(1);
if (n != null) {
assertEquals("Failed on " + datatypes[i][0], n.doubleValue(),
((Number) datatypes[i][2]).doubleValue(), 0.001);
} else {
assertEquals("Failed on " + datatypes[i][0], n, datatypes[i][2]);
}
} else {
assertEquals("Failed on " + datatypes[i][0], cstmt.getObject(1), datatypes[i][2]);
}
cstmt.close();
} // for (pass
stmt.executeUpdate(" drop procedure #jtds_outputTest");
} // for (int
stmt.close();
}
public void testStatements0020() throws Exception {
Statement stmt = con.createStatement();
stmt.executeUpdate("create table #t0020a ( " +
" i1 int not null, " +
" s1 char(10) not null " +
") " +
"");
stmt.executeUpdate("create table #t0020b ( " +
" i2a int not null, " +
" i2b int not null, " +
" s2 char(10) not null " +
") " +
"");
stmt.executeUpdate("create table #t0020c ( " +
" i3 int not null, " +
" s3 char(10) not null " +
") " +
"");
int nextB = 1;
int nextC = 1;
for (int i = 1; i < 50; i++) {
stmt.executeUpdate("insert into #t0020a " +
" values(" + i + ", " +
" 'row" + i + "') " +
"");
for (int j = nextB; (nextB % 5) != 0; j++, nextB++) {
stmt.executeUpdate("insert into #t0020b " +
" values(" + i + ", " +
" " + j + ", " +
" 'row" + i + "." + j + "' " +
" )" +
"");
for (int k = nextC; (nextC % 3) != 0; k++, nextC++) {
stmt.executeUpdate("insert into #t0020c " +
" values(" + j + ", " +
" 'row" + i + "." + j + "." + k + "' " +
" )" +
"");
}
}
}
Statement stmtA = con.createStatement();
PreparedStatement stmtB = con.prepareStatement(
"select i2b, s2 from #t0020b where i2a=?");
PreparedStatement stmtC = con.prepareStatement(
"select s3 from #t0020c where i3=?");
ResultSet rs1 = stmtA.executeQuery("select i1 from #t0020a");
assertNotNull(rs1);
while (rs1.next()) {
stmtB.setInt(1, rs1.getInt("i1"));
ResultSet rs2 = stmtB.executeQuery();
assertNotNull(rs2);
while (rs2.next()) {
stmtC.setInt(1, rs2.getInt(1));
ResultSet rs3 = stmtC.executeQuery();
assertNotNull(rs3);
rs3.next();
}
}
stmt.close();
stmtA.close();
stmtB.close();
stmtC.close();
}
public void testBlob0021() throws Exception {
byte smallarray[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10
};
byte array1[] = {
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08
};
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" +
"";
Statement stmt = con.createStatement();
dropTable("#t0021");
stmt.executeUpdate(
"create table #t0021 ( " +
" mybinary binary(16) not null, " +
" myimage image not null, " +
" mynullimage image null, " +
" mytext text not null, " +
" mynulltext text null) ");
// Insert a row without nulls via a Statement
PreparedStatement insert = con.prepareStatement(
"insert into #t0021( " +
" mybinary, " +
" myimage, " +
" mynullimage, " +
" mytext, " +
" mynulltext " +
") " +
"values(?, ?, ?, ?, ?) ");
insert.setBytes(1, smallarray);
insert.setBytes(2, array1);
insert.setBytes(3, array1);
insert.setString(4, bigtext1);
insert.setString(5, bigtext1);
int count = insert.executeUpdate();
assertEquals(count, 1);
insert.close();
ResultSet rs = stmt.executeQuery("select * from #t0021");
assertNotNull(rs);
assertTrue("Expected a result set", rs.next());
byte[] a1 = rs.getBytes("myimage");
byte[] a2 = rs.getBytes("mynullimage");
String s1 = rs.getString("mytext");
String s2 = rs.getString("mynulltext");
assertEquals(0, compareBytes(a1, array1));
assertEquals(0, compareBytes(a2, array1));
assertEquals(bigtext1, s1);
assertEquals(bigtext1, s2);
stmt.close();
}
public void testNestedStatements0022() throws Exception {
Statement stmt = con.createStatement();
stmt.executeUpdate("create table #t0022a "
+ " (i integer not null, "
+ " str char(254) not null) ");
stmt.executeUpdate("create table #t0022b "
+ " (i integer not null, "
+ " t datetime not null) ");
PreparedStatement pStmtA = con.prepareStatement(
"insert into #t0022a values (?, ?)");
PreparedStatement pStmtB = con.prepareStatement(
"insert into #t0022b values (?, getdate())");
final int rowsToAdd = 100;
int count = 0;
for (int i = 1; i <= rowsToAdd; i++) {
pStmtA.setInt(1, i);
StringBuffer tmp = new StringBuffer(255);
while (tmp.length() < 240) {
tmp.append("row ").append(i).append(". ");
}
pStmtA.setString(2, tmp.toString());
count += pStmtA.executeUpdate();
pStmtB.setInt(1, i);
pStmtB.executeUpdate();
}
pStmtA.close();
pStmtB.close();
assertEquals(count, rowsToAdd);
Statement stmtA = con.createStatement();
Statement stmtB = con.createStatement();
count = 0;
ResultSet rsA = stmtA.executeQuery("select * from #t0022a");
assertNotNull(rsA);
while (rsA.next()) {
count++;
ResultSet rsB = stmtB.executeQuery(
"select * from #t0022b where i=" + rsA.getInt("i"));
assertNotNull(rsB);
assertTrue("Expected a result set", rsB.next());
assertTrue("Expected no result set", !rsB.next());
}
assertEquals(count, rowsToAdd);
stmt.close();
stmtA.close();
stmtB.close();
}
public void testPrimaryKeyFloat0023() throws Exception {
Double d[] = {
new Double(-1.0),
new Double(1234.543),
new Double(0.0),
new Double(1),
new Double(-2.0),
new Double(0.14),
new Double(0.79),
new Double(1000000.12345),
new Double(-1000000.12345),
new Double(1000000),
new Double(-1000000),
new Double(1.7E+308),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -