Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/data/UserDB.java
Show First 20 Lines • Show All 184 Lines • ▼ Show 20 Lines | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||||
*/ | */ | ||||
public static String getStopUserName(SQLiteDatabase db, String stopID) { | public static String getStopUserName(SQLiteDatabase db, String stopID) { | ||||
String username = null; | String username = null; | ||||
try { | try { | ||||
Cursor c = db.query(TABLE_NAME, usernameColumnNameAsArray, "ID = ?", new String[] {stopID}, null, null, null); | Cursor c = db.query(TABLE_NAME, usernameColumnNameAsArray, "ID = ?", new String[] {stopID}, null, null, null); | ||||
if(c.moveToNext()) { | if(c.moveToNext()) { | ||||
username = c.getString(c.getColumnIndex("username")); | int userNameIndex = c.getColumnIndex("username"); | ||||
if (userNameIndex>=0) | |||||
username = c.getString(userNameIndex); | |||||
} | } | ||||
c.close(); | c.close(); | ||||
} catch(SQLiteException ignored) {} | } catch(SQLiteException ignored) {} | ||||
return username; | return username; | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||||
} | } | ||||
public static ArrayList<Stop> getFavoritesFromCursor(Cursor cursor, String[] columns){ | public static ArrayList<Stop> getFavoritesFromCursor(Cursor cursor, String[] columns){ | ||||
List<String> colsList = Arrays.asList(columns); | List<String> colsList = Arrays.asList(columns); | ||||
if (!colsList.contains(getFavoritesColumnNamesAsArray[0]) || !colsList.contains(getFavoritesColumnNamesAsArray[1])){ | if (!colsList.contains(getFavoritesColumnNamesAsArray[0]) || !colsList.contains(getFavoritesColumnNamesAsArray[1])){ | ||||
throw new IllegalArgumentException(); | throw new IllegalArgumentException(); | ||||
} | } | ||||
ArrayList<Stop> l = new ArrayList<>(); | ArrayList<Stop> l = new ArrayList<>(); | ||||
if (cursor==null){ | |||||
Log.e("UserDB-BusTO", "Null cursor given in getFavoritesFromCursor"); | |||||
return l; | |||||
} | |||||
final int colID = cursor.getColumnIndex("ID"); | final int colID = cursor.getColumnIndex("ID"); | ||||
final int colUser = cursor.getColumnIndex("username"); | final int colUser = cursor.getColumnIndex("username"); | ||||
while(cursor.moveToNext()) { | while(cursor.moveToNext()) { | ||||
final String stopUserName = cursor.getString(colUser); | final String stopUserName = cursor.getString(colUser); | ||||
final String stopID = cursor.getString(colID); | final String stopID = cursor.getString(colID); | ||||
final Stop s = new Stop(stopID.trim()); | final Stop s = new Stop(stopID.trim()); | ||||
if (stopUserName!=null) s.setStopUserName(stopUserName); | if (stopUserName!=null) s.setStopUserName(stopUserName); | ||||
▲ Show 20 Lines • Show All 60 Lines • Show Last 20 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register