Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b9deede

Browse files
author
Dave Cramer
committed
fixed up OID74 test to conform with other tests, by Kris Jurka
1 parent e9aec81 commit b9deede

File tree

1 file changed

+80
-99
lines changed

1 file changed

+80
-99
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,80 @@
1-
package org.postgresql.test.jdbc2;
2-
3-
import org.postgresql.test.TestUtil;
4-
import junit.framework.TestCase;
5-
import java.io.*;
6-
import java.sql.*;
7-
8-
import java.io.ByteArrayInputStream;
9-
import java.io.InputStream;
10-
import java.sql.*;
11-
12-
/**
13-
* User: alexei
14-
* Date: 17-Dec-2003
15-
* Time: 11:01:44
16-
* @version $Id: OID74Test.java,v 1.2 2003/12/17 15:45:05 davec Exp $
17-
*/
18-
public class OID74Test extends TestCase
19-
{
20-
private Connection con;
21-
22-
23-
public OID74Test( String name )
24-
{
25-
super(name);
26-
}
27-
public void setUp() throws Exception
28-
{
29-
}
30-
public void tearDown() throws Exception
31-
{
32-
}
33-
public void testBinaryStream()
34-
{
35-
//set up conection here
36-
Connection c = null;
37-
38-
Statement st = null;
39-
try
40-
{
41-
c = DriverManager.getConnection("jdbc:postgresql://localhost/test?compatible=7.1&user=test");
42-
c.setAutoCommit(false);
43-
st = c.createStatement();
44-
st.execute("CREATE temp TABLE temp (col oid)");
45-
}
46-
catch (SQLException e)
47-
{
48-
//another issue: when connecting to 7.3 database and this exception occurs because the table already exists,
49-
//st.setBinaryStream throws internal error in LargeObjectManager initialisation code
50-
fail("table creating error, probably already exists, code=" + e.getErrorCode());
51-
}
52-
finally
53-
{
54-
try{ if (st != null) st.close(); }catch(SQLException ex){};
55-
}
56-
57-
PreparedStatement pstmt = null;
58-
try
59-
{
60-
61-
pstmt = c.prepareStatement("INSERT INTO temp VALUES (?)");
62-
//in case of 7.4 server, should block here
63-
pstmt.setBinaryStream(1, new ByteArrayInputStream(new byte[]{1, 2, 3, 4, 5}), 5);
64-
assertTrue( (pstmt.executeUpdate() == 1) );
65-
pstmt.close();
66-
67-
pstmt = c.prepareStatement("SELECT col FROM temp LIMIT 1");
68-
ResultSet rs = pstmt.executeQuery();
69-
70-
assertTrue("No results from query", rs.next() );
71-
72-
//in case of 7.4 server, should block here
73-
InputStream in = rs.getBinaryStream(1);
74-
int data;
75-
while ((data = in.read()) != -1)
76-
System.out.println(data);
77-
rs.close();
78-
st.close();
79-
c.createStatement().executeUpdate("DELETE FROM temp");
80-
c.commit();
81-
}
82-
catch ( IOException ioex )
83-
{
84-
fail( ioex.getMessage() );
85-
}
86-
catch (SQLException ex)
87-
{
88-
fail( ex.getMessage() );
89-
}
90-
finally
91-
{
92-
try
93-
{
94-
if ( c!=null) c.close();
95-
}
96-
catch( SQLException e1){}
97-
}
98-
}
99-
}
1+
package org.postgresql.test.jdbc2;
2+
3+
import org.postgresql.test.TestUtil;
4+
import junit.framework.TestCase;
5+
import java.io.*;
6+
import java.sql.*;
7+
8+
import java.io.ByteArrayInputStream;
9+
import java.io.InputStream;
10+
import java.util.Properties;
11+
import java.sql.*;
12+
13+
/**
14+
* User: alexei
15+
* Date: 17-Dec-2003
16+
* Time: 11:01:44
17+
* @version $Id: OID74Test.java,v 1.3 2003/12/18 04:08:30 davec Exp $
18+
*/
19+
public class OID74Test extends TestCase
20+
{
21+
22+
public OID74Test( String name )
23+
{
24+
super(name);
25+
}
26+
public void setUp() throws Exception
27+
{
28+
}
29+
public void tearDown() throws Exception
30+
{
31+
}
32+
public void testBinaryStream() throws SQLException
33+
{
34+
//set up conection here
35+
Properties props = new Properties();
36+
props.setProperty("compatible","7.1");
37+
Connection c = TestUtil.openDB(props);
38+
c.setAutoCommit(false);
39+
40+
TestUtil.createTable(c,"temp","col oid");
41+
42+
Statement st = null;
43+
44+
PreparedStatement pstmt = null;
45+
try
46+
{
47+
48+
pstmt = c.prepareStatement("INSERT INTO temp VALUES (?)");
49+
pstmt.setBinaryStream(1, new ByteArrayInputStream(new byte[]{1, 2, 3, 4, 5}), 5);
50+
assertTrue( (pstmt.executeUpdate() == 1) );
51+
pstmt.close();
52+
53+
pstmt = c.prepareStatement("SELECT col FROM temp LIMIT 1");
54+
ResultSet rs = pstmt.executeQuery();
55+
56+
assertTrue("No results from query", rs.next() );
57+
58+
InputStream in = rs.getBinaryStream(1);
59+
int data;
60+
int i = 1;
61+
while ((data = in.read()) != -1)
62+
assertEquals(data,i++);
63+
rs.close();
64+
pstmt.close();
65+
c.createStatement().executeUpdate("DELETE FROM temp");
66+
c.commit();
67+
}
68+
catch ( IOException ioex )
69+
{
70+
fail( ioex.getMessage() );
71+
}
72+
catch (SQLException ex)
73+
{
74+
fail( ex.getMessage() );
75+
}
76+
77+
TestUtil.dropTable(c,"temp");
78+
TestUtil.closeDB(c);
79+
}
80+
}

0 commit comments

Comments
 (0)