gt:             int tripId = cursor.getInt(1);
context: package com.njtransit;
  
  import java.io.File;
  import java.text.SimpleDateFormat;
  import java.util.ArrayList;
  import java.util.Calendar;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.TimeZone;
  import java.util.TreeSet;
  
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.util.Log;
  
  import com.njtransit.domain.AlternateService;
  import com.njtransit.domain.IService;
  import com.njtransit.domain.Service;
  import com.njtransit.domain.Station;
  import com.njtransit.domain.Stop;
  import com.njtransit.domain.Trip;
  import com.njtransit.model.StopsQueryResult;
  
  public class DatabaseAdapter {
  	public static String[] DAYS = new String[] { "sunday", "monday", "tuesday",
  			"wednesday", "thursday", "friday", "saturday" };
  	private static SimpleDateFormat DF = new SimpleDateFormat("yyyyMMdd");
  	private static SimpleDateFormat DTF = new SimpleDateFormat("HH:mm:ss");
  	private static SimpleDateFormat YDTF = new SimpleDateFormat(
  			"yyyy-MM-dd HH:mm:ss");
  
  	private Context context;
  
  	private SQLiteDatabase db;
  
  	private TransitDBHelper helper;
  
  	private SQLiteDatabase localDb;
  
  	private LocalStorageHelper localStorageHelper;
  
  	private Integer tempTableIndex = 0;
  
  	private InstallDatabaseMeter installMeter;
  
  	private static final int BOTH = 1;
  	private static final int CALENDAR_ONLY = 2;
  	private static final int CALENDAR_DATES_ONLY = 3;
  
  	public void determineCalendarType() {
  		if (calendarType > 0) {
  			return;
  		}
  		Cursor c = db
  				.rawQuery("select calendar_date from calendar_dates", null);
  		int count = c.getCount();
  		c.close();
  		if (count > 0) {
  			c = db.rawQuery("select start from calendar limit 1", null);
  			count = c.getCount();
  			c.close();
  			if (count > 0) {
  				calendarType = BOTH;
  			} else {
  				calendarType = CALENDAR_DATES_ONLY;
  			}
  			return;
  		} else {
  			calendarType = CALENDAR_ONLY;
  		}
  	}
  
  	private int calendarType;
  
  	public DatabaseAdapter(Context context, InstallDatabaseMeter meter) {
  		this.context = context;
  		this.installMeter = meter;
  	}
  
  	public void closeDB() {
  		if (helper != null) {
  			helper.close();
  		}
  		if (localStorageHelper != null) {
  			localStorageHelper.close();
  		}
  	}
  
  	public int countStations() {
  		Cursor cursor = db.rawQuery("select count(*) from stops", null);
  		cursor.moveToFirst();
  		int count = cursor.getInt(0);
  		cursor.close();
  		return count;
  	}
  
  	public ArrayList<Station> getAllStationsLike(String name) {
  		Cursor cursor = null;
  		ArrayList<Station> stations = null;
  		try {
  			db.beginTransaction();
  			String sql = "select id, name, lat, lon, zone_id, alternate_id from stops where name like ?";
  			cursor = db.rawQuery(sql, new String[] { "%" + name + "%" });
  			int count = cursor.getCount();
  			stations = new ArrayList<Station>(count);
  			cursor.moveToFirst();
  			while (count > 0) {
  				count--;
  				stations.add(new Station(cursor.getInt(0), cursor.getString(1),
  						cursor.getDouble(2), cursor.getDouble(3), cursor.getString(4)));
  				
  				cursor.moveToNext();
  			}
  			cursor.close();
  		} finally {
  			if (cursor != null) {
  				cursor.close();
  			}
  			db.endTransaction();
  		}
  		return stations;
  	}
  
  	public ArrayList<IService> getServices() {
  		long before = System.currentTimeMillis();
  		Cursor cursor = db
  				.rawQuery(
  						"select service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday from calendar",
  						null);
  		cursor.moveToFirst();
  		ArrayList<IService> services = new ArrayList<IService>(cursor
  				.getCount());
  		for (int i = 0; i < cursor.getCount(); i++) {
  			boolean[] result = new boolean[7];
  			result[0] = cursor.getInt(1) == 1;
  			result[1] = cursor.getInt(2) == 1;
  			result[2] = cursor.getInt(3) == 1;
  			result[3] = cursor.getInt(4) == 1;
  			result[4] = cursor.getInt(5) == 1;
  			result[5] = cursor.getInt(6) == 1;
  			result[6] = cursor.getInt(7) == 1;
  
  			Service s = new Service(cursor.getInt(0), result);
  			services.add(s);
  			cursor.moveToNext();
  		}
  		cursor.close();
  
  		Log.d("DatebaseAdapter", String.format("getServices (%s ms)", System
  				.currentTimeMillis()
  				- before));
  
  		return services;
  	}
  
  	public ArrayList<Station> getStations() {
  		Long start = System.currentTimeMillis();
  		Cursor cursor = db.rawQuery(
  				"select id,name,lat,lon,alternate_id from stops order by name", null);
  		ArrayList<Station> stations = new ArrayList<Station>(cursor.getCount());
  		for (int i = 0; i < cursor.getCount(); i++) {
  			cursor.moveToNext();
  			int id = cursor.getInt(0);
  			String name = cursor.getString(1);
  			// String descName = cursor.getString(2);
  			float lat = cursor.getFloat(2);
  			float lng = cursor.getFloat(3);
  			String alternateId = cursor.getString(4);
  			Station s = new Station(id, name, (double) lat, (double) lng, alternateId);
  			stations.add(s);
  		}
  		cursor.close();
  		Long end = System.currentTimeMillis();
  		Root.saveGetStationsDuration(context, end - start);
  		Log.d(getClass().getSimpleName(), "getStations() took "
  				+ Root.getGetStationsDuration(context) + "ms");
  		return stations;
  	}
  
  	IService both = new IService() {
  
  		@Override
  		public int getId() {
  			return 1;
  		}
  
  		@Override
  		public boolean isToday() {
  			return true;
  		}
  
  		@Override
  		public boolean isTomorrow() {
  			return true;
  		}
  
  		@Override
  		public boolean isDate(Calendar cal) {
  			// TODO Auto-generated method stub
  			return false;
  		}
  
  	};
  
  	public long getMaxCalendarDate() {
  		Cursor c = db.rawQuery(
  				"select calendar_date from calendar_dates limit 1", null);
  		boolean fromCalendarDate = true;
  		try {
  			fromCalendarDate = c.getCount() > 0;
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  		c.close();
  		String table = fromCalendarDate ? "calendar_dates" : "calendar";
  		String column = fromCalendarDate ? "calendar_date" : "end";
  		c = db.rawQuery("select max(" + column + ") from " + table, null);
  		try {
  			if (c.getCount() == 1) {
  				c.moveToNext();
  				String date = c.getString(0);
  				Date _date = DF.parse(date);
  				return _date.getTime();
  			}
  
  		} catch (Exception e) {
  			throw new RuntimeException(e);
  		} finally {
  			c.close();
  		}
  		return Long.MAX_VALUE;
  	}
  
  	public long getMinCalendarDate() {
  		Cursor c = db.rawQuery(
  				"select calendar_date from calendar_dates limit 1", null);
  		boolean fromCalendarDate = true;
  		try {
  			fromCalendarDate = c.getCount() > 0;
  		} catch (Exception e) {
  			e.printStackTrace();
  		}
  		c.close();
  		String table = fromCalendarDate ? "calendar_dates" : "calendar";
  		String column = fromCalendarDate ? "calendar_date" : "start";
  		c = db.rawQuery("select min(" + column + ") from " + table, null);
  		try {
  			if (c.getCount() == 1) {
  				c.moveToNext();
  				String date = c.getString(0);
  				Date _date = DF.parse(date);
  				return _date.getTime();
  			}
  
  		} catch (Exception e) {
  			throw new RuntimeException(e);
  		} finally {
  			c.close();
  		}
  		return Long.MAX_VALUE;
  	}
  
      public Set<Integer> getStopsOnEachRoute(Collection<Integer> routeIds) {
          if(routeIds==null || routeIds.size()==0) {
              return null;
          }
          Set<Integer> stops = new HashSet<Integer>();
          Set<Integer> lastStops = new HashSet<Integer>();
          boolean first = true;
          for(Integer routeId : routeIds) {
              String query = "select st.stop_id from stop_times st where st.trip_id in (select id from trips where route_id=%s) group by stop_id";
              query = String.format(query, routeId);
              Cursor cursor = db.rawQuery(query, null);
              for(int i = 0; i < cursor.getCount(); i++) {
                  cursor.moveToNext();
                  int stopId = cursor.getInt(0);
                  if(first) {
                      stops.add(stopId);
                  } else {
                      lastStops.add(stopId);
                  }
              }
              cursor.close();
              if(first) {
                  first = false;
              } else {
                  Set<Integer> intersection = new TreeSet<Integer>(stops);
                  intersection.retainAll(lastStops);
                  stops.clear();
                  stops.addAll(intersection);
              }
  
          }
          return stops;
      }
  
      public Map<Integer, Set<Integer>> getRoutesStationIsOn(Station...stations) {
          if (stations==null || stations.length==0) {
              return Collections.emptyMap();
          }
          String query = "select route_id,id from trips where id in (select trip_id from stop_times where ";
          String stationIds = "(";
          for(int i = 0; i < stations.length; i++) {
              query+=" stop_id = ";
              query+=stations[i].getId();
              stationIds+=stations[i].getId();
              if(i+1<stations.length) {
                  query+=" or ";
                  stationIds+=',';
              }
          }
          stationIds+=")";
          query+=") ";
          Cursor cursor = db.rawQuery(query,null);
          Map<Integer,Integer> tripIdToRouteId = new HashMap<Integer,Integer>();
          for(int i =0; i < cursor.getCount(); i++) {
              cursor.moveToNext();
              int routeId = cursor.getInt(0);
              int tripId = cursor.getInt(1);
              tripIdToRouteId.put(tripId,routeId);
          }
          cursor.close();
          String tripIds = "(";
          for(Iterator<Integer> i = tripIdToRouteId.keySet().iterator();i.hasNext();) {
              tripIds+=i.next();
              if(i.hasNext()) {
                  tripIds+=",";
              }
          }
          tripIds+=")";
          String stopIdQuery = "select stop_id,trip_id from stop_times where trip_id in %s and stop_id in %s";
          stopIdQuery = String.format(stopIdQuery,tripIds,stationIds);
          Map<Integer, Set<Integer>> stationsToRouteIds = new HashMap<Integer,Set<Integer>>();
          cursor = db.rawQuery(stopIdQuery,null);
          for(int i = 0; i < cursor.getCount(); i++) {
              cursor.moveToNext();
              int stopId = cursor.getInt(0);
              Set<Integer> routeIds = stationsToRouteIds.get(stopId);
              if(routeIds==null) {
                  routeIds = new HashSet<Integer>();
                  stationsToRouteIds.put(stopId,routeIds);
              }
  