HELP FOR POSTGRESQL NEEDED...
От | ozric tentacle |
---|---|
Тема | HELP FOR POSTGRESQL NEEDED... |
Дата | |
Msg-id | 20020706122244.55874.qmail@web13106.mail.yahoo.com обсуждение исходный текст |
Ответы |
Re: HELP FOR POSTGRESQL NEEDED...
(Steve Howe <howe@carcass.dhs.org>)
|
Список | pgsql-interfaces |
<p>Hello.I am experiencing a quite strange behavior with my <strong>postgreSQL database</strong>.<p>I have edited the file<strong>pg_hba.conf</strong> like this:<p># TYPE DATABASE IP_ADDRESS MASK AUTH_TYPE AUTH_ARGUMENT<br/>local all password<br />host all 127.0.0.1 255.255.255.255 password<p>in order to require user authentication.Thisworks perfectly when I connect to the database with <strong>psql</strong> or <strong>pgaccess</strong>and I'm able to perform<p>all kinds of queries.<p>However when I try to connect to the databasewith <strong>C++</strong> even though it allows me to connect (providing the correct username & password)<p><strong>allthe queries fail...</strong>The C++ code I use is the following:<p><br />#include <stdio.h><br/>#include <stdlib.h><br />#include <string.h><br />#include <iostream.h><br />#include<string><p>#include "libpq++.h"<p>using namespace std;<p><br />int main()<p>{<br /> string login,pwd;<br/> char name[10];<br /> char query_string[256];<p> cout << ">username:";<br /> cin >> login;<br/> cout << ">password:";<br /> cin >> pwd;<p> cout<<"user to search:";<br /> cin >>name;<p><br /> // Open the connection to the database and make sure it's OK<p> PgDatabase data("dbname=goumero");<p><br/> char *pghost,*pgport,*pgoptions,*pgtty;<br /> char *dbName;<p> pghost = NULL; /* host name of the backend server */<br /> pgport = NULL; /* port of the backend server*/<br /> pgoptions = NULL; /* special options to start up the backend server */<br /> pgtty = NULL; /* debugging tty for the backend server */<br /> dbName = "goumero";<p> PGconn* conn;<p> conn = PQsetdbLogin(pghost,pgport,pgoptions,pgtty,dbName,login.c_str(),pwd.c_str()) ;<p> if (PQstatus(conn) == CONNECTION_BAD) {<br /> fprintf(stderr, "Connection to database '%s' failed.\n", dbName);<br /> fprintf(stderr,"%s", PQerrorMessage(conn));<br /> return 1;<br /> }<br /> else<br /> //Connection successful...<p><br/> data.Exec("BEGIN WORK");<br /> data.Exec("LOCK TABLE account in ACCESS EXCLUSIVE MODE");<p><br/> sprintf(query_string, // create an SQL query string<br /> "SELECT * \<br /> FROM account \<br /> WHERE name='%s'" ,name);<br /> if ( !data.ExecTuplesOk(query_string) ) // send the query<br /> {<br /> cerr << "query failed." << endl;<br /> exit(1);<br /> }<p> for (int i=0; i < data.Tuples(); i++) // loop through all rows returned<br /> cout << data.GetValue(i,0) << endl; // print the value returned<p>/**************************************************************************************/<p> data.Exec("COMMITWORK");<br /> PQfinish(conn);<p>return 0;<p>} // End main()<p><strong><font color="blue"><u>Note</u></font></strong>:Thesame query above is correctly executed when I connect with <strong>psql</strong>.<p><strong><u>Also if I remove the user authentication stuff then the same code is executed correctly.</u></strong><p><strong><fontcolor="red">I would be grateful if you helped me - I'm desperate....</font></strong><p> <p> <p><br/> <p> <p><br /> <p> <p><br /><hr size="1" /><b>Do You Yahoo!?</b><br />Αποκτήστετην δωρεάν σας @yahoo.gr διεύθυνση στο <a href="http://www.otenet.gr/">Yahoo! Mail</a>.<br />
В списке pgsql-interfaces по дате отправления: