0

正如标题所说。我正在寻找解决方案,但我认为我走错了路。我觉得最简单的方法是在应用程序识别出用户更改时设置一个新的数据库。最多 2-3 个用户。所有用户的流程都是ContentProvider相同的。好吧,是的,我可以用一些用户 ID 标记所有插入,但这听起来很容易 :) 我可以放弃ContentProviderif`necessary 来完成这项工作。关于解决这个问题的好方法有什么想法吗?

经过一些研究,我发现它ContentProvider是在应用程序之前加载的,因此很难更改数据库名称。这种情况下还 SQLiteOpenHelper onUpgrade()需要升级很多数据库文件。清单注册的ContentProvider数据库名称是用石头写的吗?

这是表格布局的一部分,我还有更多,比如 10 个表格

public final class TableUser {

    public TableUser() {
    }

    public static final class User implements BaseColumns {
        private User() {
        }
        public static final Uri CONTENT_URI = Uri.parse("content://" + UserContentProvider.AUTHORITY + "/user");

        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.doktor.user";

        public static final String USER_ID = "_id";

        public static final String UUID = "uuid";

        public static final String USERNAME = "username";

        public static final String USERPASSWORD = "userpassword";

        public static final String REGISTRATIONID = "registrationid";

        public static final String LAST_LOGGED_IN = "lastloggedin";     

    }

    public static final class FriendRequests implements BaseColumns {

        private FriendRequests() {
        }
        public static final Uri CONTENT_URI = Uri.parse("content://" + UserContentProvider.AUTHORITY + "/friendRequests");

        public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.doktor.friendRequests";

        public static final String FRIENDREQUESTS_ID = "_id";

        public static final String NAME = "name";

        public static final String UUID = "uuid";

        public static final String MESSAGE = "message"; 

        public static final String NOTIFICATION_ID = "notification_id";     

        public static final String DEVICE_TYPE = "device_type";

        public static final String ADDEDDATE = "added_date";
    }
}

这是表创建

db.execSQL("CREATE TABLE " +  USER_TABLE_NAME + " (" +
       User.USER_ID         + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
       User.UUID            + " VARCHAR(255)," + 
       User.USERNAME        + " VARCHAR(255)," + 
       User.USERPASSWORD    + " VARCHAR(255)," + 
       User.REGISTRATIONID  + " LONGTEXT," + 
       User.LAST_LOGGED_IN  + " VARCHAR(255)" + ");");

db.execSQL("CREATE TABLE " +  FRIEND_REQUEST_TABLE_NAME + " (" + 
    FriendRequests.FRIENDREQUESTS_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + 
    FriendRequests.NAME              + " VARCHAR(255)," +
    FriendRequests.UUID              + " VARCHAR(255)," +
    FriendRequests.MESSAGE           + " VARCHAR(255)," +
    FriendRequests.NOTIFICATION_ID   + " VARCHAR(255)," +   
    FriendRequests.DEVICE_TYPE       + " VARCHAR(255)," +                          
    FriendRequests.ADDEDDATE         + " VARCHAR(255)" + ");"); 
4

1 回答 1

1

正如我在评论中所说,我将使用一个数据库,其中包含您拥有的每个表中的所有数据(来自所有可能的用户),另一个额外的列表示实际用户标识符(存在于您需要用户标识的任何表中)。然后,您将使用此列过滤正常的数据库查询(插入、查询等),以仅获取/修改该特定用户的数据。Uri如果您使用 a ,则该标识符必须通过ContentProvider,然后使用 . 附加到正常的选择子句中AND user_identif=user_id_extracted_from_uri

并且您可以使用电子邮件地址作为标识符,这将比某些生成的用户 ID 更可靠地跨设备。

于 2013-10-25T04:47:21.847 回答