liquid_feedback_core

annotate lf_update_suggestion_order.c @ 370:794974af6d6d

Bugfix in "lf_update_suggestion_order" related to floating point error workaround
author jbe
date Sun Mar 17 16:15:28 2013 +0100 (2013-03-17)
parents cad83f274b79
children 8344753f2ac1
rev   line source
jbe@352 1 #include <stdlib.h>
jbe@352 2 #include <stdio.h>
jbe@352 3 #include <string.h>
jbe@352 4 #include <libpq-fe.h>
jbe@352 5 #include <search.h>
jbe@352 6
jbe@352 7 static char *escapeLiteral(PGconn *conn, const char *str, size_t len) {
jbe@352 8 // provides compatibility for PostgreSQL versions prior 9.0
jbe@352 9 // in future: return PQescapeLiteral(conn, str, len);
jbe@352 10 char *res;
jbe@352 11 size_t res_len;
jbe@352 12 res = malloc(2*len+3);
jbe@358 13 if (!res) return NULL;
jbe@352 14 res[0] = '\'';
jbe@352 15 res_len = PQescapeStringConn(conn, res+1, str, len, NULL);
jbe@352 16 res[res_len+1] = '\'';
jbe@352 17 res[res_len+2] = 0;
jbe@352 18 return res;
jbe@352 19 }
jbe@352 20
jbe@352 21 static void freemem(void *ptr) {
jbe@352 22 // to be used for "escapeLiteral" function
jbe@352 23 // provides compatibility for PostgreSQL versions prior 9.0
jbe@352 24 // in future: PQfreemem(ptr);
jbe@352 25 free(ptr);
jbe@352 26 }
jbe@352 27
jbe@352 28 #define COL_MEMBER_ID 0
jbe@352 29 #define COL_WEIGHT 1
jbe@352 30 #define COL_PREFERENCE 2
jbe@352 31 #define COL_SUGGESTION_ID 3
jbe@352 32
jbe@353 33 struct candidate {
jbe@353 34 char *key;
jbe@356 35 double score_per_step;
jbe@353 36 double score;
jbe@353 37 int seat;
jbe@353 38 };
jbe@353 39
jbe@369 40 static int compare_id(char *id1, char *id2) {
jbe@369 41 int ldiff;
jbe@369 42 ldiff = strlen(id1) - strlen(id2);
jbe@369 43 if (ldiff) return ldiff;
jbe@369 44 else return strcmp(id1, id2);
jbe@369 45 }
jbe@369 46
jbe@353 47 static int compare_candidate(struct candidate *c1, struct candidate *c2) {
jbe@369 48 return compare_id(c1->key, c2->key);
jbe@353 49 }
jbe@352 50
jbe@353 51 static int candidate_count;
jbe@353 52 static struct candidate *candidates;
jbe@353 53
jbe@353 54 static void register_candidate(char **candidate_key, VISIT visit, int level) {
jbe@352 55 if (visit == postorder || visit == leaf) {
jbe@353 56 struct candidate *candidate;
jbe@353 57 candidate = candidates + (candidate_count++);
jbe@353 58 candidate->key = *candidate_key;
jbe@353 59 candidate->seat = 0;
jbe@352 60 }
jbe@352 61 }
jbe@352 62
jbe@353 63 static struct candidate *candidate_by_key(char *candidate_key) {
jbe@353 64 struct candidate *candidate;
jbe@353 65 struct candidate compare;
jbe@353 66 compare.key = candidate_key;
jbe@353 67 candidate = bsearch(&compare, candidates, candidate_count, sizeof(struct candidate), (void *)compare_candidate);
jbe@353 68 if (!candidate) {
jbe@356 69 fprintf(stderr, "Candidate not found (should not happen).\n");
jbe@352 70 abort();
jbe@352 71 }
jbe@353 72 return candidate;
jbe@352 73 }
jbe@352 74
jbe@352 75 struct ballot_section {
jbe@352 76 int count;
jbe@353 77 struct candidate **candidates;
jbe@352 78 };
jbe@352 79
jbe@352 80 struct ballot {
jbe@352 81 int weight;
jbe@352 82 struct ballot_section sections[4];
jbe@352 83 };
jbe@352 84
jbe@356 85 static struct candidate *loser(int round_number, struct ballot *ballots, int ballot_count) {
jbe@356 86 int i, j, k;
jbe@356 87 int remaining;
jbe@356 88 for (i=0; i<candidate_count; i++) {
jbe@356 89 candidates[i].score = 0.0;
jbe@356 90 }
jbe@356 91 remaining = candidate_count - round_number;
jbe@356 92 while (1) {
jbe@356 93 double scale;
jbe@356 94 if (remaining <= 1) break;
jbe@356 95 for (i=0; i<candidate_count; i++) {
jbe@356 96 candidates[i].score_per_step = 0.0;
jbe@356 97 }
jbe@356 98 for (i=0; i<ballot_count; i++) {
jbe@356 99 for (j=0; j<4; j++) {
jbe@356 100 int matches = 0;
jbe@356 101 for (k=0; k<ballots[i].sections[j].count; k++) {
jbe@356 102 struct candidate *candidate;
jbe@356 103 candidate = ballots[i].sections[j].candidates[k];
jbe@356 104 if (candidate->score < 1.0 && !candidate->seat) matches++;
jbe@356 105 }
jbe@356 106 if (matches) {
jbe@356 107 double score_inc;
jbe@368 108 score_inc = (double)ballots[i].weight / (double)matches;
jbe@356 109 for (k=0; k<ballots[i].sections[j].count; k++) {
jbe@356 110 struct candidate *candidate;
jbe@356 111 candidate = ballots[i].sections[j].candidates[k];
jbe@356 112 if (candidate->score < 1.0 && !candidate->seat) {
jbe@356 113 candidate->score_per_step += score_inc;
jbe@356 114 }
jbe@356 115 }
jbe@356 116 break;
jbe@356 117 }
jbe@356 118 }
jbe@356 119 }
jbe@368 120 scale = (double)0.0;
jbe@356 121 for (i=0; i<candidate_count; i++) {
jbe@356 122 double max_scale;
jbe@356 123 if (candidates[i].score_per_step > 0.0) {
jbe@356 124 max_scale = (1.0-candidates[i].score) / candidates[i].score_per_step;
jbe@368 125 if (scale == 0.0 || max_scale <= scale) {
jbe@356 126 scale = max_scale;
jbe@356 127 }
jbe@356 128 }
jbe@356 129 }
jbe@356 130 for (i=0; i<candidate_count; i++) {
jbe@356 131 if (candidates[i].score_per_step > 0.0) {
jbe@370 132 double max_scale;
jbe@370 133 max_scale = (1.0-candidates[i].score) / candidates[i].score_per_step;
jbe@370 134 if (max_scale == scale) {
jbe@356 135 candidates[i].score = 1.0;
jbe@356 136 remaining--;
jbe@356 137 } else {
jbe@356 138 candidates[i].score += scale * candidates[i].score_per_step;
jbe@356 139 if (candidates[i].score >= 1.0) remaining--;
jbe@356 140 }
jbe@356 141 if (remaining <= 1) break;
jbe@356 142 }
jbe@356 143 }
jbe@356 144 }
jbe@356 145 for (i=candidate_count-1; i>=0; i--) {
jbe@356 146 if (candidates[i].score < 1.0 && !candidates[i].seat) return candidates+i;
jbe@356 147 }
jbe@356 148 fprintf(stderr, "No remaining candidate (should not happen).");
jbe@356 149 abort();
jbe@356 150 }
jbe@356 151
jbe@359 152 static int write_ranks(PGconn *db, char *escaped_initiative_id, int final) {
jbe@358 153 PGresult *res;
jbe@358 154 char *cmd;
jbe@358 155 int i;
jbe@359 156 if (final) {
jbe@359 157 if (asprintf(&cmd, "BEGIN; UPDATE \"initiative\" SET \"final_suggestion_order_calculated\" = TRUE WHERE \"id\" = %s; UPDATE \"suggestion\" SET \"proportional_order\" = NULL WHERE \"initiative_id\" = %s", escaped_initiative_id, escaped_initiative_id) < 0) {
jbe@359 158 fprintf(stderr, "Could not prepare query string in memory.\n");
jbe@359 159 abort();
jbe@359 160 }
jbe@359 161 } else {
jbe@359 162 if (asprintf(&cmd, "BEGIN; UPDATE \"suggestion\" SET \"proportional_order\" = NULL WHERE \"initiative_id\" = %s", escaped_initiative_id) < 0) {
jbe@359 163 fprintf(stderr, "Could not prepare query string in memory.\n");
jbe@359 164 abort();
jbe@359 165 }
jbe@358 166 }
jbe@358 167 res = PQexec(db, cmd);
jbe@358 168 free(cmd);
jbe@358 169 if (!res) {
jbe@358 170 fprintf(stderr, "Error in pqlib while sending SQL command to initiate suggestion update.\n");
jbe@358 171 return 1;
jbe@358 172 } else if (
jbe@358 173 PQresultStatus(res) != PGRES_COMMAND_OK &&
jbe@358 174 PQresultStatus(res) != PGRES_TUPLES_OK
jbe@358 175 ) {
jbe@358 176 fprintf(stderr, "Error while executing SQL command to initiate suggestion update:\n%s", PQresultErrorMessage(res));
jbe@358 177 PQclear(res);
jbe@358 178 return 1;
jbe@358 179 } else {
jbe@358 180 PQclear(res);
jbe@358 181 }
jbe@358 182 for (i=0; i<candidate_count; i++) {
jbe@358 183 char *escaped_suggestion_id;
jbe@358 184 escaped_suggestion_id = escapeLiteral(db, candidates[i].key, strlen(candidates[i].key));
jbe@358 185 if (!escaped_suggestion_id) {
jbe@358 186 fprintf(stderr, "Could not escape literal in memory.\n");
jbe@358 187 abort();
jbe@358 188 }
jbe@358 189 if (asprintf(&cmd, "UPDATE \"suggestion\" SET \"proportional_order\" = %i WHERE \"id\" = %s", candidates[i].seat, escaped_suggestion_id) < 0) {
jbe@358 190 fprintf(stderr, "Could not prepare query string in memory.\n");
jbe@358 191 abort();
jbe@358 192 }
jbe@358 193 freemem(escaped_suggestion_id);
jbe@358 194 res = PQexec(db, cmd);
jbe@358 195 free(cmd);
jbe@358 196 if (!res) {
jbe@358 197 fprintf(stderr, "Error in pqlib while sending SQL command to update suggestion order.\n");
jbe@358 198 } else if (
jbe@358 199 PQresultStatus(res) != PGRES_COMMAND_OK &&
jbe@358 200 PQresultStatus(res) != PGRES_TUPLES_OK
jbe@358 201 ) {
jbe@358 202 fprintf(stderr, "Error while executing SQL command to update suggestion order:\n%s", PQresultErrorMessage(res));
jbe@358 203 PQclear(res);
jbe@358 204 } else {
jbe@358 205 PQclear(res);
jbe@358 206 continue;
jbe@358 207 }
jbe@358 208 res = PQexec(db, "ROLLBACK");
jbe@358 209 if (res) PQclear(res);
jbe@358 210 return 1;
jbe@358 211 }
jbe@358 212 res = PQexec(db, "COMMIT");
jbe@358 213 if (!res) {
jbe@358 214 fprintf(stderr, "Error in pqlib while sending SQL command to commit transaction.\n");
jbe@358 215 return 1;
jbe@358 216 } else if (
jbe@358 217 PQresultStatus(res) != PGRES_COMMAND_OK &&
jbe@358 218 PQresultStatus(res) != PGRES_TUPLES_OK
jbe@358 219 ) {
jbe@358 220 fprintf(stderr, "Error while executing SQL command to commit transaction:\n%s", PQresultErrorMessage(res));
jbe@358 221 PQclear(res);
jbe@358 222 return 1;
jbe@358 223 } else {
jbe@358 224 PQclear(res);
jbe@358 225 return 0;
jbe@358 226 }
jbe@358 227 }
jbe@358 228
jbe@359 229 static int process_initiative(PGconn *db, PGresult *res, char *escaped_initiative_id, int final) {
jbe@358 230 int err;
jbe@366 231 int ballot_count = 1;
jbe@356 232 struct ballot *ballots;
jbe@355 233 int i;
jbe@355 234 {
jbe@355 235 void *candidate_tree = NULL;
jbe@355 236 int tuple_count;
jbe@355 237 char *old_member_id = NULL;
jbe@355 238 struct ballot *ballot;
jbe@355 239 int candidates_in_sections[4] = {0, };
jbe@367 240 candidate_count = 0;
jbe@359 241 tuple_count = PQntuples(res);
jbe@359 242 if (!tuple_count) {
jbe@359 243 if (final) {
jbe@359 244 printf("No suggestions found, but marking initiative as finally calculated.\n");
jbe@359 245 err = write_ranks(db, escaped_initiative_id, final);
jbe@359 246 printf("Done.\n");
jbe@359 247 return err;
jbe@359 248 } else {
jbe@359 249 printf("Nothing to do.\n");
jbe@359 250 return 0;
jbe@359 251 }
jbe@359 252 }
jbe@366 253 for (i=0; i<tuple_count; i++) {
jbe@355 254 char *member_id, *suggestion_id;
jbe@366 255 member_id = PQgetvalue(res, i, COL_MEMBER_ID);
jbe@366 256 suggestion_id = PQgetvalue(res, i, COL_SUGGESTION_ID);
jbe@369 257 if (!candidate_tree || !tfind(suggestion_id, &candidate_tree, (void *)compare_id)) {
jbe@366 258 candidate_count++;
jbe@369 259 if (!tsearch(suggestion_id, &candidate_tree, (void *)compare_id)) {
jbe@366 260 fprintf(stderr, "Insufficient memory while inserting into candidate tree.\n");
jbe@366 261 abort();
jbe@352 262 }
jbe@352 263 }
jbe@366 264 if (old_member_id && strcmp(old_member_id, member_id)) ballot_count++;
jbe@355 265 old_member_id = member_id;
jbe@352 266 }
jbe@355 267 printf("Candidate count: %i\n", candidate_count);
jbe@355 268 candidates = malloc(candidate_count * sizeof(struct candidate));
jbe@355 269 if (!candidates) {
jbe@356 270 fprintf(stderr, "Insufficient memory while creating candidate list.\n");
jbe@353 271 abort();
jbe@352 272 }
jbe@355 273 candidate_count = 0;
jbe@355 274 twalk(candidate_tree, (void *)register_candidate);
jbe@369 275 while (candidate_tree) tdelete(*(void **)candidate_tree, &candidate_tree, (void *)compare_id);
jbe@355 276 printf("Ballot count: %i\n", ballot_count);
jbe@355 277 ballots = calloc(ballot_count, sizeof(struct ballot));
jbe@355 278 if (!ballots) {
jbe@356 279 fprintf(stderr, "Insufficient memory while creating ballot list.\n");
jbe@353 280 abort();
jbe@352 281 }
jbe@355 282 ballot = ballots;
jbe@365 283 old_member_id = NULL;
jbe@355 284 for (i=0; i<tuple_count; i++) {
jbe@363 285 char *member_id;
jbe@355 286 int weight, preference;
jbe@352 287 member_id = PQgetvalue(res, i, COL_MEMBER_ID);
jbe@355 288 weight = (int)strtol(PQgetvalue(res, i, COL_WEIGHT), (char **)NULL, 10);
jbe@355 289 if (weight <= 0) {
jbe@356 290 fprintf(stderr, "Unexpected weight value.\n");
jbe@358 291 free(ballots);
jbe@358 292 free(candidates);
jbe@358 293 return 1;
jbe@355 294 }
jbe@352 295 preference = (int)strtol(PQgetvalue(res, i, COL_PREFERENCE), (char **)NULL, 10);
jbe@352 296 if (preference < 1 || preference > 4) {
jbe@356 297 fprintf(stderr, "Unexpected preference value.\n");
jbe@358 298 free(ballots);
jbe@358 299 free(candidates);
jbe@358 300 return 1;
jbe@352 301 }
jbe@352 302 preference--;
jbe@366 303 if (old_member_id && strcmp(old_member_id, member_id)) ballot++;
jbe@355 304 ballot->weight = weight;
jbe@355 305 ballot->sections[preference].count++;
jbe@355 306 old_member_id = member_id;
jbe@355 307 }
jbe@355 308 for (i=0; i<ballot_count; i++) {
jbe@355 309 int j;
jbe@355 310 for (j=0; j<4; j++) {
jbe@355 311 if (ballots[i].sections[j].count) {
jbe@355 312 ballots[i].sections[j].candidates = malloc(ballots[i].sections[j].count * sizeof(struct candidate *));
jbe@355 313 if (!ballots[i].sections[j].candidates) {
jbe@356 314 fprintf(stderr, "Insufficient memory while creating ballot section.\n");
jbe@355 315 abort();
jbe@355 316 }
jbe@355 317 }
jbe@355 318 }
jbe@352 319 }
jbe@365 320 old_member_id = NULL;
jbe@355 321 ballot = ballots;
jbe@365 322 for (i=0; i<tuple_count; i++) {
jbe@355 323 char *member_id, *suggestion_id;
jbe@355 324 int preference;
jbe@366 325 member_id = PQgetvalue(res, i, COL_MEMBER_ID);
jbe@366 326 suggestion_id = PQgetvalue(res, i, COL_SUGGESTION_ID);
jbe@366 327 preference = (int)strtol(PQgetvalue(res, i, COL_PREFERENCE), (char **)NULL, 10);
jbe@366 328 preference--;
jbe@366 329 if (old_member_id && strcmp(old_member_id, member_id)) {
jbe@366 330 ballot++;
jbe@366 331 candidates_in_sections[0] = 0;
jbe@366 332 candidates_in_sections[1] = 0;
jbe@366 333 candidates_in_sections[2] = 0;
jbe@366 334 candidates_in_sections[3] = 0;
jbe@355 335 }
jbe@366 336 ballot->sections[preference].candidates[candidates_in_sections[preference]++] = candidate_by_key(suggestion_id);
jbe@355 337 old_member_id = member_id;
jbe@352 338 }
jbe@352 339 }
jbe@355 340
jbe@356 341 for (i=0; i<candidate_count; i++) {
jbe@356 342 struct candidate *candidate = loser(i, ballots, ballot_count);
jbe@356 343 candidate->seat = candidate_count - i;
jbe@358 344 printf("Assigning rank #%i to suggestion #%s.\n", candidate_count - i, candidate->key);
jbe@356 345 }
jbe@356 346
jbe@354 347 for (i=0; i<ballot_count; i++) {
jbe@354 348 int j;
jbe@354 349 for (j=0; j<4; j++) {
jbe@354 350 if (ballots[i].sections[j].count) {
jbe@354 351 free(ballots[i].sections[j].candidates);
jbe@354 352 }
jbe@354 353 }
jbe@354 354 }
jbe@354 355 free(ballots);
jbe@358 356
jbe@361 357 if (final) {
jbe@361 358 printf("Writing final ranks to database.\n");
jbe@361 359 } else {
jbe@361 360 printf("Writing ranks to database.\n");
jbe@361 361 }
jbe@359 362 err = write_ranks(db, escaped_initiative_id, final);
jbe@358 363 printf("Done.\n");
jbe@358 364
jbe@358 365 free(candidates);
jbe@358 366
jbe@358 367 return err;
jbe@352 368 }
jbe@352 369
jbe@352 370 int main(int argc, char **argv) {
jbe@352 371
jbe@352 372 // variable declarations:
jbe@352 373 int err = 0;
jbe@352 374 int i, count;
jbe@352 375 char *conninfo;
jbe@352 376 PGconn *db;
jbe@352 377 PGresult *res;
jbe@352 378
jbe@352 379 // parse command line:
jbe@352 380 if (argc == 0) return 1;
jbe@352 381 if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
jbe@352 382 FILE *out;
jbe@352 383 out = argc == 1 ? stderr : stdout;
jbe@362 384 fprintf(out, "\n");
jbe@362 385 fprintf(out, "Usage: %s <conninfo>\n", argv[0]);
jbe@362 386 fprintf(out, "\n");
jbe@362 387 fprintf(out, "<conninfo> is specified by PostgreSQL's libpq,\n");
jbe@362 388 fprintf(out, "see http://www.postgresql.org/docs/9.1/static/libpq-connect.html\n");
jbe@362 389 fprintf(out, "\n");
jbe@362 390 fprintf(out, "Example: %s dbname=liquid_feedback\n", argv[0]);
jbe@362 391 fprintf(out, "\n");
jbe@352 392 return argc == 1 ? 1 : 0;
jbe@352 393 }
jbe@352 394 {
jbe@352 395 size_t len = 0;
jbe@352 396 for (i=1; i<argc; i++) len += strlen(argv[i]) + 1;
jbe@352 397 conninfo = malloc(len * sizeof(char));
jbe@352 398 if (!conninfo) {
jbe@358 399 fprintf(stderr, "Error: Could not allocate memory for conninfo string.\n");
jbe@358 400 abort();
jbe@352 401 }
jbe@352 402 conninfo[0] = 0;
jbe@352 403 for (i=1; i<argc; i++) {
jbe@352 404 if (i>1) strcat(conninfo, " ");
jbe@352 405 strcat(conninfo, argv[i]);
jbe@352 406 }
jbe@352 407 }
jbe@352 408
jbe@352 409 // connect to database:
jbe@352 410 db = PQconnectdb(conninfo);
jbe@352 411 if (!db) {
jbe@358 412 fprintf(stderr, "Error: Could not create database handle.\n");
jbe@352 413 return 1;
jbe@352 414 }
jbe@352 415 if (PQstatus(db) != CONNECTION_OK) {
jbe@352 416 fprintf(stderr, "Could not open connection:\n%s", PQerrorMessage(db));
jbe@352 417 return 1;
jbe@352 418 }
jbe@352 419
jbe@352 420 // check initiatives:
jbe@352 421 res = PQexec(db, "SELECT \"initiative_id\", \"final\" FROM \"initiative_suggestion_order_calculation\"");
jbe@352 422 if (!res) {
jbe@358 423 fprintf(stderr, "Error in pqlib while sending SQL command selecting initiatives to process.\n");
jbe@352 424 err = 1;
jbe@352 425 } else if (PQresultStatus(res) != PGRES_TUPLES_OK) {
jbe@358 426 fprintf(stderr, "Error while executing SQL command selecting initiatives to process:\n%s", PQresultErrorMessage(res));
jbe@352 427 err = 1;
jbe@352 428 PQclear(res);
jbe@359 429 } else if (PQnfields(res) < 2) {
jbe@359 430 fprintf(stderr, "Too few columns returned by SQL command selecting initiatives to process.\n");
jbe@359 431 err = 1;
jbe@359 432 PQclear(res);
jbe@352 433 } else {
jbe@352 434 count = PQntuples(res);
jbe@352 435 printf("Number of initiatives to process: %i\n", count);
jbe@352 436 for (i=0; i<count; i++) {
jbe@352 437 char *initiative_id, *escaped_initiative_id;
jbe@359 438 int final;
jbe@352 439 char *cmd;
jbe@352 440 PGresult *res2;
jbe@352 441 initiative_id = PQgetvalue(res, i, 0);
jbe@359 442 final = (PQgetvalue(res, i, 1)[0] == 't') ? 1 : 0;
jbe@352 443 printf("Processing initiative_id: %s\n", initiative_id);
jbe@352 444 escaped_initiative_id = escapeLiteral(db, initiative_id, strlen(initiative_id));
jbe@358 445 if (!escaped_initiative_id) {
jbe@358 446 fprintf(stderr, "Could not escape literal in memory.\n");
jbe@358 447 abort();
jbe@358 448 }
jbe@352 449 if (asprintf(&cmd, "SELECT \"member_id\", \"weight\", \"preference\", \"suggestion_id\" FROM \"individual_suggestion_ranking\" WHERE \"initiative_id\" = %s ORDER BY \"member_id\", \"preference\"", escaped_initiative_id) < 0) {
jbe@352 450 fprintf(stderr, "Could not prepare query string in memory.\n");
jbe@355 451 abort();
jbe@352 452 }
jbe@352 453 res2 = PQexec(db, cmd);
jbe@352 454 free(cmd);
jbe@352 455 if (!res2) {
jbe@358 456 fprintf(stderr, "Error in pqlib while sending SQL command selecting individual suggestion rankings.\n");
jbe@352 457 err = 1;
jbe@352 458 } else if (PQresultStatus(res2) != PGRES_TUPLES_OK) {
jbe@358 459 fprintf(stderr, "Error while executing SQL command selecting individual suggestion rankings:\n%s", PQresultErrorMessage(res));
jbe@352 460 err = 1;
jbe@352 461 PQclear(res2);
jbe@356 462 } else if (PQnfields(res2) < 4) {
jbe@358 463 fprintf(stderr, "Too few columns returned by SQL command selecting individual suggestion rankings.\n");
jbe@356 464 err = 1;
jbe@356 465 PQclear(res2);
jbe@352 466 } else {
jbe@359 467 if (process_initiative(db, res2, escaped_initiative_id, final)) err = 1;
jbe@352 468 PQclear(res2);
jbe@352 469 }
jbe@352 470 freemem(escaped_initiative_id);
jbe@352 471 }
jbe@352 472 PQclear(res);
jbe@352 473 }
jbe@352 474
jbe@352 475 // cleanup and exit
jbe@352 476 PQfinish(db);
jbe@358 477 if (!err) printf("Successfully terminated.\n");
jbe@358 478 else fprintf(stderr, "Exiting with error code #%i.\n", err);
jbe@352 479 return err;
jbe@352 480
jbe@352 481 }

Impressum / About Us