Android: Updating user database using SQLiteAssetHelper

It seems I don’t understand how to update the database after reading the documents at https://github.com/jgilfelt/android-sqlite-asset-helper

I want to save user data in only one table. I do not need to change tables. The update pretty much adds new rows to another table.

So the thread (I assume):

onUpgrade:
1) get ArrayList from user data from table 1
2) update the database
3) return user data to table 1

I think this is all wrong?
Any advice would be greatly appreciated.

+4
source share
4

script.
, . script, .

, , . sql script.

, .

:

-- add a FullNames column to Employees
ALTER TABLE "Employees" RENAME TO 'Employees_ME_TMP';

CREATE TABLE "Employees" 
(
    "EmployeeID" int NOT NULL,
    "LastName" varchar(20) NOT NULL,
    "FirstName" varchar(10) NOT NULL,
    "FullName" varchar(150),
    PRIMARY KEY ("EmployeeID")
);

INSERT INTO "Employees"  
(
    "EmployeeID", 
    "LastName", 
    "FirstName", 
    "FullName"
) 
SELECT 
    "EmployeeID", 
    "LastName", 
    "FirstName", 
    "FirstName" || ' ' || "LastName" 
FROM 
    "Employees_ME_TMP";

DROP TABLE "Employees_ME_TMP";
+2

. . .

, onUpdate.

0

There is an easier way that I found. After updating the database in the main / assets / databases folder with Firefox SQLite Manager, simply delete the previous database before creating the database in code , then send the database to the application again. To send: click ,
To delete:

this.deleteDatabase("<yourdatabasename>");

For instance:

this.deleteDatabase("db.db");
0
source
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
0
source

Source: https://habr.com/ru/post/1530384/


All Articles