Initial import
[uccvend-vendserver.git] / sql-edition / convert.c
diff --git a/sql-edition/convert.c b/sql-edition/convert.c
new file mode 100644 (file)
index 0000000..bac3b86
--- /dev/null
@@ -0,0 +1,31 @@
+/* Prints a list of all usernames with useable coke balances
+ * delimited by newlines.
+ *
+ *  - Bernard Blackham <[email protected]>
+ */
+
+
+#include <stdio.h>
+#include "ucc.h"
+
+int main(int argc, char* argv[]) {
+       char username[30];
+       int32 balance;
+
+       if (argc != 1) {
+               fprintf(stderr, "Usage: %s\n", argv[0]);
+               return 1;
+       }
+       
+       SetCokebankToSocks();
+
+       cokebank_open();
+       printf("DELETE from users;\n");
+       printf("COPY users (user_name, user_balance_cents, user_balance_bytes) FROM stdin;\n");
+       while (cokebank_get_next(username, &balance, 0)) {
+               printf("%s\t%d\t%d\n", username, cokebank_get(username), cokebank_get_bytes(username));
+       }
+       printf("\\.\n");
+       cokebank_close();
+       return 0;
+}

UCC git Repository :: git.ucc.asn.au