char middle[USERS_MIDDLE_SIZE], last[USERS_LAST_SIZE];
char fullname[USERS_FIRST_SIZE + USERS_MIDDLE_SIZE + USERS_LAST_SIZE];
char class[USERS_TYPE_SIZE], pin[USERS_PIN_SIZE];
- int uid, status, secure, sqlstatus;
+ int uid, status, secure, sqlstatus, count;
EXEC SQL END DECLARE SECTION;
if (rc->uid || argc != 4)
ulast = argv[2];
id = argv[3];
+ EXEC SQL SELECT count(login) INTO :count FROM users WHERE clearid = :id;
+
/* "ORDER BY status" so that if there's both a matching state 0 entry
and a matching state 3 entry, we'll get the former. */
EXEC SQL DECLARE csr_id CURSOR FOR
strtrim(class);
strtrim(pin);
+ /* It's possible they have both a deleted account and a status 8
+ * account. We can't compensate for that in the ORDER BY clause
+ * above, so check here. If they have more than one entry and the
+ * first one we get is deleted, skip it.
+ */
+ if (status == US_DELETED && count > 1)
+ continue;
+
/* Check names, allowing for the possibility that Moira and the
user might have them split up differently. eg, Mary/Ann/Singleton
vs. Mary Ann/Singleton. */
return;
}
- /* "ORDER BY status" so that if there's both a matching state 0 entry
- and a matching state 3 entry, we'll get the former. */
EXEC SQL SELECT pin INTO :pin FROM users WHERE clearid = :rc->id
- ORDER BY status;
+ AND status = :rc->user_status;
strtrim(pin);
if (strcmp(argv[0], pin) != 0)
{