pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
HELP FOR POSTGRESQL NEEDED...
2+ messages / 2 participants
[nested] [flat]

* HELP FOR POSTGRESQL NEEDED...
@ 2002-07-06 12:22  ozric tentacle <ozric02@yahoo.gr>
  0 siblings, 1 reply; 2+ messages in thread

From: ozric tentacle @ 2002-07-06 12:22 UTC (permalink / raw)
  To: pgsql-questions@postgresql.org; pgsql-interfaces


Hello.I am experiencing a quite strange behavior with my postgreSQL database.

I have edited the file pg_hba.conf like this:

# TYPE     DATABASE    IP_ADDRESS    MASK               AUTH_TYPE  AUTH_ARGUMENT
local      all                                                                       password
host       all         127.0.0.1     255.255.255.255                   password

in order to require user authentication.This works perfectly when I connect to the database with psql or pgaccess and I'm able to perform

all kinds of queries.

However when I try to connect to the database with C++ even though it allows me to connect (providing the correct username & password)

all the queries fail...The C++ code I use is the following:


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream.h>
#include <string>

#include "libpq++.h"

using namespace std;


int main()

{
  string login,pwd;
  char name[10];
  char query_string[256];

  cout << ">username:";
  cin >> login;
  cout << ">password:";
  cin >> pwd;

  cout<<"user to search:";
  cin >> name;


  // Open the connection to the database and make sure it's OK

  PgDatabase data("dbname=goumero");


  char       *pghost,*pgport,*pgoptions,*pgtty;
  char       *dbName;

   pghost = NULL;              /* host name of the backend server */
   pgport = NULL;              /* port of the backend server */
   pgoptions = NULL;         /* special options to start up the backend server */
   pgtty = NULL;               /* debugging tty for the backend server */
   dbName = "goumero";

   PGconn* conn;

   conn =  PQsetdbLogin(pghost,pgport,pgoptions,pgtty,dbName,login.c_str(),pwd.c_str()) ;

  if (PQstatus(conn) == CONNECTION_BAD ) {
        fprintf(stderr, "Connection to database '%s' failed.\n", dbName);
        fprintf(stderr, "%s", PQerrorMessage(conn));
        return 1;
  }
  else
      //Connection successful...


      data.Exec("BEGIN WORK");
      data.Exec("LOCK TABLE account in ACCESS EXCLUSIVE  MODE");


            sprintf(query_string,                               // create an SQL query string
                    "SELECT *   \
                     FROM account \
                     WHERE name='%s'" , name);
              if ( !data.ExecTuplesOk(query_string) )             // send the query
            {
                cerr << "query failed." << endl;
                exit(1);
            }

            for (int i=0; i < data.Tuples(); i++)               // loop through all rows returned
                    cout << data.GetValue(i,0) << endl;   // print the value returned

/**************************************************************************************/

      data.Exec("COMMIT WORK");
      PQfinish(conn);

return 0;

} // End main()

Note:The same query above is correctly executed when I connect with psql .

Also if I remove the user authentication stuff then the same code is executed correctly.

I would be grateful if you helped me - I'm desperate....

  

 


 

 


 

 



---------------------------------
Do You Yahoo!?
ÁðïêôÞóôå ôçí äùñåÜí óáò@yahoo.gr äéåýèõíóç  óôï Yahoo! Mail.

^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: HELP FOR POSTGRESQL NEEDED...
@ 2002-07-08 16:41  Steve Howe <howe@carcass.dhs.org>
  parent: ozric tentacle <ozric02@yahoo.gr>
  0 siblings, 0 replies; 2+ messages in thread

From: Steve Howe @ 2002-07-08 16:41 UTC (permalink / raw)
  To: pgsql-interfaces-owner@postgresql.org, ozric tentacle <ozric02@yahoo.gr>; +Cc: pgsql-questions@postgresql.org; pgsql-interfaces

Hello ozric,

Saturday, July 6, 2002, 9:22:44 AM, you wrote:


ot> Hello.I am experiencing a quite strange behavior with my
ot> postgreSQL database.

ot> I have edited the file pg_hba.conf like this:

ot> # TYPE     DATABASE    IP_ADDRESS    MASK               AUTH_TYPE  AUTH_ARGUMENT
ot> local      all                                                                       password
ot> host       all         127.0.0.1     255.255.255.255                   password

ot> in order to require user authentication.This works perfectly when
ot> I connect to the database with psql or pgaccess and I'm able to
ot> perform

ot> all kinds of queries.

ot> However when I try to connect to the database with C++ even though
ot> it allows me to connect (providing the correct username &
ot> password)

ot> all the queries fail...The C++ code I use is the following:

Did you start the postmaster with -i parameter so that it allows
TCP/IP connections ?
Run a nmap localhost command to check if your 5432 port is open. If
PostgreSQL is running and accepting connections, it should be listed
as open.
Psql will connect through unix sockets, not as TCP sockets.

------------- 
Best regards,
 Steve Howe                           mailto:howe@carcass.dhs.org






^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2002-07-08 16:41 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-07-06 12:22 HELP FOR POSTGRESQL NEEDED... ozric tentacle <ozric02@yahoo.gr>
2002-07-08 16:41 ` Steve Howe <howe@carcass.dhs.org>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox