Subject: " GetAttributeByName " ..

From: [email-masked] (Bruce Taneja.)
Date: Sun, 26 Jun 1994 17:50:57 -0400 (EDT)

Howdy again ,
 
with respect to my last query , and the function below, which
I had in my circle.c , ..

--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
bool  test(t, char1)
 TUPLE t;
 char *char1;
{
        extern char * GetAttributeByName();
        CIRCLE * bca;

/*        bca = (CIRCLE *) GetAttributeByName(t, "a");  */

  return strncmp(char1, "1");
}
-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

                 define function test
  (language = "c", returntype = bool)
  arg is (tutorial, char16)
  as "/usr/local/postgres/circle.o" \g

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

....... Upon running the query           

retrieve (tutorial.all)
               where test(tutorial, "1"::char16) \g

, I get the expected results OK, BUT when I uncomment the above
line in the code i.e " bca = (CIRCLE *) GetAttributeByName(t, "a"); "
and run the same query, the computer hangs ... !

.. has any body else had any good luck with GetAttributeByName(), 
can any body see why the monitor program hangs for me .. ?

All comments appreciated !
Bruce.

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "[email-masked]"

   If this fails, send mail to "[email-masked]" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================

---

From: [email-masked] (Paul M. Aoki)
Date: Sun, 26 Jun 94 23:18:45 -0700

> /*        bca = (CIRCLE *) GetAttributeByName(t, "a");  */

GetAttributeByName has three arguments, one of which is a bool.

> can any body see why the monitor program hangs for me .. ?

this is postgres 4.2 on ultrix.  sorry, haven't the time to load 4.1 
on a sparc, or to fix a bug in 4.1 if your problem is a bug.  here goes..

Script started on Sun Jun 26 23:15:17 1994
faerie:aoki (1)> createdb bruce
faerie:aoki (2)> monitor bruce < bruce.pq
Welcome to the POSTGRES terminal monitor

Go 
* 
Query sent to backend is "define function circle_in ( language = "c",                             returntype = circle )        arg is (any)        as "/faerie/aoki/postgres/src/regress/regress/obj/regress.o" "
NOTICE:Jun 27 06:15:46:ProcedureDefine: type 'circle' is not yet defined
NOTICE:Jun 27 06:15:46:ProcedureDefine: creating a shell for type 'circle'
DEFINE
Go 
* 
Query sent to backend is "define function circle_out ( language = "c",                               returntype = any )        arg is (any)        as "/faerie/aoki/postgres/src/regress/regress/obj/regress.o" "
DEFINE
Go 
* 
Query sent to backend is "define type circle ( internallength = 24,                       input = circle_in,                      output = circle_out ) "
DEFINE
Go 
* 
Query sent to backend is "load "/faerie/aoki/postgres/src/regress/regress/obj/regress.o" "
LOAD
Go 
* 
Query sent to backend is "create tutorial (a = circle) "
CREATE
Go 
* 
Query sent to backend is "append tutorial (a = "(15,12,1)"::circle) "
APPEND 21386
Go 
* 
Query sent to backend is "define function test (language = "c", returntype = bool)   arg is (tutorial, char16)   as "/faerie/aoki/postgres/src/regress/regress/obj/bruce.o" "
DEFINE
Go 
* 
Query sent to backend is "retrieve (x = test(t, "1"::char16)) from t in tutorial "
NOTICE:Jun 27 06:15:50:test: circle = (15.000000,12.000000,1.000000), string = 1
---------------
| x           |
---------------
| t           |
---------------

Go 
* faerie:aoki (3)> cat bruce.c
#include "tmp/postgres.h"
#include "tmp/libpq-fe.h"
#include "utils/geo-decls.h"
#include "utils/log.h"	/* for elog status codes */

typedef struct {
	POINT	center;
	double	radius;
} CIRCLE;

bool
test(t, s)
    TUPLE t;
    char *s;
{
    bool isnull = 0;
    CIRCLE *c = (CIRCLE *) GetAttributeByName(t, "a", &isnull);

    if (isnull)
	return(0);

    elog(NOTICE, "test: circle = (%f,%f,%f), string = %.16s",
	 c->center.x, c->center.y, c->radius, s);

    return(1);
}
faerie:aoki (4)> exit

script done on Sun Jun 26 23:16:01 1994
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720-1776      |  ...!uunet!ucbvax!aoki

---

From: [email-masked] (Bruce Taneja.)
Date: Mon, 27 Jun 1994 15:10:05 -0400 (EDT)

> 	 c->center.x, c->center.y, c->radius, s);

Hi Paul, 
Thanks for your help!

  After playing around with your exmaple above, I think I found
what was wrong, but I can't really explain it:

The above example runs perfectly even on ver 4.1 (  :)  ) , but 

to the following:

>     CIRCLE *c = (CIRCLE *) GetAttributeByName(t, "a");

  i.e removed the "&isnull)" and etc. in the test()  , the computer 
hanged !

Now why does the GetAttributeByName() work OK w/o the 3rd param.
when running the overpaid(EMP) example in the 8.4.3 section (user manual)
and simply hangs when used w/o the 3rd param in the circle example .. !?

thanks for your help!
Bruce.

---

From: George Hartzell <[email-masked]>
Date: Mon, 27 Jun 1994 12:46:43 -0700

> and simply hangs when used w/o the 3rd param in the circle example .. !?

In general, if a function takes 3 arguments, and you pass it two, then
you really should expect trouble since it's going to go ahead and use
some randome system trash as it's third arg.  I'm not in a position to
go digging around in the source code to find out just what that
function does with that arg., but it's not surprising that giving it
something meaningless makes it blow up sometimes.

g.

---

From: [email-masked] (Bruce Taneja.)
Date: Mon, 27 Jun 1994 15:48:30 -0400 (EDT)

> something meaningless makes it blow up sometimes.

I think your explanation is quite clear and obvious and in fact goes
without saying .. 
  BUT .. WHY does the user manual do the example in sect.8.4.3. w/o the
 3rd param .. ??????  Was that a mistake ?? 
and what beats me is why did this example work while it failed for the 
circle.c ??

Bruce.

---

From: [email-masked] (Paul M. Aoki)
Date: Mon, 27 Jun 94 13:03:31 -0700

>  3rd param .. ??????  Was that a mistake ?? 

well, as you say, this is quite clear and obvious.  yet another case of 
someone not updating the doc after changing an interface..

> and what beats me is why did this example work while it failed for the 

one of those mysteries of life.  i wouldn't spend much time thinking 
about it.
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  [email-masked]
                |  Berkeley, CA 94720-1776      |  ...!uunet!ucbvax!aoki