/[projects]/android/TrainInfoService/src/dk/thoerup/traininfoservice/DumpResultSet.java
ViewVC logotype

Diff of /android/TrainInfoService/src/dk/thoerup/traininfoservice/DumpResultSet.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 314 by torben, Fri Sep 11 08:02:33 2009 UTC revision 815 by torben, Thu Jun 10 07:25:47 2010 UTC
# Line 49  public class DumpResultSet extends HttpS Line 49  public class DumpResultSet extends HttpS
49                                                                    
50                                  sb.append("<tr>");                                  sb.append("<tr>");
51                                  for (int i=1; i<=columns; i++) {                                  for (int i=1; i<=columns; i++) {
52                                          sb.append("<td>").append(rs.getString(i)).append("</td>");                                          String value = rs.getString(i);
53                                            if (value != null) {
54                                                    value = value.replace("\n", "<br>");
55                                            }
56                                            sb.append("<td>").append( value ).append("</td>");
57                                  }                                  }
58                                  sb.append("</tr>\n");                                  sb.append("</tr>\n");
59                          }                          }
# Line 77  public class DumpResultSet extends HttpS Line 81  public class DumpResultSet extends HttpS
81                  return sb.toString();                  return sb.toString();
82          }          }
83                    
84            String dumpUpdate(String query) throws ServletException {
85                    StringBuilder sb = new StringBuilder();
86    
87                    Connection conn = null;
88                    Statement stmt = null;
89                    try {
90                            conn =  DBConnection.getConnection();
91                            stmt = conn.createStatement();
92                            stmt.execute(query);
93                            int count = stmt.getUpdateCount();
94                            
95                            sb.append("<h2>").append(query).append("</h2>");
96                            sb.append("Affected rows: ").append(count);
97                    } catch (Exception e) {
98                            throw new ServletException(e);
99                    } finally {
100                            try {
101                                    if (stmt != null && !stmt.isClosed())
102                                            stmt.close();
103                            } catch (Exception e) {}
104                            
105                            try {
106                                    if (conn != null && !conn.isClosed())
107                                            conn.close();
108                            } catch (Exception e) {}
109                    }
110                    
111                    return sb.toString();
112            }
113            
114            
115            
116          @Override          @Override
117          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {          protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
118                  String dump = req.getParameter("dump");                  String dump = req.getParameter("dump");
# Line 92  public class DumpResultSet extends HttpS Line 128  public class DumpResultSet extends HttpS
128                                  res = dumpResultset("SELECT name,count(*) FROM trainstations GROUP BY name HAVING count(*) > 1");                                  res = dumpResultset("SELECT name,count(*) FROM trainstations GROUP BY name HAVING count(*) > 1");
129                          } else if (dump.equals("allfull")) {                          } else if (dump.equals("allfull")) {
130                                  res = dumpResultset("select *, " +                                  res = dumpResultset("select *, " +
131                                                  "'<a href=\"http://maps.google.com/?q=' ||latitude || ',' || longitude || '\">Maps</a>' AS maps, " +                                                  "'<a href=\"http://maps.google.dk/?q=' ||latitude || ',' || longitude || '\">Maps</a>' AS maps, " +
132                                                  "'<a href=\"http://www.bane.dk/visStation.asp?ArtikelID=4275&W=FJRN&S=' || stationcode_fjrn  || '\">Bane.dk Fjern</a>' as banedk1, " +                                                  "'<a href=\"http://www.bane.dk/visStation.asp?ArtikelID=4275&W=FJRN&S=' || stationcode_fjrn  || '\">Bane.dk Fjern</a>' as banedk1, " +
133                                                  "'<a href=\"http://www.bane.dk/visStation.asp?ArtikelID=4275&W=S2&S=' || stationcode_stog  || '\">Bane.dk stog</a>' as banedk2 " +                                                  "'<a href=\"http://www.bane.dk/visStation.asp?ArtikelID=4275&W=S2&S=' || stationcode_stog  || '\">Bane.dk stog</a>' as banedk2 " +
134                                                  "FROM trainstations ORDER BY id");                                                  "FROM trainstations ORDER BY id");
135                            } else if (dump.equals("disabled")) {
136                                    res = dumpResultset("SELECT * FROM trainstations WHERE enabled = false ORDER BY id");
137                            } else if (dump.equals("noaddress")) {
138                                    res = dumpResultset("SELECT * FROM trainstations WHERE address IS NULL or address = '' ");
139                            } else if (dump.equals("aliases")) {
140                                    res = dumpResultset("SELECT * FROM trainstations WHERE aliases IS NOT null");
141                            } else if (dump.equals("updatecoords")) {
142                                    res = dumpUpdate("UPDATE trainstations SET earth_coord = ll_to_earth(latitude,longitude)");
143                            } else if (dump.equals("trainstatistics")) {
144                                    res = dumpResultset("SELECT * FROM trainstatistics ORDER BY statisticsdate DESC");
145                            } else if (dump.equals("trainstatistics_avg")) {
146                                    res = dumpResultset("SELECT  round(avg(location),1) as location, round(avg(name),1) as name, round(avg(favorites),1) as favorites, " +
147                                                    "round(avg(departure),1) as departure, round(avg(depcache),1) as depcache, round(avg(deperror),1) as deperror, " +
148                                                    "round(avg(timetable),1) as timetable, round(avg(timecache),1) as timecache, round(avg(timeerror),1) as timeerror " +
149                                                    "FROM trainstatistics");
150                          }                          }
151                  }                  }
152                  if (res == null) {                  if (res == null) {
153                          res = "<a href=DumpResultSet?dump=all>All</a><br><a href=DumpResultSet?dump=allfull>All with links</a><br><a href=DumpResultSet?dump=coords>Missing coords</a><br><a href=DumpResultSet?dump=duplicate>Duplicate stations</a>";                          res = "<a href=DumpResultSet?dump=all>All</a><br>" +
154                                            "<a href=DumpResultSet?dump=allfull>All with links</a><br>" +
155                                            "<a href=DumpResultSet?dump=coords>Missing coords</a><br>" +
156                                            "<a href=DumpResultSet?dump=duplicate>Duplicate stations</a><br>" +
157                                            "<a href=DumpResultSet?dump=disabled>Disabled stations</a><br>" +
158                                            "<a href=DumpResultSet?dump=noaddress>No address</a><br>" +
159                                            "<a href=DumpResultSet?dump=aliases>Has aliases</a><br>" +
160                                            "<a href=DumpResultSet?dump=updatecoords>update coords</a><br>" +
161                                            "<a href=DumpResultSet?dump=trainstatistics>statistics</a><br>" +
162                                            "<a href=DumpResultSet?dump=trainstatistics_avg>stats_avg</a><br>";
163                  }                  }
164                                    
165                  resp.setContentType("text/html");                  resp.setContentType("text/html");

Legend:
Removed from v.314  
changed lines
  Added in v.815

  ViewVC Help
Powered by ViewVC 1.1.20