/* * AOPPA -- A program for extracting the AnarchyOnline resource database * Auno.org PostgreSQL perk profession requirement table updater. * * $Id: aunoorg-perkupdate.c 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 . * */ #include #include #include #include #include static int exec_and_info(PGconn *, const char *); int main(int argc, char **argv) { PGconn *dbconn; char buf[0x200]; const char *dbname, *dbuser; if(argc != 3) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } dbuser = (const char *)(argv[2]); dbname = (const char *)(argv[1]); 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); } PGresult *q = PQexec(dbconn, "select aoid, perkline, perklineid, perklevel from aodb_perk order by perkline asc, perklineid asc, perklevel asc"); int i, rows = PQntuples(q); if(rows <= 0) { printf("No perks found!\n"); } else { int lastprof=-1, lastlreq=0, lastplid=0; for(i=0; i