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;
"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
public AbstractJdbc1DatabaseMetaData(AbstractJdbc1Connection conn)
{
this.connection = conn;
+ try {
+ this.encoding = conn.getEncoding();
+ }
+ catch (SQLException sqle) {
+ this.encoding = Encoding.defaultEncoding();
+ }
+
}
/*
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);
}
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);
}
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);
}
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);
}
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);
}
}
sortStringArray(permNames);
for (i=0; i<permNames.length; i++) {
- byte[] privilege = permNames[i].getBytes();
+ byte[] privilege = encoding.encode(permNames[i]);
Vector grantees = (Vector)permissions.get(permNames[i]);
for (int j=0; j<grantees.size(); j++) {
String grantee = (String)grantees.elementAt(j);
tuple[1] = schemaName;
tuple[2] = tableName;
tuple[3] = column;
- tuple[4] = owner.getBytes();
- tuple[5] = grantee.getBytes();
+ tuple[4] = encoding.encode(owner);
+ tuple[5] = encoding.encode(grantee);
tuple[6] = privilege;
- tuple[7] = grantable.getBytes();
+ tuple[7] = encoding.encode(grantable);
v.addElement(tuple);
}
}
}
sortStringArray(permNames);
for (i=0; i<permNames.length; i++) {
- byte[] privilege = permNames[i].getBytes();
+ byte[] privilege = encoding.encode(permNames[i]);
Vector grantees = (Vector)permissions.get(permNames[i]);
for (int j=0; j<grantees.size(); j++) {
String grantee = (String)grantees.elementAt(j);
tuple[0] = null;
tuple[1] = schema;
tuple[2] = table;
- tuple[3] = owner.getBytes();
- tuple[4] = grantee.getBytes();
+ tuple[3] = encoding.encode(owner);
+ tuple[4] = encoding.encode(grantee);
tuple[5] = privilege;
- tuple[6] = grantable.getBytes();
+ tuple[6] = encoding.encode(grantable);
v.addElement(tuple);
}
}
while (rs.next()) {
byte tuple[][] = new byte[8][];
int columnTypeOid = rs.getInt("atttypid");
- tuple[0] = Integer.toString(scope).getBytes();
+ tuple[0] = encoding.encode(Integer.toString(scope));
tuple[1] = rs.getBytes("attname");
- tuple[2] = Integer.toString(connection.getSQLType(columnTypeOid)).getBytes();
- tuple[3] = connection.getPGType(columnTypeOid).getBytes();
+ tuple[2] = encoding.encode(Integer.toString(connection.getSQLType(columnTypeOid)));
+ tuple[3] = encoding.encode(connection.getPGType(columnTypeOid));
tuple[4] = null;
tuple[5] = null;
tuple[6] = null;
- tuple[7] = Integer.toString(java.sql.DatabaseMetaData.bestRowNotPseudo).getBytes();
+ tuple[7] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.bestRowNotPseudo));
v.addElement(tuple);
}
*/
tuple[0] = null;
- tuple[1] = "ctid".getBytes();
- tuple[2] = Integer.toString(connection.getSQLType("tid")).getBytes();
- tuple[3] = "tid".getBytes();
+ tuple[1] = encoding.encode("ctid");
+ tuple[2] = encoding.encode(Integer.toString(connection.getSQLType("tid")));
+ tuple[3] = encoding.encode("tid");
tuple[4] = null;
tuple[5] = null;
tuple[6] = null;
- tuple[7] = Integer.toString(java.sql.DatabaseMetaData.versionColumnPseudo).getBytes();
+ tuple[7] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.versionColumnPseudo));
v.addElement(tuple);
/* Perhaps we should check that the given
else if ("restrict".equals(rule))
action = java.sql.DatabaseMetaData.importedKeyRestrict;
- tuple[9] = Integer.toString(action).getBytes();
+ tuple[9] = encoding.encode(Integer.toString(action));
}
action = java.sql.DatabaseMetaData.importedKeySetDefault;
else if ("restrict".equals(rule))
action = java.sql.DatabaseMetaData.importedKeyRestrict;
- tuple[10] = Integer.toString(action).getBytes();
+ tuple[10] = encoding.encode(Integer.toString(action));
}
pkeyColumn = (String)tokens.elementAt(element);
}
- tuple[3] = pkeyColumn.getBytes(); //PKCOLUMN_NAME
- tuple[7] = fkeyColumn.getBytes(); //FKCOLUMN_NAME
+ tuple[3] = encoding.encode(pkeyColumn); //PKCOLUMN_NAME
+ tuple[7] = encoding.encode(fkeyColumn); //FKCOLUMN_NAME
tuple[8] = rs.getBytes(6); //KEY_SEQ
- tuple[11] = fkName.getBytes(); //FK_NAME this will give us a unique name for the foreign key
+ tuple[11] = encoding.encode(fkName); //FK_NAME this will give us a unique name for the foreign key
tuple[12] = rs.getBytes(7); //PK_NAME
// DEFERRABILITY
else
deferrability = java.sql.DatabaseMetaData.importedKeyInitiallyImmediate;
}
- tuple[13] = Integer.toString(deferrability).getBytes();
+ tuple[13] = encoding.encode(Integer.toString(deferrability));
tuples.addElement(tuple);
}
ResultSet rs = connection.createStatement().executeQuery(sql);
// cache some results, this will keep memory useage down, and speed
// things up a little.
- byte b9[] = "9".getBytes();
- byte b10[] = "10".getBytes();
- byte bf[] = "f".getBytes();
- byte bnn[] = Integer.toString(java.sql.DatabaseMetaData.typeNoNulls).getBytes();
- byte bts[] = Integer.toString(java.sql.DatabaseMetaData.typeSearchable).getBytes();
+ byte b9[] = encoding.encode("9");
+ byte b10[] = encoding.encode("10");
+ byte bf[] = encoding.encode("f");
+ byte bnn[] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.typeNoNulls));
+ byte bts[] = encoding.encode(Integer.toString(java.sql.DatabaseMetaData.typeSearchable));
while (rs.next())
{
byte[][] tuple = new byte[18][];
String typname = rs.getString(1);
- tuple[0] = typname.getBytes();
- tuple[1] = Integer.toString(connection.getSQLType(typname)).getBytes();
+ tuple[0] = encoding.encode(typname);
+ tuple[1] = encoding.encode(Integer.toString(connection.getSQLType(typname)));
tuple[2] = b9; // for now
tuple[6] = bnn; // for now
tuple[7] = bf; // false for now - not case sensitive