From 655e867add447f1e1aeb84557b02ea18d8ea1b34 Mon Sep 17 00:00:00 2001 From: Magnus Lindhult Date: Wed, 29 Sep 2010 18:36:07 +0200 Subject: Protection against bookmarks with url=null in the database Modified the database to only accept bookmarks with a url != null, as a bookmark without url has no meaning and also makes the Browser crash in a number of places. Change-Id: I0a90c32a5c8846b96a231fb95b203aef4761f52d --- src/com/android/browser/BrowserProvider.java | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/com/android/browser/BrowserProvider.java b/src/com/android/browser/BrowserProvider.java index bf1f9d5..a6ceb8b 100644 --- a/src/com/android/browser/BrowserProvider.java +++ b/src/com/android/browser/BrowserProvider.java @@ -159,7 +159,8 @@ public class BrowserProvider extends ContentProvider { // 20 -> 21 Added touch_icon // 21 -> 22 Remove "clientid" // 22 -> 23 Added user_entered - private static final int DATABASE_VERSION = 23; + // 23 -> 24 Url not allowed to be null anymore. + private static final int DATABASE_VERSION = 24; // Regular expression which matches http://, followed by some stuff, followed by // optionally a trailing slash, all matched as separate groups. @@ -239,7 +240,7 @@ public class BrowserProvider extends ContentProvider { db.execSQL("CREATE TABLE bookmarks (" + "_id INTEGER PRIMARY KEY," + "title TEXT," + - "url TEXT," + + "url TEXT NOT NULL," + "visits INTEGER," + "date LONG," + "created LONG," + @@ -291,6 +292,27 @@ public class BrowserProvider extends ContentProvider { } if (oldVersion < 23) { db.execSQL("ALTER TABLE bookmarks ADD COLUMN user_entered INTEGER;"); + } + if (oldVersion < 24) { + /* SQLite does not support ALTER COLUMN, hence the lengthy code. */ + db.execSQL("DELETE FROM bookmarks WHERE url IS NULL;"); + db.execSQL("ALTER TABLE bookmarks RENAME TO bookmarks_temp;"); + db.execSQL("CREATE TABLE bookmarks (" + + "_id INTEGER PRIMARY KEY," + + "title TEXT," + + "url TEXT NOT NULL," + + "visits INTEGER," + + "date LONG," + + "created LONG," + + "description TEXT," + + "bookmark INTEGER," + + "favicon BLOB DEFAULT NULL," + + "thumbnail BLOB DEFAULT NULL," + + "touch_icon BLOB DEFAULT NULL," + + "user_entered INTEGER" + + ");"); + db.execSQL("INSERT INTO bookmarks SELECT * FROM bookmarks_temp;"); + db.execSQL("DROP TABLE bookmarks_temp;"); } else { db.execSQL("DROP TABLE IF EXISTS bookmarks"); db.execSQL("DROP TABLE IF EXISTS searches"); -- cgit v1.1