liquid_feedback_core
diff lf_update.c @ 65:bdccc56fb705
lf_update continues on error (but still reports errors)
and version number changed to v1.2.4 (without any other schema changes)
and version number changed to v1.2.4 (without any other schema changes)
author | jbe |
---|---|
date | Sun Aug 15 17:10:47 2010 +0200 (2010-08-15) |
parents | 6133c0a62378 |
children | bc8aa59b0945 |
line diff
1.1 --- a/lf_update.c Sat Jul 24 16:52:51 2010 +0200 1.2 +++ b/lf_update.c Sun Aug 15 17:10:47 2010 +0200 1.3 @@ -6,6 +6,7 @@ 1.4 int main(int argc, char **argv) { 1.5 1.6 // variable declarations: 1.7 + int err = 0; 1.8 int i, count; 1.9 char *conninfo; 1.10 PGconn *db; 1.11 @@ -57,97 +58,105 @@ 1.12 status = PQexec(db, "DELETE FROM \"expired_session\""); 1.13 if (!status) { 1.14 fprintf(stderr, "Error in pqlib while sending SQL command deleting expired sessions\n"); 1.15 - return 1; 1.16 - } 1.17 - if ( 1.18 + err = 1; 1.19 + } else if ( 1.20 PQresultStatus(status) != PGRES_COMMAND_OK && 1.21 PQresultStatus(status) != PGRES_TUPLES_OK 1.22 ) { 1.23 fprintf(stderr, "Error while executing SQL command deleting expired sessions:\n%s", PQresultErrorMessage(status)); 1.24 - return 1; 1.25 + err = 1; 1.26 + PQclear(status); 1.27 + } else { 1.28 + PQclear(status); 1.29 } 1.30 1.31 // calculate member counts: 1.32 status = PQexec(db, "SELECT \"calculate_member_counts\"()"); 1.33 if (!status) { 1.34 fprintf(stderr, "Error in pqlib while sending SQL command calculating member counts\n"); 1.35 - return 1; 1.36 - } 1.37 - if ( 1.38 + err = 1; 1.39 + } else if ( 1.40 PQresultStatus(status) != PGRES_COMMAND_OK && 1.41 PQresultStatus(status) != PGRES_TUPLES_OK 1.42 ) { 1.43 fprintf(stderr, "Error while executing SQL command calculating member counts:\n%s", PQresultErrorMessage(status)); 1.44 - return 1; 1.45 + err = 1; 1.46 + PQclear(status); 1.47 + } else { 1.48 + PQclear(status); 1.49 } 1.50 1.51 // update open issues: 1.52 list = PQexec(db, "SELECT \"id\" FROM \"open_issue\""); 1.53 if (!list) { 1.54 fprintf(stderr, "Error in pqlib while sending SQL command selecting open issues\n"); 1.55 - return 1; 1.56 - } 1.57 - if (PQresultStatus(list) != PGRES_TUPLES_OK) { 1.58 + err = 1; 1.59 + } else if (PQresultStatus(list) != PGRES_TUPLES_OK) { 1.60 fprintf(stderr, "Error while executing SQL command selecting open issues:\n%s", PQresultErrorMessage(list)); 1.61 - return 1; 1.62 + err = 1; 1.63 + PQclear(list); 1.64 + } else { 1.65 + count = PQntuples(list); 1.66 + for (i=0; i<count; i++) { 1.67 + const char *params[1]; 1.68 + params[0] = PQgetvalue(list, i, 0); 1.69 + status = PQexecParams( 1.70 + db, "SELECT \"check_issue\"($1)", 1, NULL, params, NULL, NULL, 0 1.71 + ); 1.72 + if (!status) { 1.73 + fprintf(stderr, "Error in pqlib while sending SQL command to call function \"check_issue\"(...):\n"); 1.74 + err = 1; 1.75 + } else if ( 1.76 + PQresultStatus(status) != PGRES_COMMAND_OK && 1.77 + PQresultStatus(status) != PGRES_TUPLES_OK 1.78 + ) { 1.79 + fprintf(stderr, "Error while calling SQL function \"check_issue\"(...):\n%s", PQresultErrorMessage(status)); 1.80 + err = 1; 1.81 + PQclear(status); 1.82 + } else { 1.83 + PQclear(status); 1.84 + } 1.85 + } 1.86 + PQclear(list); 1.87 } 1.88 - count = PQntuples(list); 1.89 - for (i=0; i<count; i++) { 1.90 - const char *params[1]; 1.91 - params[0] = PQgetvalue(list, i, 0); 1.92 - status = PQexecParams( 1.93 - db, "SELECT \"check_issue\"($1)", 1, NULL, params, NULL, NULL, 0 1.94 - ); 1.95 - if (!status) { 1.96 - fprintf(stderr, "Error in pqlib while sending SQL command to call function \"check_issue\"(...):\n"); 1.97 - return 1; 1.98 - } 1.99 - if ( 1.100 - PQresultStatus(status) != PGRES_COMMAND_OK && 1.101 - PQresultStatus(status) != PGRES_TUPLES_OK 1.102 - ) { 1.103 - fprintf(stderr, "Error while calling SQL function \"check_issue\"(...):\n%s", PQresultErrorMessage(status)); 1.104 - return 1; 1.105 - } 1.106 - PQclear(status); 1.107 - } 1.108 - PQclear(list); 1.109 1.110 // calculate ranks after voting is finished: 1.111 // (NOTE: This is a seperate process to avoid long transactions with locking) 1.112 list = PQexec(db, "SELECT \"id\" FROM \"issue_with_ranks_missing\""); 1.113 if (!list) { 1.114 fprintf(stderr, "Error in pqlib while sending SQL command selecting issues where ranks are missing\n"); 1.115 - return 1; 1.116 - } 1.117 - if (PQresultStatus(list) != PGRES_TUPLES_OK) { 1.118 + err = 1; 1.119 + } else if (PQresultStatus(list) != PGRES_TUPLES_OK) { 1.120 fprintf(stderr, "Error while executing SQL command selecting issues where ranks are missing:\n%s", PQresultErrorMessage(list)); 1.121 - return 1; 1.122 + err = 1; 1.123 + PQclear(list); 1.124 + } else { 1.125 + count = PQntuples(list); 1.126 + for (i=0; i<count; i++) { 1.127 + const char *params[1]; 1.128 + params[0] = PQgetvalue(list, i, 0); 1.129 + status = PQexecParams( 1.130 + db, "SELECT \"calculate_ranks\"($1)", 1, NULL, params, NULL, NULL, 0 1.131 + ); 1.132 + if (!status) { 1.133 + fprintf(stderr, "Error in pqlib while sending SQL command to call function \"calculate_ranks\"(...):\n"); 1.134 + err = 1; 1.135 + } else if ( 1.136 + PQresultStatus(status) != PGRES_COMMAND_OK && 1.137 + PQresultStatus(status) != PGRES_TUPLES_OK 1.138 + ) { 1.139 + fprintf(stderr, "Error while calling SQL function \"calculate_ranks\"(...):\n%s", PQresultErrorMessage(status)); 1.140 + err = 1; 1.141 + PQclear(status); 1.142 + } else { 1.143 + PQclear(status); 1.144 + } 1.145 + } 1.146 + PQclear(list); 1.147 } 1.148 - count = PQntuples(list); 1.149 - for (i=0; i<count; i++) { 1.150 - const char *params[1]; 1.151 - params[0] = PQgetvalue(list, i, 0); 1.152 - status = PQexecParams( 1.153 - db, "SELECT \"calculate_ranks\"($1)", 1, NULL, params, NULL, NULL, 0 1.154 - ); 1.155 - if (!status) { 1.156 - fprintf(stderr, "Error in pqlib while sending SQL command to call function \"calculate_ranks\"(...):\n"); 1.157 - return 1; 1.158 - } 1.159 - if ( 1.160 - PQresultStatus(status) != PGRES_COMMAND_OK && 1.161 - PQresultStatus(status) != PGRES_TUPLES_OK 1.162 - ) { 1.163 - fprintf(stderr, "Error while calling SQL function \"calculate_ranks\"(...):\n%s", PQresultErrorMessage(status)); 1.164 - return 1; 1.165 - } 1.166 - PQclear(status); 1.167 - } 1.168 - PQclear(list); 1.169 1.170 // cleanup and exit 1.171 PQfinish(db); 1.172 - return 0; 1.173 + return err; 1.174 1.175 }