Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ccc8f4c

Browse files
author
Dave Cramer
committed
Modifications to pass JDBC CTS
Added test cases which are essentially the same as the CTS to make sure we continue to pass it.
1 parent e6619c6 commit ccc8f4c

19 files changed

+454
-227
lines changed

org/postgresql/core/Oid.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgjdbc/org/postgresql/core/Oid.java,v 1.7 2005/01/11 08:25:43 jurka Exp $
6+
* $PostgreSQL: pgjdbc/org/postgresql/core/Oid.java,v 1.8 2005/04/10 21:54:16 jurka Exp $
77
*
88
*-------------------------------------------------------------------------
99
*/
@@ -35,5 +35,6 @@ public class Oid {
3535
public static final int MONEY = 790;
3636
public static final int NAME = 19;
3737
public static final int BIT = 1560;
38+
public static final int VOID = 2278;
3839

3940
}

org/postgresql/core/ParameterList.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2004, Open Cloud Limited.
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgjdbc/org/postgresql/core/ParameterList.java,v 1.5 2005/01/11 08:25:43 jurka Exp $
7+
* $PostgreSQL: pgjdbc/org/postgresql/core/ParameterList.java,v 1.6 2005/02/01 07:27:53 jurka Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -28,13 +28,24 @@
2828
* @author Oliver Jowett ([email protected])
2929
*/
3030
public interface ParameterList {
31+
32+
33+
void registerOutParameter( int index, int sqlType );
3134
/**
3235
* Get the number of parameters in this list. This value never changes
3336
* for a particular instance, and might be zero.
3437
*
3538
* @return the number of parameters in this list.
3639
*/
3740
int getParameterCount();
41+
42+
/**
43+
* Get the number of parameters in this list. This value may be different,
44+
* and might be zero.
45+
*
46+
* @return the number of in parameters in this list
47+
*/
48+
int getInParameterCount();
3849

3950

4051
/**

org/postgresql/core/v2/FastpathParameterList.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2004, Open Cloud Limited.
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgjdbc/org/postgresql/core/v2/FastpathParameterList.java,v 1.6 2005/01/11 08:25:43 jurka Exp $
7+
* $PostgreSQL: pgjdbc/org/postgresql/core/v2/FastpathParameterList.java,v 1.7 2005/02/01 07:27:54 jurka Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -34,14 +34,20 @@ class FastpathParameterList implements ParameterList {
3434
this.paramValues = new Object[paramCount];
3535
}
3636

37-
public int getParameterCount() {
37+
public void registerOutParameter(int index, int sqlType ){}
38+
public void registerOutParameter(int index, int sqlType, int precision ){};
39+
40+
public int getInParameterCount() {
41+
return paramValues.length;
42+
}
43+
public int getParameterCount()
44+
{
3845
return paramValues.length;
3946
}
40-
4147
public int[] getTypeOIDs() {
4248
return null;
4349
}
44-
50+
4551
public void setIntParameter(int index, int value) throws SQLException {
4652
if (index < 1 || index > paramValues.length)
4753
throw new PSQLException(GT.tr("The column index is out of range: {0}, number of columns: {1}.", new Object[]{new Integer(index), new Integer(paramValues.length)}), PSQLState.INVALID_PARAMETER_VALUE );

org/postgresql/core/v2/SimpleParameterList.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2004, Open Cloud Limited.
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgjdbc/org/postgresql/core/v2/SimpleParameterList.java,v 1.5 2005/01/11 08:25:43 jurka Exp $
7+
* $PostgreSQL: pgjdbc/org/postgresql/core/v2/SimpleParameterList.java,v 1.6 2005/02/01 07:27:54 jurka Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -31,11 +31,16 @@ class SimpleParameterList implements ParameterList {
3131
SimpleParameterList(int paramCount) {
3232
this.paramValues = new Object[paramCount];
3333
}
34-
35-
public int getParameterCount() {
34+
public void registerOutParameter(int index, int sqlType ){};
35+
public void registerOutParameter(int index, int sqlType, int precision ){};
36+
37+
public int getInParameterCount() {
38+
return paramValues.length;
39+
}
40+
public int getParameterCount()
41+
{
3642
return paramValues.length;
3743
}
38-
3944
public int[] getTypeOIDs() {
4045
return null;
4146
}

org/postgresql/core/v3/CompositeParameterList.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2004, Open Cloud Limited.
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/CompositeParameterList.java,v 1.6 2005/01/11 08:25:44 jurka Exp $
7+
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/CompositeParameterList.java,v 1.7 2005/02/01 07:27:54 jurka Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -29,7 +29,7 @@ class CompositeParameterList implements V3ParameterList {
2929
CompositeParameterList(SimpleParameterList[] subparams, int[] offsets) {
3030
this.subparams = subparams;
3131
this.offsets = offsets;
32-
this.total = offsets[offsets.length - 1] + subparams[offsets.length - 1].getParameterCount();
32+
this.total = offsets[offsets.length - 1] + subparams[offsets.length - 1].getInParameterCount();
3333
}
3434

3535
private final int findSubParam(int index) throws SQLException {
@@ -42,8 +42,17 @@ private final int findSubParam(int index) throws SQLException {
4242

4343
throw new IllegalArgumentException("I am confused; can't find a subparam for index " + index);
4444
}
45-
46-
public int getParameterCount() {
45+
public void registerOutParameter(int index, int sqlType)
46+
{
47+
48+
}
49+
public int getDirection(int i)
50+
{return 0;}
51+
public int getParameterCount()
52+
{
53+
return total;
54+
}
55+
public int getInParameterCount() {
4756
return total;
4857
}
4958

org/postgresql/core/v3/SimpleParameterList.java

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2004, Open Cloud Limited.
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleParameterList.java,v 1.7 2005/01/27 22:50:14 oliver Exp $
7+
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleParameterList.java,v 1.8 2005/02/01 07:27:54 jurka Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -27,10 +27,26 @@
2727
* @author Oliver Jowett ([email protected])
2828
*/
2929
class SimpleParameterList implements V3ParameterList {
30+
31+
private final static int IN=1;
32+
private final static int OUT=2;
33+
private final static int INOUT=3;
34+
// this is here to avoid creating objects for copy
35+
// copy will simply discard them
36+
37+
38+
3039
SimpleParameterList(int paramCount) {
3140
this.paramValues = new Object[paramCount];
3241
this.paramTypes = new int[paramCount];
3342
this.encoded = new byte[paramCount][];
43+
this.direction = new int[paramCount];
44+
}
45+
46+
47+
public void registerOutParameter( int index, int sqlType )
48+
{
49+
direction[index-1] |= OUT;
3450
}
3551

3652
private void bind(int index, Object value, int oid) throws SQLException {
@@ -40,8 +56,9 @@ private void bind(int index, Object value, int oid) throws SQLException {
4056
--index;
4157

4258
encoded[index] = null;
43-
paramValues[index] = value;
44-
59+
paramValues[index] = value ;
60+
direction[index] |= IN;
61+
4562
// If we are setting something to null, don't overwrite our existing type
4663
// for it. We don't need the correct type info to send NULL and we
4764
// don't want to overwrite and require a reparse.
@@ -51,9 +68,22 @@ private void bind(int index, Object value, int oid) throws SQLException {
5168
paramTypes[index] = oid;
5269
}
5370

54-
public int getParameterCount() {
71+
public int getParameterCount()
72+
{
5573
return paramValues.length;
5674
}
75+
public int getInParameterCount()
76+
{
77+
int count=0;
78+
for( int i=0; i< paramTypes.length;i++)
79+
{
80+
if (direction[i] != OUT )
81+
{
82+
count++;
83+
}
84+
}
85+
return count;
86+
}
5787

5888
public void setIntParameter(int index, int value) throws SQLException {
5989
byte[] data = new byte[4];
@@ -86,7 +116,6 @@ public void setNull(int index, int oid) throws SQLException {
86116

87117
public String toString(int index) {
88118
--index;
89-
90119
if (paramValues[index] == null)
91120
return "?";
92121
else if (paramValues[index] == NULL_OBJECT)
@@ -98,7 +127,7 @@ else if (paramValues[index] == NULL_OBJECT)
98127
public void checkAllParametersSet() throws SQLException {
99128
for (int i = 0; i < paramTypes.length; ++i)
100129
{
101-
if (paramValues[i] == null)
130+
if (direction[i] != OUT && paramValues[i] == null)
102131
throw new PSQLException(GT.tr("No value specified for parameter {0}.", new Integer(i + 1)), PSQLState.INVALID_PARAMETER_VALUE);
103132
}
104133
}
@@ -127,11 +156,17 @@ public int[] getTypeOIDs() {
127156
//
128157

129158
int getTypeOID(int index) {
130-
return paramTypes[index -1];
159+
if (direction[index-1] == OUT)
160+
{
161+
paramTypes[index-1] = Oid.VOID;
162+
paramValues[index-1] = "null";
163+
}
164+
165+
return paramTypes[index-1];
131166
}
132167

133168
boolean hasUnresolvedTypes() {
134-
for (int i=0; i<paramTypes.length; i++) {
169+
for (int i=0; i< paramTypes.length; i++) {
135170
if (paramTypes[i] == Oid.INVALID)
136171
return true;
137172
}
@@ -148,18 +183,18 @@ void setResolvedType(int index, int oid) {
148183
}
149184

150185
boolean isNull(int index) {
151-
return (paramValues[index -1] == NULL_OBJECT);
186+
return (paramValues[index-1] == NULL_OBJECT);
152187
}
153188

154189
boolean isBinary(int index) {
155190
// Currently, only StreamWrapper uses the binary parameter form.
156-
return (paramValues[index -1] instanceof StreamWrapper);
191+
return (paramValues[index-1] instanceof StreamWrapper);
157192
}
158193

159194
int getV3Length(int index) {
160195
--index;
161196

162-
// Null?
197+
// Null?
163198
if (paramValues[index] == NULL_OBJECT)
164199
throw new IllegalArgumentException("can't getV3Length() on a null parameter");
165200

@@ -208,31 +243,37 @@ void writeV3Value(int index, PGStream pgStream) throws IOException {
208243
pgStream.Send(encoded[index]);
209244
}
210245

246+
247+
211248
public ParameterList copy() {
212249
SimpleParameterList newCopy = new SimpleParameterList(paramValues.length);
213250
System.arraycopy(paramValues, 0, newCopy.paramValues, 0, paramValues.length);
214251
System.arraycopy(paramTypes, 0, newCopy.paramTypes, 0, paramTypes.length);
252+
System.arraycopy(direction, 0, newCopy.direction, 0, direction.length);
215253
return newCopy;
216254
}
217255

218256
public void clear() {
219257
Arrays.fill(paramValues, null);
220258
Arrays.fill(paramTypes, 0);
221259
Arrays.fill(encoded, null);
260+
Arrays.fill(direction, 0);
222261
}
223-
224262
public SimpleParameterList[] getSubparams() {
225263
return null;
226264
}
227265

228266
private final Object[] paramValues;
229267
private final int[] paramTypes;
268+
private final int[] direction;
230269
private final byte[][] encoded;
231-
270+
232271
/**
233272
* Marker object representing NULL; this distinguishes
234273
* "parameter never set" from "parameter set to null".
235274
*/
236275
private final static Object NULL_OBJECT = new Object();
276+
277+
237278
}
238279

org/postgresql/core/v3/SimpleQuery.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2004, Open Cloud Limited.
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleQuery.java,v 1.7 2005/01/27 22:50:14 oliver Exp $
7+
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/SimpleQuery.java,v 1.8 2005/02/01 07:27:54 jurka Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -70,6 +70,8 @@ String[] getFragments() {
7070
return fragments;
7171
}
7272

73+
74+
7375
void setStatementName(String statementName) {
7476
this.statementName = statementName;
7577
this.encodedStatementName = Utils.encodeUTF8(statementName);

org/postgresql/core/v3/V3ParameterList.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright (c) 2004, Open Cloud Limited.
55
*
66
* IDENTIFICATION
7-
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/V3ParameterList.java,v 1.3 2004/11/09 08:46:20 jurka Exp $
7+
* $PostgreSQL: pgjdbc/org/postgresql/core/v3/V3ParameterList.java,v 1.4 2005/01/11 08:25:44 jurka Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -39,4 +39,7 @@ interface V3ParameterList extends ParameterList {
3939
* parameter list.
4040
*/
4141
SimpleParameterList[] getSubparams();
42+
43+
44+
4245
}

org/postgresql/jdbc2/AbstractJdbc2Connection.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.29 2005/04/20 00:10:58 oliver Exp $
6+
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Connection.java,v 1.30 2005/06/21 18:07:08 davec Exp $
77
*
88
*-------------------------------------------------------------------------
99
*/
@@ -15,6 +15,7 @@
1515
import java.util.*;
1616
import org.postgresql.core.*;
1717
import org.postgresql.Driver;
18+
import org.postgresql.PGConnection;
1819
import org.postgresql.PGNotification;
1920
import org.postgresql.fastpath.Fastpath;
2021
import org.postgresql.largeobject.LargeObjectManager;

org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2005, PostgreSQL Global Development Group
44
*
55
* IDENTIFICATION
6-
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.21 2005/04/28 14:56:56 jurka Exp $
6+
* $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.22 2005/05/25 17:15:52 jurka Exp $
77
*
88
*-------------------------------------------------------------------------
99
*/
@@ -1244,7 +1244,7 @@ public boolean supportsSelectForUpdate() throws SQLException
12441244
*/
12451245
public boolean supportsStoredProcedures() throws SQLException
12461246
{
1247-
return false;
1247+
return true;
12481248
}
12491249

12501250
/*

0 commit comments

Comments
 (0)