[Refdb-cvs] CVS: refdb/src noteshandler.c,1.18.2.9,1.18.2.10
Status: Beta
Brought to you by:
mhoenicka
From: Markus H. <mho...@us...> - 2005-09-21 23:32:32
|
Update of /cvsroot/refdb/refdb/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21147/src Modified Files: Tag: Release_0_9_5_stable noteshandler.c Log Message: renamed set_notesdata_int_field() to set_notesdata_longlong_field(); added set_notesdata_int_field(); added share attribute handling Index: noteshandler.c =================================================================== RCS file: /cvsroot/refdb/refdb/src/noteshandler.c,v retrieving revision 1.18.2.9 retrieving revision 1.18.2.10 diff -u -U2 -r1.18.2.9 -r1.18.2.10 --- noteshandler.c 19 Sep 2005 20:10:29 -0000 1.18.2.9 +++ noteshandler.c 21 Sep 2005 23:32:24 -0000 1.18.2.10 @@ -50,5 +50,6 @@ /* forward declaration of local functions */ static int set_notesdata_field(const char* field, const char* value, dbi_conn conn, unsigned long long n_note_id); -static int set_notesdata_int_field(const char* field, unsigned long long n_value, dbi_conn conn, unsigned long long n_note_id); +static int set_notesdata_int_field(const char* field, int n_value, dbi_conn conn, unsigned long long n_note_id); +static int set_notesdata_longlong_field(const char* field, unsigned long long n_value, dbi_conn conn, unsigned long long n_note_id); @@ -72,4 +73,5 @@ const char* key = NULL; const char* date = NULL; + const char* share = NULL; char* new_msgpool; char sql_command[1024] = ""; @@ -110,4 +112,5 @@ /* reset a few variables relevant to entries */ ptr_andata->create_new = 1; + ptr_andata->share = -1; /* undecided */ *(ptr_andata->date_buffer) = '\0'; *(ptr_andata->content_type) = '\0'; @@ -129,4 +132,7 @@ date = ptr_attr[i+1]; } + else if (!strcmp(ptr_attr[i], "share")) { + share = ptr_attr[i+1]; + } } @@ -145,4 +151,13 @@ } + if (share && *share) { + if (!strcmp(share, "public")) { + ptr_andata->share = 1; + } + else if (!strcmp(share, "private")) { + ptr_andata->share = 0; + } + } + if (date && strlen(date) == 10) { /* try to parse date according to YYYY-MM-DD */ @@ -507,5 +522,14 @@ /* } */ - result = set_notesdata_int_field("user_id", ptr_andata->n_user_id, ptr_andata->conn, ptr_andata->n_note_id); + result = set_notesdata_longlong_field("user_id", ptr_andata->n_user_id, ptr_andata->conn, ptr_andata->n_note_id); + + if (result == 1) { + LOG_PRINT(LOG_WARNING, "out of memory"); + } + else if (result == 2) { + LOG_PRINT(LOG_WARNING, "insert into t_note failed"); + } + + result = set_notesdata_int_field("share", ptr_andata->share, ptr_andata->conn, ptr_andata->n_note_id); if (result == 1) { @@ -1362,4 +1386,52 @@ const char *field ptr to a string containing the field name + int n_value the field value + + dbi_conn conn connection to database server + + unsigned long long n_note_id id value of note + + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ +static int set_notesdata_int_field(const char* field, int n_value, dbi_conn conn, unsigned long long n_note_id) { + char* sql_command; + char* new_sql_command; + char buffer[256]; /* buffer for assembling strings */ + size_t sql_cmd_len = 128; + dbi_result dbires; + + if (!field || !*field) { + /* nothing to do */ + return 0; + } + + if ((sql_command = malloc(sql_cmd_len)) == NULL) { + LOG_PRINT(LOG_WARNING, "malloc failed"); + return 1; + } + + /* assemble query */ + sprintf(sql_command, "UPDATE t_note SET note_%s=%d WHERE note_id="ULLSPEC, field, n_value, (unsigned long long)n_note_id); + + LOG_PRINT(LOG_DEBUG, sql_command); + + dbires = dbi_conn_query(conn, sql_command); + free(sql_command); + + if (!dbires) { + return 2; + } + dbi_result_free(dbires); + + return 0; +} + +/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + set_notesdata_longlong_field(): sets a longlong value in t_notes + + static int set_notesdata_longlong_field returns 0 if ok, 1 if out of memory, + 2 if query error + + const char *field ptr to a string containing the field name + unsigned long long n_value the field value @@ -1369,5 +1441,5 @@ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ -static int set_notesdata_int_field(const char* field, unsigned long long n_value, dbi_conn conn, unsigned long long n_note_id) { +static int set_notesdata_longlong_field(const char* field, unsigned long long n_value, dbi_conn conn, unsigned long long n_note_id) { char* sql_command; char* new_sql_command; |