/* * AOPPA -- A program for extracting the AnarchyOnline resource database * Auno.org PostgreSQL patch reverting tool. * * Copyright (C) 2003 Oskari Saarenmaa * * $Id: aunoorg-revert.cc,v 1.3 2003/10/21 09:15:52 pickett Exp $ * * 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 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * */ // XXX: This is too slow to be used #include #include #include #include using namespace std; int main(int argc, char **argv) { PGconn *dbconn; char buf[0x200]; const char *dbname, *dbuser; int patch; list edelete, erevert; 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::iterator li; printf("Delete (%d).", edelete.size()); for(li=edelete.begin(); li!=edelete.end(); li++) { snprintf(buf, sizeof buf, "delete from aodb where xid = %d", *li); PQclear(PQexec(dbconn, buf)); snprintf(buf, sizeof buf, "delete from aodb_eff where xid = %d", *li); PQclear(PQexec(dbconn, buf)); snprintf(buf, sizeof buf, "delete from aodb_ext where xid = %d", *li); PQclear(PQexec(dbconn, buf)); snprintf(buf, sizeof buf, "delete from aodb_nano where xid = %d", *li); PQclear(PQexec(dbconn, buf)); snprintf(buf, sizeof buf, "delete from aodb_other where xid = %d", *li); PQclear(PQexec(dbconn, buf)); snprintf(buf, sizeof buf, "delete from aodb_skill where xid = %d", *li); PQclear(PQexec(dbconn, buf)); snprintf(buf, sizeof buf, "delete from aodb_req where xid = %d", *li); PQclear(PQexec(dbconn, buf)); } printf("Revert (%d).", erevert.size()); for(li=erevert.begin(); li!=erevert.end(); li++) { snprintf(buf, sizeof buf, "update aodb set current = true where xid = %d", *li); PQclear(PQexec(dbconn, buf)); } } end: PQfinish(dbconn); return 0; }