add object_get/set_name/information
Signed-off-by: Folling <mail@folling.io>
This commit is contained in:
parent
b5939bbabd
commit
bf2c971669
2 changed files with 99 additions and 0 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include <cppbase/strings.hpp>
|
||||
|
||||
#include <ikarus/errors.h>
|
||||
#include <ikarus/objects/object.h>
|
||||
|
||||
#include <errors.hpp>
|
||||
|
|
@ -21,6 +24,64 @@ IkarusProject * ikarus_object_get_project(IkarusObject const * object, IkarusErr
|
|||
return object->project;
|
||||
}
|
||||
|
||||
char const * ikarus_object_get_name(IkarusObject const * object, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(object, nullptr);
|
||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, nullptr);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
std::string ret,
|
||||
nullptr,
|
||||
"unable to get object name: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
object->project->db->template query_one<std::string>("SELECT `name` FROM `objects` WHERE `id` = ?", object->id)
|
||||
);
|
||||
|
||||
return strdup(ret.data());
|
||||
}
|
||||
|
||||
void ikarus_object_set_name(IkarusObject * object, char const * name, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(object, );
|
||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
||||
IKARUS_FAIL_IF_NULL(name, );
|
||||
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(name), , "name must not be empty", IkarusErrorInfo_Client_InvalidInput);
|
||||
|
||||
IKARUS_TRYRV_OR_FAIL(
|
||||
,
|
||||
"unable to set object name: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
object->project->db->template execute("UPDATE `objects` SET `name` = ? WHERE `id` = ?", name, object->id)
|
||||
);
|
||||
}
|
||||
|
||||
char const * ikarus_object_get_information(IkarusObject const * object, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(object, nullptr);
|
||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, nullptr);
|
||||
|
||||
IKARUS_VTRYRV_OR_FAIL(
|
||||
std::string ret,
|
||||
nullptr,
|
||||
"unable to get object information: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
object->project->db->template query_one<std::string>("SELECT `information` FROM `objects` WHERE `id` = ?", object->id)
|
||||
);
|
||||
|
||||
return strdup(ret.data());
|
||||
}
|
||||
|
||||
void ikarus_object_set_information(IkarusObject * object, char const * information, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(object, );
|
||||
IKARUS_FAIL_IF_OBJECT_MISSING(object, );
|
||||
IKARUS_FAIL_IF_NULL(information, );
|
||||
IKARUS_FAIL_IF(cppbase::is_empty_or_blank(information), , "information must not be empty", IkarusErrorInfo_Client_InvalidInput);
|
||||
|
||||
IKARUS_TRYRV_OR_FAIL(
|
||||
,
|
||||
"unable to set object information: {}",
|
||||
IkarusErrorInfo_Database_QueryFailed,
|
||||
object->project->db->template execute("UPDATE `objects` SET `information` = ? WHERE `id` = ?", information, object->id)
|
||||
);
|
||||
}
|
||||
|
||||
bool ikarus_object_is_equal(IkarusObject const * lhs, IkarusObject const * rhs, IkarusErrorData * error_out) {
|
||||
IKARUS_FAIL_IF_NULL(lhs, false);
|
||||
IKARUS_FAIL_IF_OBJECT_MISSING(lhs, false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue