src/pEpEngine.c
changeset 2505 1102a11afe18
parent 2504 99b930afc2a0
child 2506 876532219d20
     1.1 --- a/src/pEpEngine.c	Wed Feb 14 16:02:08 2018 +0100
     1.2 +++ b/src/pEpEngine.c	Wed Feb 14 18:49:09 2018 +0100
     1.3 @@ -93,7 +93,8 @@
     1.4      "               when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1)"
     1.5      "               else 0"
     1.6      "          end) = 1"
     1.7 -    "   and identity.user_id = ?2;";
     1.8 +    "   and identity.user_id = ?2" 
     1.9 +    "   order by is_own desc; ";
    1.10  
    1.11  static const char *sql_get_identity_without_trust_check =  
    1.12      "select identity.main_key_id, username, lang,"
    1.13 @@ -105,7 +106,8 @@
    1.14      "               when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1)"
    1.15      "               else 0"
    1.16      "          end) = 1"
    1.17 -    "   and identity.user_id = ?2;";
    1.18 +    "   and identity.user_id = ?2 "
    1.19 +    "   order by is_own desc; ";
    1.20  
    1.21  static const char *sql_get_identities_by_address =  
    1.22      "select user_id, identity.main_key_id, username, lang,"
    1.23 @@ -116,7 +118,8 @@
    1.24      "               when (lower(address) = lower(?1)) then (1)"
    1.25      "               when (replace(lower(address),'.','') = replace(lower(?1),'.','')) then (1)"
    1.26      "               else 0"
    1.27 -    "          end) = 1;";
    1.28 +    "          end) = 1 "
    1.29 +    "   order by is_own desc; ";
    1.30  
    1.31  static const char *sql_replace_identities_fpr =  
    1.32      "update identity"
    1.33 @@ -131,12 +134,8 @@
    1.34  // if main_key_id already set, don't touch.
    1.35  static const char *sql_set_person = 
    1.36       "insert into person (id, username, lang, main_key_id, device_group)"
    1.37 -     "  values (?1, ?2, ?3,"
    1.38 -//     "    (select coalesce( "
    1.39 -//     "          (select main_key_id from person where id = ?1), " 
    1.40 -//     "           upper(replace(?4,' ','')))),"
    1.41 -    "   ?4,"
    1.42 -     "    (select device_group from person where id = ?1)) ;";
    1.43 +     "  values (?1, ?2, ?3, ?4, "
    1.44 +     "          (select device_group from person where id = ?1)) ;";
    1.45  
    1.46  static const char *sql_update_person = 
    1.47      "update person "