[Ils-source] r1404 - trunk/webapp

scribe at crosswire.org scribe at crosswire.org
Wed Mar 2 13:12:06 MST 2016


Author: scribe
Date: 2016-03-02 13:12:05 -0700 (Wed, 02 Mar 2016)
New Revision: 1404

Modified:
   trunk/webapp/SQL.jsp
Log:
fixed output summary of good/bad records


Modified: trunk/webapp/SQL.jsp
===================================================================
--- trunk/webapp/SQL.jsp	2016-03-02 17:46:19 UTC (rev 1403)
+++ trunk/webapp/SQL.jsp	2016-03-02 20:12:05 UTC (rev 1404)
@@ -296,7 +296,7 @@
 				MessageFormat format = new MessageFormat(rSQL);
 				rSQL  = format.format(fields.toArray());
 				int result = runSQL(rSQL, linkColumn, num, i + 1, out);
-				if (result > 0) ++goodCount;
+				if (result == 0) ++goodCount;
 				else ++badCount;
 			}
 			else {
@@ -586,128 +586,128 @@
   private static int runSQL(String testSQL, String linkColumn, int exec, int stage, JspWriter out) {
 	  return runSQL(testSQL, linkColumn, exec, stage, out, 10, null);
   }
-  private static int runSQL(String testSQL, String linkColumn, int exec, int stage, JspWriter out, int outputLevel, String ignoreException) {
-    Connection c = null;
-    PreparedStatement stmt = null;
-    ResultSet rs = null;
-    int retVal = 0;
-    String result = "Success";
-    SQLException resultException = null;
-    try {
-      c = getDBConnection(out);
-      if (c == null) {
-        out.println("<br>couldn't get DB connection");
-        return 0;
-      }
-      try {
-        stmt = c.prepareStatement(testSQL);
-        if ((testSQL+"          ").substring(0, 10).toUpperCase().trim().startsWith("SELECT")) {
-          rs = stmt.executeQuery();
-        }
-        else {
-          int r = stmt.executeUpdate();
-          result = (r == 0) ? "Success" : Integer.toString(r);
-        }
-      }
-      catch (SQLException e) {
-        result = "Exception";
-	if (ignoreException == null || getAllSQLExceptions(e).indexOf(ignoreException) < 0)
-		resultException = e;
-      }
-      catch (Exception e1) {
-//        if (outputLevel >= 9) {
-		e1.printStackTrace();
-//	   }
-        result = e1.toString();
-      }
-      if (out != null) {
-	   	  if (outputLevel >= 9) out.write("<table border=\"1\"> <tr> <th>Executing SQL</th> <td>" + testSQL + "</td> </tr>");
-	   	  else if (outputLevel < 6) outputTick(out);
-	         if (rs == null) {
-	             if (resultException != null && outputLevel < 6) out.write("<br/>");
-	             if (outputLevel >=9) out.println("<tr> <td>Result</td> <td>" + result + "</td> </tr>");
-	             else if (outputLevel >= 6 || resultException !=  null) out.println("<b>Result:</b> " + result + " <b>SQL:</b> " + testSQL + "<br/>");
-	             if (resultException != null) {
-		    	  if (outputLevel >= 9) out.println("<tr> <td>Exception</td> <td>");
-	                  out.println(getAllSQLExceptions(resultException));
-		    	  if (outputLevel >= 9) out.println("</td> </tr>");
-		    	  else out.println("<br/>");
-	             }
-	         }
-	   	  if (outputLevel >= 9) out.println("</table><br />");
-	      if (rs != null) {
-	        ResultSetMetaData meta = rs.getMetaData();
-	        int colCount = meta.getColumnCount();
-	        if (outputLevel >= 7) {
-	             out.println("<table border=\"1\"><tr><th></th>");
-	            for (int i = 0; i < colCount; i++) {
-	                String colName = meta.getColumnName(i + 1);
-	                out.println("<th>" + colName + "</th>");
-	            }
-	            out.println("</tr>");
-	        }
-	        if (outputLevel >= 5) {
-	        while (rs.next()) {
-		  ++retVal;
-	          if (outputLevel > 5) {
-	              if (outputLevel >= 7) out.print("<tr> <th>" + rs.getRow() + "</th>");
-	              else if (outputLevel >= 5) out.print("<b>" + rs.getRow() + "</b>");
-	              String colVals = "";
-	              for (int i = 1; i < colCount + 1; i++) {
-	                  Object o = rs.getObject(i);
-	                  if (o == null) o = "";
-	                  colVals += "&val" + Integer.toString(i) + "=" + URLEncoder.encode(o.toString());
-	              }
-	              for (int i = 0; i < colCount; i++) {
-	                 Object o = rs.getObject(i + 1);
-	                 String colVal = (o != null) ? o.toString() : "";
-	                  if (outputLevel >= 7) out.print("<td>");
-	                  if (meta.getColumnName(i + 1).equalsIgnoreCase(linkColumn)) {
-	                      out.print("<a href=\"SQL.jsp?exec=" + exec + "&stage=" + stage + "&val0=" + URLEncoder.encode(colVal) + colVals + "\">" + colVal + "</a>");
-	                  }
-		                  else {
-	                      out.println(colVal);
-	                  }
-	                  if (outputLevel >= 7) out.print("</td>");
-	              }
-	              if (outputLevel >= 7) out.print("</tr>");
-	              else if (outputLevel >= 5) out.print("<br/>");
-		      }
-	          else outputTick(out);
-	        }
-	        if (outputLevel >= 7) out.println("</table>");
-	        }
-		else {
-			while (rs.next()) {
-			  ++retVal;
+	private static int runSQL(String testSQL, String linkColumn, int exec, int stage, JspWriter out, int outputLevel, String ignoreException) {
+		Connection c = null;
+		PreparedStatement stmt = null;
+		ResultSet rs = null;
+		int retVal = 0;
+		String result = "Success";
+		SQLException resultException = null;
+		try {
+			c = getDBConnection(out);
+			if (c == null) {
+				out.println("<br>couldn't get DB connection");
+				return 0;
 			}
+			try {
+				stmt = c.prepareStatement(testSQL);
+				if ((testSQL+"          ").substring(0, 10).toUpperCase().trim().startsWith("SELECT")) {
+					rs = stmt.executeQuery();
+				}
+				else {
+					int r = stmt.executeUpdate();
+					result = (r == 0) ? "Success" : Integer.toString(r);
+				}
+			}
+			catch (SQLException e) {
+				result = "Exception";
+				if (ignoreException == null || getAllSQLExceptions(e).indexOf(ignoreException) < 0)
+					resultException = e;
+			}
+			catch (Exception e1) {
+			//        if (outputLevel >= 9) {
+				e1.printStackTrace();
+			//	   }
+				result = e1.toString();
+			}
+			if (out != null) {
+				if (outputLevel >= 9) out.write("<table border=\"1\"> <tr> <th>Executing SQL</th> <td>" + testSQL + "</td> </tr>");
+				else if (outputLevel < 6) outputTick(out);
+				if (rs == null) {
+					if (resultException != null && outputLevel < 6) out.write("<br/>");
+					if (outputLevel >=9) out.println("<tr> <td>Result</td> <td>" + result + "</td> </tr>");
+					else if (outputLevel >= 6 || resultException !=  null) out.println("<b>Result:</b> " + result + " <b>SQL:</b> " + testSQL + "<br/>");
+					if (resultException != null) {
+						if (outputLevel >= 9) out.println("<tr> <td>Exception</td> <td>");
+						out.println(getAllSQLExceptions(resultException));
+						if (outputLevel >= 9) out.println("</td> </tr>");
+						else out.println("<br/>");
+					}
+				}
+				if (outputLevel >= 9) out.println("</table><br />");
+				if (rs != null) {
+					ResultSetMetaData meta = rs.getMetaData();
+					int colCount = meta.getColumnCount();
+					if (outputLevel >= 7) {
+						out.println("<table border=\"1\"><tr><th></th>");
+						for (int i = 0; i < colCount; i++) {
+							String colName = meta.getColumnName(i + 1);
+							out.println("<th>" + colName + "</th>");
+						}
+						out.println("</tr>");
+					}
+					if (outputLevel >= 5) {
+						while (rs.next()) {
+							++retVal;
+							if (outputLevel > 5) {
+								if (outputLevel >= 7) out.print("<tr> <th>" + rs.getRow() + "</th>");
+								else if (outputLevel >= 5) out.print("<b>" + rs.getRow() + "</b>");
+								String colVals = "";
+								for (int i = 1; i < colCount + 1; i++) {
+									Object o = rs.getObject(i);
+									if (o == null) o = "";
+									colVals += "&val" + Integer.toString(i) + "=" + URLEncoder.encode(o.toString());
+								}
+								for (int i = 0; i < colCount; i++) {
+									Object o = rs.getObject(i + 1);
+									String colVal = (o != null) ? o.toString() : "";
+									if (outputLevel >= 7) out.print("<td>");
+									if (meta.getColumnName(i + 1).equalsIgnoreCase(linkColumn)) {
+										out.print("<a href=\"SQL.jsp?exec=" + exec + "&stage=" + stage + "&val0=" + URLEncoder.encode(colVal) + colVals + "\">" + colVal + "</a>");
+									}
+									else {
+										out.println(colVal);
+									}
+									if (outputLevel >= 7) out.print("</td>");
+								}
+								if (outputLevel >= 7) out.print("</tr>");
+								else if (outputLevel >= 5) out.print("<br/>");
+							}
+							else outputTick(out);
+						}
+						if (outputLevel >= 7) out.println("</table>");
+					}
+					else {
+						while (rs.next()) {
+							++retVal;
+						}
+					}
+				}
+			}	// out != null
+			else {
+				while (rs.next()) {
+					++retVal;
+				}
+			}
 		}
-	      }
-      }	// out != null
-		else {
-			while (rs.next()) {
-			  ++retVal;
+		catch (Exception e) {
+			e.printStackTrace();
+		}
+		finally {
+			try {
+				if (stmt != null) {
+					stmt.close();
+				}
+				if (c != null) {
+					c.close();
+				}
 			}
+			catch (Exception e) {
+				e.printStackTrace();
+			}
 		}
-    }
-    catch (Exception e) {
-      e.printStackTrace();
-    }
-    finally {
-      try {
-        if (stmt != null) {
-          stmt.close();
-        }
-        if (c != null) {
-          c.close();
-        }
-      }
-      catch (Exception e) {
-        e.printStackTrace();
-      }
-    }
-    return retVal;
-  }
+		return retVal;
+	}
   
   
   private static int exportSQL(String testSQL, FileWriter out, JspWriter errOut) {




More information about the Ils-source mailing list