Commit 36c471ce authored by Giovanne Marcelo's avatar Giovanne Marcelo

add alias functions to increase coupling

parent 891f2674
......@@ -11,11 +11,16 @@
#include <jansson.h>
#include <stdlib.h>
typedef PGresult DBresult;
PGconn* db_connect();
PGresult* db_select(char *columns, char *table, char *where);
PGresult* db_find_by_id(int id, char *table);
char* db_get_value(DBresult *result, int row, int column);
int db_count_colums(DBresult *result);
int db_count(DBresult *result);
DBresult* db_select(char *columns, char *table, char *where);
DBresult* db_find_by_id(int id, char *table);
void db_disconnect(PGconn *conn);
void read_conf(const char *path, char * conninfo);
#endif
......@@ -60,11 +60,11 @@ PGconn* db_connect() {
return conn;
}
PGresult* db_select( char *columns, char *table, char *where) {
DBresult* db_select( char *columns, char *table, char *where) {
PGconn *conn = db_connect();
char query[QUERY_LEN];
PGresult *result;
DBresult *result;
// Build query
strcpy(query, "SELECT ");
......@@ -92,12 +92,24 @@ PGresult* db_select( char *columns, char *table, char *where) {
return result;
}
PGresult* db_find_by_id(int id, char *table) {
DBresult* db_find_by_id(int id, char *table) {
char query[QUERY_LEN];
sprintf(query,"id=%d", id);
return db_select("*", table, query);
}
int db_count(DBresult *result) {
return PQntuples(result);
}
int db_count_colums(DBresult *result) {
return PQnfields(result);
}
char* db_get_value(DBresult *result, int row, int column) {
return PQgetvalue(result, row, column);
}
void db_disconnect(PGconn *conn) {
PQfinish(conn);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment