+void BDB::bdb_list_snapshot_records(JCR *jcr, SNAPSHOT_DBR *sdbr,
+ DB_LIST_HANDLER *sendit, void *ctx, e_list_type type)
+{
+ POOLMEM *filter = get_pool_memory(PM_MESSAGE);
+ POOLMEM *tmp = get_pool_memory(PM_MESSAGE);
+ POOLMEM *esc = get_pool_memory(PM_MESSAGE);
+ char ed1[50];
+
+ bdb_lock();
+ *filter = 0;
+
+ if (sdbr->Name[0]) {
+ bdb_escape_string(jcr, esc, sdbr->Name, strlen(sdbr->Name));
+ Mmsg(tmp, "Name='%s'", esc);
+ append_filter(filter, tmp);
+ }
+ if (sdbr->SnapshotId > 0) {
+ Mmsg(tmp, "Snapshot.SnapshotId=%d", sdbr->SnapshotId);
+ append_filter(filter, tmp);
+ }
+ if (sdbr->ClientId > 0) {
+ Mmsg(tmp, "Snapshot.ClientId=%d", sdbr->ClientId);
+ append_filter(filter, tmp);
+ }
+ if (sdbr->JobId > 0) {
+ Mmsg(tmp, "Snapshot.JobId=%d", sdbr->JobId);
+ append_filter(filter, tmp);
+ }
+ if (*sdbr->Client) {
+ bdb_escape_string(jcr, esc, sdbr->Client, strlen(sdbr->Client));
+ Mmsg(tmp, "Client.Name='%s'", esc);
+ append_filter(filter, tmp);
+ }
+ if (sdbr->Device && *(sdbr->Device)) {
+ esc = check_pool_memory_size(esc, strlen(sdbr->Device) * 2 + 1);
+ bdb_escape_string(jcr, esc, sdbr->Device, strlen(sdbr->Device));
+ Mmsg(tmp, "Device='%s'", esc);
+ append_filter(filter, tmp);
+ }
+ if (*sdbr->Type) {
+ bdb_escape_string(jcr, esc, sdbr->Type, strlen(sdbr->Type));
+ Mmsg(tmp, "Type='%s'", esc);
+ append_filter(filter, tmp);
+ }
+ if (*sdbr->created_before) {
+ bdb_escape_string(jcr, esc, sdbr->created_before, strlen(sdbr->created_before));
+ Mmsg(tmp, "CreateDate <= '%s'", esc);
+ append_filter(filter, tmp);
+ }
+ if (*sdbr->created_after) {
+ bdb_escape_string(jcr, esc, sdbr->created_after, strlen(sdbr->created_after));
+ Mmsg(tmp, "CreateDate >= '%s'", esc);
+ append_filter(filter, tmp);
+ }
+ if (sdbr->expired) {
+ Mmsg(tmp, "CreateTDate < (%s - Retention)", edit_int64(time(NULL), ed1));
+ append_filter(filter, tmp);
+ }
+ if (*sdbr->CreateDate) {
+ bdb_escape_string(jcr, esc, sdbr->CreateDate, strlen(sdbr->CreateDate));
+ Mmsg(tmp, "CreateDate = '%s'", esc);
+ append_filter(filter, tmp);
+ }
+
+ if (sdbr->sorted_client) {
+ pm_strcat(filter, " ORDER BY Client.Name, SnapshotId DESC");
+
+ } else {
+ pm_strcat(filter, " ORDER BY SnapshotId DESC");
+ }
+
+ if (type == VERT_LIST || type == ARG_LIST) {
+ Mmsg(cmd, "SELECT SnapshotId, Snapshot.Name, CreateDate, Client.Name AS Client, "
+ "FileSet.FileSet AS FileSet, JobId, Volume, Device, Type, Retention, Comment "
+ "FROM Snapshot JOIN Client USING (ClientId) LEFT JOIN FileSet USING (FileSetId) %s", filter);
+
+ } else if (type == HORZ_LIST) {
+ Mmsg(cmd, "SELECT SnapshotId, Snapshot.Name, CreateDate, Client.Name AS Client, "
+ "Device, Type "
+ "FROM Snapshot JOIN Client USING (ClientId) %s", filter);
+ }
+
+ if (!QueryDB(jcr, cmd)) {
+ goto bail_out;
+ }
+
+ list_result(jcr, this, sendit, ctx, type);
+
+bail_out:
+ sql_free_result();
+ bdb_unlock();
+
+ free_pool_memory(filter);
+ free_pool_memory(esc);
+ free_pool_memory(tmp);
+}