Query Problem

Started by Sheikh Salman Ahmedalmost 18 years ago3 messagesgeneral
Jump to latest
#1Sheikh Salman Ahmed
salman_sheikh@hotmail.com

Hi Fellows

I still have problem to access my databank.It shows syntax problem,I am using VC++ 2005 with postgresql 8.3.My table name is Person and it has three column,Person ID,first name and last name (testing version).whole c++ code is

// Test_postgres.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "libpq-fe.h"

int _tmain(int argc, _TCHAR* argv[])
{
const char *conninfo;
PGconn *conn;
const char *paramtext = "server_version";
PGresult *res;
conninfo = "hostaddr = 127.0.0.1 dbname = Salman_db user = postgres password = 732047";
conn = PQconnectdb(conninfo);
if (PQstatus(conn) != CONNECTION_OK)
{
printf("Unable to establish connection: %s",
PQerrorMessage(conn));
return 1;
} else
{

res = PQexec(conn, "INSERT INTO public.Person VALUES (221,'Siddiqi','Umer')");
if (PQresultStatus(res) != PGRES_COMMAND_OK)
{
printf("Problem with command: %s\n", PQerrorMessage(conn));
PQclear(res);
PQfinish(conn);
return 1;
}
PQclear(res);
}
PQfinish(conn);

return 0;
}

It shows no relation between public and person,if i write only person ,it show ,Person doesn't exist.

hope, u ppl can help me.

Sheikh Salman AhmedDiplomand in Nano Struktur TechnologieDuisburg-Essen UniversitätMobile : 0049-179-9463738Home :0049-203-3945028
_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us

#2Dave Page
dpage@pgadmin.org
In reply to: Sheikh Salman Ahmed (#1)
Re: Query Problem

On Sun, Jul 6, 2008 at 12:04 AM, Sheikh Salman Ahmed
<salman_sheikh@hotmail.com> wrote:

res = PQexec(conn, "INSERT INTO public.Person VALUES

Without quotes around Person, it will be shifted to lower case to
match a table called person. I suspect you need to do:

res = PQexec(conn, "INSERT INTO public.\"Person\" VALUES

It's almost always easier to use lower case names in Postgres.

--
Dave Page
EnterpriseDB UK: http://www.enterprisedb.com

#3Ragnar
gnari@hive.is
In reply to: Sheikh Salman Ahmed (#1)
Re: Query Problem

On lau, 2008-07-05 at 23:04 +0000, Sheikh Salman Ahmed wrote:

Hi Fellows

I still have problem to access my databank.It shows syntax problem,I
am using VC++ 2005 with postgresql 8.3.My table name is Person and it
has three column,Person ID,first name and last name (testing
version).whole c++ code is

more precise schema definition would be more helpful

...
res = PQexec(conn, "INSERT INTO public.Person VALUES
(221,'Siddiqi','Umer')");
...
It shows no relation between public and person,if i write only
person ,it show ,Person doesn't exist.

and real error messages are preferred.

As someone already told you a few days ago, the problem
could be that the table was created "Person" (mixed case
with double quotes). you have not confirmed or denied this.

If that is the case, you need to quote the name in your SQL:

INSERT INTO public."Person" VALUES (221,'Siddiqi','Umer')

(of course, you need to escape those quotes for your c)

If this is not your problem, please suply us with more information, and
someone may be able to help you.

gnari