On Freitag 12 Dezember 2008 Paul J Stevens wrote:
> And as always: patches are most welcome.

I'm not a coder, but I tried figuring out what to do. In 
do_purge_deleted() you just write the text and call db_deleted_purge. I 
quote the function below with my questions.

int db_deleted_purge(u64_t * affected_rows)
{
   unsigned i;
   char query[DEF_QUERYSIZE];
   memset(query,0,DEF_QUERYSIZE);

   u64_t *message_idnrs;

## what does assert do?
   assert(affected_rows != NULL);
   *affected_rows = 0;

## the comment speaks about delete of messageblks, but we do a select 
##from dbmail_messages???
   /* first we're deleting all the messageblks */
   snprintf(query, DEF_QUERYSIZE,
       "SELECT message_idnr FROM %smessages WHERE status=%d",DBPFX,
       MESSAGE_STATUS_PURGE);
   TRACE(TRACE_DEBUG, "executing query [%s]", query);

   if (db_query(query) == -1) {
## There's a typo "Cound" instead "Could"
      TRACE(TRACE_ERROR, "Cound not fetch message ID numbers");
      return DM_EQUERY;
   }

   *affected_rows = db_num_rows();
   if (*affected_rows == 0) {
      TRACE(TRACE_DEBUG, "no messages to purge");
      db_free_result();
      return DM_SUCCESS;
   }

   message_idnrs = g_new0(u64_t, *affected_rows);

## you write about delete here. But db_get_result_u64 doesn't delete,
## right? What does it do?
   /* delete each message */
   for (i = 0; i < *affected_rows; i++)
      message_idnrs[i] = db_get_result_u64(i, 0);


## what is db_free_result for?
   db_free_result();

## here finally the real delete happens, one at a time
   for (i = 0; i < *affected_rows; i++) {
      if (db_delete_message(message_idnrs[i]) == -1) {
         TRACE(TRACE_ERROR, "error deleting message");
         g_free(message_idnrs);
         return DM_EQUERY;
      }
   }
   g_free(message_idnrs);

   return DM_EGENERAL;
}


Couldn't we reduce the function to
int db_deleted_purge(u64_t * affected_rows)
{
   unsigned i;
   char query[DEF_QUERYSIZE];
   memset(query,0,DEF_QUERYSIZE);

   snprintf(query, DEF_QUERYSIZE,
       "DELETE FROM %smessages WHERE status=%d",DBPFX,
       MESSAGE_STATUS_PURGE);
   TRACE(TRACE_DEBUG, "executing query [%s]", query);

   if (db_query(query) == -1) {
      TRACE(TRACE_ERROR, "Could not delete messages");
      return DM_EQUERY;
   }
## this or something similar to get the number of deleted rows
## I don't know what function exists
   *affected_rows=query_num_deleted_records();
   return DM_EGENERAL;
}

mfg zmi
-- 
// Michael Monnerie, Ing.BSc    -----      http://it-management.at
// Tel: 0660 / 415 65 31                      .network.your.ideas.
// PGP Key:         "curl -s http://zmi.at/zmi.asc | gpg --import"
// Fingerprint: AC19 F9D5 36ED CD8A EF38  500E CE14 91F7 1C12 09B4
// Keyserver: www.keyserver.net                   Key-ID: 1C1209B4

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
DBmail mailing list
[email protected]
https://mailman.fastxs.nl/mailman/listinfo/dbmail

Reply via email to