Commits

tbrugz committed 1d56cfe

resultset-pivot: better validation

Comments (0)

Files changed (2)

src/tbrugz/sqldump/resultset/pivot/PivotResultSet.java

 		ResultSetMetaData rsmd = rs.getMetaData();
 		rsColsCount = rsmd.getColumnCount();
 		measureCols = new ArrayList<String>();
+		List<String> colsToPivotNotFound = new ArrayList<String>();
+		List<String> colsNotToPivotNotFound = new ArrayList<String>();
+		colsToPivotNotFound.addAll(colsToPivotNames);
+		colsNotToPivotNotFound.addAll(colsNotToPivot);
 		for(int i=1;i<=rsColsCount;i++) {
 			String colName = rsmd.getColumnName(i);
-			if(!colsNotToPivot.contains(colName) && !colsToPivotNames.contains(colName)) {
+			if(colsToPivotNotFound.contains(colName)) {
+				colsToPivotNotFound.remove(colName);
+			}
+			else if(colsNotToPivotNotFound.contains(colName)) {
+				colsNotToPivotNotFound.remove(colName);
+			}
+			else {
+			//if(!colsNotToPivot.contains(colName) && !colsToPivotNames.contains(colName)) {
 				measureCols.add(colName);
 				valuesForEachMeasure.add(new HashMap<String, String>());
 			}
 			log.debug("colName "+i+" [colCount="+rsColsCount+"]: "+colName);
 		}
 		
+		if(colsToPivotNotFound.size()>0) {
+			throw new RuntimeException("cols to pivot not found: "+colsToPivotNotFound);
+		}
+		if(colsNotToPivotNotFound.size()>0) {
+			throw new RuntimeException("cols not to pivot not found: "+colsNotToPivotNotFound);
+		}
+		
 		metadata = new RSMetaDataAdapter(null, null, newColNames);
 		
 		if(doProcess) { process(); }
 			
 			//TODO: multi-measure!
 		}
-		throw new SQLException("unknown column: "+columnLabel);
+		throw new SQLException("unknown column: '"+columnLabel+"'");
 	}
 
 	@Override

src_test/tbrugz/sqldump/pivot/pivot.properties

 union all select false, true \
 union all select true, false \
 union all select true, true \
-) /* pivot b nonpivot a */
+) /* pivot B nonpivot A */
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.