/* DatabaseMetaData - Decompiled by JODE
 * Visit http://jode.sourceforge.net/
 */

   public java.sql.ResultSet getIndexInfo(String catalogName, String schemaName, String tableName, boolean unique, boolean accurate) throws SQLException {
      
      Field[] fields = new Field[13];
      Vector vector = new Vector();
      
      fields[0] = new Field(connection, "TABLE_CAT", 1043, 32);
      fields[1] = new Field(connection, "TABLE_SCHEM", 1043, 32);
      fields[2] = new Field(connection, "TABLE_NAME", 1043, 32);
      fields[3] = new Field(connection, "NON_UNIQUE", 16, 1);
      fields[4] = new Field(connection, "INDEX_QUALIFIER", 1043, 32);
      fields[5] = new Field(connection, "INDEX_NAME", 1043, 32);
      fields[6] = new Field(connection, "TYPE", 21, 2);
      fields[7] = new Field(connection, "ORDINAL_POSITION", 21, 2);
      fields[8] = new Field(connection, "COLUMN_NAME", 1043, 32);
      fields[9] = new Field(connection, "ASC_OR_DESC", 1043, 32);
      fields[10] = new Field(connection, "CARDINALITY", 23, 4);
      fields[11] = new Field(connection, "PAGES", 23, 4);
      fields[12] = new Field(connection, "FILTER_CONDITION", 1043, 32);
      
      java.sql.ResultSet rs = (connection.ExecSQL("select c.relname, x.indisunique, i.relname, x.indisclustered, a.amname, x.indkey, c.reltuples, c.relpages, x.indexrelid FROM pg_index x, pg_class c, pg_class i, pg_am a WHERE ((c.relname = '"
      + tableName.toLowerCase() + "') "
      
//    changed by Witchcraft: add functionality to filter non/unique indexes
      
      + ((unique) ? (" AND (x.indisunique = true)") : (""))
      + " AND (c.oid = x.indrelid) " + " AND (i.oid = x.indexrelid) "
      + " AND (i.relam = a.oid)) " + "ORDER BY x.indisunique DESC, "
      + " x.indisclustered, a.amname, i.relname"));
      
      while (rs.next()) {
         
         String string_44_ = rs.getString(6);
         StringTokenizer stringtokenizer = new StringTokenizer(string_44_);
         int[] is = new int[stringtokenizer.countTokens()];
         int i = 0;
         
         while (stringtokenizer.hasMoreTokens()) {
            is[i++] = Integer.parseInt(stringtokenizer.nextToken());
         }
         
         for (int i_45_ = 0; i_45_ < is.length; i_45_++) {
            byte[][] is_46_ = new byte[13][];
            is_46_[0] = "".getBytes();
            is_46_[1] = "".getBytes();
            is_46_[2] = rs.getBytes(1);
            is_46_[3] = (rs.getBoolean(2) ? "false".getBytes() : "true".getBytes());
            is_46_[4] = null;
            is_46_[5] = rs.getBytes(3);
            is_46_[6] = (rs.getBoolean(4) ? Integer.toString(1).getBytes()
            : rs.getString(5).equals("hash")
            ? Integer.toString(2).getBytes()
            : Integer.toString(3).getBytes());
            is_46_[7] = Integer.toString(i_45_ + 1).getBytes();
            
            
//          changed by Witchcraft (attnum-field deleted in where-clause)
//				the query returns now column names for all indexes
//				the result may be null, because the pg_attribute.attname can be null

            String sqlCommand = "select a.attname " +
                                "FROM pg_attribute a " + 
                                "WHERE (a.attrelid = " + rs.getInt(9) + ")";
            java.sql.ResultSet rs2 = (connection.ExecSQL(sqlCommand));
            
            if (rs2.next())
               is_46_[8] = rs2.getBytes(1);
            else
               is_46_[8] = "".getBytes();
            
//          changed by Witchcraft, statement deleted, because it has no sense
//            is_46_[8] = rs2.getBytes(1);
            
            is_46_[9] = null;
            is_46_[10] = rs.getBytes(7);
            is_46_[11] = rs.getBytes(8);
            is_46_[12] = null;
            vector.addElement(is_46_);
         }
         
      }
      
      return new ResultSet(connection, fields, vector, "OK", 1);
   }
