Commits

littledot5566 committed be47778

*Used LEFT JOIN instead of inner join.

Comments (0)

Files changed (3)

src/nctuw/littledot/localtreasure/components/HistoryActivityAdapter.java

 		mCtx = ctx;
 		mDB = new Database(ctx).open(Database.MODE_READ);
 
-		Cursor cur = mDB.rawQuery(String
-				.format("select * from %s, %s where %s.%s=%s.%s order by %s",
-						Expedition.TABLE_NAME, Profile.TABLE_NAME,
-						Expedition.TABLE_NAME, Expedition.KEY_PID,
-						Profile.TABLE_NAME, Profile.KEY_ID,
-						Expedition.KEY_START_TIMESTAMP));
-
-		if (!cur.moveToFirst())
-			throw new IllegalAccessError("bad sql");
-
-		while (!cur.isAfterLast()) {
-			Leg.a(DatabaseUtils.dumpCurrentRowToString(cur));
-			ContentValues kv = Expedition.toContentValues(cur);
-			kv.putAll(Profile.toContentValues(cur));
-			mData.add(kv);
-			dbg.add(DatabaseUtils.dumpCurrentRowToString(cur));
-
-			cur.moveToNext();
+		Cursor cur = mDB.rawQuery(String.format(
+				"SELECT * FROM %s, %s WHERE %s.%s=%s.%s ORDER BY %s",
+				Expedition.TABLE_NAME, Profile.TABLE_NAME,
+				Expedition.TABLE_NAME, Expedition.KEY_PID,
+				Profile.TABLE_NAME, Profile.KEY_ID,
+				Expedition.KEY_START_TIMESTAMP));
+
+		if (cur.moveToFirst()) {
+			while (!cur.isAfterLast()) {
+				Leg.a(DatabaseUtils.dumpCurrentRowToString(cur));
+				ContentValues kv = Expedition.toContentValues(cur);
+				kv.putAll(Profile.toContentValues(cur));
+				mData.add(kv);
+				dbg.add(DatabaseUtils.dumpCurrentRowToString(cur));
+
+				cur.moveToNext();
+			}
 		}
-
 		cur.close();
 		mDB.close();
 	}

src/nctuw/littledot/localtreasure/database/Database.java

 	 */
 
 	public Profile queryProfile(long profileID) {
-		Cursor cur = rawQuery(String.format(
-				"SELECT *, %s, %s FROM %s, %s WHERE %s.%s=%s.%s AND %s=%d GROUP BY %s",
-				Expedition.SUM_TRAVELED, Expedition.COUNT_ID,
-				Profile.TABLE_NAME, Expedition.TABLE_NAME,
-				Profile.TABLE_NAME, Profile.KEY_ID,
-				Expedition.TABLE_NAME,
-				Expedition.KEY_PID,
-				Profile.KEY_ID, profileID,
-				Profile.KEY_ID));
+		Cursor cur = rawQuery(String
+				.format(
+						"SELECT *, %s, %s FROM %s LEFT JOIN %s ON %s.%s=%s.%s WHERE %s=%d GROUP BY %s",
+						Expedition.SUM_TRAVELED, Expedition.COUNT_ID,
+						Profile.TABLE_NAME, Expedition.TABLE_NAME,
+						Profile.TABLE_NAME, Profile.KEY_ID,
+						Expedition.TABLE_NAME,
+						Expedition.KEY_PID,
+						Profile.KEY_ID, profileID,
+						Profile.KEY_ID));
+
+		Leg.dumpCursor(cur);
 
 		if (cur.moveToFirst()) {
-			// Leg.dumpCursor(cur);
-			DatabaseUtils.dumpCurrentRow(cur);
 			Profile profile = new Profile(cur);
 			cur.close();
 
 							+ ") is not equal to the number of values("
 							+ values.length + ").");
 
-		ContentValues kvPair = new ContentValues();
+		ContentValues kv = new ContentValues();
 
 		for (int i = 0; i < keys.length; i++) {
 			if (values[i] instanceof String)
-				kvPair.put(keys[i], (String) values[i]);
+				kv.put(keys[i], (String) values[i]);
 			else if (values[i] instanceof Integer)
-				kvPair.put(keys[i], (Integer) values[i]);
+				kv.put(keys[i], (Integer) values[i]);
 			else if (values[i] instanceof Double)
-				kvPair.put(keys[i], (Double) values[i]);
+				kv.put(keys[i], (Double) values[i]);
 			else if (values[i] instanceof Float)
-				kvPair.put(keys[i], (Float) values[i]);
+				kv.put(keys[i], (Float) values[i]);
 			else if (values[i] instanceof Long)
-				kvPair.put(keys[i], (Long) values[i]);
+				kv.put(keys[i], (Long) values[i]);
 			else if (values[i] instanceof Short)
-				kvPair.put(keys[i], (Short) values[i]);
+				kv.put(keys[i], (Short) values[i]);
 			else if (values[i] instanceof Boolean)
-				kvPair.put(keys[i], (Boolean) values[i]);
+				kv.put(keys[i], (Boolean) values[i]);
 			else if (values[i] instanceof Byte)
-				kvPair.put(keys[i], (Byte) values[i]);
+				kv.put(keys[i], (Byte) values[i]);
 			else if (values[i] instanceof byte[])
-				kvPair.put(keys[i], (byte[]) values[i]);
+				kv.put(keys[i], (byte[]) values[i]);
 			else
-				throw new IllegalArgumentException("Type "
-						+ values[i].getClass().getName() + " is not supported.");
+				throw new IllegalArgumentException("kv[" + i
+						+ "]'s type is not supported.");
 		}
 
-		return kvPair;
+		return kv;
 	}
 
 	/**

src/nctuw/littledot/localtreasure/database/Profile.java

 import android.os.Parcelable;
 
 public class Profile implements Parcelable {
-	private long mProfileID;
-	private String mName;
+	private long mProfileID = 1;
+	private String mName = "<John Doe>";
 	private long mExpeditionCount;
 	private double mDistanceTravelled;