Subject: Updating tuple attributes with vars from C program

From: [email-masked]
Date: Thu, 16 Sep 1993 0:50:43 -0500 (CDT)

I am just starting to work with  Postgres as the platform for my
masters' thesis project.

I am facing the following problem, and would very much appreciate if someone 
could clarify the same :

   I have not been able to update tuples of a class, with values from
   variables  in my C program.  I give below a simplified version of the
   program segment I used.

#include <stdio.h>
#include "/home/coyote/postgres/src/backend/libpq.h"

main()

{
  int x = 4;
  int y = 6;

  PQsetdb("foo");

  PQexec("create testclass (a=int4, b=int4)"); 
  PQexec("copy testclass from stdin"); 

  PQputline(x	y);
  PQputline (".\n");

  PQfinish ();

}

The program compiles sucessfully and runs. However the attributes 
a and b in the class do not get updated with the values in x and y.

Any clarification on the above would be very helpful to me.

My user id is [email-masked]

Sriram Kal.

---

From: [email-masked] (Paul M. Aoki)
Date: Thu, 16 Sep 93 10:24:17 -0700

>   PQexec("copy testclass from stdin"); 

the input format for the copy command is documented under "copy".
copy normally wants a string containing tab-separated fields.  so
something like

	char buffer[100];

	sprintf(buffer, "%d\t%d\n", x, y);
	PQputline(buffer);

is what you need.

as documented under "libpq", you need to wrap up with PQendcopy.

src/bin/monitor/monitor.c contains a (cheesy) example of using
copy from an application.
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki