mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-30 17:59:21 +00:00
Only alter sip_uri column in update + close/reopen connection needed after schema update + do it in transaction just in case...
This commit is contained in:
parent
5b19181748
commit
d843d27890
1 changed files with 13 additions and 15 deletions
|
|
@ -1199,27 +1199,20 @@ static void linphone_create_table(sqlite3* db) {
|
|||
}
|
||||
}
|
||||
|
||||
static void linphone_update_table(sqlite3* db) {
|
||||
static bool_t linphone_update_table(sqlite3* db) {
|
||||
char *errmsg = NULL;
|
||||
int ret = sqlite3_exec(db,
|
||||
"BEGIN TRANSACTION;\n"
|
||||
"PRAGMA writable_schema = 1;\n"
|
||||
"UPDATE SQLITE_MASTER SET SQL = 'CREATE TABLE friends ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"friend_list_id INTEGER,"
|
||||
"sip_uri TEXT,"
|
||||
"subscribe_policy INTEGER,"
|
||||
"send_subscribe INTEGER,"
|
||||
"ref_key TEXT,"
|
||||
"vCard TEXT,"
|
||||
"vCard_etag TEXT,"
|
||||
"vCard_url TEXT,"
|
||||
"presence_received INTEGER"
|
||||
")' WHERE NAME = 'friends';\n"
|
||||
"PRAGMA writable_schema = 0;", 0, 0, &errmsg);
|
||||
"UPDATE SQLITE_MASTER SET SQL = replace(SQL, 'sip_uri TEXT NOT NULL', 'sip_uri TEXT NULL') WHERE NAME = 'friends';\n"
|
||||
"PRAGMA writable_schema = 0;\n"
|
||||
"COMMIT;", 0, 0, &errmsg);
|
||||
if (ret != SQLITE_OK) {
|
||||
ms_error("Error altering table friends: %s.\n", errmsg);
|
||||
sqlite3_free(errmsg);
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void linphone_core_friends_storage_init(LinphoneCore *lc) {
|
||||
|
|
@ -1239,7 +1232,12 @@ void linphone_core_friends_storage_init(LinphoneCore *lc) {
|
|||
}
|
||||
|
||||
linphone_create_table(db);
|
||||
linphone_update_table(db);
|
||||
if (linphone_update_table(db)) {
|
||||
// After updating schema, database need to be closed/reopenned
|
||||
sqlite3_close(lc->friends_db);
|
||||
_linphone_sqlite3_open(lc->friends_db_file, &db);
|
||||
}
|
||||
|
||||
lc->friends_db = db;
|
||||
|
||||
friends_lists = linphone_core_fetch_friends_lists_from_db(lc);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue