diff --git a/src/db_query.c b/src/db_query.c index b7b2f32..a26903a 100644 --- a/src/db_query.c +++ b/src/db_query.c @@ -284,7 +284,7 @@ int64_t countQuery(struct stored_conn_t *sconn, const char *table, where_builder strbld_str(sb, "SELECT COUNT(*) AS `C` FROM `", 0); strbld_str(sb, table, 0); strbld_str(sb, "` WHERE ", 0); - compileWhereBuilder_sb(wb, sb, 0); + compileWhereBuilder_sb(wb, sb, 1); if (strbld_finalize_or_destroy(&sb, &qry, &qry_len) != 0) { return -1; } @@ -308,7 +308,7 @@ int deleteQuery(struct stored_conn_t *sconn, const char *table, where_builder *w strbld_str(sb, "DELETE FROM `", 0); strbld_str(sb, table, 0); strbld_str(sb, "` WHERE ", 0); - compileWhereBuilder_sb(wb, sb, 0); + compileWhereBuilder_sb(wb, sb, 1); if (strbld_finalize_or_destroy(&sb, &qry, &qry_len) != 0) { return -1; } @@ -330,15 +330,15 @@ int syncIdMap(struct stored_conn_t *sconn, const char *table, unsigned int primary_id, size_t n_maps, unsigned int *map_ids) { str_builder *sb; - where_builder *wb; char *qry; size_t qry_len; int qry_ret; size_t idx; - wb = where(0, primary_col, EQ, TYPE_ID, 1, primary_id); - qry_ret = deleteQuery(sconn, table, wb); - freeWhereBuilder(&wb); + qry_ret = deleteQuery( + sconn, table, + where(0, primary_col, EQ, TYPE_ID, 1, primary_id) + ); if (qry_ret != 1) { return qry_ret; @@ -405,14 +405,14 @@ int hasIdMap(struct stored_conn_t *sconn, const char *table, unsigned int primary_id, unsigned int map_id) { int64_t qry_ret; - where_builder *wb; - wb = whereAnd( - where(table, primary_col, EQ, TYPE_ID, 1, primary_id), - where(table, map_col, EQ, TYPE_ID, 1, map_id) + qry_ret = countQuery( + sconn, table, + whereAnd( + where(table, primary_col, EQ, TYPE_ID, 1, primary_id), + where(table, map_col, EQ, TYPE_ID, 1, map_id) + ) ); - qry_ret = countQuery(sconn, table, wb); - freeWhereBuilder(&wb); return qry_ret > 0; } @@ -462,14 +462,14 @@ int removeIdMap(struct stored_conn_t *sconn, const char *table, unsigned int primary_id, unsigned int map_id) { int qry_ret; - where_builder *wb; - wb = whereAnd( - where(0, primary_col, EQ, TYPE_ID, 1, primary_id), - where(0, map_col, EQ, TYPE_ID, 1, map_id) + qry_ret = deleteQuery( + sconn, table, + whereAnd( + where(0, primary_col, EQ, TYPE_ID, 1, primary_id), + where(0, map_col, EQ, TYPE_ID, 1, map_id) + ) ); - qry_ret = deleteQuery(sconn, table, wb); - freeWhereBuilder(&wb); return qry_ret; } diff --git a/src/db_query.h b/src/db_query.h index 88dbaee..bcaf904 100644 --- a/src/db_query.h +++ b/src/db_query.h @@ -29,7 +29,7 @@ char *scalarString(struct stored_conn_t *sconn, const char *qry, size_t qry_len, // Where query methods int64_t countQuery(struct stored_conn_t *sconn, const char *table, where_builder *wb); -uint64_t deleteQuery(struct stored_conn_t *sconn, const char *table, where_builder *wb); +int deleteQuery(struct stored_conn_t *sconn, const char *table, where_builder *wb); // Map helpers