X-Original-To: pgsql-docs-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 7CC09D1B956 for ; Wed, 24 Sep 2003 14:48:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 56622-03 for ; Wed, 24 Sep 2003 11:48:22 -0300 (ADT) Received: from hotmail.com (sea1-f145.sea1.hotmail.com [207.68.163.145]) by svr1.postgresql.org (Postfix) with ESMTP id 4317CD1B8A3 for ; Wed, 24 Sep 2003 11:48:18 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 24 Sep 2003 07:48:22 -0700 Received: from 203.193.129.35 by sea1fd.sea1.hotmail.msn.com with HTTP; Wed, 24 Sep 2003 14:48:22 GMT X-Originating-IP: [203.193.129.35] X-Originating-Email: [goutham4u@hotmail.com] From: "Vutharkar Goutham" To: pgsql-docs@postgresql.org Subject: Re: Select statement error !!!! Date: Wed, 24 Sep 2003 14:48:22 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 24 Sep 2003 14:48:22.0494 (UTC) FILETIME=[E6CFDFE0:01C382AA] X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=BAYES_20, PLING_PLING, RCVD_IN_OSIRUSOFT_COM X-Spam-Level: X-Archive-Number: 200309/61 X-Sequence-Number: 2017 Hello, I am sorry that this isn't the right group to putup the question but i am desperate to get it right and moreover thats what the major hindrance to our project. We are doing Intrusion Detection System as project to fulfill the requirement of completion of Post Graduation in MSIT. So we are using PostgreSQL as our database to store the captured data from a LAN or from outside network. So in the mean process we successfully captured the data packets and sent them into the database tables but the problem is when we are are trying to retrieve data then we are failing and we dont know how to proceed further. We searched all the forums for right answer but didn't get to it so i was forced to post here. Now let me paste the code here .... #include #include void exit_nicely(PGconn *conn) { PQfinish(conn); exit(1); } int main() { char *pghost,*pgport,*pgoptions,*pgtty; char *dbname; char query[1024]; struct PQprintOpt *po; int nFields; int i,j; FILE *fp; fp = fopen("data.txt","w+"); strcpy(query,"select * from UDP_Table"); printf("\nInitial Query is : %s\n",query); PGconn *conn; PGresult *res; pghost = NULL; pgport = NULL; pgoptions = NULL; pgtty = NULL; dbname = "Project"; conn = PQsetdb(pghost,pgport,pgoptions,pgtty,dbname); if(PQstatus(conn) == CONNECTION_BAD) { fprintf(stderr,"Failed to make a connection.\n",dbname); fprintf(stderr,"%s",PQerrorMessage(conn)); exit_nicely(conn); } else printf("\nConnection established with backend.\n"); res = PQexec(conn,"BEGIN"); if(!res || PQresultStatus(res)!=PGRES_TUPLES_OK) { fprintf(stderr,"Begin Failed.\n"); PQclear(res); exit_nicely(conn); } else printf("\nBegin Transaction Completed Successfully.\n"); printf("\nQuery B4 execution is : %s\n",query); res = PQexec(conn,query); if(!res || PQresultStatus(res)!=PGRES_COMMAND_OK) { fprintf(stderr,"\nSelect Statement Failed.\n"); PQclear(res); exit_nicely(conn); } else { printf("\nSelect statement executed successfully.\n"); PQprint(fp,res,(const struct PQprintOpt *)po); } // Print Attribute Names printf("\nThe Attribute Names are \n\n"); nFields = PQnfields(res); for(i = 0;i