summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOliver Schinagl <oliver@schinagl.nl>2008-05-06 12:01:18 (GMT)
committerOliver Schinagl <oliver@schinagl.nl>2008-05-06 12:01:18 (GMT)
commit23b16ab5373c0869cd00eed3aa2b52fd0a04cbad (patch)
tree59eed6653b687a0d414b1b3177b8058ad14df98f
parent90e452660d230c7dd181ee7c3fbc5b5a117ed937 (diff)
download2iv55-23b16ab5373c0869cd00eed3aa2b52fd0a04cbad.zip
2iv55-23b16ab5373c0869cd00eed3aa2b52fd0a04cbad.tar.gz
2iv55-23b16ab5373c0869cd00eed3aa2b52fd0a04cbad.tar.bz2
-rw-r--r--reset/Makefile15
-rwxr-xr-xreset/resetbin0 -> 13121 bytes
-rw-r--r--reset/reset.c96
-rw-r--r--reset/reset.h25
4 files changed, 136 insertions, 0 deletions
diff --git a/reset/Makefile b/reset/Makefile
new file mode 100644
index 0000000..afb19bd
--- /dev/null
+++ b/reset/Makefile
@@ -0,0 +1,15 @@
+# House of mozart statistic reseter (c) 2003 Oliver
+# -================================================-
+
+CC = gcc
+CFLAGS += -O2 -I`/usr/local/pgsql/bin/pg_config --includedir` -L`/usr/local/pgsql/bin/pg_config --libdir` -lpq
+
+DESTDIR = /usr/local/bin
+BIN = reset
+
+all:
+ $(CC) $(CFLAGS) reset.c -o $(BIN)
+
+
+clean:
+ rm -rf *~ *.o $(BIN)
diff --git a/reset/reset b/reset/reset
new file mode 100755
index 0000000..f64b33c
--- /dev/null
+++ b/reset/reset
Binary files differ
diff --git a/reset/reset.c b/reset/reset.c
new file mode 100644
index 0000000..b52f5c4
--- /dev/null
+++ b/reset/reset.c
@@ -0,0 +1,96 @@
+/*
+ * reset.c
+ * House of Mozart statistic database reset app (c) 2003 oliver
+ *
+ * GNU public license *FIXME*
+ */
+
+#include "reset.h"
+#include <stdio.h>
+#include <getopt.h>
+#include <time.h>
+#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));
+ PQfinish(conn);
+ 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);
+
+ 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;
+}
diff --git a/reset/reset.h b/reset/reset.h
new file mode 100644
index 0000000..766d74c
--- /dev/null
+++ b/reset/reset.h
@@ -0,0 +1,25 @@
+/*
+ * reset.h
+ * House of Mozart statistic database reset app (c) 2003 oliver
+ *
+ * GNU public license *FIXME*
+ */
+
+#define VERSION 0.0.1
+
+#define PGHOST "127.0.0.1"
+#define PGPORT "5432"
+#define PGOPTIONS "\0"
+#define PGTTY "\0"
+#define DBNAME "houseofmozart"
+#define LOGIN "houseofmozart"
+#define PWD "M0z4rT"
+
+#define SHORTHELP \
+"Not enough or incorrect arguments try -h for help\n"
+
+#define LONGHELP \
+" -h\tprint this help message\n \
+ -d\tReset daily stats\n \
+ -m\tReset monthly stats\n \
+ -a\tReset All stats (month day)\n"