src/cats/sql_delete.c
static int do_media_purge(BDB *mdb, MEDIA_DBR *mr)
{
   POOLMEM *query = get_pool_memory(PM_MESSAGE);
   struct s_del_ctx del;
   char ed1[50];
   int i;

   del.num_ids = 0;
   del.tot_ids = 0;
   del.num_del = 0;
   del.max_ids = 0;
   Mmsg(mdb->cmd, "SELECT JobId from JobMedia WHERE MediaId=%lu", mr->MediaId);
   del.max_ids = mr->VolJobs;
   if (del.max_ids < 100) {
      del.max_ids = 100;
   } else if (del.max_ids > MAX_DEL_LIST_LEN) {
      del.max_ids = MAX_DEL_LIST_LEN;
   }
   del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids);
   mdb->bdb_sql_query(mdb->cmd, delete_handler, (void *)&del);

   for (i=0; i < del.num_ids; i++) {
      Dmsg1(400, "Delete JobId=%d\n", del.JobId[i]);
      Mmsg(query, "DELETE FROM Job WHERE JobId=%s", edit_int64(del.JobId[i], ed1));
      mdb->bdb_sql_query(query, NULL, (void *)NULL);
      Mmsg(query, "DELETE FROM File WHERE JobId=%s", edit_int64(del.JobId[i], ed1));
      mdb->bdb_sql_query(query, NULL, (void *)NULL);
      Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", edit_int64(del.JobId[i], ed1));
      mdb->bdb_sql_query(query, NULL, (void *)NULL);
   }
   free(del.JobId);
   free_pool_memory(query);
   return 1;
}
/*
 * This routine will purge (delete) all records
 * associated with a particular Volume. It will
 * not delete the media record itself.
 * TODO: This function is broken and it doesn't purge
 *       File, BaseFiles, Log, ...
 *       We call it from relabel and delete volume=, both ensure
 *       that the volume is properly purged.
 */
This routine will purge (delete) all records
associated with a particular Volume. It will
not delete the media record itself.
TODO: This function is broken and it doesn't purge
File, BaseFiles, Log,
We call it from relabel and delete volume=, both ensure
that the volume is properly purged.
This routine will purge ( delete ) all records associated with a particular Volume . It will not delete the media record itself . TODO : This function is broken and it doesn ' t purge File BaseFiles Log We call it from relabel and delete volume = both ensure that the volume is properly purged .
static int do_media_purge(BDB *mdb, MEDIA_DBR *mr)
{
   POOLMEM *query = get_pool_memory(PM_MESSAGE);
   struct s_del_ctx del;
   char ed1[50];
   int i;
   del.num_ids = 0;
   del.tot_ids = 0;
   del.num_del = 0;
   del.max_ids = 0;
   Mmsg(mdb->cmd, "SELECT JobId from JobMedia WHERE MediaId=%lu", mr->MediaId);
   del.max_ids = mr->VolJobs;
   if (del.max_ids < 100) {
      del.max_ids = 100;
   } else if (del.max_ids > MAX_DEL_LIST_LEN) {
      del.max_ids = MAX_DEL_LIST_LEN;
   }
   del.JobId = (JobId_t *)malloc(sizeof(JobId_t) * del.max_ids);
   mdb->bdb_sql_query(mdb->cmd, delete_handler, (void *)&del);
   for (i=0; i < del.num_ids; i++) {
      Dmsg1(400, "Delete JobId=%d\n", del.JobId[i]);
      Mmsg(query, "DELETE FROM Job WHERE JobId=%s", edit_int64(del.JobId[i], ed1));
      mdb->bdb_sql_query(query, NULL, (void *)NULL);
      Mmsg(query, "DELETE FROM File WHERE JobId=%s", edit_int64(del.JobId[i], ed1));
      mdb->bdb_sql_query(query, NULL, (void *)NULL);
      Mmsg(query, "DELETE FROM JobMedia WHERE JobId=%s", edit_int64(del.JobId[i], ed1));
      mdb->bdb_sql_query(query, NULL, (void *)NULL);
   }
   free(del.JobId);
   free_pool_memory(query);
   return 1;
}
static int do_media_purge ( BDB * mdb , MEDIA_DBR * mr ) { POOLMEM * query = get_pool_memory ( PM_MESSAGE ) ; struct s_del_ctx del ; char ed1 [ 50 ] ; int i ; del . num_ids = 0 ; del . tot_ids = 0 ; del . num_del = 0 ; del . max_ids = 0 ; Mmsg ( mdb -> cmd , " " , mr -> MediaId ) ; del . max_ids = mr -> VolJobs ; if ( del . max_ids < 100 ) { del . max_ids = 100 ; } else if ( del . max_ids > MAX_DEL_LIST_LEN ) { del . max_ids = MAX_DEL_LIST_LEN ; } del . JobId = ( JobId_t * ) malloc ( sizeof ( JobId_t ) * del . max_ids ) ; mdb -> bdb_sql_query ( mdb -> cmd , delete_handler , ( void * ) & del ) ; for ( i = 0 ; i < del . num_ids ; i ++ ) { Dmsg1 ( 400 , " \n " , del . JobId [ i ] ) ; Mmsg ( query , " " , edit_int64 ( del . JobId [ i ] , ed1 ) ) ; mdb -> bdb_sql_query ( query , NULL , ( void * ) NULL ) ; Mmsg ( query , " " , edit_int64 ( del . JobId [ i ] , ed1 ) ) ; mdb -> bdb_sql_query ( query , NULL , ( void * ) NULL ) ; Mmsg ( query , " " , edit_int64 ( del . JobId [ i ] , ed1 ) ) ; mdb -> bdb_sql_query ( query , NULL , ( void * ) NULL ) ; } free ( del . JobId ) ; free_pool_memory ( query ) ; return 1 ; }
This routine will purge (delete) all records
 associated with a particular Volume.
This routine will purge ( delete ) all records associated with a particular Volume .