001: //jTDS JDBC Driver for Microsoft SQL Server and Sybase
002: //Copyright (C) 2004 The jTDS Project
003: //
004: //This library is free software; you can redistribute it and/or
005: //modify it under the terms of the GNU Lesser General Public
006: //License as published by the Free Software Foundation; either
007: //version 2.1 of the License, or (at your option) any later version.
008: //
009: //This library is distributed in the hope that it will be useful,
010: //but WITHOUT ANY WARRANTY; without even the implied warranty of
011: //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: //Lesser General Public License for more details.
013: //
014: //You should have received a copy of the GNU Lesser General Public
015: //License along with this library; if not, write to the Free Software
016: //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: //
018: package net.sourceforge.jtds.test;
019:
020: import java.io.*;
021: import java.sql.*;
022:
023: import junit.framework.Test;
024: import junit.framework.TestSuite;
025:
026: /**
027: * @version 1.0
028: */
029: public class LargeLOBTest extends TestBase {
030: private static final int LOB_LENGTH = 100000000;
031:
032: /**
033: * Only run the test suite if the "jTDS.runLargeLOBTest" system property is defined, as the test takes A LOT of time
034: * to execute.
035: */
036: public static Test suite() {
037: if (System.getProperty("jTDS.runLargeLOBTest") == null) {
038: return new TestSuite();
039: }
040:
041: return new TestSuite(LargeLOBTest.class);
042: }
043:
044: public LargeLOBTest(String name) {
045: super (name);
046: }
047:
048: /*************************************************************************
049: *************************************************************************
050: ** BLOB TESTS **
051: *************************************************************************
052: *************************************************************************/
053:
054: /**
055: * Test for bug [945507] closing statement after selecting a large IMAGE - Exception
056: */
057: public void testLargeBlob1() throws Exception {
058: File data = File.createTempFile("blob", ".tmp");
059: data.deleteOnExit();
060:
061: FileOutputStream fos = new FileOutputStream(data);
062: BufferedOutputStream bos = new BufferedOutputStream(fos);
063:
064: byte buf[] = new byte[256];
065:
066: for (int i = 0; i < 256; i++) {
067: buf[i] = (byte) i;
068: }
069:
070: for (int i = 0; i < LOB_LENGTH; i += buf.length) {
071: bos.write(buf);
072: }
073: bos.write(buf, 0, LOB_LENGTH % buf.length);
074:
075: bos.close();
076:
077: Statement stmt = con.createStatement();
078: stmt.execute("CREATE TABLE #largeblob1 (data IMAGE)");
079: stmt.close();
080:
081: PreparedStatement pstmt = con
082: .prepareStatement("INSERT INTO #largeblob1 (data) VALUES (?)");
083: FileInputStream fis = new FileInputStream(data);
084: BufferedInputStream bis = new BufferedInputStream(fis);
085:
086: // Test PreparedStatement.setBinaryStream()
087: pstmt.setBinaryStream(1, bis, LOB_LENGTH);
088: assertTrue(pstmt.executeUpdate() == 1);
089:
090: pstmt.close();
091: bis.close();
092:
093: Statement stmt2 = con.createStatement();
094: ResultSet rs = stmt2
095: .executeQuery("SELECT data FROM #largeblob1");
096:
097: assertTrue(rs.next());
098:
099: fis = new FileInputStream(data);
100: bis = new BufferedInputStream(fis);
101:
102: // Test ResultSet.getBinaryStream()
103: compareInputStreams(bis, rs.getBinaryStream(1));
104: bis.close();
105:
106: assertFalse(rs.next());
107: stmt2.close();
108: rs.close();
109:
110: assertTrue(data.delete());
111: }
112:
113: public static void main(String[] args) {
114: junit.textui.TestRunner.run(LOBTest.class);
115: }
116: }
|