[Android] Add IF NOT EXISTS condition to triggers creation

Geoffrey Métais git at videolan.org
Thu Jun 23 19:28:03 CEST 2016


vlc-android | branch: 2.0.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Jun 23 14:18:38 2016 +0200| [cd95e5004872f4ef921a9352b0e192b74543d424] | committer: Geoffrey Métais

Add IF NOT EXISTS condition to triggers creation

(cherry picked from commit 6303ffdb238667b8e05bbd5d9bb169cd3598c6d5)

> https://code.videolan.org/videolan/vlc-android/commit/cd95e5004872f4ef921a9352b0e192b74543d424
---

 vlc-android/src/org/videolan/vlc/media/MediaDatabase.java | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java b/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java
index 1ef1f91..c261548 100644
--- a/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java
+++ b/vlc-android/src/org/videolan/vlc/media/MediaDatabase.java
@@ -245,7 +245,7 @@ public class MediaDatabase {
                     + MEDIA_ALBUMARTIST
                     + ");";
             db.execSQL(query);
-            query = " CREATE TRIGGER media_insert_trigger AFTER INSERT ON "+
+            query = " CREATE TRIGGER IF NOT EXISTS media_insert_trigger AFTER INSERT ON "+
                     MEDIA_TABLE_NAME+ " BEGIN "+
                     "INSERT INTO "+MEDIA_VIRTUAL_TABLE_NAME+" ("+MEDIA_LOCATION+", "+MEDIA_TITLE+
                     ", "+MEDIA_ARTIST+", "+MEDIA_GENRE+", "+MEDIA_ALBUM+", "+MEDIA_ALBUMARTIST+" )"+
@@ -253,7 +253,7 @@ public class MediaDatabase {
                     ", new."+MEDIA_GENRE+", new."+MEDIA_ALBUM+", new."+MEDIA_ALBUMARTIST+
                     "); END;";
             db.execSQL(query);
-            query = " CREATE TRIGGER media_delete_trigger AFTER DELETE ON "+MEDIA_TABLE_NAME+ " BEGIN "+
+            query = " CREATE TRIGGER IF NOT EXISTS media_delete_trigger AFTER DELETE ON "+MEDIA_TABLE_NAME+ " BEGIN "+
                     "DELETE FROM "+MEDIA_VIRTUAL_TABLE_NAME+" WHERE "+MEDIA_LOCATION+" = old."+MEDIA_LOCATION+";"+
                     " END;";
             db.execSQL(query);
@@ -283,7 +283,7 @@ public class MediaDatabase {
                     MRL_DATE + " DATETIME NOT NULL"
                     +");";
             db.execSQL(createMrlTableQuery);
-            createMrlTableQuery = " CREATE TRIGGER mrl_history_trigger AFTER INSERT ON "+
+            createMrlTableQuery = " CREATE TRIGGER IF NOT EXISTS mrl_history_trigger AFTER INSERT ON "+
                     MRL_TABLE_NAME+ " BEGIN "+
                     " DELETE FROM "+MRL_TABLE_NAME+" where "+MRL_URI+" NOT IN (SELECT "+MRL_URI+
                     " from "+MRL_TABLE_NAME+" ORDER BY "+MRL_DATE+" DESC LIMIT "+MRL_TABLE_SIZE+");"+
@@ -311,7 +311,7 @@ public class MediaDatabase {
                     HISTORY_DATE + " DATETIME NOT NULL"
                     +");";
             db.execSQL(createHistoryTableQuery);
-            createHistoryTableQuery = " CREATE TRIGGER history_trigger AFTER INSERT ON "+
+            createHistoryTableQuery = " CREATE TRIGGER IF NOT EXISTS history_trigger AFTER INSERT ON "+
                     HISTORY_TABLE_NAME+ " BEGIN "+
                     " DELETE FROM "+HISTORY_TABLE_NAME+" where "+HISTORY_URI+" NOT IN (SELECT "+HISTORY_URI+
                     " from "+HISTORY_TABLE_NAME+" ORDER BY "+HISTORY_DATE+" DESC LIMIT "+HISTORY_TABLE_SIZE+");"+



More information about the Android mailing list