Commit f95e6b1a authored by Marco Nelissen's avatar Marco Nelissen
Browse files

Column in log table is not unique

DATETIME was set as primary key but that value is not always unique.
This solution is to remove primary key constraint from column "time"
to avoid SQLiteConstraintException caused in case same DATETIME value
is attempted to be inserted into log table.

(this is externally contributed change ef8c5a39
which was skipped in an earlier automerge)
b/8832525

Change-Id: I26ba5356f54b589882447f4aa51892e6b2928acd
parent 32e29cf6
......@@ -2,7 +2,7 @@
package="com.android.providers.media"
android:sharedUserId="android.media"
android:sharedUserLabel="@string/uid_label"
android:versionCode="600">
android:versionCode="601">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
......
......@@ -1807,6 +1807,15 @@ public class MediaProvider extends ContentProvider {
}
}
if (fromVersion < 601) {
// remove primary key constraint because column time is not necessarily unique
db.execSQL("CREATE TABLE IF NOT EXISTS log_tmp (time DATETIME, message TEXT);");
db.execSQL("DELETE FROM log_tmp;");
db.execSQL("INSERT INTO log_tmp SELECT time, message FROM log order by rowid;");
db.execSQL("DROP TABLE log;");
db.execSQL("ALTER TABLE log_tmp RENAME TO log;");
}
sanityCheck(db, fromVersion);
long elapsedSeconds = (SystemClock.currentTimeMicro() - startTime) / 1000000;
logToDb(db, "Database upgraded from version " + fromVersion + " to " + toVersion
......@@ -1822,7 +1831,7 @@ public class MediaProvider extends ContentProvider {
new String[] { message });
// delete all but the last 500 rows
db.execSQL("DELETE FROM log WHERE rowid IN" +
" (SELECT rowid FROM log ORDER BY time DESC LIMIT 500,-1);");
" (SELECT rowid FROM log ORDER BY rowid DESC LIMIT 500,-1);");
}
/**
......@@ -5404,7 +5413,7 @@ public class MediaProvider extends ContentProvider {
}
if (dumpDbLog) {
c = db.query("log", new String[] {"time", "message"},
null, null, null, null, "time");
null, null, null, null, "rowid");
try {
if (c != null) {
while (c.moveToNext()) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment