bool bdb_get_used_base_jobids(JCR *jcr, POOLMEM *jobids, db_list_ctx *result);
bool bdb_get_restoreobject_record(JCR *jcr, ROBJECT_DBR *rr);
bool bdb_get_plugin_object_record(JCR *jcr, OBJECT_DBR *obj_r);
+ bool bdb_get_plugin_objects_ids(JCR *jcr, OBJECT_DBR *obj_r, db_list_ctx *ids);
int bdb_get_num_restoreobject_records(JCR *jcr, ROBJECT_DBR *rr);
bool bdb_get_job_statistics(JCR *jcr, JOB_DBR *jr);
bool bdb_get_client_pool(JCR *jcr, alist *results);
ObjectSize = str_to_uint64(p);
}
-
+void OBJECT_DBR::create_db_filter(JCR *jcr, POOLMEM **where)
+{
+ POOL_MEM esc(PM_MESSAGE), tmp(PM_MESSAGE);
+
+ if (ObjectId > 0) {
+ Mmsg(tmp, " Object.ObjectId=%lu", ObjectId);
+ append_filter(*where, tmp.c_str());
+ } else {
+ if (JobId != 0) {
+ Mmsg(tmp, " Object.JobId=%lu", JobId);
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (Path[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), Path, strlen(Path));
+ Mmsg(tmp, " Object.Path='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (Filename[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), Filename, strlen(Filename));
+ Mmsg(tmp, " Object.Filename='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (PluginName[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), PluginName, strlen(PluginName));
+ Mmsg(tmp, " Object.PluginName='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (ObjectCategory[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), ObjectCategory, strlen(ObjectCategory));
+ Mmsg(tmp, " Object.ObjectCategory='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (ObjectType[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), ObjectType, strlen(ObjectType));
+ Mmsg(tmp, " Object.ObjectType='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (ObjectName[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), ObjectName, strlen(ObjectName));
+ Mmsg(tmp, " Object.Objectname='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (ObjectSource[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), ObjectSource, strlen(ObjectSource));
+ Mmsg(tmp, " Object.ObjectSource='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (ObjectUUID[0] != 0) {
+ db_escape_string(jcr, jcr->db, esc.c_str(), ObjectUUID, strlen(ObjectUUID));
+ Mmsg(tmp, " Object.ObjectUUID='%s'", esc.c_str());
+ append_filter(*where, tmp.c_str());
+ }
+
+ if (ObjectSize > 0) {
+ Mmsg(tmp, " Object.ObjectSize=%llu", ObjectSize);
+ append_filter(*where, tmp.c_str());
+ }
+ }
+
+}
+
void parse_restore_object_string(char **r_obj_str, ROBJECT_DBR *robj_r)
{
char *p = *r_obj_str;
};
/* Parse OBJECT record from stream */
void parse_plugin_object_string(char **obj_str);
+ /* Helper for creating the 'where' part of jcr's related sql query based on fields from the Object */
+ void create_db_filter(JCR *jcr, POOLMEM **where);
DBId_t ObjectId;
JobId_t JobId;
mdb->bdb_get_restoreobject_record(jcr, rr)
#define db_get_plugin_object_record(jcr, mdb, obj_r) \
mdb->bdb_get_plugin_object_record(jcr, obj_r)
+#define db_get_plugin_objects_ids(jcr, mdb, obj_r, ids) \
+ mdb->bdb_get_plugin_objects_ids(jcr, obj_r, ids)
#define db_get_num_restoreobject_records(jcr, mdb, rr) \
mdb->bdb_get_num_restoreobject_records(jcr, rr)
#define db_get_type_index(mdb) \
}
/*
- * Get specified Plugin Object by ObjectId
+ * Get list of Object Ids from search based by provided Object fields
* */
-bool BDB::bdb_get_plugin_object_record(JCR *jcr, OBJECT_DBR *obj_r)
+bool BDB::bdb_get_plugin_objects_ids(JCR *jcr, OBJECT_DBR *obj_r, db_list_ctx *ids)
{
- SQL_ROW row;
- POOL_MEM esc(PM_MESSAGE), tmp(PM_MESSAGE), where(PM_MESSAGE);
+ POOL_MEM where(PM_MESSAGE);
int stat = false;
- if (obj_r->ObjectId > 0) {
- Mmsg(tmp, " Object.ObjectId=%lu", obj_r->ObjectId);
- append_filter(where.addr(), tmp.c_str());
- } else {
- if (obj_r->JobId != 0) {
- Mmsg(tmp, " Object.JobId=%lu", obj_r->JobId);
- append_filter(where.addr(), tmp.c_str());
- }
-
- if (obj_r->Path[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->Path, strlen(obj_r->Path));
- Mmsg(tmp, " Object.Path='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
-
- if (obj_r->Filename[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->Filename, strlen(obj_r->Filename));
- Mmsg(tmp, " Object.Filename='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
+ obj_r->create_db_filter(jcr, where.handle());
- if (obj_r->PluginName[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->PluginName, strlen(obj_r->PluginName));
- Mmsg(tmp, " Object.PluginName='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
+ Mmsg(cmd, "SELECT ObjectId FROM Object %s ORDER BY ObjectId ASC", where.c_str());
- if (obj_r->ObjectCategory[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->ObjectCategory, strlen(obj_r->ObjectCategory));
- Mmsg(tmp, " Object.ObjectCategory='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
+ ids->reset();
- if (obj_r->ObjectType[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->ObjectType, strlen(obj_r->ObjectType));
- Mmsg(tmp, " Object.ObjectType='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
+ bdb_lock();
+ if(!bdb_sql_query(cmd, db_list_handler, ids)) {
+ Jmsg(jcr, M_ERROR, 0, _("Getting plugin object ids query %s failed!\n"), cmd);
+ goto bail_out;
+ }
- if (obj_r->ObjectName[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->ObjectName, strlen(obj_r->ObjectName));
- Mmsg(tmp, " Object.Objectname='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
+ stat = true;
- if (obj_r->ObjectSource[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->ObjectSource, strlen(obj_r->ObjectSource));
- Mmsg(tmp, " Object.ObjectSource='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
+bail_out:
+ bdb_unlock();
+ return stat;
+}
- if (obj_r->ObjectUUID[0] != 0) {
- bdb_escape_string(jcr, esc.c_str(), obj_r->ObjectUUID, strlen(obj_r->ObjectUUID));
- Mmsg(tmp, " Object.ObjectUUID='%s'", esc.c_str());
- append_filter(where.addr(), tmp.c_str());
- }
+/*
+ * Get specified Plugin Object by ObjectId
+ * */
+bool BDB::bdb_get_plugin_object_record(JCR *jcr, OBJECT_DBR *obj_r)
+{
+ SQL_ROW row;
+ POOL_MEM where(PM_MESSAGE);
+ int stat = false;
- if (obj_r->ObjectSize > 0) {
- Mmsg(tmp, " Object.ObjectSize=%llu", obj_r->ObjectSize);
- append_filter(where.addr(), tmp.c_str());
- }
- }
+ obj_r->create_db_filter(jcr, where.handle());
Mmsg(cmd,
"SELECT ObjectId, JobId, Path, Filename, PluginName, ObjectCategory, "