From 10874aa7a76a1d8a64fc13e7c01aa6740f41ebd2 Mon Sep 17 00:00:00 2001 From: masensio Date: Fri, 11 Dec 2015 14:35:45 +0100 Subject: [PATCH] Add new table for uploads on database --- src/com/owncloud/android/db/ProviderMeta.java | 13 +- .../providers/FileContentProvider.java | 472 ++++++++++-------- 2 files changed, 275 insertions(+), 210 deletions(-) diff --git a/src/com/owncloud/android/db/ProviderMeta.java b/src/com/owncloud/android/db/ProviderMeta.java index 5f63eb1043..5bdf16fd84 100644 --- a/src/com/owncloud/android/db/ProviderMeta.java +++ b/src/com/owncloud/android/db/ProviderMeta.java @@ -1,4 +1,3 @@ - /** * ownCloud Android client application * @@ -32,7 +31,7 @@ import com.owncloud.android.MainApp; public class ProviderMeta { public static final String DB_NAME = "filelist"; - public static final int DB_VERSION = 13; + public static final int DB_VERSION = 14; private ProviderMeta() { } @@ -41,6 +40,7 @@ public class ProviderMeta { public static final String FILE_TABLE_NAME = "filelist"; public static final String OCSHARES_TABLE_NAME = "ocshares"; public static final String CAPABILITIES_TABLE_NAME = "capabilities"; + public static final String UPLOADS_TABLE_NAME = "list_of_uploads"; public static final Uri CONTENT_URI = Uri.parse("content://" + MainApp.getAuthority() + "/"); public static final Uri CONTENT_URI_FILE = Uri.parse("content://" @@ -51,6 +51,8 @@ public class ProviderMeta { + MainApp.getAuthority() + "/shares"); public static final Uri CONTENT_URI_CAPABILITIES = Uri.parse("content://" + MainApp.getAuthority() + "/capabilities"); + public static final Uri CONTENT_URI_UPLOADS = Uri.parse("content://" + + MainApp.getAuthority() + "/uploads"); public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.owncloud.file"; public static final String CONTENT_TYPE_ITEM = "vnd.android.cursor.item/vnd.owncloud.file"; @@ -130,5 +132,12 @@ public class ProviderMeta { public static final String CAPABILITIES_DEFAULT_SORT_ORDER = CAPABILITIES_ACCOUNT_NAME + " collate nocase asc"; + + //Columns of Uploads table + public static final String UPLOADS_FILE_ID = "file_id"; + public static final String UPLOADS_PATH = "path"; + public static final String UPLOADS_STATUS = "status"; + + public static final String UPLOADS_DEFAULT_SORT_ORDER = UPLOADS_FILE_ID + " collate nocase asc"; } } diff --git a/src/com/owncloud/android/providers/FileContentProvider.java b/src/com/owncloud/android/providers/FileContentProvider.java index e652baded0..52be86f7ac 100644 --- a/src/com/owncloud/android/providers/FileContentProvider.java +++ b/src/com/owncloud/android/providers/FileContentProvider.java @@ -3,6 +3,7 @@ * * @author Bartek Przybylski * @author David A. Velasco + * @author masensio * Copyright (C) 2011 Bartek Przybylski * Copyright (C) 2015 ownCloud Inc. * @@ -65,6 +66,7 @@ public class FileContentProvider extends ContentProvider { private static final int ROOT_DIRECTORY = 3; private static final int SHARES = 4; private static final int CAPABILITIES = 5; + private static final int UPLOADS = 6; private static final String TAG = FileContentProvider.class.getSimpleName(); @@ -89,25 +91,25 @@ public class FileContentProvider extends ContentProvider { private int delete(SQLiteDatabase db, Uri uri, String where, String[] whereArgs) { int count = 0; switch (mUriMatcher.match(uri)) { - case SINGLE_FILE: - Cursor c = query(db, uri, null, where, whereArgs, null); - String remoteId = ""; - if (c != null && c.moveToFirst()) { - remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)); - //ThumbnailsCacheManager.removeFileFromCache(remoteId); - c.close(); - } - Log_OC.d(TAG, "Removing FILE " + remoteId); + case SINGLE_FILE: + Cursor c = query(db, uri, null, where, whereArgs, null); + String remoteId = ""; + if (c != null && c.moveToFirst()) { + remoteId = c.getString(c.getColumnIndex(ProviderTableMeta.FILE_REMOTE_ID)); + //ThumbnailsCacheManager.removeFileFromCache(remoteId); + c.close(); + } + Log_OC.d(TAG, "Removing FILE " + remoteId); - count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, - ProviderTableMeta._ID - + "=" - + uri.getPathSegments().get(1) - + (!TextUtils.isEmpty(where) ? " AND (" + where - + ")" : ""), whereArgs); - break; - case DIRECTORY: - // deletion of folder is recursive + count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, + ProviderTableMeta._ID + + "=" + + uri.getPathSegments().get(1) + + (!TextUtils.isEmpty(where) ? " AND (" + where + + ")" : ""), whereArgs); + break; + case DIRECTORY: + // deletion of folder is recursive /* Uri folderUri = ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, Long.parseLong(uri.getPathSegments().get(1))); Cursor folder = query(db, folderUri, null, null, null, null); @@ -116,63 +118,66 @@ public class FileContentProvider extends ContentProvider { folderName = folder.getString(folder.getColumnIndex(ProviderTableMeta.FILE_PATH)); } */ - Cursor children = query(uri, null, null, null, null); - if (children != null && children.moveToFirst()) { - long childId; - boolean isDir; - while (!children.isAfterLast()) { - childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID)); - isDir = "DIR".equals(children.getString( - children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE) - )); - //remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH)); - if (isDir) { - count += delete( - db, - ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId), - null, - null - ); - } else { - count += delete( - db, - ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId), - null, - null - ); + Cursor children = query(uri, null, null, null, null); + if (children != null && children.moveToFirst()) { + long childId; + boolean isDir; + while (!children.isAfterLast()) { + childId = children.getLong(children.getColumnIndex(ProviderTableMeta._ID)); + isDir = "DIR".equals(children.getString( + children.getColumnIndex(ProviderTableMeta.FILE_CONTENT_TYPE) + )); + //remotePath = children.getString(children.getColumnIndex(ProviderTableMeta.FILE_PATH)); + if (isDir) { + count += delete( + db, + ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_DIR, childId), + null, + null + ); + } else { + count += delete( + db, + ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, childId), + null, + null + ); + } + children.moveToNext(); } - children.moveToNext(); - } - children.close(); - } /*else { + children.close(); + } /*else { Log_OC.d(TAG, "No child to remove in DIRECTORY " + folderName); } Log_OC.d(TAG, "Removing DIRECTORY " + folderName + " (or maybe not) "); */ - count += db.delete(ProviderTableMeta.FILE_TABLE_NAME, - ProviderTableMeta._ID - + "=" - + uri.getPathSegments().get(1) - + (!TextUtils.isEmpty(where) ? " AND (" + where - + ")" : ""), whereArgs); + count += db.delete(ProviderTableMeta.FILE_TABLE_NAME, + ProviderTableMeta._ID + + "=" + + uri.getPathSegments().get(1) + + (!TextUtils.isEmpty(where) ? " AND (" + where + + ")" : ""), whereArgs); /* Just for log if (folder != null) { folder.close(); }*/ - break; - case ROOT_DIRECTORY: - //Log_OC.d(TAG, "Removing ROOT!"); - count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs); - break; - case SHARES: - count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs); - break; - case CAPABILITIES: - count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs); - break; - default: - //Log_OC.e(TAG, "Unknown uri " + uri); - throw new IllegalArgumentException("Unknown uri: " + uri.toString()); + break; + case ROOT_DIRECTORY: + //Log_OC.d(TAG, "Removing ROOT!"); + count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs); + break; + case SHARES: + count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs); + break; + case CAPABILITIES: + count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs); + break; + case UPLOADS: + count = db.delete(ProviderTableMeta.UPLOADS_TABLE_NAME, where, whereArgs); + break; + default: + //Log_OC.e(TAG, "Unknown uri " + uri); + throw new IllegalArgumentException("Unknown uri: " + uri.toString()); } return count; } @@ -207,68 +212,81 @@ public class FileContentProvider extends ContentProvider { private Uri insert(SQLiteDatabase db, Uri uri, ContentValues values) { switch (mUriMatcher.match(uri)){ - case ROOT_DIRECTORY: - case SINGLE_FILE: - String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH); - String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER); - String[] projection = new String[] { - ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, - ProviderTableMeta.FILE_ACCOUNT_OWNER - }; - String where = ProviderTableMeta.FILE_PATH + "=? AND " + - ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; - String[] whereArgs = new String[] {remotePath, accountName}; - Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null); - // ugly patch; serious refactorization is needed to reduce work in - // FileDataStorageManager and bring it to FileContentProvider - if (doubleCheck == null || !doubleCheck.moveToFirst()) { - if (doubleCheck != null) { + case ROOT_DIRECTORY: + case SINGLE_FILE: + String remotePath = values.getAsString(ProviderTableMeta.FILE_PATH); + String accountName = values.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER); + String[] projection = new String[] { + ProviderTableMeta._ID, ProviderTableMeta.FILE_PATH, + ProviderTableMeta.FILE_ACCOUNT_OWNER + }; + String where = ProviderTableMeta.FILE_PATH + "=? AND " + + ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?"; + String[] whereArgs = new String[] {remotePath, accountName}; + Cursor doubleCheck = query(db, uri, projection, where, whereArgs, null); + // ugly patch; serious refactorization is needed to reduce work in + // FileDataStorageManager and bring it to FileContentProvider + if (doubleCheck == null || !doubleCheck.moveToFirst()) { + if (doubleCheck != null) { + doubleCheck.close(); + } + long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values); + if (rowId > 0) { + return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId); + } else { + throw new SQLException("ERROR " + uri); + } + } else { + // file is already inserted; race condition, let's avoid a duplicated entry + Uri insertedFileUri = ContentUris.withAppendedId( + ProviderTableMeta.CONTENT_URI_FILE, + doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID)) + ); doubleCheck.close(); + + return insertedFileUri; } - long rowId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values); - if (rowId > 0) { - return ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_FILE, rowId); + + case SHARES: + Uri insertedShareUri = null; + long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values); + if (rowId >0) { + insertedShareUri = + ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId); } else { throw new SQLException("ERROR " + uri); + } - } else { - // file is already inserted; race condition, let's avoid a duplicated entry - Uri insertedFileUri = ContentUris.withAppendedId( - ProviderTableMeta.CONTENT_URI_FILE, - doubleCheck.getLong(doubleCheck.getColumnIndex(ProviderTableMeta._ID)) - ); - doubleCheck.close(); + updateFilesTableAccordingToShareInsertion(db, values); + return insertedShareUri; - return insertedFileUri; - } + case CAPABILITIES: + Uri insertedCapUri = null; + long id = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values); + if (id >0) { + insertedCapUri = + ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, id); + } else { + throw new SQLException("ERROR " + uri); - case SHARES: - Uri insertedShareUri = null; - long rowId = db.insert(ProviderTableMeta.OCSHARES_TABLE_NAME, null, values); - if (rowId >0) { - insertedShareUri = - ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_SHARE, rowId); - } else { - throw new SQLException("ERROR " + uri); + } + return insertedCapUri; - } - updateFilesTableAccordingToShareInsertion(db, values); - return insertedShareUri; + case UPLOADS: + Uri insertedUploadUri = null; + long uploadId = db.insert(ProviderTableMeta.UPLOADS_TABLE_NAME, null, values); + if (uploadId >0) { + insertedUploadUri = + ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_UPLOADS, uploadId); + } else { + throw new SQLException("ERROR " + uri); - case CAPABILITIES: - Uri insertedCapUri = null; - long id = db.insert(ProviderTableMeta.CAPABILITIES_TABLE_NAME, null, values); - if (id >0) { - insertedCapUri = - ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_CAPABILITIES, id); - } else { - throw new SQLException("ERROR " + uri); - - } - return insertedCapUri; - - default: - throw new IllegalArgumentException("Unknown uri id: " + uri); + } + // TODO?? + // updateFilesTableAccordingToUploadInsertion(db, values); + return insertedUploadUri; + default: + throw new IllegalArgumentException("Unknown uri id: " + uri); } } @@ -309,6 +327,8 @@ public class FileContentProvider extends ContentProvider { mUriMatcher.addURI(authority, "shares/#", SHARES); mUriMatcher.addURI(authority, "capabilities/", CAPABILITIES); mUriMatcher.addURI(authority, "capabilities/#", CAPABILITIES); + mUriMatcher.addURI(authority, "uploads/", UPLOADS); + mUriMatcher.addURI(authority, "uploads/#", UPLOADS); return true; } @@ -349,35 +369,42 @@ public class FileContentProvider extends ContentProvider { sqlQuery.setTables(ProviderTableMeta.FILE_TABLE_NAME); switch (mUriMatcher.match(uri)) { - case ROOT_DIRECTORY: - break; - case DIRECTORY: - String folderId = uri.getPathSegments().get(1); - sqlQuery.appendWhere(ProviderTableMeta.FILE_PARENT + "=" - + folderId); - break; - case SINGLE_FILE: - if (uri.getPathSegments().size() > 1) { - sqlQuery.appendWhere(ProviderTableMeta._ID + "=" - + uri.getPathSegments().get(1)); - } - break; - case SHARES: - sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME); - if (uri.getPathSegments().size() > 1) { - sqlQuery.appendWhere(ProviderTableMeta._ID + "=" - + uri.getPathSegments().get(1)); - } - break; - case CAPABILITIES: - sqlQuery.setTables(ProviderTableMeta.CAPABILITIES_TABLE_NAME); - if (uri.getPathSegments().size() > 1) { - sqlQuery.appendWhere(ProviderTableMeta._ID + "=" - + uri.getPathSegments().get(1)); - } - break; - default: - throw new IllegalArgumentException("Unknown uri id: " + uri); + case ROOT_DIRECTORY: + break; + case DIRECTORY: + String folderId = uri.getPathSegments().get(1); + sqlQuery.appendWhere(ProviderTableMeta.FILE_PARENT + "=" + + folderId); + break; + case SINGLE_FILE: + if (uri.getPathSegments().size() > 1) { + sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + + uri.getPathSegments().get(1)); + } + break; + case SHARES: + sqlQuery.setTables(ProviderTableMeta.OCSHARES_TABLE_NAME); + if (uri.getPathSegments().size() > 1) { + sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + + uri.getPathSegments().get(1)); + } + break; + case CAPABILITIES: + sqlQuery.setTables(ProviderTableMeta.CAPABILITIES_TABLE_NAME); + if (uri.getPathSegments().size() > 1) { + sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + + uri.getPathSegments().get(1)); + } + break; + case UPLOADS: + sqlQuery.setTables(ProviderTableMeta.UPLOADS_TABLE_NAME); + if (uri.getPathSegments().size() > 1) { + sqlQuery.appendWhere(ProviderTableMeta._ID + "=" + + uri.getPathSegments().get(1)); + } + break; + default: + throw new IllegalArgumentException("Unknown uri id: " + uri); } String order; @@ -389,6 +416,9 @@ public class FileContentProvider extends ContentProvider { case CAPABILITIES: order = ProviderTableMeta.CAPABILITIES_DEFAULT_SORT_ORDER; break; + case UPLOADS: + order = ProviderTableMeta.UPLOADS_DEFAULT_SORT_ORDER; + break; default: // Files order = ProviderTableMeta.FILE_DEFAULT_SORT_ORDER; break; @@ -440,6 +470,10 @@ public class FileContentProvider extends ContentProvider { return db.update( ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs ); + case UPLOADS: + return db.update( + ProviderTableMeta.UPLOADS_TABLE_NAME, values, selection, selectionArgs + ); default: return db.update( ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs @@ -482,53 +516,17 @@ public class FileContentProvider extends ContentProvider { public void onCreate(SQLiteDatabase db) { // files table Log_OC.i("SQL", "Entering in onCreate"); - db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "(" - + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " - + ProviderTableMeta.FILE_NAME + " TEXT, " - + ProviderTableMeta.FILE_PATH + " TEXT, " - + ProviderTableMeta.FILE_PARENT + " INTEGER, " - + ProviderTableMeta.FILE_CREATION + " INTEGER, " - + ProviderTableMeta.FILE_MODIFIED + " INTEGER, " - + ProviderTableMeta.FILE_CONTENT_TYPE + " TEXT, " - + ProviderTableMeta.FILE_CONTENT_LENGTH + " INTEGER, " - + ProviderTableMeta.FILE_STORAGE_PATH + " TEXT, " - + ProviderTableMeta.FILE_ACCOUNT_OWNER + " TEXT, " - + ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, " - + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, " - + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, " - + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " - + ProviderTableMeta.FILE_ETAG + " TEXT, " - + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER, " - + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, " - + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null," - + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null," - + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean - + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER," //boolean - + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT," - + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);" - ); + createFilesTable(db); - // Create table ocshares - db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "(" - + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " - + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, " - + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, " - + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, " - + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, " - + ProviderTableMeta.OCSHARES_PATH + " TEXT, " - + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, " - + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, " - + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, " - + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, " - + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, " - + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, " // boolean - + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, " - + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," - + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" ); + // Create ocshares table + createOCSharesTable(db); - // Create table capabilities + // Create capabilities table createCapabilitiesTable(db); + // Create uploads table + createUploadsTable(db); + } @Override @@ -616,22 +614,7 @@ public class FileContentProvider extends ContentProvider { " DEFAULT NULL"); // Create table ocshares - db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "(" - + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " - + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, " - + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, " - + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, " - + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, " - + ProviderTableMeta.OCSHARES_PATH + " TEXT, " - + ProviderTableMeta.OCSHARES_PERMISSIONS + " INTEGER, " - + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, " - + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, " - + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, " - + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, " - + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, " // boolean - + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, " - + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," - + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );"); + createOCSharesTable(db); upgraded = true; db.setTransactionSuccessful(); @@ -757,6 +740,22 @@ public class FileContentProvider extends ContentProvider { db.endTransaction(); } } + + if (oldVersion < 14 && newVersion >= 14) { + Log_OC.i("SQL", "Entering in the #14 ADD in onUpgrade"); + db.beginTransaction(); + try { + // drop old instant_upload table + db.execSQL("DROP TABLE IF EXISTS " + "instant_upload" + ";"); + // Create uploads table + createUploadsTable(db); + upgraded = true; + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + } + if (!upgraded) Log_OC.i("SQL", "OUT of the ADD in onUpgrade; oldVersion == " + oldVersion + ", newVersion == " + newVersion); @@ -764,8 +763,56 @@ public class FileContentProvider extends ContentProvider { } } + private void createFilesTable(SQLiteDatabase db){ + db.execSQL("CREATE TABLE " + ProviderTableMeta.FILE_TABLE_NAME + "(" + + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + + ProviderTableMeta.FILE_NAME + " TEXT, " + + ProviderTableMeta.FILE_PATH + " TEXT, " + + ProviderTableMeta.FILE_PARENT + " INTEGER, " + + ProviderTableMeta.FILE_CREATION + " INTEGER, " + + ProviderTableMeta.FILE_MODIFIED + " INTEGER, " + + ProviderTableMeta.FILE_CONTENT_TYPE + " TEXT, " + + ProviderTableMeta.FILE_CONTENT_LENGTH + " INTEGER, " + + ProviderTableMeta.FILE_STORAGE_PATH + " TEXT, " + + ProviderTableMeta.FILE_ACCOUNT_OWNER + " TEXT, " + + ProviderTableMeta.FILE_LAST_SYNC_DATE + " INTEGER, " + + ProviderTableMeta.FILE_KEEP_IN_SYNC + " INTEGER, " + + ProviderTableMeta.FILE_LAST_SYNC_DATE_FOR_DATA + " INTEGER, " + + ProviderTableMeta.FILE_MODIFIED_AT_LAST_SYNC_FOR_DATA + " INTEGER, " + + ProviderTableMeta.FILE_ETAG + " TEXT, " + + ProviderTableMeta.FILE_SHARED_VIA_LINK + " INTEGER, " + + ProviderTableMeta.FILE_PUBLIC_LINK + " TEXT, " + + ProviderTableMeta.FILE_PERMISSIONS + " TEXT null," + + ProviderTableMeta.FILE_REMOTE_ID + " TEXT null," + + ProviderTableMeta.FILE_UPDATE_THUMBNAIL + " INTEGER," //boolean + + ProviderTableMeta.FILE_IS_DOWNLOADING + " INTEGER," //boolean + + ProviderTableMeta.FILE_ETAG_IN_CONFLICT + " TEXT," + + ProviderTableMeta.FILE_SHARED_WITH_SHAREE + " INTEGER);" + ); + } + + private void createOCSharesTable(SQLiteDatabase db) { + // Create ocshares table + db.execSQL("CREATE TABLE " + ProviderTableMeta.OCSHARES_TABLE_NAME + "(" + + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + + ProviderTableMeta.OCSHARES_FILE_SOURCE + " INTEGER, " + + ProviderTableMeta.OCSHARES_ITEM_SOURCE + " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARE_TYPE + " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARE_WITH + " TEXT, " + + ProviderTableMeta.OCSHARES_PATH + " TEXT, " + + ProviderTableMeta.OCSHARES_PERMISSIONS+ " INTEGER, " + + ProviderTableMeta.OCSHARES_SHARED_DATE + " INTEGER, " + + ProviderTableMeta.OCSHARES_EXPIRATION_DATE + " INTEGER, " + + ProviderTableMeta.OCSHARES_TOKEN + " TEXT, " + + ProviderTableMeta.OCSHARES_SHARE_WITH_DISPLAY_NAME + " TEXT, " + + ProviderTableMeta.OCSHARES_IS_DIRECTORY + " INTEGER, " // boolean + + ProviderTableMeta.OCSHARES_USER_ID + " INTEGER, " + + ProviderTableMeta.OCSHARES_ID_REMOTE_SHARED + " INTEGER," + + ProviderTableMeta.OCSHARES_ACCOUNT_OWNER + " TEXT );" ); + } + private void createCapabilitiesTable(SQLiteDatabase db){ - // Create table capabilities + // Create capabilities table db.execSQL("CREATE TABLE " + ProviderTableMeta.CAPABILITIES_TABLE_NAME + "(" + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + ProviderTableMeta.CAPABILITIES_ACCOUNT_NAME + " TEXT, " @@ -792,6 +839,15 @@ public class FileContentProvider extends ContentProvider { + ProviderTableMeta.CAPABILITIES_FILES_VERSIONING + " INTEGER );" ); // boolean } + private void createUploadsTable(SQLiteDatabase db){ + // Create uploads table + db.execSQL("CREATE TABLE " + ProviderTableMeta.UPLOADS_TABLE_NAME + "(" + + ProviderTableMeta._ID + " INTEGER PRIMARY KEY, " + + ProviderTableMeta.UPLOADS_FILE_ID + " INTEGER, " + + ProviderTableMeta.UPLOADS_PATH + " TEXT, " + + ProviderTableMeta.UPLOADS_STATUS + " INTEGER );" ); // UploadStatus + } + /** * Version 10 of database does not modify its scheme. It coincides with the upgrade of the ownCloud account names * structure to include in it the path to the server instance. Updating the account names and path to local files