/* * AOPPA -- A program for extracting the AnarchyOnline resource database * Auno.org PostgreSQL nano table generator. * * Copyright (C) 2003 Oskari Saarenmaa * * $Id: aunoorg-nanos.cc,v 1.4 2003/10/21 09:12:37 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 * */ #include #include #include #include #include using namespace std; static PGresult * execf(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 aodb.xid,aodb.aoid,aodb_ext.icon,aodb_nano.school,aodb_strain.strain,aodb.ql,aodb_nano.ncu,aodb_ext.name,aodb_ext.info from aodb, aodb_nano, aodb_ext, aodb_strain where aodb.aoid = aodb_strain.aoid and aodb.xid = aodb_nano.xid and aodb.xid = aodb_ext.xid and aodb.current is true and aodb.metatype = 'n'"); int i, rows = PQntuples(q); if(rows <= 0) { printf("No nanos found!\n"); } else { PQclear(PQexec(dbconn, "drop table nanos")); PQclear(PQexec(dbconn, "create table nanos (aoid int4, icon int4, school int2, strain int2, es int2, ql int2, ncu int2, stack int2, prof int2, lvl int2, mm int2, bm int2, pm int2, mc int2, ts int2, si int2, name text, info text)")); for(i=0; i