Skip to content
Permalink
Browse files

fix missing metadata columns, and misspelled columns (#1323)

* fix missing metadata columns, and misspelled columns
  • Loading branch information...
davecramer committed Nov 22, 2018
1 parent 84e8d90 commit 0ed0e8f2dcd0ae4bbb5caee27b7057cef182c146
@@ -1066,7 +1066,7 @@ public ResultSet getProcedureColumns(String catalog, String schemaPattern,
f[13] = new Field("COLUMN_DEF", Oid.VARCHAR);
f[14] = new Field("SQL_DATA_TYPE", Oid.INT4);
f[15] = new Field("SQL_DATETIME_SUB", Oid.INT4);
f[16] = new Field("CHAR_OCTECT_LENGTH", Oid.INT4);
f[16] = new Field("CHAR_OCTET_LENGTH", Oid.INT4);
f[17] = new Field("ORDINAL_POSITION", Oid.INT4);
f[18] = new Field("IS_NULLABLE", Oid.VARCHAR);
f[19] = new Field("SPECIFIC_NAME", Oid.VARCHAR);
@@ -1284,7 +1284,9 @@ public ResultSet getTables(String catalog, String schemaPattern, String tableNam
+ " END "
+ " ELSE NULL "
+ " END "
+ " AS TABLE_TYPE, d.description AS REMARKS "
+ " AS TABLE_TYPE, d.description AS REMARKS, "
+ " '' as TYPE_CAT, '' as TYPE_SCHEM, '' as TYPE_NAME, "
+ "'' AS SELF_REFERENCING_COL_NAME, '' AS REF_GENERATION "
+ " FROM pg_catalog.pg_namespace n, pg_catalog.pg_class c "
+ " LEFT JOIN pg_catalog.pg_description d ON (c.oid = d.objoid AND d.objsubid = 0) "
+ " LEFT JOIN pg_catalog.pg_class dc ON (d.classoid=dc.oid AND dc.relname='pg_class') "
@@ -1451,7 +1453,7 @@ public ResultSet getTableTypes() throws SQLException {
public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern,
String columnNamePattern) throws SQLException {

int numberOfFields = 23; // JDBC4
int numberOfFields = 24; // JDBC4
List<byte[][]> v = new ArrayList<byte[][]>(); // The new ResultSet tuple stuff
Field[] f = new Field[numberOfFields]; // The field descriptors for the new ResultSet

@@ -1473,11 +1475,12 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
f[15] = new Field("CHAR_OCTET_LENGTH", Oid.VARCHAR);
f[16] = new Field("ORDINAL_POSITION", Oid.INT4);
f[17] = new Field("IS_NULLABLE", Oid.VARCHAR);
f[18] = new Field("SCOPE_CATLOG", Oid.VARCHAR);
f[18] = new Field("SCOPE_CATALOG", Oid.VARCHAR);
f[19] = new Field("SCOPE_SCHEMA", Oid.VARCHAR);
f[20] = new Field("SCOPE_TABLE", Oid.VARCHAR);
f[21] = new Field("SOURCE_DATA_TYPE", Oid.INT2);
f[22] = new Field("IS_AUTOINCREMENT", Oid.VARCHAR);
f[23] = new Field( "IS_GENERATED", Oid.VARCHAR);

String sql;
// a.attnum isn't decremented when preceding columns are dropped,
@@ -1619,6 +1622,8 @@ public ResultSet getColumns(String catalog, String schemaPattern, String tableNa
autoinc = "YES";
}
tuple[22] = connection.encodeString(autoinc);
// there is no way to tell if the value was actually autogenerated.
tuple[23] = connection.encodeString("");

v.add(tuple);
}
@@ -177,8 +177,16 @@ public void testTables() throws Exception {
assertEquals("metadatatest", tableName);
String tableType = rs.getString("TABLE_TYPE");
assertEquals("TABLE", tableType);
assertEquals(rs.findColumn("REMARKS"), 5);
assertEquals(rs.findColumn("TYPE_CAT"), 6);
assertEquals(rs.findColumn("TYPE_SCHEM"),7);
assertEquals(rs.findColumn("TYPE_NAME"), 8);
assertEquals(rs.findColumn("SELF_REFERENCING_COL_NAME"), 9);
assertEquals(rs.findColumn("REF_GENERATION"), 10);

// There should only be one row returned
assertTrue("getTables() returned too many rows", rs.next() == false);

rs.close();

rs = dbmd.getColumns("", "", "meta%", "%");
@@ -455,9 +463,21 @@ public void testForeignKeys() throws Exception {
@Test
public void testColumns() throws SQLException {
// At the moment just test that no exceptions are thrown KJ
String [] metadataColumns = {"TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME",
"DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH",
"DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS",
"COLUMN_DEF","SQL_DATA_TYPE","SQL_DATETIME_SUB","CHAR_OCTET_LENGTH",
"ORDINAL_POSITION", "IS_NULLABLE", "SCOPE_CATALOG", "SCOPE_SCHEMA",
"SCOPE_TABLE", "SOURCE_DATA_TYPE", "IS_AUTOINCREMENT", "IS_GENERATED"};

DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
ResultSet rs = dbmd.getColumns(null, null, "pg_class", null);
if ( rs.next() ) {
for (int i = 0; i < metadataColumns.length; i++) {
assertEquals(i + 1, rs.findColumn(metadataColumns[i]));
}
}
rs.close();
}

0 comments on commit 0ed0e8f

Please sign in to comment.
You can’t perform that action at this time.