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

Re: want basic help with C

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Arindam Haldar <arindamhaldar(at)hotpop(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: want basic help with C
Date: 2002-05-21 13:31:18
Message-ID: 1021987878.1400.23.camel@linda (view raw, whole thread or download thread mbox)
Lists: pgsql-generalpgsql-interfaces
On Tue, 2002-05-21 at 13:34, Arindam Haldar wrote:
> Arindam Haldar wrote:
>   hi,
>   i went thru the docs on programming interface of postgresql with c. But

This is the libpq interface, yes?

You need to read the libpq reference: chapter 1 of the Programmer's

>   am unable to understnad to use the interface to query a select
>   statement. the database is--->masterdb & in it there is a table
>   -->colleges with a few columns & a few records for testing..
>   now i want to use a general select statement--> select * from colleges,
>   but going thru the docs again & again from different sites am unable to
>   undestand how to use it.
>   can u gove me a basics to use the funstion to use the same & print the
>   rows in the tables

First you have to connect to the database, using PQconnectdb() or a
related function.  This returns a handle which you have to use in all
other API calls for this connection.

Send your command or query to the backend with PQExec()
This returns a query handle which you can use to get the results with
the various calls listed in section 1.3.4 of the Programmer's Guide.

Close the connection with PQfinish()

> pls--> i wanted to ask this 2nd Question-->is it necessary to start 
> postgreswith option -i too to accept connection from localhost(C 
> programme). command line works fine without the said option but unless i 
> use -i , i cannot connect to postgres.

If you connect through TCP/IP you always need the -i option on the
postmaster.  Connecting with host set to localhost is a TCP/IP
connection.  Connecting with host set to nothing connects through a Unix
socket on the local machine; this does not need the -i option.

Oliver Elphick                                Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight                    
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C

     "O come, let us worship and bow down; let us kneel
      before the LORD our maker."          Psalms 95:6 

In response to

pgsql-interfaces by date

Next:From: Gaston MicheriDate: 2002-05-21 21:24:38
Subject: Graphical Tool
Previous:From: Arindam HaldarDate: 2002-05-21 12:58:41
Subject: Re: want basic help with C

pgsql-general by date

Next:From: Joel BurtonDate: 2002-05-21 13:38:38
Subject: Re: [NOVICE] Problem with inserting: attribute 'extended_reason'
Previous:From: Marin DimitrovDate: 2002-05-21 13:19:57
Subject: Re: Help..

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