[Refdb-cvs] CVS: refdb/src risdb.c,1.44.2.11,1.44.2.12 risdb.h,1.11.2.3,1.11.2.4
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2005-11-02 22:38:09
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1479 Modified Files: Tag: Release_0_9_5_stable risdb.c risdb.h Log Message: new function remove_user_entries() Index: risdb.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/risdb.c,v retrieving revision 1.44.2.11 retrieving revision 1.44.2.12 diff -u -U2 -r1.44.2.11 -r1.44.2.12 --- risdb.c 18 Sep 2005 22:51:25 -0000 1.44.2.11 +++ risdb.c 2 Nov 2005 22:37:52 -0000 1.44.2.12 @@ -3445,4 +3445,69 @@ /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + remove_user_entries(): removes the user entry associated with + a particular dataset if it is an orphan + + int remove_user_entries returns 0 if ok, > 0 if error + error codes: 1 = select from t_user failed + 2 = select from t_note failed + 3 = delete from t_user failed + 4 = not an orphan + + unsigned long long user_id id of the user to be deleted + + dbi_conn conn the database connection + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +int remove_user_entries(unsigned long long user_id, dbi_conn conn) { + char sql_command[256]; + unsigned long long numrows; + + dbi_result dbires; + + /* select all xuser and note entries of the given user; if there are + none, the user is an orphan and can safely be deleted */ + sprintf(sql_command, "SELECT xuser_id FROM t_xuser WHERE user_id="ULLSPEC, (unsigned long long)user_id); + + LOG_PRINT(LOG_DEBUG, sql_command); + dbires = dbi_conn_query(conn, sql_command); + if (!dbires) { + LOG_PRINT(LOG_WARNING, "select from t_xuser failed"); + return 1; + } + + numrows = dbi_result_get_numrows(dbires); + + dbi_result_free(dbires); + + sprintf(sql_command, "SELECT note_id FROM t_note WHERE note_user_id="ULLSPEC, (unsigned long long)user_id); + + LOG_PRINT(LOG_DEBUG, sql_command); + dbires = dbi_conn_query(conn, sql_command); + if (!dbires) { + LOG_PRINT(LOG_WARNING, "select from t_note failed"); + return 2; + } + + numrows += dbi_result_get_numrows(dbires); + + dbi_result_free(dbires); + + if (!numrows) { + /* no other note or reference belong to this user */ + /* delete entry in t_user table */ + sprintf(sql_command, "DELETE FROM t_user WHERE user_id="ULLSPEC, (unsigned long long)user_id); + LOG_PRINT(LOG_DEBUG, sql_command); + dbires = dbi_conn_query(conn, sql_command); + if (!dbires) { + return 3; + } + dbi_result_free(dbires); + return 0; + } + + return 4; +} + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ remove_xuser_entries(): removes the xuser entry associated with a particular dataset and a particular user Index: risdb.h =================================================================== RCS file: /cvsroot/refdb/refdb/src/risdb.h,v retrieving revision 1.11.2.3 retrieving revision 1.11.2.4 diff -u -U2 -r1.11.2.3 -r1.11.2.4 --- risdb.h 7 Sep 2005 23:45:03 -0000 1.11.2.3 +++ risdb.h 2 Nov 2005 22:37:52 -0000 1.11.2.4 @@ -37,4 +37,5 @@ int remove_xnote_entries(unsigned long long xref_id, dbi_conn conn, int mode); int remove_periodical_entries(unsigned long long periodical_id, dbi_conn conn); +int remove_user_entries(unsigned long long user_id, dbi_conn conn); int remove_xuser_entries(unsigned long long ref_id, char* set_owner, dbi_conn conn); int remove_ulink_entries(unsigned long long ref_id, dbi_conn conn, int mode); |