0001: /*
0002: * CSUnitTest.java
0003: *
0004: * Created on 8. September 2001, 07:54
0005: */
0006: package net.sourceforge.jtds.test;
0007:
0008: import java.sql.*;
0009: import java.math.BigDecimal;
0010: import junit.framework.TestSuite;
0011: import java.io.*;
0012:
0013: import net.sourceforge.jtds.util.Logger;
0014:
0015: /**
0016: *
0017: * @author builder
0018: * @version 1.0
0019: */
0020: public class CSUnitTest extends DatabaseTestCase {
0021: public CSUnitTest(String name) {
0022: super (name);
0023:
0024: if (output == null)
0025: try {
0026: output = new PrintStream(new FileOutputStream("nul"));
0027: } catch (FileNotFoundException ex) {
0028: throw new RuntimeException(
0029: "could not create device nul");
0030: }
0031: }
0032:
0033: static PrintStream output = null;
0034:
0035: public static void main(String args[]) {
0036: Logger.setActive(true);
0037:
0038: if (args.length > 0) {
0039: output = System.out;
0040: junit.framework.TestSuite s = new TestSuite();
0041:
0042: for (int i = 0; i < args.length; i++) {
0043: s.addTest(new CSUnitTest(args[i]));
0044: }
0045:
0046: junit.textui.TestRunner.run(s);
0047: } else {
0048: junit.textui.TestRunner.run(CSUnitTest.class);
0049: }
0050: }
0051:
0052: public void testMaxRows0003() throws Exception {
0053: dropTable("#t0003");
0054: Statement stmt = con.createStatement();
0055:
0056: stmt.executeUpdate("create table #t0003 "
0057: + " (i integer not null) ");
0058: stmt.close();
0059:
0060: PreparedStatement pstmt = con
0061: .prepareStatement("insert into #t0003 values (?)");
0062:
0063: final int rowsToAdd = 100;
0064: int count = 0;
0065:
0066: for (int i = 1; i <= rowsToAdd; i++) {
0067: pstmt.setInt(1, i);
0068: count += pstmt.executeUpdate();
0069: }
0070:
0071: assertEquals("count: " + count + " rowsToAdd: " + rowsToAdd,
0072: rowsToAdd, count);
0073: pstmt.close();
0074: pstmt = con.prepareStatement("select i from #t0003 order by i");
0075: int rowLimit = 32;
0076: pstmt.setMaxRows(rowLimit);
0077:
0078: assertTrue(pstmt.getMaxRows() == rowLimit);
0079: ResultSet rs = pstmt.executeQuery();
0080: count = 0;
0081:
0082: while (rs.next()) {
0083: count++;
0084: assertEquals(rs.getInt("i"), count);
0085: }
0086: pstmt.close();
0087:
0088: assertEquals(rowLimit, count);
0089: }
0090:
0091: public void testGetAsciiStream0018() throws Exception {
0092: Statement stmt = con.createStatement();
0093: ResultSet rs;
0094:
0095: String bigtext1 = "abcdefghijklmnop" + "abcdefghijklmnop"
0096: + "abcdefghijklmnop" + "abcdefghijklmnop"
0097: + "abcdefghijklmnop" + "abcdefghijklmnop"
0098: + "abcdefghijklmnop" + "abcdefghijklmnop"
0099: + "abcdefghijklmnop" + "abcdefghijklmnop"
0100: + "abcdefghijklmnop" + "abcdefghijklmnop"
0101: + "abcdefghijklmnop" + "abcdefghijklmnop"
0102: + "abcdefghijklmnop" + "abcdefghijklmnop"
0103: + "abcdefghijklmnop" + "abcdefghijklmnop"
0104: + "abcdefghijklmnop" + "abcdefghijklmnop"
0105: + "abcdefghijklmnop" + "abcdefghijklmnop"
0106: + "abcdefghijklmnop" + "abcdefghijklmnop"
0107: + "abcdefghijklmnop" + "abcdefghijklmnop"
0108: + "abcdefghijklmnop" + "abcdefghijklmnop"
0109: + "abcdefghijklmnop" + "abcdefghijklmnop" + "";
0110: String bigimage1 = "0x" + "0123456789abcdef"
0111: + "fedcba9876543210" + "fedcba9876543210"
0112: + "fedcba9876543210" + "fedcba9876543210"
0113: + "fedcba9876543210" + "fedcba9876543210"
0114: + "fedcba9876543210" + "fedcba9876543210"
0115: + "fedcba9876543210" + "fedcba9876543210"
0116: + "fedcba9876543210" + "fedcba9876543210"
0117: + "fedcba9876543210" + "fedcba9876543210"
0118: + "fedcba9876543210" + "fedcba9876543210"
0119: + "fedcba9876543210" + "fedcba9876543210"
0120: + "fedcba9876543210" + "fedcba9876543210"
0121: + "fedcba9876543210" + "fedcba9876543210"
0122: + "fedcba9876543210" + "fedcba9876543210"
0123: + "fedcba9876543210" + "fedcba9876543210"
0124: + "fedcba9876543210" + "fedcba9876543210"
0125: + "fedcba9876543210" + "fedcba9876543210"
0126: + "fedcba9876543210" + "fedcba9876543210"
0127: + "fedcba9876543210" + "fedcba9876543210"
0128: + "fedcba9876543210" + "fedcba9876543210"
0129: + "fedcba9876543210" + "fedcba9876543210"
0130: + "fedcba9876543210" + "fedcba9876543210"
0131: + "fedcba9876543210" + "fedcba9876543210"
0132: + "fedcba9876543210" + "fedcba9876543210"
0133: + "fedcba9876543210" + "fedcba9876543210"
0134: + "fedcba9876543210" + "fedcba9876543210"
0135: + "fedcba9876543210" + "fedcba9876543210"
0136: + "fedcba9876543210" + "fedcba9876543210"
0137: + "fedcba9876543210" + "fedcba9876543210"
0138: + "fedcba9876543210" + "fedcba9876543210"
0139: + "fedcba9876543210" + "fedcba9876543210"
0140: + "fedcba9876543210" + "fedcba9876543210"
0141: + "fedcba9876543210" + "fedcba9876543210"
0142: + "fedcba9876543210" + "";
0143: dropTable("#t0018");
0144: String sql = "create table #t0018 ( "
0145: + " mybinary binary(5) not null, "
0146: + " myvarbinary varbinary(4) not null, "
0147: + " mychar char(10) not null, "
0148: + " myvarchar varchar(8) not null, "
0149: + " mytext text not null, "
0150: + " myimage image not null, "
0151: + " mynullbinary binary(3) null, "
0152: + " mynullvarbinary varbinary(6) null, "
0153: + " mynullchar char(10) null, "
0154: + " mynullvarchar varchar(40) null, "
0155: + " mynulltext text null, "
0156: + " mynullimage image null) ";
0157:
0158: assertEquals(stmt.executeUpdate(sql), 0);
0159: // Insert a row without nulls via a Statement
0160: sql = "insert into #t0018( "
0161: + " mybinary, "
0162: + " myvarbinary, "
0163: + " mychar, "
0164: + " myvarchar, "
0165: + " mytext, "
0166: + " myimage, "
0167: + " mynullbinary, "
0168: + " mynullvarbinary, "
0169: + " mynullchar, "
0170: + " mynullvarchar, "
0171: + " mynulltext, "
0172: + " mynullimage "
0173: + ") "
0174: + "values( "
0175: + " 0xffeeddccbb, " + // mybinary
0176: " 0x78, " + // myvarbinary
0177: " 'Z', " + // mychar
0178: " '', " + // myvarchar
0179: " '" + bigtext1 + "', " + // mytext
0180: " " + bigimage1 + ", " + // myimage
0181: " null, " + // mynullbinary
0182: " null, " + // mynullvarbinary
0183: " null, " + // mynullchar
0184: " null, " + // mynullvarchar
0185: " null, " + // mynulltext
0186: " null " + // mynullimage
0187: ")";
0188:
0189: assertEquals(stmt.executeUpdate(sql), 1);
0190:
0191: sql = "select * from #t0018";
0192: rs = stmt.executeQuery(sql);
0193: if (!rs.next()) {
0194: fail("should get Result");
0195: } else {
0196: output.println("Getting the results");
0197: output.println("mybinary is " + rs.getObject("mybinary"));
0198: output.println("myvarbinary is "
0199: + rs.getObject("myvarbinary"));
0200: output.println("mychar is " + rs.getObject("mychar"));
0201: output.println("myvarchar is " + rs.getObject("myvarchar"));
0202: output.println("mytext is " + rs.getObject("mytext"));
0203: output.println("myimage is " + rs.getObject("myimage"));
0204: output.println("mynullbinary is "
0205: + rs.getObject("mynullbinary"));
0206: output.println("mynullvarbinary is "
0207: + rs.getObject("mynullvarbinary"));
0208: output.println("mynullchar is "
0209: + rs.getObject("mynullchar"));
0210: output.println("mynullvarchar is "
0211: + rs.getObject("mynullvarchar"));
0212: output.println("mynulltext is "
0213: + rs.getObject("mynulltext"));
0214: output.println("mynullimage is "
0215: + rs.getObject("mynullimage"));
0216: }
0217: stmt.close();
0218: }
0219:
0220: public void testMoneyHandling0019() throws Exception {
0221: java.sql.Statement stmt;
0222: int i;
0223: BigDecimal money[] = { new BigDecimal("922337203685477.5807"),
0224: new BigDecimal("-922337203685477.5807"),
0225: new BigDecimal("1.0000"), new BigDecimal("0.0000"),
0226: new BigDecimal("-1.0000") };
0227: BigDecimal smallmoney[] = { new BigDecimal("214748.3647"),
0228: new BigDecimal("-214748.3648"),
0229: new BigDecimal("1.0000"), new BigDecimal("0.0000"),
0230: new BigDecimal("-1.0000") };
0231:
0232: if (smallmoney.length != money.length) {
0233: throw new SQLException(
0234: "Must have same number of elements in "
0235: + "money and smallmoney");
0236: }
0237:
0238: stmt = con.createStatement();
0239:
0240: dropTable("#t0019");
0241:
0242: stmt.executeUpdate("create table #t0019 ( "
0243: + " i integer primary key, "
0244: + " mymoney money not null, "
0245: + " mysmallmoney smallmoney not null) " + "");
0246:
0247: for (i = 0; i < money.length; i++) {
0248: stmt.executeUpdate("insert into #t0019 values (" + i + ", "
0249: + money[i] + ", " + smallmoney[i] + ") ");
0250: }
0251:
0252: // long l = System.currentTimeMillis();
0253: // while (l + 500 > System.currentTimeMillis()) ;
0254: ResultSet rs = stmt
0255: .executeQuery("select * from #t0019 order by i");
0256:
0257: for (i = 0; rs.next(); i++) {
0258: BigDecimal m;
0259: BigDecimal sm;
0260:
0261: m = (BigDecimal) rs.getObject("mymoney");
0262: sm = (BigDecimal) rs.getObject("mysmallmoney");
0263:
0264: assertEquals(m, money[i]);
0265: assertEquals(sm, smallmoney[i]);
0266:
0267: output.println(m + ", " + sm);
0268: }
0269: stmt.close();
0270: }
0271:
0272: /*
0273: public void testBooleanAndCompute0026() throws Exception {
0274: Statement stmt = con.createStatement();
0275: dropTable("#t0026");
0276: int count = stmt.executeUpdate("create table #t0026 " +
0277: " (i integer, " +
0278: " b bit, " +
0279: " s char(5), " +
0280: " f float) ");
0281: output.println("Creating table affected " + count + " rows");
0282:
0283: stmt.executeUpdate("insert into #t0026 values(0, 0, 'false', 0.0)");
0284: stmt.executeUpdate("insert into #t0026 values(0, 0, 'N', 10)");
0285: stmt.executeUpdate("insert into #t0026 values(1, 1, 'true', 7.0)");
0286: stmt.executeUpdate("insert into #t0026 values(2, 1, 'Y', -5.0)");
0287:
0288: ResultSet rs = stmt.executeQuery(
0289: "select * from #t0026 order by i compute sum(f) by i");
0290:
0291: assertTrue(rs.next());
0292:
0293: assertTrue(!(rs.getBoolean("i")
0294: || rs.getBoolean("b")
0295: || rs.getBoolean("s")
0296: || rs.getBoolean("f")));
0297:
0298: assertTrue(rs.next());
0299:
0300: assertTrue(!(rs.getBoolean("i")
0301: || rs.getBoolean("b")
0302: || rs.getBoolean("s")
0303: || rs.getBoolean("f")));
0304: assertTrue(rs.next());
0305:
0306: assertTrue(rs.getBoolean("i")
0307: && rs.getBoolean("b")
0308: && rs.getBoolean("s")
0309: && rs.getBoolean("f"));
0310: assertTrue(rs.next());
0311:
0312: assertTrue(rs.getBoolean("i")
0313: && rs.getBoolean("b")
0314: && rs.getBoolean("s")
0315: && rs.getBoolean("f"));
0316:
0317: ResultSet rs = stmt.executeQuery(
0318: "select * from #t0026 order by i compute sum(f) by i");
0319:
0320:
0321:
0322: if (!rs.next())
0323: {
0324: throw new SQLException("Failed");
0325: }
0326: passed = passed && (! (rs.getBoolean("i")
0327: || rs.getBoolean("b")
0328: || rs.getBoolean("s")
0329: || rs.getBoolean("f")));
0330:
0331:
0332: if (!rs.next())
0333: {
0334: throw new SQLException("Failed");
0335: }
0336: passed = passed && (! (rs.getBoolean("i")
0337: || rs.getBoolean("b")
0338: || rs.getBoolean("s")
0339: || rs.getBoolean("f")));
0340:
0341:
0342: if (!rs.next())
0343: {
0344: throw new SQLException("Failed");
0345: }
0346: passed = passed && (rs.getBoolean("i")
0347: && rs.getBoolean("b")
0348: && rs.getBoolean("s")
0349: && rs.getBoolean("f"));
0350:
0351: if (!rs.next())
0352: {
0353: throw new SQLException("Failed");
0354: }
0355: passed = passed && (rs.getBoolean("i")
0356: && rs.getBoolean("b")
0357: && rs.getBoolean("s")
0358: && rs.getBoolean("f"));
0359:
0360: assertTrue(passed);
0361: }
0362: */
0363:
0364: public void testDataTypes0027() throws Exception {
0365: output
0366: .println("Test all the SQLServer datatypes in Statement\n"
0367: + "and PreparedStatement using the preferred getXXX()\n"
0368: + "instead of getObject like #t0017.java does.");
0369: output
0370: .println("!!!Note- This test is not fully implemented yet!!!");
0371: Statement stmt = con.createStatement();
0372: ResultSet rs;
0373: stmt.execute("set dateformat ymd");
0374: dropTable("#t0027");
0375: String sql = "create table #t0027 ( "
0376: + " mybinary binary(5) not null, "
0377: + " myvarbinary varbinary(4) not null, "
0378: + " mychar char(10) not null, "
0379: + " myvarchar varchar(8) not null, "
0380: + " mydatetime datetime not null, "
0381: + " mysmalldatetime smalldatetime not null, "
0382: + " mydecimal10_3 decimal(10,3) not null, "
0383: + " mynumeric5_4 numeric (5,4) not null, "
0384: + " myfloat6 float(6) not null, "
0385: + " myfloat14 float(6) not null, "
0386: + " myreal real not null, "
0387: + " myint int not null, "
0388: + " mysmallint smallint not null, "
0389: + " mytinyint tinyint not null, "
0390: + " mymoney money not null, "
0391: + " mysmallmoney smallmoney not null, "
0392: + " mybit bit not null, "
0393: + " mytimestamp timestamp not null, "
0394: + " mytext text not null, "
0395: + " myimage image not null, "
0396: + " mynullbinary binary(3) null, "
0397: + " mynullvarbinary varbinary(6) null, "
0398: + " mynullchar char(10) null, "
0399: + " mynullvarchar varchar(40) null, "
0400: + " mynulldatetime datetime null, "
0401: + " mynullsmalldatetime smalldatetime null, "
0402: + " mynulldecimal10_3 decimal(10,3) null, "
0403: + " mynullnumeric15_10 numeric(15,10) null, "
0404: + " mynullfloat6 float(6) null, "
0405: + " mynullfloat14 float(14) null, "
0406: + " mynullreal real null, "
0407: + " mynullint int null, "
0408: + " mynullsmallint smallint null, "
0409: + " mynulltinyint tinyint null, "
0410: + " mynullmoney money null, "
0411: + " mynullsmallmoney smallmoney null, "
0412: + " mynulltext text null, "
0413: + " mynullimage image null) ";
0414:
0415: assertEquals(stmt.executeUpdate(sql), 0);
0416:
0417: // Insert a row without nulls via a Statement
0418: sql = "insert into #t0027 "
0419: + " (mybinary, "
0420: + " myvarbinary, "
0421: + " mychar, "
0422: + " myvarchar, "
0423: + " mydatetime, "
0424: + " mysmalldatetime, "
0425: + " mydecimal10_3, "
0426: + " mynumeric5_4, "
0427: + " myfloat6, "
0428: + " myfloat14, "
0429: + " myreal, "
0430: + " myint, "
0431: + " mysmallint, "
0432: + " mytinyint, "
0433: + " mymoney, "
0434: + " mysmallmoney, "
0435: + " mybit, "
0436: + " mytimestamp, "
0437: + " mytext, "
0438: + " myimage, "
0439: + " mynullbinary, "
0440: + " mynullvarbinary, "
0441: + " mynullchar, "
0442: + " mynullvarchar, "
0443: + " mynulldatetime, "
0444: + " mynullsmalldatetime, "
0445: + " mynulldecimal10_3, "
0446: + " mynullnumeric15_10, "
0447: + " mynullfloat6, "
0448: + " mynullfloat14, "
0449: + " mynullreal, "
0450: + " mynullint, "
0451: + " mynullsmallint, "
0452: + " mynulltinyint, "
0453: + " mynullmoney, "
0454: + " mynullsmallmoney, "
0455: + " mynulltext, "
0456: + " mynullimage) "
0457: + " values "
0458: + " (0x1213141516, " + // mybinary,
0459: " 0x1718191A, " + // myvarbinary
0460: " '1234567890', " + // mychar
0461: " '12345678', " + // myvarchar
0462: " '19991015 21:29:59.01', " + // mydatetime
0463: " '19991015 20:45', " + // mysmalldatetime
0464: " 1234567.089, " + // mydecimal10_3
0465: " 1.2345, " + // mynumeric5_4
0466: " 65.4321, " + // myfloat6
0467: " 1.123456789, " + // myfloat14
0468: " 987654321.0, " + // myreal
0469: " 4097, " + // myint
0470: " 4094, " + // mysmallint
0471: " 200, " + // mytinyint
0472: " 19.95, " + // mymoney
0473: " 9.97, " + // mysmallmoney
0474: " 1, " + // mybit
0475: " null, " + // mytimestamp
0476: " 'abcdefg', " + // mytext
0477: " 0x0AAABB, " + // myimage
0478: " 0x123456, " + // mynullbinary
0479: " 0xAB, " + // mynullvarbinary
0480: " 'z', " + // mynullchar
0481: " 'zyx', " + // mynullvarchar
0482: " '1976-07-04 12:00:00.04', " + // mynulldatetime
0483: " '2000-02-29 13:46', " + // mynullsmalldatetime
0484: " 1.23, " + // mynulldecimal10_3
0485: " 7.1234567891, " + // mynullnumeric15_10
0486: " 987654, " + // mynullfloat6
0487: " 0, " + // mynullfloat14
0488: " -1.1, " + // mynullreal
0489: " -10, " + // mynullint
0490: " 126, " + // mynullsmallint
0491: " 7, " + // mynulltinyint
0492: " -19999.00, " + // mynullmoney
0493: " -9.97, " + // mynullsmallmoney
0494: " '1234', " + // mynulltext
0495: " 0x1200340056) " + // mynullimage)
0496: "";
0497:
0498: assertEquals(stmt.executeUpdate(sql), 1);
0499:
0500: sql = "select * from #t0027";
0501: rs = stmt.executeQuery(sql);
0502: assertTrue(rs.next());
0503: output.println("mybinary is " + rs.getObject("mybinary"));
0504: output.println("myvarbinary is " + rs.getObject("myvarbinary"));
0505: output.println("mychar is " + rs.getString("mychar"));
0506: output.println("myvarchar is " + rs.getString("myvarchar"));
0507: output
0508: .println("mydatetime is "
0509: + rs.getTimestamp("mydatetime"));
0510: output.println("mysmalldatetime is "
0511: + rs.getTimestamp("mysmalldatetime"));
0512: output.println("mydecimal10_3 is "
0513: + rs.getObject("mydecimal10_3"));
0514: output.println("mynumeric5_4 is "
0515: + rs.getObject("mynumeric5_4"));
0516: output.println("myfloat6 is " + rs.getDouble("myfloat6"));
0517: output.println("myfloat14 is " + rs.getDouble("myfloat14"));
0518: output.println("myreal is " + rs.getDouble("myreal"));
0519: output.println("myint is " + rs.getInt("myint"));
0520: output.println("mysmallint is " + rs.getShort("mysmallint"));
0521: output.println("mytinyint is " + rs.getByte("mytinyint"));
0522: output.println("mymoney is " + rs.getObject("mymoney"));
0523: output.println("mysmallmoney is "
0524: + rs.getObject("mysmallmoney"));
0525: output.println("mybit is " + rs.getObject("mybit"));
0526: output.println("mytimestamp is " + rs.getObject("mytimestamp"));
0527: output.println("mytext is " + rs.getObject("mytext"));
0528: output.println("myimage is " + rs.getObject("myimage"));
0529: output.println("mynullbinary is "
0530: + rs.getObject("mynullbinary"));
0531: output.println("mynullvarbinary is "
0532: + rs.getObject("mynullvarbinary"));
0533: output.println("mynullchar is " + rs.getString("mynullchar"));
0534: output.println("mynullvarchar is "
0535: + rs.getString("mynullvarchar"));
0536: output.println("mynulldatetime is "
0537: + rs.getTimestamp("mynulldatetime"));
0538: output.println("mynullsmalldatetime is "
0539: + rs.getTimestamp("mynullsmalldatetime"));
0540: output.println("mynulldecimal10_3 is "
0541: + rs.getObject("mynulldecimal10_3"));
0542: output.println("mynullnumeric15_10 is "
0543: + rs.getObject("mynullnumeric15_10"));
0544: output.println("mynullfloat6 is "
0545: + rs.getDouble("mynullfloat6"));
0546: output.println("mynullfloat14 is "
0547: + rs.getDouble("mynullfloat14"));
0548: output.println("mynullreal is " + rs.getDouble("mynullreal"));
0549: output.println("mynullint is " + rs.getInt("mynullint"));
0550: output.println("mynullsmallint is "
0551: + rs.getShort("mynullsmallint"));
0552: output.println("mynulltinyint is "
0553: + rs.getByte("mynulltinyint"));
0554: output.println("mynullmoney is " + rs.getObject("mynullmoney"));
0555: output.println("mynullsmallmoney is "
0556: + rs.getObject("mynullsmallmoney"));
0557: output.println("mynulltext is " + rs.getObject("mynulltext"));
0558: output.println("mynullimage is " + rs.getObject("mynullimage"));
0559: stmt.close();
0560: }
0561:
0562: public void testCallStoredProcedures0028() throws Exception {
0563: Statement stmt = con.createStatement();
0564: ResultSet rs;
0565:
0566: boolean isResultSet;
0567: int updateCount;
0568:
0569: int resultSetCount = 0;
0570: int rowCount = 0;
0571: int numberOfUpdates = 0;
0572:
0573: isResultSet = stmt.execute("EXEC sp_who");
0574: output.println("execute(EXEC sp_who) returned: " + isResultSet);
0575:
0576: updateCount = stmt.getUpdateCount();
0577:
0578: while (isResultSet || (updateCount != -1)) {
0579: if (isResultSet) {
0580: resultSetCount++;
0581: rs = stmt.getResultSet();
0582:
0583: ResultSetMetaData rsMeta = rs.getMetaData();
0584: int columnCount = rsMeta.getColumnCount();
0585: output.println("columnCount: "
0586: + Integer.toString(columnCount));
0587: for (int n = 1; n <= columnCount; n++) {
0588: output.println(Integer.toString(n) + ": "
0589: + rsMeta.getColumnName(n));
0590: }
0591:
0592: while (rs.next()) {
0593: rowCount++;
0594: for (int n = 1; n <= columnCount; n++) {
0595: output.println(Integer.toString(n) + ": "
0596: + rs.getString(n));
0597: }
0598: }
0599:
0600: } else {
0601: numberOfUpdates += updateCount;
0602: output.println("UpdateCount: "
0603: + Integer.toString(updateCount));
0604: }
0605: isResultSet = stmt.getMoreResults();
0606: updateCount = stmt.getUpdateCount();
0607: }
0608: stmt.close();
0609:
0610: output.println("resultSetCount: " + resultSetCount);
0611: output.println("Total rowCount: " + rowCount);
0612: output.println("Number of updates: " + numberOfUpdates);
0613:
0614: assertTrue((rowCount >= 1) && (numberOfUpdates == 0)
0615: && (resultSetCount == 1));
0616: }
0617:
0618: public void testxx0029() throws Exception {
0619: Statement stmt = con.createStatement();
0620: ResultSet rs;
0621:
0622: boolean isResultSet;
0623: int updateCount;
0624:
0625: int resultSetCount = 0;
0626: int rowCount = 0;
0627: int numberOfUpdates = 0;
0628:
0629: output.println("before execute DROP PROCEDURE");
0630:
0631: try {
0632: isResultSet = stmt.execute("DROP PROCEDURE #t0029_p1");
0633: updateCount = stmt.getUpdateCount();
0634: do {
0635: output.println("DROP PROCEDURE isResultSet: "
0636: + isResultSet);
0637: output.println("DROP PROCEDURE updateCount: "
0638: + updateCount);
0639: isResultSet = stmt.getMoreResults();
0640: updateCount = stmt.getUpdateCount();
0641: } while (((updateCount != -1) && !isResultSet)
0642: || isResultSet);
0643: } catch (SQLException e) {
0644: }
0645:
0646: try {
0647: isResultSet = stmt.execute("DROP PROCEDURE #t0029_p2");
0648: updateCount = stmt.getUpdateCount();
0649: do {
0650: output.println("DROP PROCEDURE isResultSet: "
0651: + isResultSet);
0652: output.println("DROP PROCEDURE updateCount: "
0653: + updateCount);
0654: isResultSet = stmt.getMoreResults();
0655: updateCount = stmt.getUpdateCount();
0656: } while (((updateCount != -1) && !isResultSet)
0657: || isResultSet);
0658: } catch (SQLException e) {
0659: }
0660:
0661: dropTable("#t0029_t1");
0662:
0663: isResultSet = stmt
0664: .execute(" create table #t0029_t1 "
0665: + " (t1 datetime not null, "
0666: + " t2 datetime null, "
0667: + " t3 smalldatetime not null, "
0668: + " t4 smalldatetime null, "
0669: + " t5 text null) ");
0670: updateCount = stmt.getUpdateCount();
0671: do {
0672: output.println("CREATE TABLE isResultSet: " + isResultSet);
0673: output.println("CREATE TABLE updateCount: " + updateCount);
0674: isResultSet = stmt.getMoreResults();
0675: updateCount = stmt.getUpdateCount();
0676: } while (((updateCount != -1) && !isResultSet) || isResultSet);
0677:
0678: isResultSet = stmt
0679: .execute("CREATE PROCEDURE #t0029_p1 AS "
0680: +
0681:
0682: " insert into #t0029_t1 values "
0683: + " ('1999-01-07', '1998-09-09 15:35:05', "
0684: + " getdate(), '1998-09-09 15:35:00', null) "
0685: +
0686:
0687: " update #t0029_t1 set t1='1999-01-01' "
0688: +
0689:
0690: " insert into #t0029_t1 values "
0691: + " ('1999-01-08', '1998-09-09 15:35:05', "
0692: + " getdate(), '1998-09-09 15:35:00','456') "
0693: +
0694:
0695: " update #t0029_t1 set t2='1999-01-02' "
0696: +
0697:
0698: " declare @ptr varbinary(16) "
0699: + " select @ptr=textptr(t5) from #t0029_t1 "
0700: + " where t1='1999-01-08' "
0701: + " writetext #t0029_t1.t5 @ptr with log '123' ");
0702:
0703: updateCount = stmt.getUpdateCount();
0704: do {
0705: output.println("CREATE PROCEDURE isResultSet: "
0706: + isResultSet);
0707: output.println("CREATE PROCEDURE updateCount: "
0708: + updateCount);
0709: isResultSet = stmt.getMoreResults();
0710: updateCount = stmt.getUpdateCount();
0711: } while (((updateCount != -1) && !isResultSet) || isResultSet);
0712:
0713: isResultSet = stmt
0714: .execute("CREATE PROCEDURE #t0029_p2 AS "
0715: +
0716:
0717: " set nocount on "
0718: + " EXEC #t0029_p1 "
0719: + " SELECT * FROM #t0029_t1 ");
0720:
0721: updateCount = stmt.getUpdateCount();
0722: do {
0723: output.println("CREATE PROCEDURE isResultSet: "
0724: + isResultSet);
0725: output.println("CREATE PROCEDURE updateCount: "
0726: + updateCount);
0727: isResultSet = stmt.getMoreResults();
0728: updateCount = stmt.getUpdateCount();
0729: } while (((updateCount != -1) && !isResultSet) || isResultSet);
0730:
0731: isResultSet = stmt.execute("EXEC #t0029_p2 ");
0732:
0733: output.println("execute(EXEC #t0029_p2) returned: "
0734: + isResultSet);
0735:
0736: updateCount = stmt.getUpdateCount();
0737:
0738: while (isResultSet || (updateCount != -1)) {
0739: if (isResultSet) {
0740: resultSetCount++;
0741: rs = stmt.getResultSet();
0742:
0743: ResultSetMetaData rsMeta = rs.getMetaData();
0744: int columnCount = rsMeta.getColumnCount();
0745: output.println("columnCount: "
0746: + Integer.toString(columnCount));
0747: for (int n = 1; n <= columnCount; n++) {
0748: output.println(Integer.toString(n) + ": "
0749: + rsMeta.getColumnName(n));
0750: }
0751:
0752: while (rs.next()) {
0753: rowCount++;
0754: for (int n = 1; n <= columnCount; n++) {
0755: output.println(Integer.toString(n) + ": "
0756: + rs.getString(n));
0757: }
0758: }
0759:
0760: } else {
0761: numberOfUpdates += updateCount;
0762: output.println("UpdateCount: "
0763: + Integer.toString(updateCount));
0764: }
0765: isResultSet = stmt.getMoreResults();
0766: updateCount = stmt.getUpdateCount();
0767: }
0768: stmt.close();
0769:
0770: output.println("resultSetCount: " + resultSetCount);
0771: output.println("Total rowCount: " + rowCount);
0772: output.println("Number of updates: " + numberOfUpdates);
0773:
0774: assertTrue((resultSetCount == 1) && (rowCount == 2)
0775: && (numberOfUpdates == 0));
0776: }
0777:
0778: public void testDataTypesByResultSetMetaData0030() throws Exception {
0779: Statement stmt = con.createStatement();
0780: ResultSet rs;
0781:
0782: String sql = ("select " + " convert(tinyint, 2), "
0783: + " convert(smallint, 5) ");
0784:
0785: rs = stmt.executeQuery(sql);
0786: if (!rs.next()) {
0787: fail("Expecting one row");
0788: } else {
0789: ResultSetMetaData meta = rs.getMetaData();
0790:
0791: if (meta.getColumnType(1) != java.sql.Types.TINYINT) {
0792: fail("tinyint column was read as "
0793: + meta.getColumnType(1));
0794: }
0795: if (meta.getColumnType(2) != java.sql.Types.SMALLINT) {
0796: fail("smallint column was read as "
0797: + meta.getColumnType(2));
0798: }
0799: if (rs.getInt(1) != 2) {
0800: fail("Bogus value read for tinyint");
0801: }
0802: if (rs.getInt(2) != 5) {
0803: fail("Bogus value read for smallint");
0804: }
0805: }
0806: stmt.close();
0807: }
0808:
0809: public void testTextColumns0031() throws Exception {
0810: Statement stmt = con.createStatement();
0811:
0812: assertEquals(0, stmt
0813: .executeUpdate("create table #t0031 "
0814: + " (t_nullable text null, "
0815: + " t_notnull text not null, "
0816: + " i int not null) "));
0817:
0818: stmt.executeUpdate("insert into #t0031 values(null, '', 1)");
0819: stmt.executeUpdate("insert into #t0031 values(null, 'b1', 2)");
0820: stmt.executeUpdate("insert into #t0031 values('', '', 3)");
0821: stmt.executeUpdate("insert into #t0031 values('', 'b2', 4)");
0822: stmt.executeUpdate("insert into #t0031 values('a1', '', 5)");
0823: stmt.executeUpdate("insert into #t0031 values('a2', 'b3', 6)");
0824:
0825: ResultSet rs = stmt.executeQuery("select * from #t0031 "
0826: + " order by i ");
0827:
0828: assertTrue(rs.next());
0829: assertEquals(null, rs.getString(1));
0830: assertEquals("", rs.getString(2));
0831: assertEquals(1, rs.getInt(3));
0832:
0833: assertTrue(rs.next());
0834: assertEquals(null, rs.getString(1));
0835: assertEquals("b1", rs.getString(2));
0836: assertEquals(2, rs.getInt(3));
0837:
0838: assertTrue(rs.next());
0839: assertEquals("", rs.getString(1));
0840: assertEquals("", rs.getString(2));
0841: assertEquals(3, rs.getInt(3));
0842:
0843: assertTrue(rs.next());
0844: assertEquals("", rs.getString(1));
0845: assertEquals("b2", rs.getString(2));
0846: assertEquals(4, rs.getInt(3));
0847:
0848: assertTrue(rs.next());
0849: assertEquals("a1", rs.getString(1));
0850: assertEquals("", rs.getString(2));
0851: assertEquals(5, rs.getInt(3));
0852:
0853: assertTrue(rs.next());
0854: assertEquals("a2", rs.getString(1));
0855: assertEquals("b3", rs.getString(2));
0856: assertEquals(6, rs.getInt(3));
0857:
0858: stmt.close();
0859: }
0860:
0861: public void testSpHelpSysUsers0032() throws Exception {
0862: Statement stmt = con.createStatement();
0863: boolean passed = true;
0864: boolean isResultSet;
0865: boolean done;
0866: int i;
0867: int updateCount;
0868:
0869: output.println("Starting test #t0032- test sp_help sysusers");
0870:
0871: isResultSet = stmt.execute("sp_help sysusers");
0872:
0873: output.println("Executed the statement. rc is " + isResultSet);
0874:
0875: do {
0876: if (isResultSet) {
0877: output.println("About to call getResultSet");
0878: ResultSet rs = stmt.getResultSet();
0879: ResultSetMetaData meta = rs.getMetaData();
0880: updateCount = 0;
0881: while (rs.next()) {
0882: for (i = 1; i <= meta.getColumnCount(); i++) {
0883: output.print(rs.getString(i) + "\t");
0884: }
0885: output.println("");
0886: }
0887: output.println("Done processing the result set");
0888: } else {
0889: output.println("About to call getUpdateCount()");
0890: updateCount = stmt.getUpdateCount();
0891: output.println("Updated " + updateCount + " rows");
0892: }
0893: output.println("About to call getMoreResults()");
0894: isResultSet = stmt.getMoreResults();
0895: done = !isResultSet && updateCount == -1;
0896: } while (!done);
0897: stmt.close();
0898:
0899: assertTrue(passed);
0900: }
0901:
0902: static String longString(char ch) {
0903: int i;
0904: StringBuffer str255 = new StringBuffer(255);
0905:
0906: for (i = 0; i < 255; i++) {
0907: str255.append(ch);
0908: }
0909: return str255.toString();
0910: }
0911:
0912: public void testExceptionByUpdate0033() throws Exception {
0913: boolean passed;
0914: Statement stmt = con.createStatement();
0915: output
0916: .println("Starting test #t0033- make sure Statement.executeUpdate() throws exception");
0917:
0918: try {
0919: passed = false;
0920: stmt.executeUpdate("I am sure this is an error");
0921: } catch (SQLException e) {
0922: output.println("The exception is " + e.getMessage());
0923: passed = true;
0924: }
0925: stmt.close();
0926: assertTrue(passed);
0927: }
0928:
0929: public void testInsertConflict0049() throws Exception {
0930: try {
0931: dropTable("jTDS_t0049b"); // important: first drop this because of foreign key
0932: dropTable("jTDS_t0049a");
0933:
0934: Statement stmt = con.createStatement();
0935:
0936: String query = "create table jTDS_t0049a( "
0937: + " a integer identity(1,1) primary key, "
0938: + " b char not null)";
0939:
0940: assertEquals(0, stmt.executeUpdate(query));
0941:
0942: query = "create table jTDS_t0049b( "
0943: + " a integer not null, "
0944: + " c char not null, "
0945: + " foreign key (a) references jTDS_t0049a(a)) ";
0946: assertEquals(0, stmt.executeUpdate(query));
0947:
0948: query = "insert into jTDS_t0049b (a, c) values (?, ?)";
0949: java.sql.PreparedStatement pstmt = con
0950: .prepareStatement(query);
0951:
0952: try {
0953: pstmt.setInt(1, 1);
0954: pstmt.setString(2, "a");
0955: pstmt.executeUpdate();
0956: fail("Was expecting INSERT to fail");
0957: } catch (SQLException e) {
0958: assertEquals("23000", e.getSQLState());
0959: }
0960: pstmt.close();
0961:
0962: assertEquals(
0963: 1,
0964: stmt
0965: .executeUpdate("insert into jTDS_t0049a (b) values ('a')"));
0966:
0967: pstmt = con.prepareStatement(query);
0968: pstmt.setInt(1, 1);
0969: pstmt.setString(2, "a");
0970: assertEquals(1, pstmt.executeUpdate());
0971:
0972: stmt.close();
0973: pstmt.close();
0974: } finally {
0975: dropTable("jTDS_t0049b"); // important: first drop this because of foreign key
0976: dropTable("jTDS_t0049a");
0977: }
0978: }
0979:
0980: public void testxx0050() throws Exception {
0981: try {
0982: Statement stmt = con.createStatement();
0983:
0984: dropTable("jTDS_t0050b");
0985: dropTable("jTDS_t0050a");
0986:
0987: String query = "create table jTDS_t0050a( "
0988: + " a integer identity(1,1) primary key, "
0989: + " b char not null)";
0990:
0991: assertEquals(0, stmt.executeUpdate(query));
0992:
0993: query = "create table jTDS_t0050b( "
0994: + " a integer not null, "
0995: + " c char not null, "
0996: + " foreign key (a) references jTDS_t0050a(a)) ";
0997: assertEquals(0, stmt.executeUpdate(query));
0998:
0999: query = "create procedure #p0050 (@a integer, @c char) as "
1000: + " insert into jTDS_t0050b (a, c) values (@a, @c)";
1001: assertEquals(0, stmt.executeUpdate(query));
1002:
1003: query = "exec #p0050 ?, ?";
1004: java.sql.CallableStatement cstmt = con.prepareCall(query);
1005:
1006: try {
1007: cstmt.setInt(1, 1);
1008: cstmt.setString(2, "a");
1009: cstmt.executeUpdate();
1010: fail("Expecting INSERT to fail");
1011: } catch (SQLException e) {
1012: assertEquals("23000", e.getSQLState());
1013: }
1014:
1015: assertEquals(
1016: 1,
1017: stmt
1018: .executeUpdate("insert into jTDS_t0050a (b) values ('a')"));
1019:
1020: assertEquals(1, cstmt.executeUpdate());
1021:
1022: stmt.close();
1023: cstmt.close();
1024: } finally {
1025: dropTable("jTDS_t0050b");
1026: dropTable("jTDS_t0050a");
1027: }
1028: }
1029:
1030: public void testxx0051() throws Exception {
1031: boolean passed = true;
1032:
1033: try {
1034: String types[] = { "TABLE" };
1035: DatabaseMetaData dbMetaData = con.getMetaData();
1036: ResultSet rs = dbMetaData.getTables(null, "%", "t%", types);
1037:
1038: while (rs.next()) {
1039: output.println("Table " + rs.getString(3));
1040: output.println(" catalog " + rs.getString(1));
1041: output.println(" schema " + rs.getString(2));
1042: output.println(" name " + rs.getString(3));
1043: output.println(" type " + rs.getString(4));
1044: output.println(" remarks " + rs.getString(5));
1045: }
1046: } catch (java.sql.SQLException e) {
1047: passed = false;
1048: output.println("Exception caught. " + e.getMessage());
1049: e.printStackTrace();
1050: }
1051: assertTrue(passed);
1052: }
1053:
1054: public void testxx0055() throws Exception {
1055: boolean passed = true;
1056: int i;
1057:
1058: try {
1059: String expectedNames[] = { "TABLE_CAT", "TABLE_SCHEM",
1060: "TABLE_NAME", "TABLE_TYPE", "REMARKS", "TYPE_CAT",
1061: "TYPE_SCHEM", "TYPE_NAME",
1062: "SELF_REFERENCING_COL_NAME", "REF_GENERATION" };
1063: String types[] = { "TABLE" };
1064: DatabaseMetaData dbMetaData = con.getMetaData();
1065: ResultSet rs = dbMetaData.getTables(null, "%", "t%", types);
1066: ResultSetMetaData rsMetaData = rs.getMetaData();
1067:
1068: if (rsMetaData.getColumnCount() != expectedNames.length) {
1069: passed = false;
1070: output.println("Bad column count. Should be "
1071: + expectedNames.length + ", was "
1072: + rsMetaData.getColumnCount());
1073: }
1074:
1075: for (i = 0; passed && i < expectedNames.length; i++) {
1076: if (!rsMetaData.getColumnName(i + 1).equals(
1077: expectedNames[i])) {
1078: passed = false;
1079: output.println("Bad name for column " + (i + 1)
1080: + ". " + "Was "
1081: + rsMetaData.getColumnName(i + 1)
1082: + ", expected " + expectedNames[i]);
1083: }
1084: }
1085: } catch (java.sql.SQLException e) {
1086: passed = false;
1087: output.println("Exception caught. " + e.getMessage());
1088: e.printStackTrace();
1089: }
1090: assertTrue(passed);
1091: }
1092:
1093: public void testxx0052() throws Exception {
1094: boolean passed = true;
1095:
1096: // ugly, I know
1097: byte[] image = { (byte) 0x47, (byte) 0x49, (byte) 0x46,
1098: (byte) 0x38, (byte) 0x39, (byte) 0x61, (byte) 0x0A,
1099: (byte) 0x00, (byte) 0x0A, (byte) 0x00, (byte) 0x80,
1100: (byte) 0xFF, (byte) 0x00, (byte) 0xD7, (byte) 0x3D,
1101: (byte) 0x1B, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1102: (byte) 0x2C, (byte) 0x00, (byte) 0x00, (byte) 0x00,
1103: (byte) 0x00, (byte) 0x0A, (byte) 0x00, (byte) 0x0A,
1104: (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x08,
1105: (byte) 0x84, (byte) 0x8F, (byte) 0xA9, (byte) 0xCB,
1106: (byte) 0xED, (byte) 0x0F, (byte) 0x63, (byte) 0x2B,
1107: (byte) 0x00, (byte) 0x3B, };
1108:
1109: int i;
1110: int count;
1111: Statement stmt = con.createStatement();
1112:
1113: dropTable("#t0052");
1114:
1115: try {
1116: String sql = "create table #t0052 ( "
1117: + " myvarchar varchar(2000) not null, "
1118: + " myvarbinary varbinary(2000) not null) ";
1119:
1120: stmt.executeUpdate(sql);
1121:
1122: sql = "insert into #t0052 "
1123: + " (myvarchar, "
1124: + " myvarbinary) "
1125: + " values "
1126: + " (\'This is a test with german umlauts äöü\', "
1127: + " 0x4749463839610A000A0080FF00D73D1B0000002C000000000A000A00000208848FA9CBED0F632B003B"
1128: + " )";
1129: stmt.executeUpdate(sql);
1130:
1131: sql = "select * from #t0052";
1132: ResultSet rs = stmt.executeQuery(sql);
1133: if (!rs.next()) {
1134: passed = false;
1135: } else {
1136: output.println("Testing getAsciiStream()");
1137: InputStream in = rs.getAsciiStream("myvarchar");
1138: String expect = "This is a test with german umlauts ???";
1139: byte[] toRead = new byte[expect.length()];
1140: count = in.read(toRead);
1141: if (count == expect.length()) {
1142: for (i = 0; i < expect.length(); i++) {
1143: if (expect.charAt(i) != toRead[i]) {
1144: passed = false;
1145: output.println("Expected "
1146: + expect.charAt(i) + " but was "
1147: + toRead[i]);
1148: }
1149: }
1150: } else {
1151: passed = false;
1152: output.println("Premature end in "
1153: + "getAsciiStream(\"myvarchar\") " + count
1154: + " instead of " + expect.length());
1155: }
1156: in.close();
1157:
1158: in = rs.getAsciiStream(2);
1159: toRead = new byte[41];
1160: count = in.read(toRead);
1161: if (count == 41) {
1162: for (i = 0; i < 41; i++) {
1163: if (toRead[i] != (toRead[i] & 0x7F)) {
1164: passed = false;
1165: output
1166: .println("Non ASCII characters in getAsciiStream");
1167: break;
1168: }
1169: }
1170: } else {
1171: passed = false;
1172: output
1173: .println("Premature end in getAsciiStream(1) "
1174: + count + " instead of 41");
1175: }
1176: in.close();
1177:
1178: output.println("Testing getUnicodeStream()");
1179: Reader reader = rs.getCharacterStream("myvarchar");
1180: expect = "This is a test with german umlauts äöü";
1181: char[] charsToRead = new char[expect.length()];
1182: count = reader.read(charsToRead, 0, expect.length());
1183: if (count == expect.length()) {
1184: String result = new String(charsToRead);
1185: if (!expect.equals(result)) {
1186: passed = false;
1187: output.println("Expected " + expect
1188: + " but was " + result);
1189: }
1190: } else {
1191: passed = false;
1192: output.println("Premature end in "
1193: + "getUnicodeStream(\"myvarchar\") "
1194: + count + " instead of " + expect.length());
1195: }
1196: reader.close();
1197:
1198: /* Cannot think of a meaningfull test */
1199: reader = rs.getCharacterStream(2);
1200: reader.close();
1201:
1202: output.println("Testing getBinaryStream()");
1203:
1204: /* Cannot think of a meaningfull test */
1205: in = rs.getBinaryStream("myvarchar");
1206: in.close();
1207:
1208: in = rs.getBinaryStream(2);
1209: count = 0;
1210: toRead = new byte[image.length];
1211: do {
1212: int actuallyRead = in.read(toRead, count,
1213: image.length - count);
1214: if (actuallyRead == -1) {
1215: passed = false;
1216: output.println("Premature end in "
1217: + " getBinaryStream(2) " + count
1218: + " instead of " + image.length);
1219: break;
1220: }
1221: count += actuallyRead;
1222: } while (count < image.length);
1223:
1224: for (i = 0; i < count; i++) {
1225: if (toRead[i] != image[i]) {
1226: passed = false;
1227: output.println("Expected " + toRead[i]
1228: + "but was " + image[i]);
1229: break;
1230: }
1231: }
1232: in.close();
1233:
1234: output.println("Testing getCharacterStream()");
1235: try {
1236: reader = (Reader) UnitTestBase
1237: .invokeInstanceMethod(rs,
1238: "getCharacterStream",
1239: new Class[] { String.class },
1240: new Object[] { "myvarchar" });
1241: expect = "This is a test with german umlauts äöü";
1242: charsToRead = new char[expect.length()];
1243: count = reader
1244: .read(charsToRead, 0, expect.length());
1245: if (count == expect.length()) {
1246: String result = new String(charsToRead);
1247: if (!expect.equals(result)) {
1248: passed = false;
1249: output.println("Expected " + expect
1250: + " but was " + result);
1251: }
1252: } else {
1253: passed = false;
1254: output.println("Premature end in "
1255: + "getCharacterStream(\"myvarchar\") "
1256: + count + " instead of "
1257: + expect.length());
1258: }
1259: reader.close();
1260:
1261: /* Cannot think of a meaningfull test */
1262: reader = (Reader) UnitTestBase
1263: .invokeInstanceMethod(rs,
1264: "getCharacterStream",
1265: new Class[] { Integer.TYPE },
1266: new Object[] { new Integer(2) });
1267: reader.close();
1268: } catch (RuntimeException e) {
1269: // FIXME - This will not compile under 1.3...
1270: /*
1271: if (e.getCause() instanceof NoSuchMethodException) {
1272: output.println("JDBC 2 only");
1273: } else {
1274: */
1275: throw e;
1276: // }
1277: } catch (Throwable t) {
1278: passed = false;
1279: output.println("Exception: " + t.getMessage());
1280: }
1281: }
1282: rs.close();
1283:
1284: } catch (java.sql.SQLException e) {
1285: passed = false;
1286: output.println("Exception caught. " + e.getMessage());
1287: e.printStackTrace();
1288: }
1289: assertTrue(passed);
1290: stmt.close();
1291: }
1292:
1293: public void testxx0053() throws Exception {
1294: boolean passed = true;
1295:
1296: Statement stmt = con.createStatement();
1297:
1298: dropTable("#t0053");
1299: try {
1300: String sql = "create table #t0053 ( "
1301: + " myvarchar varchar(2000) not null, "
1302: + " mynchar nchar(2000) not null, "
1303: + " mynvarchar nvarchar(2000) not null, "
1304: + " myntext ntext not null "
1305: + " ) ";
1306:
1307: stmt.executeUpdate(sql);
1308:
1309: sql = "insert into #t0053 "
1310: + " (myvarchar, "
1311: + " mynchar, "
1312: + " mynvarchar, "
1313: + " myntext) "
1314: + " values "
1315: + " (\'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\', "
1316: + " \'äöüÄÖÜ\', "
1317: + " \'äöüÄÖÜ\', "
1318: + " \'äöüÄÖÜ\' " + " )";
1319: stmt.executeUpdate(sql);
1320:
1321: sql = "select * from #t0053";
1322: ResultSet rs = stmt.executeQuery(sql);
1323: if (!rs.next()) {
1324: passed = false;
1325: } else {
1326: System.err.print("Testing varchars > 255 chars: ");
1327: String test = rs.getString(1);
1328: if (test.length() == 270) {
1329: System.err.println("passed");
1330: } else {
1331: System.err.println("failed");
1332: passed = false;
1333: }
1334:
1335: System.err.print("Testing nchar: ");
1336: test = rs.getString(2);
1337: if (test.length() == 2000
1338: && "äöüÄÖÜ".equals(test.trim())) {
1339: System.err.println("passed");
1340: } else {
1341: System.err.print("failed, got \'");
1342: System.err.print(test.trim());
1343: System.err.println("\' instead of \'äöüÄÖÜ\'");
1344: passed = false;
1345: }
1346:
1347: System.err.print("Testing nvarchar: ");
1348: test = rs.getString(3);
1349: if (test.length() == 6 && "äöüÄÖÜ".equals(test)) {
1350: System.err.println("passed");
1351: } else {
1352: System.err.print("failed, got \'");
1353: System.err.print(test);
1354: System.err.println("\' instead of \'äöüÄÖÜ\'");
1355: passed = false;
1356: }
1357:
1358: System.err.print("Testing ntext: ");
1359: test = rs.getString(4);
1360: if (test.length() == 6 && "äöüÄÖÜ".equals(test)) {
1361: System.err.println("passed");
1362: } else {
1363: System.err.print("failed, got \'");
1364: System.err.print(test);
1365: System.err.println("\' instead of \'äöüÄÖÜ\'");
1366: passed = false;
1367: }
1368: }
1369: } catch (java.sql.SQLException e) {
1370: passed = false;
1371: output.println("Exception caught. " + e.getMessage());
1372: e.printStackTrace();
1373: }
1374: assertTrue(passed);
1375: stmt.close();
1376: }
1377:
1378: public void testxx005x() throws Exception {
1379: boolean passed = true;
1380:
1381: output
1382: .println("test getting a DECIMAL as a long from the database.");
1383:
1384: Statement stmt = con.createStatement();
1385:
1386: ResultSet rs;
1387:
1388: rs = stmt.executeQuery("select convert(DECIMAL(4,0), 0)");
1389: if (!rs.next()) {
1390: passed = false;
1391: } else {
1392: long l = rs.getLong(1);
1393: if (l != 0) {
1394: passed = false;
1395: }
1396: }
1397:
1398: rs = stmt.executeQuery("select convert(DECIMAL(4,0), 1)");
1399: if (!rs.next()) {
1400: passed = false;
1401: } else {
1402: long l = rs.getLong(1);
1403: if (l != 1) {
1404: passed = false;
1405: }
1406: }
1407:
1408: rs = stmt.executeQuery("select convert(DECIMAL(4,0), -1)");
1409: if (!rs.next()) {
1410: passed = false;
1411: } else {
1412: long l = rs.getLong(1);
1413: if (l != -1) {
1414: passed = false;
1415: }
1416: }
1417: assertTrue(passed);
1418: stmt.close();
1419: }
1420:
1421: public void testxx0057() throws Exception {
1422: output
1423: .println("test putting a zero length string into a parameter");
1424:
1425: // open the database
1426:
1427: int count;
1428: Statement stmt = con.createStatement();
1429:
1430: dropTable("#t0057");
1431:
1432: count = stmt.executeUpdate("create table #t0057 "
1433: + " (a varchar(10) not null, "
1434: + " b char(10) not null) ");
1435: stmt.close();
1436: output.println("Creating table affected " + count + " rows");
1437:
1438: PreparedStatement pstmt = con
1439: .prepareStatement("insert into #t0057 values (?, ?)");
1440: pstmt.setString(1, "");
1441: pstmt.setString(2, "");
1442: count = pstmt.executeUpdate();
1443: output.println("Added " + count + " rows");
1444: if (count != 1) {
1445: pstmt.close();
1446: output.println("Failed to add rows");
1447: fail();
1448: } else {
1449: pstmt.close();
1450: pstmt = con.prepareStatement("select a, b from #t0057");
1451:
1452: ResultSet rs = pstmt.executeQuery();
1453: if (!rs.next()) {
1454: output.println("Couldn't read rows from table.");
1455: fail();
1456: } else {
1457: output.println("a is |" + rs.getString("a") + "|");
1458: output.println("b is |" + rs.getString("b") + "|");
1459: assertEquals("", rs.getString("a"));
1460: assertEquals(" ", rs.getString("b"));
1461: }
1462: pstmt.close();
1463: }
1464: }
1465:
1466: public void testxx0059() throws Exception {
1467: try {
1468: DatabaseMetaData dbMetaData = con.getMetaData();
1469: ResultSet rs = dbMetaData.getSchemas();
1470: ResultSetMetaData rsm = rs.getMetaData();
1471:
1472: boolean JDBC3 = "1.4".compareTo(System
1473: .getProperty("java.specification.version")) <= 0;
1474:
1475: assertEquals(JDBC3 ? 2 : 1, rsm.getColumnCount());
1476: assertTrue(rsm.getColumnName(1).equalsIgnoreCase(
1477: "TABLE_SCHEM"));
1478: if (JDBC3) {
1479: assertTrue(rsm.getColumnName(2).equalsIgnoreCase(
1480: "TABLE_CATALOG"));
1481: }
1482:
1483: while (rs.next()) {
1484: output.println("schema " + rs.getString(1));
1485: }
1486: } catch (java.sql.SQLException e) {
1487: output.println("Exception caught. " + e.getMessage());
1488: e.printStackTrace();
1489: fail();
1490: }
1491: }
1492: }
|