add: foreign key support in database
add: more tests fix: bad tag handling when finding 0 in column
This commit is contained in:
parent
7f3182ee96
commit
1475f605aa
14 changed files with 214 additions and 276 deletions
models
|
@ -15,8 +15,24 @@ junction_tag_insert(int tag_id, int relay_id, int schedule_id)
|
|||
sqlite3_prepare_v2(global_database, "INSERT INTO junction_tag(tag_id, schedule_id, relay_id) values (?1, ?2, ?3);", -1, &stmt, NULL);
|
||||
|
||||
sqlite3_bind_int(stmt, 1, tag_id);
|
||||
sqlite3_bind_int(stmt, 2, schedule_id);
|
||||
sqlite3_bind_int(stmt, 3, relay_id);
|
||||
|
||||
if(schedule_id)
|
||||
{
|
||||
sqlite3_bind_int(stmt, 2, schedule_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlite3_bind_null(stmt, 2);
|
||||
}
|
||||
|
||||
if(relay_id)
|
||||
{
|
||||
sqlite3_bind_int(stmt, 3, relay_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
sqlite3_bind_null(stmt, 3);
|
||||
}
|
||||
|
||||
rc = sqlite3_step(stmt);
|
||||
if (rc != SQLITE_DONE)
|
||||
|
@ -46,10 +62,13 @@ get_ids(sqlite3_stmt *stmt)
|
|||
if (s == SQLITE_ROW)
|
||||
{
|
||||
new_id = sqlite3_column_int(stmt, 0);
|
||||
row++;
|
||||
if(new_id != 0) // found row for other target (relay <> schedule)
|
||||
{
|
||||
row++;
|
||||
|
||||
ids = (int*)realloc(ids, sizeof(int) * (row + 1));
|
||||
ids[row - 1] = new_id;
|
||||
ids = (int*)realloc(ids, sizeof(int) * (row + 1));
|
||||
ids[row - 1] = new_id;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -236,7 +236,7 @@ relay_to_json(relay_t *relay)
|
|||
controller_t *controller = controller_get_by_id(relay->controller_id);
|
||||
if(!controller)
|
||||
{
|
||||
LOG_DEBUG("failed to get controller\n");
|
||||
LOG_WARN("failed to get controller\n");
|
||||
cJSON_Delete(json);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue