// The current RDB store version is 3, and the table structure is EMPLOYEE (NAME, AGE, SALARY, CODES).
constSQL_CREATE_TABLE='CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)';// SQL statement for creating a data table.
@@ -73,7 +74,28 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
return;
}
console.info(`Succeeded in getting RdbStore.`);
// When the RDB store is created, the default version is 0.
if(store.version==0){
store.executeSql(SQL_CREATE_TABLE);// Create a data table.
// Set the RDB store version, which must be an integer greater than 0.
store.version=3;
}
// If the RDB store version is not 0 and does not match the current version, upgrade or downgrade the RDB store.
// For example, upgrade the RDB store from version 1 to version 2.
if(store.version!=3&&store.version==1){
// Upgrade the RDB store from version 1 to version 2, and change the table structure from EMPLOYEE (NAME, SALARY, CODES, ADDRESS) to EMPLOYEE (NAME, AGE, SALARY, CODES, ADDRESS).
store.executeSql("ALTER TABLE EMPLOYEE ADD COLUMN AGE INTEGER",null);
store.version=2;
}
// For example, upgrade the RDB store from version 2 to version 3.
if(store.version!=3&&store.version==2){
// Upgrade the RDB store from version 2 to version 3, and change the table structure from EMPLOYEE (NAME, AGE, SALARY, CODES, ADDRESS) to EMPLOYEE (NAME, AGE, SALARY, CODES).
store.executeSql("ALTER TABLE EMPLOYEE DROP COLUMN ADDRESS TEXT",null);
store.version=3;
}
// Perform operations such as adding, deleting, modifying, and querying data in the RDB store.
...
...
@@ -97,6 +119,7 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
// The RDB store version is 3, and the table structure is EMPLOYEE (NAME, AGE, SALARY, CODES).
constSQL_CREATE_TABLE='CREATE TABLE IF NOT EXISTS EMPLOYEE (ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL, AGE INTEGER, SALARY REAL, CODES BLOB)';// SQL statement for creating a data table.
@@ -105,7 +128,28 @@ The following table lists the APIs used for RDB data persistence. Most of the AP
return;
}
console.info(`Succeeded in getting RdbStore.`);
// When the RDB store is created, the default version is 0.
if(store.version==0){
store.executeSql(SQL_CREATE_TABLE);// Create a data table.
// Set the RDB store version, which must be an integer greater than 0.
store.version=3;
}
// If the RDB store version is not 0 and does not match the current version, upgrade or downgrade the RDB store.
// For example, upgrade the RDB store from version 1 to version 2.
if(store.version!=3&&store.version==1){
// Upgrade the RDB store from version 1 to version 2, and change the table structure from EMPLOYEE (NAME, SALARY, CODES, ADDRESS) to EMPLOYEE (NAME, AGE, SALARY, CODES, ADDRESS).
store.executeSql("ALTER TABLE EMPLOYEE ADD COLUMN AGE INTEGER",null);
store.version=2;
}
// For example, upgrade the RDB store from version 2 to version 3.
if(store.version!=3&&store.version==2){
// Upgrade the RDB store from version 2 to version 3, and change the table structure from EMPLOYEE (NAME, AGE, SALARY, CODES, ADDRESS) to EMPLOYEE (NAME, AGE, SALARY, CODES).
store.executeSql("ALTER TABLE EMPLOYEE DROP COLUMN ADDRESS TEXT",null);
store.version=3;
}
// Perform operations such as adding, deleting, modifying, and querying data in the RDB store.
...
...
@@ -185,13 +229,22 @@ The following table lists the APIs used for RDB data persistence. Most of the AP