From f9d3ed65c43e04c595b097a59d4d1c4542d82794 Mon Sep 17 00:00:00 2001 From: Dave Cramer Date: Fri, 12 Dec 2003 00:21:36 +0000 Subject: [PATCH] metadata encoding patch from Kris Jurka --- .../jdbc1/AbstractJdbc1DatabaseMetaData.java | 121 ++++++++++-------- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java index f7f8241571..90c1d00711 100644 --- a/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java +++ b/src/interfaces/jdbc/org/postgresql/jdbc1/AbstractJdbc1DatabaseMetaData.java @@ -5,6 +5,7 @@ import java.sql.*; import java.util.*; import org.postgresql.core.BaseStatement; import org.postgresql.core.Field; +import org.postgresql.core.Encoding; import org.postgresql.util.PSQLException; import org.postgresql.util.PSQLState; import org.postgresql.Driver; @@ -22,6 +23,7 @@ public abstract class AbstractJdbc1DatabaseMetaData "vacuum,verbose,version"; protected AbstractJdbc1Connection connection; // The connection association + protected Encoding encoding; // These define various OID's. Hopefully they will stay constant. protected static final int iVarcharOid = 1043; // OID for varchar @@ -73,6 +75,13 @@ public abstract class AbstractJdbc1DatabaseMetaData public AbstractJdbc1DatabaseMetaData(AbstractJdbc1Connection conn) { this.connection = conn; + try { + this.encoding = conn.getEncoding(); + } + catch (SQLException sqle) { + this.encoding = Encoding.defaultEncoding(); + } + } /* @@ -1858,15 +1867,15 @@ public abstract class AbstractJdbc1DatabaseMetaData tuple[0] = null; tuple[1] = schema; tuple[2] = procedureName; - tuple[3] = "returnValue".getBytes(); - tuple[4] = Integer.toString(java.sql.DatabaseMetaData.procedureColumnReturn).getBytes(); - tuple[5] = Integer.toString(connection.getSQLType(returnType)).getBytes(); - tuple[6] = connection.getPGType(returnType).getBytes(); + tuple[3] = encoding.encode("returnValue"); + tuple[4] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureColumnReturn)); + tuple[5] = encoding.encode(Integer.toString(connection.getSQLType(returnType))); + tuple[6] = encoding.encode(connection.getPGType(returnType)); tuple[7] = null; tuple[8] = null; tuple[9] = null; tuple[10] = null; - tuple[11] = Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown).getBytes(); + tuple[11] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown)); tuple[12] = null; v.addElement(tuple); } @@ -1878,15 +1887,15 @@ public abstract class AbstractJdbc1DatabaseMetaData tuple[0] = null; tuple[1] = schema; tuple[2] = procedureName; - tuple[3] = ("$"+(i+1)).getBytes(); - tuple[4] = Integer.toString(java.sql.DatabaseMetaData.procedureColumnIn).getBytes(); - tuple[5] = Integer.toString(connection.getSQLType(argOid)).getBytes(); - tuple[6] = connection.getPGType(argOid).getBytes(); + tuple[3] = encoding.encode("$"+(i+1)); + tuple[4] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureColumnIn)); + tuple[5] = encoding.encode(Integer.toString(connection.getSQLType(argOid))); + tuple[6] = encoding.encode(connection.getPGType(argOid)); tuple[7] = null; tuple[8] = null; tuple[9] = null; tuple[10] = null; - tuple[11] = Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown).getBytes(); + tuple[11] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown)); tuple[12] = null; v.addElement(tuple); } @@ -1901,15 +1910,15 @@ public abstract class AbstractJdbc1DatabaseMetaData tuple[0] = null; tuple[1] = schema; tuple[2] = procedureName; - tuple[3] = columnrs.getString("attname").getBytes(); - tuple[4] = Integer.toString(java.sql.DatabaseMetaData.procedureColumnResult).getBytes(); - tuple[5] = Integer.toString(connection.getSQLType(columnTypeOid)).getBytes(); - tuple[6] = connection.getPGType(columnTypeOid).getBytes(); + tuple[3] = columnrs.getBytes("attname"); + tuple[4] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureColumnResult)); + tuple[5] = encoding.encode(Integer.toString(connection.getSQLType(columnTypeOid))); + tuple[6] = encoding.encode(connection.getPGType(columnTypeOid)); tuple[7] = null; tuple[8] = null; tuple[9] = null; tuple[10] = null; - tuple[11] = Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown).getBytes(); + tuple[11] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.procedureNullableUnknown)); tuple[12] = null; v.addElement(tuple); } @@ -2205,7 +2214,7 @@ public abstract class AbstractJdbc1DatabaseMetaData for (i=0; i < types.length; i++) { byte[][] tuple = new byte[1][]; - tuple[0] = types[i].getBytes(); + tuple[0] = encoding.encode(types[i]); v.addElement(tuple); } @@ -2338,46 +2347,46 @@ public abstract class AbstractJdbc1DatabaseMetaData tuple[1] = rs.getBytes("nspname"); // Schema tuple[2] = rs.getBytes("relname"); // Table name tuple[3] = rs.getBytes("attname"); // Column name - tuple[4] = Integer.toString(connection.getSQLType(typeOid)).getBytes(); + tuple[4] = encoding.encode(Integer.toString(connection.getSQLType(typeOid))); String pgType = connection.getPGType(typeOid); - tuple[5] = pgType.getBytes(); // Type name + tuple[5] = encoding.encode(pgType); // Type name // by default no decimal_digits // if the type is numeric or decimal we will // overwrite later. - tuple[8] = "0".getBytes(); + tuple[8] = encoding.encode("0"); if (pgType.equals("bpchar") || pgType.equals("varchar")) { int atttypmod = rs.getInt("atttypmod"); - tuple[6] = Integer.toString(atttypmod != -1 ? atttypmod - VARHDRSZ : 0).getBytes(); + tuple[6] = encoding.encode(Integer.toString(atttypmod != -1 ? atttypmod - VARHDRSZ : 0)); } else if (pgType.equals("numeric") || pgType.equals("decimal")) { int attypmod = rs.getInt("atttypmod") - VARHDRSZ; - tuple[6] = Integer.toString( ( attypmod >> 16 ) & 0xffff ).getBytes(); - tuple[8] = Integer.toString(attypmod & 0xffff).getBytes(); - tuple[9] = "10".getBytes(); + tuple[6] = encoding.encode(Integer.toString( ( attypmod >> 16 ) & 0xffff )); + tuple[8] = encoding.encode(Integer.toString(attypmod & 0xffff)); + tuple[9] = encoding.encode("10"); } else if (pgType.equals("bit") || pgType.equals("varbit")) { tuple[6] = rs.getBytes("atttypmod"); - tuple[9] = "2".getBytes(); + tuple[9] = encoding.encode("2"); } else { tuple[6] = rs.getBytes("attlen"); - tuple[9] = "10".getBytes(); + tuple[9] = encoding.encode("10"); } tuple[7] = null; // Buffer length - tuple[10] = Integer.toString(rs.getBoolean("attnotnull") ? java.sql.DatabaseMetaData.columnNoNulls : java.sql.DatabaseMetaData.columnNullable).getBytes(); // Nullable + tuple[10] = encoding.encode(Integer.toString(rs.getBoolean("attnotnull") ? java.sql.DatabaseMetaData.columnNoNulls : java.sql.DatabaseMetaData.columnNullable)); // Nullable tuple[11] = rs.getBytes("description"); // Description (if any) tuple[12] = rs.getBytes("adsrc"); // Column default tuple[13] = null; // sql data type (unused) tuple[14] = null; // sql datetime sub (unused) tuple[15] = tuple[6]; // char octet length tuple[16] = rs.getBytes("attnum"); // ordinal position - tuple[17] = (rs.getBoolean("attnotnull") ? "NO" : "YES").getBytes(); // Is nullable + tuple[17] = encoding.encode(rs.getBoolean("attnotnull") ? "NO" : "YES"); // Is nullable v.addElement(tuple); } @@ -2476,7 +2485,7 @@ public abstract class AbstractJdbc1DatabaseMetaData } sortStringArray(permNames); for (i=0; i