Skip site navigation (1) Skip section navigation (2)

Re: [pgadmin-support] HELP FOR POSTGRESQL NEEDED...

From: "Dave Page" <dpage(at)vale-housing(dot)co(dot)uk>
To: "ozric tentacle" <ozric02(at)yahoo(dot)gr>,<pgadmin-support(at)postgresql(dot)org>, <pgadmin-hackers(at)postgresql(dot)org>
Subject: Re: [pgadmin-support] HELP FOR POSTGRESQL NEEDED...
Date: 2002-07-07 10:37:35
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgadmin-hackerspgadmin-support
You will get a better response from one of the PostgreSQL lists (see These lists are for pgAdmin related stuff....
Regards, Dave.

	-----Original Message-----
	From: ozric tentacle [mailto:ozric02(at)yahoo(dot)gr] 
	Sent: 05 July 2002 17:19
	To: pgadmin-support(at)postgresql(dot)org; pgadmin-hackers(at)postgresql(dot)org
	Subject: [pgadmin-support] HELP FOR POSTGRESQL NEEDED...

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

	I have edited the file pg_hba.conf like this:

	local      all                                                                       password
	host       all                   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;
	      //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
	      &! nbsp;     {
	                cerr << "query failed." << endl;                     //always fails

	            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");

	return 0;

	} // End main()

	Note:The same query string 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! Mail <> .

pgadmin-hackers by date

Next:From: Dave PageDate: 2002-07-07 10:41:36
Subject: Re: Gui suggestion
Previous:From: David HollowayDate: 2002-07-05 20:46:31
Subject: Gui suggestion

pgadmin-support by date

Next:From: GeoffDate: 2002-07-09 11:04:24
Subject: FW: small problem with RA to PSQL.
Previous:From: Carmen WaiDate: 2002-07-06 06:45:12
Subject: Problem on PostgreSQL (error code, store procedures)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group