summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2008-05-07 09:31:33 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2008-05-07 09:31:33 (GMT)
commit58d04319139a590473e556ad9017e18127bfc70c (patch)
tree81dc84335fc1b7f49dfa25bada1f671c34e01eec
parent177fd758a25e954a43c20e59e6e61ba15a661c44 (diff)
download2iv55-58d04319139a590473e556ad9017e18127bfc70c.zip
2iv55-58d04319139a590473e556ad9017e18127bfc70c.tar.gz
2iv55-58d04319139a590473e556ad9017e18127bfc70c.tar.bz2
cleaned
-rw-r--r--reset/reset.c71
1 files changed, 9 insertions, 62 deletions
diff --git a/reset/reset.c b/reset/reset.c
index b52f5c4..5a851ca 100644
--- a/reset/reset.c
+++ b/reset/reset.c
@@ -12,37 +12,12 @@
#include <libpq-fe.h>
int main(int argc, char *argv[]) {
- int i;
- int options;
- int day;
- int month;
- int year;
PGconn *conn;
char SQL_query[512];
PGresult *res;
- day = month = year = 0;
-
conn = PQsetdbLogin(PGHOST, PGPORT, PGOPTIONS, PGTTY, DBNAME, LOGIN, PWD);
- for(;-1 != (options = getopt(argc, argv, "hdmya"));) {
- if('h' == options) {
- printf(LONGHELP);
- }
- if('d' == options) {
- day = 23;
- }
- if('m' == options) {
- month = 31;
- }
- if('y' == options) {
- year = 1;
- }
- if('a' == options) {
- day = 23;
- month = 31;
- }
- }
if(CONNECTION_BAD == PQstatus(conn)) {
fprintf(stderr, "Connection to database '%s' failed.\n %s", DBNAME, PQerrorMessage(conn));
@@ -50,46 +25,18 @@ int main(int argc, char *argv[]) {
return 1;
}
- if(0 < day) {
- for(i = 0; i <= day; i++) {
- sprintf(SQL_query, "UPDATE counter_day SET \"%0.2d\" = 0;", i);
- res = PQexec(conn, SQL_query);
-
- if((NULL == res) || (PGRES_COMMAND_OK != PQresultStatus(res))) {
- printf("Unable to execute query: %s\n %s\n", SQL_query, PQerrorMessage(conn));
- PQclear(res);
- PQfinish(conn);
- return 1;
- }
- PQclear(res);
- }
- }
- if(0 < month) {
- for(i = 1; i <= month; i++) {
- sprintf(SQL_query, "UPDATE counter_month SET \"%0.2d\" = 0;", i);
- res = PQexec(conn, SQL_query);
-
- if((NULL == res) || (PGRES_COMMAND_OK != PQresultStatus(res))) {
- printf("Unable to execute query: %s\n %s\n", SQL_query, PQerrorMessage(conn));
- PQclear(res);
- PQfinish(conn);
- return 1;
- }
- PQclear(res);
- }
- }
- if(1 == year) {
- sprintf(SQL_query, "INSERT INTO counter_year VALUES (counter_year.year +1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);");
- res = PQexec(conn, SQL_query);
+ sprintf(SQL_query, "");
+ res = PQexec(conn, SQL_query);
- if((NULL == res) || (PGRES_COMMAND_OK != PQresultStatus(res))) {
- printf("Unable to execute query: %s\n %s\n", SQL_query, PQerrorMessage(conn));
- PQclear(res);
- PQfinish(conn);
- return 1;
- }
+
+ if((NULL == res) || (PGRES_COMMAND_OK != PQresultStatus(res))) {
+ printf("Unable to execute query: %s\n %s\n", SQL_query, PQerrorMessage(conn));
PQclear(res);
+ PQfinish(conn);
+ return 1;
}
+ PQclear(res);
+
PQfinish(conn);
return 0;