libinvdb/source/category.cc

49 lines
1.0 KiB
C++

#include "category.hh"
#include "session.hh"
#include <stdexcept>
#include <vector>
#include <algorithm>
#include <zdb.h>
// refer to libzdb docs
#include <Exception.h>
namespace inventory {
namespace datamodel {
const char *Category::sc_table = "categories";
Category Category::from_query(ResultSet_T r) {
Category ret;
TRY {
ret.id = ResultSet_getIntByName(r, "id");
ret.parent = ResultSet_getIntByName(r, "parent");
const char *pname = ResultSet_getStringByName(r, "name");
if (pname != NULL)
ret.name = pname;
const char *pdescription = ResultSet_getStringByName(r, "description");
if (pdescription != NULL)
ret.description = pdescription;
int symbol_size;
// returns void* by default, and std::copy needs type size info
const char *psymbol =
(const char *)(ResultSet_getBlobByName(r, "symbol", &symbol_size));
if (psymbol != NULL) {
ret.symbol.resize(symbol_size);
std::copy(psymbol, psymbol + symbol_size, std::back_inserter(ret.symbol));
}
} CATCH(SQLException) {
}
END_TRY;
return ret;
}
}
}