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

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

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

revision 589 by torben, Mon Feb 8 19:25:12 2010 UTC revision 714 by torben, Fri May 7 17:08:11 2010 UTC
# Line 63  public class StationDAO { Line 63  public class StationDAO {
63                  return result;                  return result;
64          }          }
65                    
66                    /*
67             * this code requires theses statements are run on database in order to do ILIKE searches against aliases (which is defines as array of varchar(64) )
68             *     create function rlike(text,text) returns bool as
69             *     'select $2 ilike $1' language sql strict immutable;
70         *     create operator ~~~ (procedure = rlike, leftarg = text, rightarg = text, commutator = ~~);
71             */
72          public List<StationBean> getByName(String name) throws SQLException {          public List<StationBean> getByName(String name) throws SQLException {
73                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0 " +                  String SQL = "SELECT id,name,latitude,longitude,stationcode_fjrn,stationcode_stog, stationcode_metro, address, 0.0 " +
74                  "FROM trainstations " +                  "FROM trainstations " +
75                  "WHERE name ILIKE ? AND enabled = true " +                  "WHERE (name ILIKE ? OR ? ~~~ ANY(aliases)) AND enabled = true " +
76                  "ORDER BY name ";                  "ORDER BY name ";
77    
78                                    
# Line 80  public class StationDAO { Line 85  public class StationDAO {
85                          stmt = conn.prepareStatement(SQL);                          stmt = conn.prepareStatement(SQL);
86                                                    
87                          stmt.setString(1, name + "%");                          stmt.setString(1, name + "%");
88                            stmt.setString(2, name + "%");
89                                                    
90                          res = stmt.executeQuery();                          res = stmt.executeQuery();
91                          result = convertResultset(res);                          result = convertResultset(res);
# Line 155  public class StationDAO { Line 161  public class StationDAO {
161                          return result;                          return result;
162                                                    
163           }           }
164                     public static String getStationName(int stationID) {
165                     String station = "";
166    
167                     Connection conn = null;
168                     try {
169                             conn = DBConnection.getConnection();
170                             Statement stmt = conn.createStatement();
171                             ResultSet rs = stmt.executeQuery("SELECT name FROM trainstations WHERE id=" + stationID);
172                             if (rs.next()) {
173                                     station = rs.getString(1);
174                             }
175    
176                     } catch (Exception e) {        
177                     } finally {
178                             try {
179                                     if (conn != null && !conn.isClosed())
180                                             conn.close();
181                             } catch (Exception e) {}
182                     }
183    
184                     return station;
185             }
186  }  }

Legend:
Removed from v.589  
changed lines
  Added in v.714

  ViewVC Help
Powered by ViewVC 1.1.20