pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
question on accessing PostgreSQL with C
10+ messages / 5 participants
[nested] [flat]

* question on accessing PostgreSQL with C
@ 1999-02-06 03:05 hoelc <hoelc@pd.jaring.my>
  0 siblings, 0 replies; 10+ messages in thread

From: hoelc @ 1999-02-06 03:05 UTC (permalink / raw)
  To: pgsql-interfaces

Hello,
I'm a newbee in PostgreSQL, Linux world.  Currently facing some problem
in building a simple application.  I'm trying to write a C program that
get input from user, then update (insert / change) the database, or
retrieve selected data.

Questions:
(1)  Where to get more example of communicating with PostgreSQL with C
program?

(2)  How to put variables into the SQL?
      I use C program to access PostgreSQL with libpq, and use PQexec( )
to send the query. One of the failed example of mine,
                    :
           /* get input from user, a string and an integer */
                    :
        PQexec(conn,"insert into NameList (name,id) values (%s,%d)
.......
                    :
           /* I'm trying to put variables of string and integer into the
query */


(3)  How to check who are the users in PostgreSQL system?

Please advise.
Thanks & Regards,
LCH




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* question on accessing PostgreSQL with C
@ 1999-02-07 00:45 hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  0 siblings, 1 reply; 10+ messages in thread

From: hoelc @ 1999-02-07 00:45 UTC (permalink / raw)
  To: pgsql-interfaces

Hello,
I'm a newbee in PostgreSQL, Linux world.  Currently facing some problem
in building a simple application.  I'm trying to write a C program that
get input from user, then update (insert / change) the database, or
retrieve selected data.

Questions:
(1)  Where to get more example of communicating with PostgreSQL with C
program?

(2)  How to put variables into the SQL?
        I use C program to access PostgreSQL with libpq, and use PQexec(
) to send the query. One of the failed example of mine,
                    :
           /* get input from user, a string and an integer */
                    :
        PQexec(conn,"insert into NameList (name,id) values
(%s,%d).......
                    :
           /* I'm trying to put variables of string and integer into the
query */


(3)  How to check who are the users in PostgreSQL system?

Please advise.
Thanks & Regards,
LCH






^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
@ 1999-02-07 01:16 ` James Thompson <jamest@math.ksu.edu>
  1999-02-07 19:03   ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
  0 siblings, 1 reply; 10+ messages in thread

From: James Thompson @ 1999-02-07 01:16 UTC (permalink / raw)
  To: hoelc <hoelc@pd.jaring.my>; +Cc: pgsql-interfaces

On Sun, 7 Feb 1999, hoelc wrote:

> 
> (2)  How to put variables into the SQL?
>         I use C program to access PostgreSQL with libpq, and use PQexec(
> ) to send the query. One of the failed example of mine,
>

I'd recommend using ecpg that comes with postgresql in the place of libpq
direct.  It is IMHO orders of magnitude easier than libpg alone.  The
syntax follows the same as Oracle's Pro*C so you can pretty much use any
of their manuals and get a working program.  I found an on-line copy of
the Pro*c manual at

http://www.dal.ca/%7eoracle/oradoc/DOC/api/doc/PC_22/toc.htm


With it you end up with something like the following in your code

    exec sql
      insert into customer(id,name_first,name_middle,name_last,company,
			address1,address2,city,state,country,zip,phone_work,
			phone_home,phone_fax,email,date_entered,billing_terms,
                           confirmation_method)
      values (:id,:name_first, :name_middle, :name_last,
              :company,:address1,:address2,
              :city,:state,:country,:zip,:phone_work,
              :phone_home,:phone_fax,:email,date('now'),
              :billing_terms,
              :confirmation_method);

the names preceeded by : are c variables.  The ecpg preprocessor replaces
this easily readable code with much nastier looking c code that does what
you require.

The author of the code is very responsive to few problem reports I have
sent him and has sent patches, or workarounds to me usually within 24
hours.

In the few cases you can't figure out a way to make something happen using
ecpg I believe you can mix the libpg and ecpg code in the same program.
The only place I could see a need for this is when you'd need the
functionality given by Pro*C's Dynamic SQL which ecpg doesn't yet support,
but I think its in the works.

You can find examples of ecpg code in the source tree
postgresql-6.4.2/src/interfaces/ecpg/test

> 
> (3)  How to check who are the users in PostgreSQL system?
> 

select * from pg_user;

->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<
James Thompson    138 Cardwell Hall  Manhattan, Ks   66506    785-532-0561 
Kansas State University                          Department of Mathematics
->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<








^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
@ 1999-02-07 19:03   ` Michael Meskes <Michael_Meskes@topmail.de>
  1999-02-10 03:31     ` Re: [INTERFACES] question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  0 siblings, 1 reply; 10+ messages in thread

From: Michael Meskes @ 1999-02-07 19:03 UTC (permalink / raw)
  To: James Thompson <jamest@math.ksu.edu>; +Cc: hoelc <hoelc@pd.jaring.my>; pgsql-interfaces

On Sat, Feb 06, 1999 at 07:16:14PM -0600, James Thompson wrote:
> http://www.dal.ca/%7eoracle/oradoc/DOC/api/doc/PC_22/toc.htm

Gotta look at this.

> With it you end up with something like the following in your code
> 
>     exec sql
>       insert into customer(id,name_first,name_middle,name_last,company,
> 			address1,address2,city,state,country,zip,phone_work,
> 			phone_home,phone_fax,email,date_entered,billing_terms,
>                            confirmation_method)
>       values (:id,:name_first, :name_middle, :name_last,
>               :company,:address1,:address2,
>               :city,:state,:country,:zip,:phone_work,
>               :phone_home,:phone_fax,:email,date('now'),
>               :billing_terms,
>               :confirmation_method);

Xou can even add indicators like in 

... values (:id,:name_first, :name_middle:nm_ind, :name_last, ...

If nm_ind is set to -1 the name_middle entry will be set to NULL.

> The author of the code is very responsive to few problem reports I have
> sent him and has sent patches, or workarounds to me usually within 24
> hours.

Glad I can help. :-)

> In the few cases you can't figure out a way to make something happen using
> ecpg I believe you can mix the libpg and ecpg code in the same program.
> The only place I could see a need for this is when you'd need the
> functionality given by Pro*C's Dynamic SQL which ecpg doesn't yet support,
> but I think its in the works.

It is. In fact I already submitted a patch for the PREPARE and EXECUTE
commands. James, if you'd like to test this I can send you the source until
it makes its way into CVS.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net          | Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-07 19:03   ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
@ 1999-02-10 03:31     ` hoelc <hoelc@pd.jaring.my>
  1999-02-10 05:36       ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-10 06:51       ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
  0 siblings, 2 replies; 10+ messages in thread

From: hoelc @ 1999-02-10 03:31 UTC (permalink / raw)
  To: Michael Meskes <Michael_Meskes@topmail.de>; +Cc: James Thompson <jamest@math.ksu.edu>; pgsql-interfaces

Hello,
Thanks a lot.
I have a PostgreSQL-6.2.1 ( in RedHat Linux 5.0), and it doesn't has "ecpg".
I have downloaded "ecpg" from internet, but don't know how to install it into my
PostgreSQL system.  Please advise.

Thank you very much.
Regards.....LCH

Michael Meskes wrote:

> On Sat, Feb 06, 1999 at 07:16:14PM -0600, James Thompson wrote:
> > http://www.dal.ca/%7eoracle/oradoc/DOC/api/doc/PC_22/toc.htm
>
> Gotta look at this.
>
> > With it you end up with something like the following in your code
> >
> >     exec sql
> >       insert into customer(id,name_first,name_middle,name_last,company,
> >                       address1,address2,city,state,country,zip,phone_work,
> >                       phone_home,phone_fax,email,date_entered,billing_terms,
> >                            confirmation_method)
> >       values (:id,:name_first, :name_middle, :name_last,
> >               :company,:address1,:address2,
> >               :city,:state,:country,:zip,:phone_work,
> >               :phone_home,:phone_fax,:email,date('now'),
> >               :billing_terms,
> >               :confirmation_method);
>
> Xou can even add indicators like in
>
> ... values (:id,:name_first, :name_middle:nm_ind, :name_last, ...
>
> If nm_ind is set to -1 the name_middle entry will be set to NULL.
>
> > The author of the code is very responsive to few problem reports I have
> > sent him and has sent patches, or workarounds to me usually within 24
> > hours.
>
> Glad I can help. :-)
>
> > In the few cases you can't figure out a way to make something happen using
> > ecpg I believe you can mix the libpg and ecpg code in the same program.
> > The only place I could see a need for this is when you'd need the
> > functionality given by Pro*C's Dynamic SQL which ecpg doesn't yet support,
> > but I think its in the works.
>
> It is. In fact I already submitted a patch for the PREPARE and EXECUTE
> commands. James, if you'd like to test this I can send you the source until
> it makes its way into CVS.
>
> Michael
> --
> Michael Meskes                         | Go SF 49ers!
> Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
> Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
> Email: Michael.Meskes@gmx.net          | Use PostgreSQL!






^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-07 19:03   ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
  1999-02-10 03:31     ` Re: [INTERFACES] question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
@ 1999-02-10 05:36       ` James Thompson <jamest@math.ksu.edu>
  1999-02-10 06:26         ` Re: [INTERFACES] question on accessing PostgreSQL with C Rich Shepard <rshepard@appl-ecosys.com>
  1 sibling, 1 reply; 10+ messages in thread

From: James Thompson @ 1999-02-10 05:36 UTC (permalink / raw)
  To: hoelc <hoelc@pd.jaring.my>; +Cc: Michael Meskes <Michael_Meskes@topmail.de>; pgsql-interfaces

On Wed, 10 Feb 1999, hoelc wrote:

> I have a PostgreSQL-6.2.1 ( in RedHat Linux 5.0), and it doesn't has "ecpg".
> I have downloaded "ecpg" from internet, but don't know how to install it into my
> PostgreSQL system.  Please advise.

Hmmm, 

Did you get the version from the link on the postgresql web site?

If so don't install it.  I can't remember the version number but I believe
it is way behind the current version bundled with postgresql 6.4.2 which
is up around .50 I think.

To get any newer versions you need to go to the postgresql CVS code and I
haven't tried that yet.

Not much help am I? ;-)

Seriously though, is there some reason you need to run the 6.2.1 code?  
If not then I'd just rpm -e the current postgresql, grab the latest and
greatest 6.4.2 source code and compile away.  I don't recall having any
troubles building postgresql 6.4.2 on my mutated RedHat 5.1 system.  I'm
thinking quite a few gotchas were probably fixed between 6.2.x and 6.4.x.

Take care,
James

->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<
James Thompson    138 Cardwell Hall  Manhattan, Ks   66506    785-532-0561 
Kansas State University                          Department of Mathematics
->->->->->->->->->->->->->->->->->->---<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-<





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-07 19:03   ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
  1999-02-10 03:31     ` Re: [INTERFACES] question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-10 05:36       ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
@ 1999-02-10 06:26         ` Rich Shepard <rshepard@appl-ecosys.com>
  1999-02-10 14:34           ` Re: [INTERFACES] question on accessing PostgreSQL with C Mark Himsley <markh@clockworkweb.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Rich Shepard @ 1999-02-10 06:26 UTC (permalink / raw)
  To: pgsql-interfaces

On Tue, 9 Feb 1999, James Thompson wrote:

> Seriously though, is there some reason you need to run the 6.2.1 code?  
> If not then I'd just rpm -e the current postgresql, grab the latest and
> greatest 6.4.2 source code and compile away.  I don't recall having any
> troubles building postgresql 6.4.2 on my mutated RedHat 5.1 system.  I'm
> thinking quite a few gotchas were probably fixed between 6.2.x and 6.4.x.

  It's even easier than that. 6.4.2 is available as an rpm. Download that
and install it over 6.2.1 using rpm -U postgre....

Rich

Dr. Richard B. Shepard, President
Applied Ecosystem Services, Inc.
2404 SW 22nd Street
Troutdale, OR 97060-1247  U.S.A.
+ 1 503-667-4517 (voice) | + 1 503-667-8863 (fax)
rshepard@appl-ecosys.com





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-07 19:03   ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
  1999-02-10 03:31     ` Re: [INTERFACES] question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-10 05:36       ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-10 06:26         ` Re: [INTERFACES] question on accessing PostgreSQL with C Rich Shepard <rshepard@appl-ecosys.com>
@ 1999-02-10 14:34           ` Mark Himsley <markh@clockworkweb.com>
  1999-02-10 06:42             ` Re: [INTERFACES] question on accessing PostgreSQL with C Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 1 reply; 10+ messages in thread

From: markh@clockworkweb.com @ 1999-02-10 14:34 UTC (permalink / raw)
  To: Rich Shepard <rshepard@appl-ecosys.com>; +Cc: pgsql-interfaces

On Tue, 9 Feb 1999 22:26:04 -0800 (PST), you wrote:


>  It's even easier than that. 6.4.2 is available as an rpm. Download that
>and install it over 6.2.1 using rpm -U postgre....

Where from?
I have not seen an RPM of 6.4 announced any ware.

--
Mark Himsley.
Technical Director
Clockwork Web.
+44 171 471 0770
http://www.clockworkweb.com



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-07 19:03   ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
  1999-02-10 03:31     ` Re: [INTERFACES] question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-10 05:36       ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-10 06:26         ` Re: [INTERFACES] question on accessing PostgreSQL with C Rich Shepard <rshepard@appl-ecosys.com>
  1999-02-10 14:34           ` Re: [INTERFACES] question on accessing PostgreSQL with C Mark Himsley <markh@clockworkweb.com>
@ 1999-02-10 06:42             ` Rich Shepard <rshepard@appl-ecosys.com>
  0 siblings, 0 replies; 10+ messages in thread

From: Rich Shepard @ 1999-02-10 06:42 UTC (permalink / raw)
  To: pgsql-interfaces

On Wed, 10 Feb 1999, Mark Himsley wrote:

> Where from?
> I have not seen an RPM of 6.4 announced any ware.

Mark,

  I don't recall offhand; it might be ftp://contrib.redhat.com. Anyway, if
you load http://www.filewatcher.org you can use the left-hand (file name)
search window to look for postgre*6.4.2*rpm and it will show you just where
it is. That's how I found it a few weeks ago.

Rich

Dr. Richard B. Shepard, President
Applied Ecosystem Services, Inc.
2404 SW 22nd Street
Troutdale, OR 97060-1247  U.S.A.
+ 1 503-667-4517 (voice) | + 1 503-667-8863 (fax)
rshepard@appl-ecosys.com





^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: [INTERFACES] question on accessing PostgreSQL with C
  1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
  1999-02-07 01:16 ` Re: [INTERFACES] question on accessing PostgreSQL with C James Thompson <jamest@math.ksu.edu>
  1999-02-07 19:03   ` Re: [INTERFACES] question on accessing PostgreSQL with C Michael Meskes <Michael_Meskes@topmail.de>
  1999-02-10 03:31     ` Re: [INTERFACES] question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
@ 1999-02-10 06:51       ` Michael Meskes <Michael_Meskes@topmail.de>
  1 sibling, 0 replies; 10+ messages in thread

From: Michael Meskes @ 1999-02-10 06:51 UTC (permalink / raw)
  To: hoelc <hoelc@pd.jaring.my>; +Cc: Michael Meskes <Michael_Meskes@topmail.de>; James Thompson <jamest@math.ksu.edu>; pgsql-interfaces

On Wed, Feb 10, 1999 at 11:31:15AM +0800, hoelc wrote:
> I have a PostgreSQL-6.2.1 ( in RedHat Linux 5.0), and it doesn't has "ecpg".

That's correct. Ecpg is bundled with PostgreSQL since 6.3.

> I have downloaded "ecpg" from internet, but don't know how to install it into my
> PostgreSQL system.  Please advise.

Which version of ecpg? You should be able to compile ecpg standalon without
much of a problem. Just make sure all programs you develop are linked with
-lecpg -lpq. Of course both libraries must be accessible. Also ecpg come
with some additional include files that have to be installed in a place
where cpp finds them.

Michael
-- 
Michael Meskes                         | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz    | Go Rhein Fire!
Tel.: (+49) 2431/72651                 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net          | Use PostgreSQL!



^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~1999-02-10 14:34 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-02-06 03:05 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
1999-02-07 00:45 question on accessing PostgreSQL with C hoelc <hoelc@pd.jaring.my>
1999-02-07 01:16 ` James Thompson <jamest@math.ksu.edu>
1999-02-07 19:03   ` Michael Meskes <Michael_Meskes@topmail.de>
1999-02-10 03:31     ` hoelc <hoelc@pd.jaring.my>
1999-02-10 05:36       ` James Thompson <jamest@math.ksu.edu>
1999-02-10 06:26         ` Rich Shepard <rshepard@appl-ecosys.com>
1999-02-10 14:34           ` Mark Himsley <markh@clockworkweb.com>
1999-02-10 06:42             ` Rich Shepard <rshepard@appl-ecosys.com>
1999-02-10 06:51       ` Michael Meskes <Michael_Meskes@topmail.de>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox