/* * AOPPA -- A program for extracting the AnarchyOnline resource database * Auno.org PostgreSQL patch reverting tool. * * $Id: aunoorg-revert.cc 1111 2009-03-04 07:57:14Z os $ * * Copyright (C) 2003-2009 Oskari Saarenmaa . * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ // XXX: This is too slow to be used #include #include #include int main(int argc, char **argv) { PGconn *dbconn; char buf[0x200]; const char *dbname, *dbuser; int patch; std::list edelete, erevert; std::list::iterator li; if(argc != 4) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } dbuser = (const char *)(argv[1]); dbname = (const char *)(argv[2]); patch = atoi(argv[3]); snprintf(buf, sizeof buf, "dbname=%s user=%s", dbname, dbuser); dbconn = PQconnectdb(buf); if(dbconn == NULL) { fprintf(stderr, "Database structure allocation failed, out of memory?\n"); exit(1); } else if(PQstatus(dbconn) != CONNECTION_OK) { fprintf(stderr, "Database login failed.\n"); exit(1); } snprintf(buf, sizeof buf, "select xid, aoid, current from aodb where patch = %d", patch); PGresult *q = PQexec(dbconn, buf); int i, rows = PQntuples(q); if(rows <= 0) { printf("No tuples found for that patch, nothing to do.\n"); goto end; } for(i=0; i