add: device relay get one
fix: stuff
This commit is contained in:
parent
ac61c26d56
commit
a399050892
7 changed files with 64 additions and 9 deletions
|
@ -187,6 +187,14 @@ device_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func
|
|||
return device_db_select(stmt);
|
||||
}
|
||||
|
||||
device_dbo**
|
||||
device_dbo::get_by(helpers::sql_filter_builder **filters)
|
||||
{
|
||||
sqlite3_stmt *stmt = helpers::create_sql_filtered_query("SELECT * FROM devices WHERE", filters);
|
||||
|
||||
return device_db_select(stmt);
|
||||
}
|
||||
|
||||
void
|
||||
device_dbo::free_list(device_dbo **devices_list)
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <json/value.h>
|
||||
#include <helpers.h>
|
||||
|
||||
class device_dbo
|
||||
{
|
||||
|
@ -34,6 +35,9 @@ public:
|
|||
static device_dbo**
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func);
|
||||
|
||||
static device_dbo**
|
||||
get_by(helpers::sql_filter_builder **filters);
|
||||
|
||||
static device_dbo**
|
||||
get_all();
|
||||
};
|
||||
|
|
|
@ -47,7 +47,7 @@ relay_db_select_mapper(sqlite3_stmt *stmt)
|
|||
new_relay->id = sqlite3_column_int(stmt, i);
|
||||
break;
|
||||
case 'n':
|
||||
switch(name[0])
|
||||
switch(name[1])
|
||||
{
|
||||
case 'a': // name
|
||||
strncpy(new_relay->name, (const char*)sqlite3_column_text(stmt, i), 127);
|
||||
|
@ -93,9 +93,8 @@ relay_db_select(sqlite3_stmt *stmt)
|
|||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR << "Error Selecting relays from database";
|
||||
sqlite3_finalize(stmt);
|
||||
return nullptr;
|
||||
LOG_ERROR << "Error Selecting relays from database: " << sqlite3_errstr(s);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -145,8 +144,11 @@ Json::Value
|
|||
relay_dbo::to_json()
|
||||
{
|
||||
Json::Value relay_json;
|
||||
// relay_json["id"] = this->id;
|
||||
relay_json["name"] = this->name;
|
||||
relay_json["id"] = this->id;
|
||||
relay_json["number"] = this->number;
|
||||
relay_json["active_schedule_id"] = this->active_schedule_id;
|
||||
relay_json["device_id"] = this->device_id;
|
||||
|
||||
return relay_json;
|
||||
}
|
||||
|
@ -178,6 +180,13 @@ relay_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_func)
|
|||
return relay_db_select(stmt);
|
||||
}
|
||||
|
||||
relay_dbo**
|
||||
relay_dbo::get_by(helpers::sql_filter_builder **filters)
|
||||
{
|
||||
sqlite3_stmt *stmt = helpers::create_sql_filtered_query("SELECT * FROM relays WHERE", filters);
|
||||
return relay_db_select(stmt);
|
||||
}
|
||||
|
||||
void
|
||||
relay_dbo::free_list(relay_dbo **relays_list)
|
||||
{
|
||||
|
@ -187,4 +196,3 @@ relay_dbo::free_list(relay_dbo **relays_list)
|
|||
}
|
||||
free(relays_list);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <json/value.h>
|
||||
#include <helpers.h>
|
||||
|
||||
class relay_dbo
|
||||
{
|
||||
|
@ -33,6 +34,9 @@ public:
|
|||
static relay_dbo**
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func);
|
||||
|
||||
static relay_dbo**
|
||||
get_by(helpers::sql_filter_builder **filters);
|
||||
|
||||
static relay_dbo**
|
||||
get_all();
|
||||
};
|
||||
|
|
|
@ -177,6 +177,15 @@ schedule_dbo::get_by_simple(const char *key, const void *value, intptr_t bind_fu
|
|||
";"
|
||||
};
|
||||
filters[0] = &filter;
|
||||
|
||||
sqlite3_stmt *stmt = helpers::create_sql_filtered_query("SELECT * FROM schedules WHERE", filters);
|
||||
|
||||
return schedule_db_select(stmt);
|
||||
}
|
||||
|
||||
schedule_dbo**
|
||||
schedule_dbo::get_by(helpers::sql_filter_builder **filters)
|
||||
{
|
||||
sqlite3_stmt *stmt = helpers::create_sql_filtered_query("SELECT * FROM schedules WHERE", filters);
|
||||
|
||||
return schedule_db_select(stmt);
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <string>
|
||||
#include <sqlite3.h>
|
||||
#include <json/value.h>
|
||||
#include <helpers.h>
|
||||
#include "period.h"
|
||||
#include "period_list.h"
|
||||
|
||||
|
@ -35,6 +36,9 @@ public:
|
|||
static schedule_dbo**
|
||||
get_by_simple(const char *key, const void *value, intptr_t bind_func);
|
||||
|
||||
static schedule_dbo**
|
||||
get_by(helpers::sql_filter_builder **filters);
|
||||
|
||||
static schedule_dbo**
|
||||
get_all();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue