Browse Source

ENGINE-878: identity username column now added and initial retrieval sql put in there (But wait! There's more! Just not in this commit, and you don't get the GINSU Steak Knife set)

ENGINE-878
Krista Bennett 1 year ago
parent
commit
3eea3b233a
3 changed files with 57 additions and 16 deletions
  1. +3
    -0
      .gitignore
  2. +47
    -9
      src/engine_sql.c
  3. +7
    -7
      src/engine_sql.h

+ 3
- 0
.gitignore View File

@ -143,3 +143,6 @@ sync/.statemachines
sync/.copy
*.ignore
# This is temporary, to deal with shifts between ENGINE-633 and other branches
test/test_mails/default_keys_test_*.eml

+ 47
- 9
src/engine_sql.c View File

@ -703,6 +703,7 @@ static PEP_STATUS _create_core_tables(PEP_SESSION session) {
" main_key_id text\n"
" references pgp_keypair (fpr)\n"
" on delete set null,\n"
" username text,\n"
" comment text,\n"
" flags integer default 0,\n"
" is_own integer default 0,\n"
@ -928,33 +929,48 @@ PEP_STATUS get_db_user_version(PEP_SESSION session, int* version) {
return PEP_STATUS_OK;
}
// Only called if input version is 1
static PEP_STATUS _verify_version(PEP_SESSION session, int* version) {
// Sometimes the user_version wasn't set correctly.
bool version_changed = true;
int int_result;
if (table_contains_column(session, "groups", "group_identity")) {
if (table_contains_column(session, "identity", "username")) {
*version = 17;
}
else if (table_contains_column(session, "trust", "sticky")) {
*version = 16;
}
else if (table_contains_column(session, "groups", "group_identity")) {
*version = 15;
}
else if (table_contains_column(session, "identity", "enc_format")) {
*version = 14;
} else if (table_contains_column(session, "revocation_contact_list", "own_address")) {
}
else if (table_contains_column(session, "revocation_contact_list", "own_address")) {
*version = 13;
} else if (table_contains_column(session, "identity", "pEp_version_major")) {
}
else if (table_contains_column(session, "identity", "pEp_version_major")) {
*version = 12;
} else if (db_contains_table(session, "social_graph") > 0) {
}
else if (db_contains_table(session, "social_graph") > 0) {
if (!table_contains_column(session, "person", "device_group"))
*version = 10;
else
*version = 9;
} else if (table_contains_column(session, "identity", "timestamp") > 0) {
}
else if (table_contains_column(session, "identity", "timestamp") > 0) {
*version = 8;
} else if (table_contains_column(session, "person", "is_pEp_user") > 0) {
}
else if (table_contains_column(session, "person", "is_pEp_user") > 0) {
*version = 7;
} else if (table_contains_column(session, "identity", "is_own") > 0) {
}
else if (table_contains_column(session, "identity", "is_own") > 0) {
*version = 6;
} else if (table_contains_column(session, "pgp_keypair", "flags") > 0) {
}
else if (table_contains_column(session, "pgp_keypair", "flags") > 0) {
*version = 2;
} else {
}
else {
version_changed = false;
}
@ -1484,6 +1500,24 @@ static PEP_STATUS _upgrade_DB_to_ver_16(PEP_SESSION session) {
return PEP_STATUS_OK;
}
static PEP_STATUS _upgrade_DB_to_ver_17(PEP_SESSION session) {
int int_result = sqlite3_exec(
session->db,
"alter table identity\n"
" add column username;\n",
NULL,
NULL,
NULL
);
assert(int_result == SQLITE_OK);
if (int_result != SQLITE_OK)
return PEP_UNKNOWN_DB_ERROR;
return PEP_STATUS_OK;
}
static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version) {
PEP_STATUS status = PEP_STATUS_OK;
@ -1547,6 +1581,10 @@ static PEP_STATUS _check_and_execute_upgrades(PEP_SESSION session, int version)
if (status != PEP_STATUS_OK)
return status;
case 16:
status = _upgrade_DB_to_ver_17(session);
if (status != PEP_STATUS_OK)
return status;
case 17:
break;
default:
return PEP_ILLEGAL_VALUE;


+ 7
- 7
src/engine_sql.h View File

@ -3,7 +3,7 @@
#include "pEp_internal.h"
// increment this when patching DDL
#define _DDL_USER_VERSION "16"
#define _DDL_USER_VERSION "17"
PEP_STATUS init_databases(PEP_SESSION session);
PEP_STATUS pEp_sql_init(PEP_SESSION session);
@ -25,7 +25,7 @@ static const char *sql_trustword =
// Also: we've never used pgp_keypair.flags before now, but it seems to me that
// having combination of those flags is a road to ruin. Changing this for now.
static const char *sql_get_identity =
"select identity.main_key_id, username, comm_type, lang,"
"select identity.main_key_id, ifnull(identity.username, person.username), comm_type, lang,"
" identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
@ -44,7 +44,7 @@ static const char *sql_get_identity =
" timestamp desc; ";
static const char *sql_get_identities_by_main_key_id =
"select address, identity.user_id, username, comm_type, lang,"
"select address, identity.user_id, ifnull(identity.username, person.username), comm_type, lang,"
" identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
@ -58,7 +58,7 @@ static const char *sql_get_identities_by_main_key_id =
" timestamp desc; ";
static const char *sql_get_identity_without_trust_check =
"select identity.main_key_id, username, lang,"
"select identity.main_key_id, ifnull(identity.username, person.username), lang,"
" identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
@ -72,7 +72,7 @@ static const char *sql_get_identity_without_trust_check =
" timestamp desc; ";
static const char *sql_get_identities_by_address =
"select user_id, identity.main_key_id, username, lang,"
"select user_id, identity.main_key_id, ifnull(identity.username, person.username), lang,"
" identity.flags, is_own, pEp_version_major, pEp_version_minor, enc_format"
" from identity"
" join person on id = identity.user_id"
@ -85,7 +85,7 @@ static const char *sql_get_identities_by_address =
" timestamp desc; ";
static const char *sql_get_identities_by_userid =
"select address, identity.main_key_id, username, comm_type, lang,"
"select address, identity.main_key_id, ifnull(identity.username, person.username), comm_type, lang,"
" identity.flags,"
// " identity.flags | pgp_keypair.flags,"
" is_own, pEp_version_major, pEp_version_minor, enc_format"
@ -407,7 +407,7 @@ static const char *sql_is_own_address =
");";
static const char *sql_own_identities_retrieve =
"select address, identity.main_key_id, identity.user_id, username,"
"select address, identity.main_key_id, identity.user_id, ifnull(identity.username, person.username),"
" lang,"
" identity.flags,"
// " identity.flags | pgp_keypair.flags,"


Loading…
Cancel
Save