Displaying differences for changeset
 
display as  

src/csip/sdm/SDMResultSet.java

@@ -26,7 +26,7 @@
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -43,7 +43,7 @@
     static final String SDM_RESULT_HEAD = "Table";
 
     ArrayList<ResultRow> rows = new ArrayList<>();
-    HashMap<String, Integer> columns = new HashMap<>();
+    LinkedHashMap<String, ResultColumn> columns = new LinkedHashMap<>();
     int rowId;
     int maxRows;
     SDMStatement statement;
@@ -77,7 +77,14 @@
                 tempRow = mainTable.getJSONArray(0);
 
                 for (int i = 0; i < tempRow.length(); i++) {
-                    columns.put(tempRow.getString(i), i);
+                    ResultColumn rColumn = new ResultColumn();
+                    rColumn.name = tempRow.getString(i);
+                    rColumn.location = i;
+                    if (columns.containsKey(rColumn.name)) {
+                        columns.put(rColumn.name + "::" + i, rColumn);
+                    } else {
+                        columns.put(rColumn.name, rColumn);
+                    }
                 }
 
                 //Read row data
@@ -150,7 +157,7 @@
         int ret_val = -1;
         if ((maxRows > 0) && !columns.isEmpty()) {
             if (columns.containsKey(columnLabel)) {
-                ret_val = columns.get(columnLabel);
+                ret_val = columns.get(columnLabel).location;
             }
         } else {
             throw new SQLException("ResultSet is empty, no column lables are found.");
@@ -235,7 +242,7 @@
     @Override
     public boolean getBoolean(int columnIndex) throws SQLException {
         String value = findValue(columnIndex).trim();
-        return ((null != value)? ( (value.equalsIgnoreCase("1") || value.equalsIgnoreCase("yes"))? Boolean.TRUE: ( (value.equalsIgnoreCase("0") || value.equalsIgnoreCase("no"))? Boolean.FALSE:Boolean.parseBoolean(value) )): Boolean.FALSE);
+        return ((null != value) ? ((value.equalsIgnoreCase("1") || value.equalsIgnoreCase("yes")) ? Boolean.TRUE : ((value.equalsIgnoreCase("0") || value.equalsIgnoreCase("no")) ? Boolean.FALSE : Boolean.parseBoolean(value))) : Boolean.FALSE);
     }
 
     @Override
@@ -398,8 +405,8 @@
     }
 
     @Override
-    public ResultSetMetaData getMetaData() throws SQLException {        
-        return this.resultSetMetaData;     
+    public ResultSetMetaData getMetaData() throws SQLException {
+        return this.resultSetMetaData;
     }
 
     @Override
@@ -1142,8 +1149,11 @@
         String ret_val = null;
         if ((index <= columns.size()) && (index > 0)) {
             for (String key : columns.keySet()) {
-                if (columns.get(key) == (index-1)) {
+                if (columns.get(key).location == (index - 1)) {
                     ret_val = key;
+                    if ( ret_val.contains("::")){
+                        ret_val = ret_val.substring(0, ret_val.indexOf(":"));
+                    }
                 }
             }
         } else {
@@ -1153,6 +1163,12 @@
         return ret_val;
     }
 
+    private class ResultColumn {
+
+        String name;
+        int location;
+    }
+
     private class ResultRow {
 
         private final JSONArray values;