char *resolve_electorate_name(PGconn *conn, unsigned int electorate_code) { return(SQL_singleton(conn, "SELECT name FROM electorate WHERE code = %u;", electorate_code)); }
char *resolve_polling_place_name(PGconn *conn, unsigned int polling_place_code) { return(SQL_singleton(conn, "SELECT name FROM polling_place WHERE code = %u;", polling_place_code)); }
struct rotation *fetch_rotation(PGconn *conn, unsigned int rotation_num, unsigned int seat_count) { struct rotation *rot; char *rotstring; /* Get the rotation */ rotstring = SQL_singleton(conn, "SELECT rotation " "FROM robson_rotation_%u " "WHERE rotation_num = %u;", seat_count, rotation_num); if (rotstring == NULL) return NULL; rot = malloc(sizeof(*rot)); rot->size = seat_count; /* rotation is in the form {n,n,n,n,n} */ if ( seat_count == 5 ) { /* 5 seat electorate */ sscanf(rotstring, "{%u,%u,%u,%u,%u}", &rot->rotations[0], &rot->rotations[1], &rot->rotations[2], &rot->rotations[3], &rot->rotations[4]); } else { /* Assume 7 seat electorate */ sscanf(rotstring, "{%u,%u,%u,%u,%u,%u,%u}", &rot->rotations[0], &rot->rotations[1], &rot->rotations[2], &rot->rotations[3], &rot->rotations[4], &rot->rotations[5], &rot->rotations[6]); } free(rotstring); return rot; }