Skip to content

Commit 3380d41

Browse files
author
ickzon
committed
o Fixed Sybase ASE compatibility of some JUnit tests.
git-svn-id: http://svn.code.sf.net/p/jtds/code/branches/jTDS%201.3%20(stable)@1283 97a8069c-bbaa-4fa2-9e49-561d8e0b19ef
1 parent cc889f5 commit 3380d41

13 files changed

+1082
-1044
lines changed

src/test/net/sourceforge/jtds/jdbc/AsTest.java

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,17 @@ public static void main(String args[]) {
5454
public void testProc0()
5555
throws Exception
5656
{
57+
dropProcedure( "spTestProc0" );
58+
dropTable( "tableTestProc0" );
59+
5760
Statement stmt = con.createStatement();
58-
dropProcedure( "#spTestProc0" );
5961

60-
stmt.executeUpdate( "create table #tableTestProc0 ( A varchar( 10 ) )" );
61-
stmt.executeUpdate( "insert into #tableTestProc0 values( 'testval' )" );
62-
stmt.executeUpdate( "create procedure #spTestProc0 as set nocount off select * into #tmp from #tableTestProc0 select * from #tmp" );
62+
stmt.executeUpdate( "create table tableTestProc0 ( A varchar( 10 ) )" );
63+
stmt.executeUpdate( "insert into tableTestProc0 values( 'testval' )" );
64+
stmt.executeUpdate( "create procedure spTestProc0 as set nocount off select * into #tmp from tableTestProc0 select * from #tmp" );
6365
stmt.close();
6466

65-
CallableStatement cstmt = con.prepareCall( "#spTestProc0" );
67+
CallableStatement cstmt = con.prepareCall( "spTestProc0" );
6668
assertFalse( cstmt.execute() );
6769
assertEquals( 1, cstmt.getUpdateCount() );
6870

@@ -124,9 +126,11 @@ public void testProc1() throws Exception {
124126
}
125127

126128
public void testProc2() throws Exception {
129+
dropProcedure( "multi1withcount" );
130+
dropProcedure( "multi1nocount" );
127131
Statement stmt = con.createStatement();
128132
String sqlwithcount =
129-
"create procedure #multi1withcount as " +
133+
"create procedure multi1withcount as " +
130134
" set nocount off " +
131135
" select 'a' " +
132136
" select 'b' " +
@@ -137,7 +141,7 @@ public void testProc2() throws Exception {
137141
" select 'a' " +
138142
" select 'b' ";
139143
String sqlnocount =
140-
"create procedure #multi1nocount as " +
144+
"create procedure multi1nocount as " +
141145
" set nocount on " +
142146
" select 'a' " +
143147
" select 'b' " +
@@ -147,13 +151,13 @@ public void testProc2() throws Exception {
147151
" insert into #multi1nocountt VALUES ('a') " +
148152
" select 'a' " +
149153
" select 'b' ";
150-
dropProcedure("#multi1withcount");
151-
dropProcedure("#multi1nocount");
154+
dropProcedure("multi1withcount");
155+
dropProcedure("multi1nocount");
152156
stmt.executeUpdate(sqlwithcount);
153157
stmt.executeUpdate(sqlnocount);
154158
stmt.close();
155159

156-
CallableStatement cstmt = con.prepareCall("#multi1nocount");
160+
CallableStatement cstmt = con.prepareCall("multi1nocount");
157161
assertTrue(cstmt.execute());
158162
ResultSet rs = cstmt.getResultSet();
159163
assertTrue(rs.next());
@@ -175,7 +179,7 @@ public void testProc2() throws Exception {
175179
assertTrue(!cstmt.getMoreResults() && cstmt.getUpdateCount() == -1);
176180
cstmt.close();
177181

178-
cstmt = con.prepareCall("#multi1withcount");
182+
cstmt = con.prepareCall("multi1withcount");
179183

180184
// The JDBC-ODBC driver does not return update counts from stored
181185
// procedures so we won't, either.
@@ -215,13 +219,16 @@ public void testProc2() throws Exception {
215219
public void testProc3()
216220
throws Exception
217221
{
222+
dropProcedure( "spBug654" );
223+
dropTable( "Bug654" );
224+
218225
Statement stm = con.createStatement();
219-
stm.executeUpdate( "create table #Bug654 ( A int )" );
220-
stm.executeUpdate( "insert into #Bug654 values ( 1 )" );
221-
stm.executeUpdate( "create procedure #spBug654 as select * from #Bug654" );
226+
stm.executeUpdate( "create table Bug654 ( A int )" );
227+
stm.executeUpdate( "insert into Bug654 values ( 1 )" );
228+
stm.executeUpdate( "create procedure spBug654 as select * from Bug654" );
222229
stm.close();
223230

224-
CallableStatement cstm = con.prepareCall( "#spBug654" );
231+
CallableStatement cstm = con.prepareCall( "spBug654" );
225232

226233
ResultSet rs = cstm.executeQuery();
227234
assertNotNull( rs );
@@ -336,11 +343,11 @@ public void testBatch1() throws Exception {
336343

337344
public void testBug457955() throws Exception {
338345
Statement stmt = con.createStatement();
339-
dropProcedure("#Bug457955");
340-
stmt.executeUpdate(" create procedure #Bug457955 (@par1 VARCHAR(10)) as select @par1");
346+
dropProcedure("Bug457955");
347+
stmt.executeUpdate(" create procedure Bug457955 (@par1 VARCHAR(10)) as select @par1");
341348
stmt.close();
342349
String param = "123456789";
343-
CallableStatement cstmt = con.prepareCall("exec #Bug457955 ?");
350+
CallableStatement cstmt = con.prepareCall("exec Bug457955 ?");
344351
cstmt.setString(1, param);
345352
cstmt.executeQuery();
346353
cstmt.close();
@@ -489,17 +496,23 @@ public void testBigInt() throws Throwable {
489496
}
490497

491498
public void testBoolean() throws Throwable {
492-
// String crtab = "create table #testBigInt (a bigint)";
493-
String crtab = "create table #testBit (a BIT NULL)";
499+
// Sybase ASE doesn't support NULL values for fields of type BIT
500+
String crtab = "create table #testBit (a BIT" + ( isMSSQL() ? " NULL" : "" ) + ")";
494501
dropTable("#testBit");
495502
Statement stmt = con.createStatement();
496503
stmt.executeUpdate(crtab);
497-
stmt.executeUpdate("insert into #testBit values (NULL)");
504+
// Sybase ASE doesn't support NULL values for fields of type BIT
505+
if( isMSSQL() ) stmt.executeUpdate("insert into #testBit values (NULL)");
498506
stmt.executeUpdate("insert into #testBit values (0)");
499507
stmt.executeUpdate("insert into #testBit values (1)");
500-
ResultSet rs = stmt.executeQuery("select * from #testBit where a is NULL");
501-
rs.next();
502-
rs.getBoolean(1);
508+
ResultSet rs;
509+
// Sybase ASE doesn't support NULL values for fields of type BIT
510+
if( isMSSQL() )
511+
{
512+
rs = stmt.executeQuery("select * from #testBit where a is NULL");
513+
rs.next();
514+
rs.getBoolean(1);
515+
}
503516
rs = stmt.executeQuery("select * from #testBit where a = 0");
504517
rs.next();
505518
rs.getBoolean(1);

src/test/net/sourceforge/jtds/jdbc/BatchTest.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import java.sql.*;
2121
import java.util.*;
2222

23-
import net.sourceforge.jtds.jdbc.*;
24-
2523
/**
2624
* Simple test suite to exercise batch execution.
2725
*
@@ -101,7 +99,7 @@ public void testBatch() throws Exception {
10199
assertEquals(EXECUTE_FAILED, x[3]);
102100
assertEquals(EXECUTE_FAILED, x[4]);
103101
} else {
104-
// Sybase or SQL Server 6.5 - Entire batch fails due to data conversion error
102+
// Sybase or SQL Server 6.5 - Entire batch fails due to data conversion error
105103
// detected in statement 3
106104
assertEquals(5, x.length);
107105
assertEquals(EXECUTE_FAILED, x[0]);
@@ -154,7 +152,7 @@ public void testPrepStmtBatch() throws Exception {
154152
assertEquals(EXECUTE_FAILED, x[3]);
155153
assertEquals(EXECUTE_FAILED, x[4]);
156154
} else {
157-
// Sybase - Entire batch fails due to data conversion error
155+
// Sybase - Entire batch fails due to data conversion error
158156
// detected in statement 3
159157
assertEquals(5, x.length);
160158
assertEquals(EXECUTE_FAILED, x[0]);
@@ -435,7 +433,7 @@ public void testBatchDupKey() throws Exception {
435433
assertEquals(1, x[3]);
436434
assertEquals(1, x[4]);
437435
}
438-
436+
439437
/**
440438
* Test for PreparedStatement batch with no parameters.
441439
*/
@@ -498,7 +496,7 @@ public void testPrepStmtVariableParams() throws Exception {
498496
}
499497
assertEquals(5, i);
500498
}
501-
499+
502500
/**
503501
* Test batched callable statements where the call has no parameters.
504502
*/
@@ -538,9 +536,9 @@ public void testCallStmtNoParams() throws Exception {
538536
*/
539537
private class ConcurrentBatchingHelper extends Thread {
540538
/** Connection on which to do the work. */
541-
private Connection con;
539+
private final Connection con;
542540
/** Container to store any exceptions into. */
543-
private Vector exceptions;
541+
private final Vector exceptions;
544542

545543
ConcurrentBatchingHelper(Connection con, Vector exceptions) {
546544
this.con = con;
@@ -602,7 +600,7 @@ public void testConcurrentBatching() throws Exception {
602600
props.setProperty(Messages.get(net.sourceforge.jtds.jdbc.Driver.PREPARESQL),
603601
String.valueOf(TdsCore.TEMPORARY_STORED_PROCEDURES));
604602
Connection con = getConnection(props);
605-
603+
606604
try {
607605
Statement stmt = con.createStatement();
608606
stmt.execute("create table #testConcurrentBatch (v1 int, v2 int, v3 int, v4 int, v5 int, v6 int)");
@@ -703,8 +701,8 @@ public void testBatchUpdateCounts() throws SQLException {
703701
Statement statement = con.createStatement();
704702
statement.execute("CREATE TABLE #BATCHUC (id int)");
705703
statement.addBatch("insert into #BATCHUC values (1)");
706-
statement.addBatch("insert into #BATCHUC values (2);insert into #BATCHUC values (3)");
707-
statement.addBatch("insert into #BATCHUC values (4);insert into #BATCHUC values (5);insert into #BATCHUC values (6)");
704+
statement.addBatch("insert into #BATCHUC values (2) insert into #BATCHUC values (3)");
705+
statement.addBatch("insert into #BATCHUC values (4) insert into #BATCHUC values (5) insert into #BATCHUC values (6)");
708706
// below: create identifiable update counts to show if/how far they have been shifted due to bug [2827931]
709707
statement.addBatch("insert into #BATCHUC select * from #BATCHUC");
710708
statement.addBatch("insert into #BATCHUC select * from #BATCHUC where id=999");

src/test/net/sourceforge/jtds/jdbc/CSUnitTest.java

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,11 @@ public void testCallStoredProcedures0028() throws Exception {
681681
assertTrue((rowCount>=1) && (numberOfUpdates==0) && (resultSetCount==1));
682682
}
683683
public void testxx0029() throws Exception {
684+
685+
dropProcedure( "t0029_p1" );
686+
dropProcedure( "t0029_p2" );
687+
dropTable("#t0029_t1");
688+
684689
Statement stmt = con.createStatement();
685690
ResultSet rs;
686691

@@ -694,33 +699,6 @@ public void testxx0029() throws Exception {
694699

695700
output.println("before execute DROP PROCEDURE");
696701

697-
try {
698-
isResultSet =stmt.execute("DROP PROCEDURE #t0029_p1");
699-
updateCount = stmt.getUpdateCount();
700-
do {
701-
output.println("DROP PROCEDURE isResultSet: " + isResultSet);
702-
output.println("DROP PROCEDURE updateCount: " + updateCount);
703-
isResultSet = stmt.getMoreResults();
704-
updateCount = stmt.getUpdateCount();
705-
} while (((updateCount!=-1) && !isResultSet) || isResultSet);
706-
} catch (SQLException e) {
707-
}
708-
709-
try {
710-
isResultSet =stmt.execute("DROP PROCEDURE #t0029_p2");
711-
updateCount = stmt.getUpdateCount();
712-
do {
713-
output.println("DROP PROCEDURE isResultSet: " + isResultSet);
714-
output.println("DROP PROCEDURE updateCount: " + updateCount);
715-
isResultSet = stmt.getMoreResults();
716-
updateCount = stmt.getUpdateCount();
717-
} while (((updateCount!=-1) && !isResultSet) || isResultSet);
718-
} catch (SQLException e) {
719-
}
720-
721-
722-
dropTable("#t0029_t1");
723-
724702
isResultSet =
725703
stmt.execute(
726704
" create table #t0029_t1 " +
@@ -740,7 +718,7 @@ public void testxx0029() throws Exception {
740718

741719
isResultSet =
742720
stmt.execute(
743-
"CREATE PROCEDURE #t0029_p1 AS " +
721+
"CREATE PROCEDURE t0029_p1 AS " +
744722

745723
" insert into #t0029_t1 values " +
746724
" ('1999-01-07', '1998-09-09 15:35:05', " +
@@ -770,10 +748,10 @@ public void testxx0029() throws Exception {
770748

771749
isResultSet =
772750
stmt.execute(
773-
"CREATE PROCEDURE #t0029_p2 AS " +
751+
"CREATE PROCEDURE t0029_p2 AS " +
774752

775753
" set nocount on " +
776-
" EXEC #t0029_p1 " +
754+
" EXEC t0029_p1 " +
777755
" SELECT * FROM #t0029_t1 ");
778756

779757
updateCount = stmt.getUpdateCount();
@@ -785,9 +763,9 @@ public void testxx0029() throws Exception {
785763
} while (((updateCount!=-1) && !isResultSet) || isResultSet);
786764

787765

788-
isResultSet = stmt.execute( "EXEC #t0029_p2 ");
766+
isResultSet = stmt.execute( "EXEC t0029_p2 ");
789767

790-
output.println("execute(EXEC #t0029_p2) returned: " + isResultSet);
768+
output.println("execute(EXEC t0029_p2) returned: " + isResultSet);
791769

792770
updateCount=stmt.getUpdateCount();
793771

@@ -1033,6 +1011,7 @@ public void testxx0050() throws Exception {
10331011
try {
10341012
Statement stmt = con.createStatement();
10351013

1014+
dropProcedure( "p0050" );
10361015
dropTable("jTDS_t0050b");
10371016
dropTable("jTDS_t0050a");
10381017

@@ -1051,11 +1030,11 @@ public void testxx0050() throws Exception {
10511030
assertEquals(0, stmt.executeUpdate(query));
10521031

10531032
query =
1054-
"create procedure #p0050 (@a integer, @c char) as " +
1033+
"create procedure p0050 (@a integer, @c char) as " +
10551034
" insert into jTDS_t0050b (a, c) values (@a, @c)";
10561035
assertEquals(0, stmt.executeUpdate(query));
10571036

1058-
query = "exec #p0050 ?, ?";
1037+
query = "exec p0050 ?, ?";
10591038
java.sql.CallableStatement cstmt = con.prepareCall(query);
10601039

10611040
try {

0 commit comments

Comments
 (0)