{"id":3579,"url":"https://github.com/yaa110/RestorableSQLiteDatabase","last_synced_at":"2025-08-03T20:32:40.781Z","repository":{"id":29542269,"uuid":"33081304","full_name":"yaa110/RestorableSQLiteDatabase","owner":"yaa110","description":"A wrapper around Android's SQLiteDatabase with restoring capability","archived":false,"fork":false,"pushed_at":"2016-02-02T16:35:00.000Z","size":98,"stargazers_count":21,"open_issues_count":0,"forks_count":2,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-04T20:49:57.417Z","etag":null,"topics":["android","android-library","sqlite-android"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yaa110.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-03-29T17:04:32.000Z","updated_at":"2023-09-08T16:56:10.000Z","dependencies_parsed_at":"2022-09-02T06:36:41.330Z","dependency_job_id":null,"html_url":"https://github.com/yaa110/RestorableSQLiteDatabase","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2FRestorableSQLiteDatabase","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2FRestorableSQLiteDatabase/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2FRestorableSQLiteDatabase/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yaa110%2FRestorableSQLiteDatabase/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yaa110","download_url":"https://codeload.github.com/yaa110/RestorableSQLiteDatabase/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228567009,"owners_count":17937983,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-library","sqlite-android"],"created_at":"2024-01-05T20:16:45.479Z","updated_at":"2024-12-07T05:30:40.811Z","avatar_url":"https://github.com/yaa110.png","language":"Java","funding_links":[],"categories":["Database","Libraries","Libs","库"],"sub_categories":["Database","\u003cA NAME=\"Orm\"\u003e\u003c/A\u003eOrm","[](https://github.com/JStumpp/awesome-android/blob/master/readme.md#database)数据库"],"readme":"Restorable SQLiteDatabase\n=========================\n[ ![Download](https://img.shields.io/badge/Download-0.1.0-green.svg) ](https://bintray.com/yaa110/maven/restorablesqlitedatabase/view) [![License](http://img.shields.io/:license-mit-blue.svg)](https://github.com/yaa110/RestorableSQLiteDatabase/blob/master/LICENSE)\n\nRestorableSQLiteDatabase is a wrapper to replicate android's [SQLiteDatabase](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html) class with restoring capability. This wrapper makes it possible to undo changes made after execution of SQL queries.\n\n## How to use\n\n**Use Gradle**\n\nReference library using this dependency in your module's `build.gradle` file:\n\n```Gradle\ndependencies {\n    compile 'github.yaa110.db:restorablesqlitedatabase:0.1.0'\n}\n```\n\n**or Use Maven**\n\n```xml\n\u003cdependency\u003e\n\t\u003cgroupId\u003egithub.yaa110.db\u003c/groupId\u003e\n\t\u003cartifactId\u003erestorablesqlitedatabase\u003c/artifactId\u003e\n\t\u003cversion\u003e0.1.0\u003c/version\u003e\n\t\u003ctype\u003eaar\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n## Example: Undoing deleted rows\n\nFirst, create a subclass of `SQLiteOpenHelper`:\n\n```java\npublic class DbHelper extends SQLiteOpenHelper {\n\n    public DbHelper(Context context) {\n        super(context, DB_NAME, null, DB_VERSION);\n    }\n\n    @Override\n    public void onCreate(SQLiteDatabase db) {\n        db.execSQL(\n                \"CREATE TABLE IF NOT EXISTS \" + TABLE_NAME + \" (\" +\n                        COLUMN_ROWID + \" INTEGER PRIMARY KEY AUTOINCREMENT, \" +\n                        COLUMN_TITLE + \" TEXT\" +\n                        \");\"\n        );\n    }\n\n    @Override\n    public void onUpgrade(SQLiteDatabase db, int old_version, int new_version) {\n        db.execSQL(\"DROP TABLE IF EXISTS \" + TABLE_NAME);\n        onCreate(db);\n    }\n\n}\n```\n\nThen, use `RestorableSQLiteDatabase`:\n```java\nHashMap\u003cString, String\u003e tableRowid = new HashMap\u003c\u003e();\ntableRowid.put(TABLE_NAME, COLUMN_ROWID);\n\nDbHelper helper = new DbHelper(this);\n\nRestorableSQLiteDatabase db = new RestorableSQLiteDatabase(helper, tableRowid);\n\n// Delete some rows\ndb.delete(\n        TABLE_NAME,\n        COLUMN_TITLE + \" = ?\",\n        new String[] {\"demo\"},\n        \"DELETION_TAG\"\n);\n\n// Undoing deletion\ndb.restore(\"DELETION_TAG\");\n```\n\n## Documentation\n```java\npublic static RestorableSQLiteDatabase getInstance(SQLiteDatabase mSQLiteDatabase, HashMap\u003cString, String\u003e tableRowid)\n```\n\nConstructs a new instance of the `RestorableSQLiteDatabase` only if no instance is constructed.\n\n**Parameters**\n- *mSQLiteDatabase* the instance of the `SQLiteDatabase` to be wrapped.\n- *tableRowid* maps the table name to its ROWID column name.\n\n```java\npublic static \u003cT extends SQLiteOpenHelper\u003e RestorableSQLiteDatabase getInstance(T helper, HashMap\u003cString, String\u003e tableRowid)\n```\n\nConstructs a new instance of the `RestorableSQLiteDatabase` only if no instance is constructed.\n\n**Parameters**\n- *helper* the instance of the `SQLiteOpenHelper` to open a database using its [getWritableDatabase](http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getWritableDatabase()) method.\n- *tableRowid* maps the table name to its ROWID column name.\n\n```java\npublic static RestorableSQLiteDatabase getNewInstance(SQLiteDatabase mSQLiteDatabase, HashMap\u003cString, String\u003e tableRowid)\n```\n\nConstructs a new instance of the `RestorableSQLiteDatabase`.\n\n**Parameters**\n- *mSQLiteDatabase* the instance of the `SQLiteDatabase` to be wrapped.\n- *tableRowid* maps the table name to its ROWID column name.\n\n```java\npublic static \u003cT extends SQLiteOpenHelper\u003e RestorableSQLiteDatabase getNewInstance(T helper, HashMap\u003cString, String\u003e tableRowid)\n```\n\nConstructs a new instance of the `RestorableSQLiteDatabase`.\n\n**Parameters**\n- *helper* the instance of the `SQLiteOpenHelper` to open a database using its [getWritableDatabase](http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getWritableDatabase()) method.\n- *tableRowid* maps the table name to its ROWID column name.\n\n```java\npublic void close()\n```\n\nCloses the SQLite database. Use the `reopen` methods to reopen the SQLite database.\n\n```java\npublic boolean containsTag(String tag)\n```\n\nChecks if the hash table contains the tag.\n\n**Parameters**\n- *tag* possible tag of restoring query.\n\n**Returns**\n\nTrue if the hash table contains the tag; false otherwise.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic int delete(String table, String whereClause, String[] whereArgs, String tag)\n```\n\nReplicates the [delete](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#delete(java.lang.String, java.lang.String, java.lang.String[])) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic ArrayList\u003cString\u003e getQueries(String tag)\n```\n\nProvides the query to which the tag is mapped.\n\n**Parameters**\n- *tag* possible tag of restoring query.\n\n**Returns**\n\nThe queries to which the tag is mapped, or null if the hash table contains no mapping for the tag.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic SQLiteDatabase getSQLiteDatabase()\n```\n\nProvides the instance of wrapped `SQLiteDatabase`.\n\n**Returns**\n\nThe instance of wrapped `SQLiteDatabase`.\n\n```java\npublic Hashtable\u003cString, ArrayList\u003cString[]\u003e\u003e getTagQueryParameters()\n```\n\nProvides the parameters hash table.\n\n**Returns**\n\nThe parameters hash table.\n\n```java\npublic Hashtable\u003cString, ArrayList\u003cString\u003e\u003e getTagQueryTable()\n```\n\nProvides the hash table.\n\n**Returns**\n\nThe hash table.\n\n```java\npublic long insert(String table, String nullColumnHack, ContentValues values, String tag)\n```\n\nReplicates the [insert](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert(java.lang.String, java.lang.String, android.content.ContentValues)) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic long insertOrThrow(String table, String nullColumnHack, ContentValues values, String tag) throws SQLException\n```\n\nReplicates the [insertOrThrow](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insertOrThrow(java.lang.String, java.lang.String, android.content.ContentValues)) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm, String tag)\n```\n\nReplicates the [insertWithOnConflict](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insertWithOnConflict(java.lang.String, java.lang.String, android.content.ContentValues, int)) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic Cursor rawQuery(String sql, String[] selectionArgs, String tag) throws JSQLParserException, ClassCastException\n```\n\nReplicates the [rawQuery](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[])) method of the `SQLiteDatabase`.\n\nUnlike the `rawQuery` of the `SQLiteDatabase`, there is no need to call the `moveToFirst` method of the returned `Cursor` to apply SQL query.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic Cursor rawQuery(String sql, String[] selectionArgs, CancellationSignal cancellationSignal, String tag) throws JSQLParserException, ClassCastException\n```\n\nReplicates the [rawQuery](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#rawQuery(java.lang.String, java.lang.String[], android.os.CancellationSignal)) method of the `SQLiteDatabase`.\n\nUnlike the `rawQuery` of the `SQLiteDatabase`, there is no need to call the `moveToFirst` method of the returned `Cursor` to apply SQL query.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic void reopen(SQLiteDatabase mSqLiteDatabase)\n```\n\nReopens the SQLite database.\n\n**Parameters**\n- *mSqLiteDatabase* the instance of the `SQLiteDatabase` to be wrapped.\n\n```java\npublic \u003cT extends SQLiteOpenHelper\u003e void reopen(T helper)\n```\n\nReopens the SQLite database.\n\n**Parameters**\n- *helper* the instance of the `SQLiteOpenHelper` to open a database using its [getWritableDatabase](http://developer.android.com/reference/android/database/sqlite/SQLiteOpenHelper.html#getWritableDatabase()) method.\n\n```java\npublic long replace(String table, String nullColumnHack, ContentValues initialValues, String tag)\n```\n\nReplicates the [replace](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#replace(java.lang.String, java.lang.String, android.content.ContentValues)) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic long replaceOrThrow(String table, String nullColumnHack, ContentValues initialValues, String tag) throws SQLException\n```\n\nReplicates the [replaceOrThrow](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#replaceOrThrow(java.lang.String, java.lang.String, android.content.ContentValues)) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic int restore(String tag)\n```\n\nRestores the SQL queries to which the tag is mapped.\n\n**Parameters**\n- *tag* the tag mapped to restoring queries.\n\n**Returns**\n\nPossible number of restored queries to which tag is mapped.\n\n```java\npublic int restore(String[] tags)\n```\n\nRestores the queries to which each tag is mapped.\n\n**Parameters**\n- *tags* an array of tags mapped to restoring SQL queries.\n\n**Returns**\n\nPossible number of restored queries to which tag is mapped.\n\n```java\npublic int restore(Set\u003cString\u003e tags)\n```\n\nRestores the queries to which each tag is mapped.\n\n**Parameters**\n- *tags* a set of tags mapped to restoring SQL queries.\n\n**Returns**\n\nPossible number of restored queries to which tag is mapped.\n\n```java\npublic int restoreAll()\n```\n\nRestores all restoring SQL queries.\n\n**Returns**\n\nPossible number of restored queries to which tag is mapped.\n\n```java\npublic void setTagQueryParameters(Hashtable\u003cString, ArrayList\u003cString[]\u003e\u003e tagQueryParameters)\n```\n\nChanges the parameters hash table.\n\n**Parameters**\n- *tagQueryParameters* the substitute hash table.\n\n```java\npublic void setTagQueryTable(Hashtable\u003cString, ArrayList\u003cString\u003e\u003e tagQueryTable)\n```\n\nChanges the hash table.\n\n**Parameters**\n- *tagQueryTable* the substitute hash table.\n\n```java\npublic Set\u003cString\u003e tagSet()\n```\n\nProvides a `Set` view of the tags contained in the hash table.\n\n**Returns**\n\na `Set` view of the tags contained in the hash table.\n\n```java\npublic int update(String table, ContentValues values, String whereClause, String[] whereArgs, String tag)\n```\n\nReplicates the [update](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#update(java.lang.String, android.content.ContentValues, java.lang.String, java.lang.String[])) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n```java\npublic int updateWithOnConflict(String table, ContentValues values, String whereClause, String[] whereArgs, int conflictAlgorithm, String tag)\n```\n\nReplicates the [updateWithOnConflict](http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html#updateWithOnConflict(java.lang.String, android.content.ContentValues, java.lang.String, java.lang.String[], int)) method of the `SQLiteDatabase`.\n\n**Parameters**\n- *tag* the tag to be mapped to the restoring query.\n\n**Throws**\n- *IllegalArgumentException* if the tag is null.\n\n## Dependencies\n\n**[JSqlParser](https://github.com/JSQLParser/JSqlParser)** parses an SQL statement and translate it into a hierarchy of Java classes. JSqlParser is licensed under the LGPL V2.1.\n\n## License\nRestorableSQLiteDatabase is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaa110%2FRestorableSQLiteDatabase","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyaa110%2FRestorableSQLiteDatabase","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyaa110%2FRestorableSQLiteDatabase/lists"}