--- android/TrainInfoService/src/dk/thoerup/traininfoservice/DumpResultSet.java 2009/10/01 08:21:09 377 +++ android/TrainInfoService/src/dk/thoerup/traininfoservice/DumpResultSet.java 2010/07/07 09:12:32 961 @@ -5,12 +5,15 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Statement; +import java.util.Date; import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +@WebServlet(urlPatterns={"/DumpResultSet"}) public class DumpResultSet extends HttpServlet { public DumpResultSet() { @@ -49,12 +52,17 @@ sb.append(""); for (int i=1; i<=columns; i++) { - sb.append("").append(rs.getString(i)).append(""); + String value = rs.getString(i); + if (value != null) { + value = value.replace("\n", "
"); + } + sb.append("").append( value ).append(""); } sb.append("\n"); } sb.append(""); - sb.append("Rowcount: ").append(count); + sb.append("Rowcount: ").append(count).append("
\n"); + sb.append("Generated: ").append(new Date()).append("
\n"); } catch (Exception e) { throw new ServletException(e); } finally { @@ -73,10 +81,41 @@ conn.close(); } catch (Exception e) {} } + return sb.toString(); + } + + String dumpUpdate(String query) throws ServletException { + StringBuilder sb = new StringBuilder(); + + Connection conn = null; + Statement stmt = null; + try { + conn = DBConnection.getConnection(); + stmt = conn.createStatement(); + stmt.execute(query); + int count = stmt.getUpdateCount(); + + sb.append("

").append(query).append("

"); + sb.append("Affected rows: ").append(count); + } catch (Exception e) { + throw new ServletException(e); + } finally { + try { + if (stmt != null && !stmt.isClosed()) + stmt.close(); + } catch (Exception e) {} + + try { + if (conn != null && !conn.isClosed()) + conn.close(); + } catch (Exception e) {} + } return sb.toString(); } + + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String dump = req.getParameter("dump"); @@ -92,16 +131,29 @@ res = dumpResultset("SELECT name,count(*) FROM trainstations GROUP BY name HAVING count(*) > 1"); } else if (dump.equals("allfull")) { res = dumpResultset("select *, " + - "'Maps' AS maps, " + + "'Maps' AS maps, " + "'Bane.dk Fjern' as banedk1, " + "'Bane.dk stog' as banedk2 " + "FROM trainstations ORDER BY id"); } else if (dump.equals("disabled")) { res = dumpResultset("SELECT * FROM trainstations WHERE enabled = false ORDER BY id"); - } + } else if (dump.equals("noaddress")) { + res = dumpResultset("SELECT * FROM trainstations WHERE address IS NULL or address = '' "); + } else if (dump.equals("aliases")) { + res = dumpResultset("SELECT * FROM trainstations WHERE aliases IS NOT null"); + } else if (dump.equals("updatecoords")) { + res = dumpUpdate("UPDATE trainstations SET earth_coord = ll_to_earth(latitude,longitude)"); + } } if (res == null) { - res = "All
All with links
Missing coords
Duplicate stations
Disabled stations"; + res = "All
" + + "All with links
" + + "Missing coords
" + + "Duplicate stations
" + + "Disabled stations
" + + "No address
" + + "Has aliases
" + + "update coords
"; } resp.setContentType("text/html");