mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Attached is a patch to fix the current issues with building under jdbc1.
This patch moves the logic that looks up TypeOid, PGTypeName, and SQLTypeName from Field to Connection. It is moved to connection since it needs to differ from the jdbc1 to jdbc2 versions and Connection already has different subclasses for the two driver versions. It also made sense to move the logic to Connection as some of the logic was already there anyway. Barry Lind
This commit is contained in:
@ -17,7 +17,7 @@ import org.postgresql.largeobject.*;
|
||||
import org.postgresql.util.*;
|
||||
|
||||
/**
|
||||
* $Id: Connection.java,v 1.7 2001/07/30 14:51:19 momjian Exp $
|
||||
* $Id: Connection.java,v 1.8 2001/08/24 16:50:15 momjian Exp $
|
||||
*
|
||||
* A Connection represents a session with a specific database. Within the
|
||||
* context of a Connection, SQL statements are executed and results are
|
||||
@ -137,6 +137,73 @@ public class Connection extends org.postgresql.Connection implements java.sql.Co
|
||||
return new org.postgresql.jdbc1.ResultSet((org.postgresql.jdbc1.Connection)conn,fields,tuples,status,updateCount,insertOID);
|
||||
}
|
||||
|
||||
|
||||
/* An implementation of the abstract method in the parent class.
|
||||
* This implemetation uses the jdbc1Types array to support the jdbc1
|
||||
* datatypes. Basically jdbc1 and jdbc2 are the same, except that
|
||||
* jdbc2 adds the Array types.
|
||||
*/
|
||||
public int getSQLType(String pgTypeName)
|
||||
{
|
||||
int sqlType = Types.OTHER; // default value
|
||||
for(int i=0;i<jdbc1Types.length;i++) {
|
||||
if(pgTypeName.equals(jdbc1Types[i])) {
|
||||
sqlType=jdbc1Typei[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sqlType;
|
||||
}
|
||||
|
||||
/**
|
||||
* This table holds the org.postgresql names for the types supported.
|
||||
* Any types that map to Types.OTHER (eg POINT) don't go into this table.
|
||||
* They default automatically to Types.OTHER
|
||||
*
|
||||
* Note: This must be in the same order as below.
|
||||
*
|
||||
* Tip: keep these grouped together by the Types. value
|
||||
*/
|
||||
private static final String jdbc1Types[] = {
|
||||
"int2",
|
||||
"int4","oid",
|
||||
"int8",
|
||||
"cash","money",
|
||||
"numeric",
|
||||
"float4",
|
||||
"float8",
|
||||
"bpchar","char","char2","char4","char8","char16",
|
||||
"varchar","text","name","filename",
|
||||
"bool",
|
||||
"date",
|
||||
"time",
|
||||
"abstime","timestamp"
|
||||
};
|
||||
|
||||
/**
|
||||
* This table holds the JDBC type for each entry above.
|
||||
*
|
||||
* Note: This must be in the same order as above
|
||||
*
|
||||
* Tip: keep these grouped together by the Types. value
|
||||
*/
|
||||
private static final int jdbc1Typei[] = {
|
||||
Types.SMALLINT,
|
||||
Types.INTEGER,Types.INTEGER,
|
||||
Types.BIGINT,
|
||||
Types.DOUBLE,Types.DOUBLE,
|
||||
Types.NUMERIC,
|
||||
Types.REAL,
|
||||
Types.DOUBLE,
|
||||
Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,Types.CHAR,
|
||||
Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,Types.VARCHAR,
|
||||
Types.BIT,
|
||||
Types.DATE,
|
||||
Types.TIME,
|
||||
Types.TIMESTAMP,Types.TIMESTAMP
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
// ***********************************************************************
|
||||
|
@ -1963,7 +1963,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
dr.next();
|
||||
String typname=dr.getString(1);
|
||||
dr.close();
|
||||
tuple[4] = Integer.toString(Field.getSQLType(typname)).getBytes(); // Data type
|
||||
tuple[4] = Integer.toString(connection.getSQLType(typname)).getBytes(); // Data type
|
||||
tuple[5] = typname.getBytes(); // Type name
|
||||
|
||||
// Column size
|
||||
@ -2596,7 +2596,7 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
|
||||
byte[][] tuple = new byte[18][];
|
||||
String typname=rs.getString(1);
|
||||
tuple[0] = typname.getBytes();
|
||||
tuple[1] = Integer.toString(Field.getSQLType(typname)).getBytes();
|
||||
tuple[1] = Integer.toString(connection.getSQLType(typname)).getBytes();
|
||||
tuple[2] = b9; // for now
|
||||
tuple[6] = bnn; // for now
|
||||
tuple[7] = bf; // false for now - not case sensitive
|
||||
|
@ -782,7 +782,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
case Types.BIGINT:
|
||||
return new Long(getLong(columnIndex));
|
||||
case Types.NUMERIC:
|
||||
return getBigDecimal(columnIndex, ((field.mod-4) & 0xffff));
|
||||
return getBigDecimal(columnIndex, ((field.getMod()-4) & 0xffff));
|
||||
case Types.REAL:
|
||||
return new Float(getFloat(columnIndex));
|
||||
case Types.DOUBLE:
|
||||
@ -800,7 +800,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
case Types.VARBINARY:
|
||||
return getBytes(columnIndex);
|
||||
default:
|
||||
return connection.getObject(field.getTypeName(), getString(columnIndex));
|
||||
return connection.getObject(field.getPGType(), getString(columnIndex));
|
||||
}
|
||||
}
|
||||
|
||||
@ -836,7 +836,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
|
||||
int i;
|
||||
|
||||
for (i = 0 ; i < fields.length; ++i)
|
||||
if (fields[i].name.equalsIgnoreCase(columnName))
|
||||
if (fields[i].getName().equalsIgnoreCase(columnName))
|
||||
return (i+1);
|
||||
throw new PSQLException ("postgresql.res.colname",columnName);
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
*/
|
||||
public boolean isCurrency(int column) throws SQLException
|
||||
{
|
||||
String type_name = getField(column).getTypeName();
|
||||
String type_name = getField(column).getPGType();
|
||||
|
||||
return type_name.equals("cash") || type_name.equals("money");
|
||||
}
|
||||
@ -189,9 +189,9 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
public int getColumnDisplaySize(int column) throws SQLException
|
||||
{
|
||||
Field f = getField(column);
|
||||
String type_name = f.getTypeName();
|
||||
String type_name = f.getPGType();
|
||||
int sql_type = f.getSQLType();
|
||||
int typmod = f.mod;
|
||||
int typmod = f.getMod();
|
||||
|
||||
// I looked at other JDBC implementations and couldn't find a consistent
|
||||
// interpretation of the "display size" for numeric values, so this is our's
|
||||
@ -219,7 +219,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
+ 1 + ( typmod & 0xffff ); // DECIMAL(p,s) = (p digits).(s digits)
|
||||
|
||||
// if we don't know better
|
||||
return f.length;
|
||||
return f.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -246,7 +246,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
{
|
||||
Field f = getField(column);
|
||||
if(f!=null)
|
||||
return f.name;
|
||||
return f.getName();
|
||||
return "field"+column;
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
case Types.NUMERIC:
|
||||
Field f = getField(column);
|
||||
if(f != null)
|
||||
return ((0xFFFF0000)&f.mod)>>16;
|
||||
return ((0xFFFF0000)&f.getMod())>>16;
|
||||
else
|
||||
return 0;
|
||||
default:
|
||||
@ -330,7 +330,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
case Types.NUMERIC:
|
||||
Field f = getField(column);
|
||||
if(f != null)
|
||||
return (((0x0000FFFF)&f.mod)-4);
|
||||
return (((0x0000FFFF)&f.getMod())-4);
|
||||
else
|
||||
return 0;
|
||||
default:
|
||||
@ -389,7 +389,7 @@ public class ResultSetMetaData implements java.sql.ResultSetMetaData
|
||||
*/
|
||||
public String getColumnTypeName(int column) throws SQLException
|
||||
{
|
||||
return getField(column).getTypeName();
|
||||
return getField(column).getPGType();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +109,7 @@ public class Statement extends org.postgresql.Statement implements java.sql.Stat
|
||||
public boolean execute(String sql) throws SQLException
|
||||
{
|
||||
if (escapeProcessing)
|
||||
sql = escapeSql(sql);
|
||||
sql = escapeSQL(sql);
|
||||
result = connection.ExecSQL(sql);
|
||||
return (result != null && ((org.postgresql.ResultSet)result).reallyResultSet());
|
||||
}
|
||||
|
Reference in New Issue
Block a user