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

Commit76a6da8

Browse files
committed
Attached is a patch to fix the current issues with building under jdbc1.
This patch moves the logic that looks up TypeOid, PGTypeName, andSQLTypeName from Field to Connection. It is moved to connection sinceit needs to differ from the jdbc1 to jdbc2 versions and Connectionalready has different subclasses for the two driver versions. It alsomade sense to move the logic to Connection as some of the logic wasalready there anyway.Barry Lind
1 parent968d773 commit76a6da8

File tree

12 files changed

+294
-171
lines changed

12 files changed

+294
-171
lines changed

‎src/interfaces/jdbc/org/postgresql/Connection.java

Lines changed: 86 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
importorg.postgresql.core.Encoding;
1212

1313
/**
14-
* $Id: Connection.java,v 1.25 2001/08/10 14:42:07 momjian Exp $
14+
* $Id: Connection.java,v 1.26 2001/08/24 16:50:12 momjian Exp $
1515
*
1616
* This abstract class is used by org.postgresql.Driver to open either the JDBC1 or
1717
* JDBC2 versions of the Connection class.
@@ -69,11 +69,10 @@ public abstract class Connection
6969
// New for 6.3, salt value for crypt authorisation
7070
privateStringsalt;
7171

72-
// This is used by Field to cache oid -> names.
73-
// It's here, because it's shared across this connection only.
74-
// Hence it cannot be static within the Field class, because it would then
75-
// be across all connections, which could be to different backends.
76-
publicHashtablefieldCache =newHashtable();
72+
// These are used to cache oids, PGTypes and SQLTypes
73+
privatestaticHashtablesqlTypeCache =newHashtable();// oid -> SQLType
74+
privatestaticHashtablepgTypeCache =newHashtable();// oid -> PGType
75+
privatestaticHashtabletypeOidCache =newHashtable();//PGType -> oid
7776

7877
// Now handle notices as warnings, so things like "show" now work
7978
publicSQLWarningfirstWarning =null;
@@ -1108,5 +1107,86 @@ public boolean haveMinimumServerVersion(String ver) throws SQLException
11081107
{
11091108
return (getDBVersionNumber().compareTo(ver) >=0);
11101109
}
1110+
1111+
1112+
/**
1113+
* This returns the java.sql.Types type for a PG type oid
1114+
*
1115+
* @param oid PostgreSQL type oid
1116+
* @return the java.sql.Types type
1117+
* @exception SQLException if a database access error occurs
1118+
*/
1119+
publicintgetSQLType(intoid)throwsSQLException
1120+
{
1121+
IntegersqlType = (Integer)typeOidCache.get(newInteger(oid));
1122+
1123+
// it's not in the cache, so perform a query, and add the result to the cache
1124+
if(sqlType==null) {
1125+
ResultSetresult = (org.postgresql.ResultSet)ExecSQL("select typname from pg_type where oid = " +oid);
1126+
if (result.getColumnCount() !=1 ||result.getTupleCount() !=1)
1127+
thrownewPSQLException("postgresql.unexpected");
1128+
result.next();
1129+
StringpgType =result.getString(1);
1130+
IntegeriOid =newInteger(oid);
1131+
sqlType =newInteger(getSQLType(result.getString(1)));
1132+
sqlTypeCache.put(iOid,sqlType);
1133+
pgTypeCache.put(iOid,pgType);
1134+
result.close();
1135+
}
1136+
1137+
returnsqlType.intValue();
1138+
}
1139+
1140+
/**
1141+
* This returns the java.sql.Types type for a PG type
1142+
*
1143+
* @param pgTypeName PostgreSQL type name
1144+
* @return the java.sql.Types type
1145+
*/
1146+
publicabstractintgetSQLType(StringpgTypeName);
1147+
1148+
/**
1149+
* This returns the oid for a given PG data type
1150+
* @param typeName PostgreSQL type name
1151+
* @return PostgreSQL oid value for a field of this type
1152+
*/
1153+
publicintgetOID(StringtypeName)throwsSQLException
1154+
{
1155+
intoid = -1;
1156+
if(typeName !=null) {
1157+
IntegeroidValue = (Integer)typeOidCache.get(typeName);
1158+
if(oidValue !=null) {
1159+
oid =oidValue.intValue();
1160+
}else {
1161+
// it's not in the cache, so perform a query, and add the result to the cache
1162+
ResultSetresult = (org.postgresql.ResultSet)ExecSQL("select oid from pg_type where typname='"
1163+
+typeName +"'");
1164+
if (result.getColumnCount() !=1 ||result.getTupleCount() !=1)
1165+
thrownewPSQLException("postgresql.unexpected");
1166+
result.next();
1167+
oid =Integer.parseInt(result.getString(1));
1168+
typeOidCache.put(typeName,newInteger(oid));
1169+
result.close();
1170+
}
1171+
}
1172+
returnoid;
1173+
}
1174+
1175+
/**
1176+
* We also need to get the PG type name as returned by the back end.
1177+
*
1178+
* @return the String representation of the type of this field
1179+
* @exception SQLException if a database access error occurs
1180+
*/
1181+
publicStringgetPGType(intoid)throwsSQLException
1182+
{
1183+
StringpgType = (String)pgTypeCache.get(newInteger(oid));
1184+
if(pgType ==null) {
1185+
getSQLType(oid);
1186+
pgType = (String)pgTypeCache.get(newInteger(oid));
1187+
}
1188+
returnpgType;
1189+
}
1190+
11111191
}
11121192

‎src/interfaces/jdbc/org/postgresql/Field.java

Lines changed: 26 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,13 @@
1212
*/
1313
publicclassField
1414
{
15-
publicintlength;// Internal Length of this field
16-
publicintoid;// OID of the type
17-
publicintmod;// type modifier of this field
18-
publicStringname;// Name of this field
15+
privateintlength;// Internal Length of this field
16+
privateintoid;// OID of the type
17+
privateintmod;// type modifier of this field
18+
privateStringname;// Name of this field
1919

20-
protectedConnectionconn;// Connection Instantation
20+
privateConnectionconn;// Connection Instantation
2121

22-
publicintsql_type = -1;// The entry in java.sql.Types for this field
23-
publicStringtype_name =null;// The sql type name
24-
25-
privatestaticHashtableoidCache =newHashtable();
2622

2723
/**
2824
* Construct a field based on the information fed to it.
@@ -63,140 +59,49 @@ public int getOID()
6359
}
6460

6561
/**
66-
* the ResultSet and ResultMetaData both need to handle the SQL
67-
* type, which is gained from another query. Note that we cannot
68-
* use getObject() in this, since getObject uses getSQLType().
69-
*
70-
* @return the entry in Types that refers to this field
71-
* @exception SQLException if a database access error occurs
62+
* @return the mod of this Field's data type
7263
*/
73-
publicintgetSQLType()throwsSQLException
64+
publicintgetMod()
7465
{
75-
if(sql_type == -1) {
76-
type_name = (String)conn.fieldCache.get(newInteger(oid));
77-
78-
// it's not in the cache, so perform a query, and add the result to
79-
// the cache
80-
if(type_name==null) {
81-
ResultSetresult = (org.postgresql.ResultSet)conn.ExecSQL("select typname from pg_type where oid = " +oid);
82-
if (result.getColumnCount() !=1 ||result.getTupleCount() !=1)
83-
thrownewPSQLException("postgresql.unexpected");
84-
result.next();
85-
type_name =result.getString(1);
86-
conn.fieldCache.put(newInteger(oid),type_name);
87-
result.close();
88-
}
89-
90-
sql_type =getSQLType(type_name);
91-
}
92-
returnsql_type;
66+
returnmod;
9367
}
9468

9569
/**
96-
* This returns the SQL type. It is called by the Field and DatabaseMetaData classes
97-
* @param type_name PostgreSQL type name
98-
* @return java.sql.Types value for oid
70+
* @return the name of this Field's data type
9971
*/
100-
publicstaticintgetSQLType(Stringtype_name)
72+
publicStringgetName()
10173
{
102-
intsql_type =Types.OTHER;// default value
103-
for(inti=0;i<types.length;i++)
104-
if(type_name.equals(types[i]))
105-
sql_type=typei[i];
106-
returnsql_type;
74+
returnname;
10775
}
10876

10977
/**
110-
* This returns the oid for a field of a given data type
111-
* @param type_name PostgreSQL type name
112-
* @return PostgreSQL oid value for a field of this type
78+
* @return the length of this Field's data type
11379
*/
114-
publicintgetOID(Stringtype_name )throwsSQLException
80+
publicintgetLength()
11581
{
116-
intoid = -1;
117-
if(type_name !=null) {
118-
IntegeroidValue = (Integer)oidCache.get(type_name );
119-
if(oidValue !=null )
120-
oid =oidValue.intValue();
121-
else {
122-
// it's not in the cache, so perform a query, and add the result to the cache
123-
ResultSetresult = (org.postgresql.ResultSet)conn.ExecSQL("select oid from pg_type where typname='"
124-
+type_name +"'");
125-
if (result.getColumnCount() !=1 ||result.getTupleCount() !=1)
126-
thrownewPSQLException("postgresql.unexpected");
127-
result.next();
128-
oid =Integer.parseInt(result.getString(1));
129-
oidCache.put(type_name,newInteger(oid) );
130-
result.close();
131-
}
132-
}
133-
returnoid;
82+
returnlength;
13483
}
13584

13685
/**
137-
* This table holds the org.postgresql names for the types supported.
138-
* Any types that map to Types.OTHER (eg POINT) don't go into this table.
139-
* They default automatically to Types.OTHER
140-
*
141-
* Note: This must be in the same order as below.
142-
*
143-
* Tip: keep these grouped together by the Types. value
144-
*/
145-
privatestaticfinalStringtypes[] = {
146-
"int2",
147-
"int4","oid",
148-
"int8",
149-
"cash","money",
150-
"numeric",
151-
"float4",
152-
"float8",
153-
"bpchar","char","char2","char4","char8","char16",
154-
"varchar","text","name","filename",
155-
"bool",
156-
"date",
157-
"time",
158-
"abstime","timestamp",
159-
"_bool","_char","_int2","_int4","_text","_oid","_varchar","_int8",
160-
"_float4","_float8","_abstime","_date","_time","_timestamp","_numeric"
161-
};
162-
163-
/**
164-
* This table holds the JDBC type for each entry above.
86+
* We also need to get the PG type name as returned by the back end.
16587
*
166-
* Note: This must be in the same order as above
167-
*
168-
* Tip: keep these grouped together by the Types. value
88+
* @return the String representation of the PG type of this field
89+
* @exception SQLException if a database access error occurs
16990
*/
170-
privatestaticfinalinttypei[] = {
171-
Types.SMALLINT,
172-
Types.INTEGER,Types.INTEGER,
173-
Types.BIGINT,
174-
Types.DOUBLE,Types.DOUBLE,
175-
Types.NUMERIC,
176-
Types.REAL,
177-
Types.DOUBLE,
178-
Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,
179-
Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
180-
Types.BIT,
181-
Types.DATE,
182-
Types.TIME,
183-
Types.TIMESTAMP,Types.TIMESTAMP,
184-
Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,
185-
Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY,Types.ARRAY
186-
};
91+
publicStringgetPGType()throwsSQLException
92+
{
93+
returnconn.getPGType(oid);
94+
}
18795

18896
/**
189-
* We also need to get the type name as returned by the back end.
190-
* This is held in type_name AFTER a call to getSQLType. Since
191-
* we get this information within getSQLType (if it isn't already
192-
* done), we can just call getSQLType and throw away the result.
97+
* We also need to get the java.sql.types type.
19398
*
194-
* @return theString representation of the type of this field
99+
* @return theint representation of the java.sql.types type of this field
195100
* @exception SQLException if a database access error occurs
196101
*/
197-
publicStringgetTypeName()throwsSQLException
102+
publicintgetSQLType()throwsSQLException
198103
{
199-
intsql =getSQLType();
200-
returntype_name;
104+
returnconn.getSQLType(oid);
201105
}
106+
202107
}

‎src/interfaces/jdbc/org/postgresql/jdbc1/Connection.java

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
importorg.postgresql.util.*;
1818

1919
/**
20-
* $Id: Connection.java,v 1.7 2001/07/30 14:51:19 momjian Exp $
20+
* $Id: Connection.java,v 1.8 2001/08/24 16:50:15 momjian Exp $
2121
*
2222
* A Connection represents a session with a specific database. Within the
2323
* context of a Connection, SQL statements are executed and results are
@@ -137,6 +137,73 @@ protected java.sql.ResultSet getResultSet(org.postgresql.Connection conn,java.sq
137137
returnneworg.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn,fields,tuples,status,updateCount,insertOID);
138138
}
139139

140+
141+
/* An implementation of the abstract method in the parent class.
142+
* This implemetation uses the jdbc1Types array to support the jdbc1
143+
* datatypes. Basically jdbc1 and jdbc2 are the same, except that
144+
* jdbc2 adds the Array types.
145+
*/
146+
publicintgetSQLType(StringpgTypeName)
147+
{
148+
intsqlType =Types.OTHER;// default value
149+
for(inti=0;i<jdbc1Types.length;i++) {
150+
if(pgTypeName.equals(jdbc1Types[i])) {
151+
sqlType=jdbc1Typei[i];
152+
break;
153+
}
154+
}
155+
returnsqlType;
156+
}
157+
158+
/**
159+
* This table holds the org.postgresql names for the types supported.
160+
* Any types that map to Types.OTHER (eg POINT) don't go into this table.
161+
* They default automatically to Types.OTHER
162+
*
163+
* Note: This must be in the same order as below.
164+
*
165+
* Tip: keep these grouped together by the Types. value
166+
*/
167+
privatestaticfinalStringjdbc1Types[] = {
168+
"int2",
169+
"int4","oid",
170+
"int8",
171+
"cash","money",
172+
"numeric",
173+
"float4",
174+
"float8",
175+
"bpchar","char","char2","char4","char8","char16",
176+
"varchar","text","name","filename",
177+
"bool",
178+
"date",
179+
"time",
180+
"abstime","timestamp"
181+
};
182+
183+
/**
184+
* This table holds the JDBC type for each entry above.
185+
*
186+
* Note: This must be in the same order as above
187+
*
188+
* Tip: keep these grouped together by the Types. value
189+
*/
190+
privatestaticfinalintjdbc1Typei[] = {
191+
Types.SMALLINT,
192+
Types.INTEGER,Types.INTEGER,
193+
Types.BIGINT,
194+
Types.DOUBLE,Types.DOUBLE,
195+
Types.NUMERIC,
196+
Types.REAL,
197+
Types.DOUBLE,
198+
Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,
199+
Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
200+
Types.BIT,
201+
Types.DATE,
202+
Types.TIME,
203+
Types.TIMESTAMP,Types.TIMESTAMP
204+
};
205+
206+
140207
}
141208

142209
// ***********************************************************************

‎src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,7 +1963,7 @@ public java.sql.ResultSet getColumns(String catalog, String schemaPattern, Strin
19631963
dr.next();
19641964
Stringtypname=dr.getString(1);
19651965
dr.close();
1966-
tuple[4] =Integer.toString(Field.getSQLType(typname)).getBytes();// Data type
1966+
tuple[4] =Integer.toString(connection.getSQLType(typname)).getBytes();// Data type
19671967
tuple[5] =typname.getBytes();// Type name
19681968

19691969
// Column size
@@ -2596,7 +2596,7 @@ public java.sql.ResultSet getTypeInfo() throws SQLException
25962596
byte[][]tuple =newbyte[18][];
25972597
Stringtypname=rs.getString(1);
25982598
tuple[0] =typname.getBytes();
2599-
tuple[1] =Integer.toString(Field.getSQLType(typname)).getBytes();
2599+
tuple[1] =Integer.toString(connection.getSQLType(typname)).getBytes();
26002600
tuple[2] =b9;// for now
26012601
tuple[6] =bnn;// for now
26022602
tuple[7] =bf;// false for now - not case sensitive

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp