Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id D7B2A4759D8 for ; Sat, 6 Jul 2002 08:23:17 -0400 (EDT) Mailbox-Line: From ozric02@yahoo.gr Sat Jul 6 08:23:17 2002 Received: from web13106.mail.yahoo.com (web13106.mail.yahoo.com [216.136.174.151]) by postgresql.org (Postfix) with SMTP id 730134759D8 for ; Sat, 6 Jul 2002 08:22:40 -0400 (EDT) Message-ID: <20020706122244.55874.qmail@web13106.mail.yahoo.com> Received: from [212.251.92.232] by web13106.mail.yahoo.com via HTTP; Sat, 06 Jul 2002 13:22:44 BST Date: Sat, 6 Jul 2002 13:22:44 +0100 (BST) From: =?iso-8859-7?q?ozric=20tentacle?= Subject: HELP FOR POSTGRESQL NEEDED... To: pgsql-questions@postgresql.org, pgsql-interfaces@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1365950118-1025958164=:50423" Content-Transfer-Encoding: 8bit X-Spam-Status: No, hits=-0.5 required=5.0 tests=X_NOT_PRESENT,FROM_ENDS_IN_NUMS,DOUBLE_CAPSWORD, SUBJ_ALL_CAPS version=2.30 X-Spam-Level: X-Archive-Number: 200207/19 X-Sequence-Number: 2828 --0-1365950118-1025958164=:50423 Content-Type: text/plain; charset=iso-8859-7 Content-Transfer-Encoding: 8bit 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 #include #include #include #include #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. --0-1365950118-1025958164=:50423 Content-Type: text/html; charset=iso-8859-7 Content-Transfer-Encoding: 8bit

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.
--0-1365950118-1025958164=:50423--