Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb9deede

Browse files
author
Dave Cramer
committed
fixed up OID74 test to conform with other tests, by Kris Jurka
1 parente9aec81 commitb9deede

File tree

1 file changed

+80
-99
lines changed

1 file changed

+80
-99
lines changed
Lines changed: 80 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,80 @@
1-
packageorg.postgresql.test.jdbc2;
2-
3-
importorg.postgresql.test.TestUtil;
4-
importjunit.framework.TestCase;
5-
importjava.io.*;
6-
importjava.sql.*;
7-
8-
importjava.io.ByteArrayInputStream;
9-
importjava.io.InputStream;
10-
importjava.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-
publicclassOID74TestextendsTestCase
19-
{
20-
privateConnectioncon;
21-
22-
23-
publicOID74Test(Stringname )
24-
{
25-
super(name);
26-
}
27-
publicvoidsetUp()throwsException
28-
{
29-
}
30-
publicvoidtearDown()throwsException
31-
{
32-
}
33-
publicvoidtestBinaryStream()
34-
{
35-
//set up conection here
36-
Connectionc =null;
37-
38-
Statementst =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 (SQLExceptione)
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(SQLExceptionex){};
55-
}
56-
57-
PreparedStatementpstmt =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,newByteArrayInputStream(newbyte[]{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-
ResultSetrs =pstmt.executeQuery();
69-
70-
assertTrue("No results from query",rs.next() );
71-
72-
//in case of 7.4 server, should block here
73-
InputStreamin =rs.getBinaryStream(1);
74-
intdata;
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 (IOExceptionioex )
83-
{
84-
fail(ioex.getMessage() );
85-
}
86-
catch (SQLExceptionex)
87-
{
88-
fail(ex.getMessage() );
89-
}
90-
finally
91-
{
92-
try
93-
{
94-
if (c!=null)c.close();
95-
}
96-
catch(SQLExceptione1){}
97-
}
98-
}
99-
}
1+
packageorg.postgresql.test.jdbc2;
2+
3+
importorg.postgresql.test.TestUtil;
4+
importjunit.framework.TestCase;
5+
importjava.io.*;
6+
importjava.sql.*;
7+
8+
importjava.io.ByteArrayInputStream;
9+
importjava.io.InputStream;
10+
importjava.util.Properties;
11+
importjava.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+
publicclassOID74TestextendsTestCase
20+
{
21+
22+
publicOID74Test(Stringname )
23+
{
24+
super(name);
25+
}
26+
publicvoidsetUp()throwsException
27+
{
28+
}
29+
publicvoidtearDown()throwsException
30+
{
31+
}
32+
publicvoidtestBinaryStream()throwsSQLException
33+
{
34+
//set up conection here
35+
Propertiesprops =newProperties();
36+
props.setProperty("compatible","7.1");
37+
Connectionc =TestUtil.openDB(props);
38+
c.setAutoCommit(false);
39+
40+
TestUtil.createTable(c,"temp","col oid");
41+
42+
Statementst =null;
43+
44+
PreparedStatementpstmt =null;
45+
try
46+
{
47+
48+
pstmt =c.prepareStatement("INSERT INTO temp VALUES (?)");
49+
pstmt.setBinaryStream(1,newByteArrayInputStream(newbyte[]{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+
ResultSetrs =pstmt.executeQuery();
55+
56+
assertTrue("No results from query",rs.next() );
57+
58+
InputStreamin =rs.getBinaryStream(1);
59+
intdata;
60+
inti =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 (IOExceptionioex )
69+
{
70+
fail(ioex.getMessage() );
71+
}
72+
catch (SQLExceptionex)
73+
{
74+
fail(ex.getMessage() );
75+
}
76+
77+
TestUtil.dropTable(c,"temp");
78+
TestUtil.closeDB(c);
79+
}
80+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp