Fix bug: when installing the app for the first time, app crashes
[pub/Android/ownCloud.git] / src / com / owncloud / android / providers / FileContentProvider.java
index 2637f98..63a6501 100644 (file)
@@ -23,6 +23,7 @@
 package com.owncloud.android.providers;
 
 import java.io.File;
+import java.security.Provider;
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -865,9 +866,8 @@ public class FileContentProvider extends ContentProvider {
                             ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?",
                             new String[]{ oldAccountName });
                     upgraded = true;
-                    db.setTransactionSuccessful();
 
-                     Log_OC.d("SQL", "Updated account in database: old name == " + oldAccountName +
+                    Log_OC.d("SQL", "Updated account in database: old name == " + oldAccountName +
                              ", new name == " + newAccountName + " (" + num + " rows updated )");
 
                     // update path for downloaded files
@@ -893,12 +893,15 @@ public class FileContentProvider extends ContentProvider {
         boolean upgraded = false;
         boolean renamed = false;
 
-        String selectQuery = "SELECT * FROM " +
-                ProviderTableMeta.FILE_TABLE_NAME +" WHERE " +
-                ProviderTableMeta.FILE_ACCOUNT_OWNER +"=? AND " +
-                ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL;";
+        String whereClause = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=? AND " +
+                ProviderTableMeta.FILE_STORAGE_PATH + " IS NOT NULL";
+
+        Cursor c = db.query(ProviderTableMeta.FILE_TABLE_NAME,
+                null,
+                whereClause,
+                new String[] { newAccountName },
+                null, null, null);
 
-        Cursor c = db.rawQuery(selectQuery, new String[]{newAccountName});
         if (c.moveToFirst()) {
             // create storage path
             String oldAccountPath = FileStorageUtils.getSavePath(oldAccountName);
@@ -928,7 +931,6 @@ public class FileContentProvider extends ContentProvider {
                                 ProviderTableMeta.FILE_STORAGE_PATH + "=?",
                                 new String[]{oldPath});
                         upgraded = true;
-                        db.setTransactionSuccessful();
 
                         Log_OC.d("SQL", "Updated downloaded files: old file name == " + oldPath +
                                 ", new file name == " + newPath);