add: basic macro functions
add: better migration handling (transactions)
This commit is contained in:
parent
7275d66c86
commit
f67b7e9e0f
7 changed files with 122 additions and 36 deletions
src/models
33
src/models/junction_macro.c
Normal file
33
src/models/junction_macro.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <models/junction_macro.h>
|
||||
#include <logger.h>
|
||||
#include <macros.h>
|
||||
#include <database.h>
|
||||
|
||||
int
|
||||
junction_macro_insert(int macro_id, int relay_id, int schedule_id, uint8_t weekday)
|
||||
{
|
||||
int rc;
|
||||
sqlite3_stmt *stmt;
|
||||
|
||||
sqlite3_prepare_v2(global_database, "INSERT INTO junction_macro(macro_id, schedule_id, relay_id, weekday) values (?1, ?2, ?3);", -1, &stmt, NULL);
|
||||
|
||||
sqlite3_bind_int(stmt, 1, macro_id);
|
||||
sqlite3_bind_int(stmt, 2, relay_id);
|
||||
sqlite3_bind_int(stmt, 3, schedule_id);
|
||||
sqlite3_bind_int(stmt, 4, weekday);
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE)
|
||||
{
|
||||
LOGGER_ERR("error inserting data: %s", sqlite3_errmsg(global_database));
|
||||
return 1;
|
||||
}
|
||||
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue