Return-Path: owner-postman
Received: from LOCALHOST (LOCALHOST [127.0.0.1]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with SMTP id AAA03966 for postgres-redist; Thu, 16 Jun 1994 00:36:41 -0700
Resent-From: POSTGRES mailing list <postman@postgres.Berkeley.EDU>
Resent-Message-Id: <199406160736.AAA03966@nobozo.CS.Berkeley.EDU>
Sender: owner-postman@postgres.Berkeley.EDU
X-Return-Path: owner-postman
Received: from faerie.CS.Berkeley.EDU (faerie.CS.Berkeley.EDU [128.32.149.14]) by nobozo.CS.Berkeley.EDU (8.6.4/8.6.3) with ESMTP id AAA03956 for <postgres@postgres.Berkeley.EDU>; Thu, 16 Jun 1994 00:36:39 -0700
Received: from LOCALHOST (LOCALHOST [127.0.0.1]) by faerie.CS.Berkeley.EDU (8.6.4/8.1B) with SMTP id AAA22026; Thu, 16 Jun 1994 00:36:33 -0700
Message-Id: <199406160736.AAA22026@faerie.CS.Berkeley.EDU>
X-Authentication-Warning: faerie.CS.Berkeley.EDU: Host LOCALHOST didn't use HELO protocol
From: aoki@CS.Berkeley.EDU (Paul M. Aoki)
To: ejonge@tpd.TNO.NL (Eric de Jonge)
Cc: postgres@postgres.Berkeley.EDU
Subject: Re: new type & rule ?! 
Reply-To: aoki@CS.Berkeley.EDU (Paul M. Aoki)
In-reply-to: Your message of Wed, 15 Jun 1994 13:21:14 +0200 (MET DST) 
	     <9406151121.AA05432@tpdusv.tpd.tno.nl> 
Date: Thu, 16 Jun 94 00:36:33 -0700
X-Sender: aoki@postgres.Berkeley.EDU
Resent-To: postgres-redist@postgres.Berkeley.EDU
X-Mts: smtp
Resent-Date: Thu, 16 Jun 94 00:36:41 -0700
Resent-XMts: smtp

ejonge@tpd.TNO.NL (Eric de Jonge) writes:
> Conclusion : define a rule for built-in data types with CURRENT works;
>           => define a rule for new data types with CURRENT not?!
> Is this right?

hi eric.

more likely the = operator isn't working right.  below, the attribute
of "a" is of new (dynamically-loaded) type "footext" and "a" is the 
"current" of the delete rule.  this is using the 4.2beta on mips/ultrix;
your actual mileage may vary.

Script started on Thu Jun 16 00:28:01 1994
faerie:aoki (1)> destroydb chigau
faerie:aoki (2)> createdb chigau
faerie:aoki (3)> monitor chigau
Welcome to the POSTGRES terminal monitor

Go 
* \i /home2/aoki/blah

Query sent to backend is "define function footext_in ( language = "c", returntype = footext )  arg is (any) as "/home2/aoki/footext.o""
NOTICE:Jun 16 00:28:27:ProcedureDefine: type 'footext' is not yet defined
NOTICE:Jun 16 00:28:27:ProcedureDefine: creating a shell for type 'footext'
DEFINE
Query sent to backend is "define function footext_out ( language = "c", returntype = any ) arg  is (any) as "/home2/aoki/footext.o""
DEFINE
Query sent to backend is "define type footext ( internallength = variable, input = footext_in,  output = footext_out )"
DEFINE
Query sent to backend is "define function textfootexteq ( language = "c", returntype = bool )  arg is (text, footext) as "/home2/aoki/footext.o""
DEFINE
Query sent to backend is "define operator = ( arg1 = text, arg2 = footext, procedure =  textfootexteq)"
DEFINE
Query sent to backend is "create a (x=footext)"
CREATE
Query sent to backend is "create b (x=text)"
CREATE
Query sent to backend is "append a (x="foo")"
APPEND 21929
Query sent to backend is "append a (x="bar")"
APPEND 21930
Query sent to backend is "append b (x="foo")"
APPEND 21931
Query sent to backend is "append b (x="bar")"
APPEND 21932
Query sent to backend is "retrieve (a.all)"
---------------
| x           |
---------------
| foo         |
---------------
| bar         |
---------------

Query sent to backend is "retrieve (b.all)"
---------------
| x           |
---------------
| foo         |
---------------
| bar         |
---------------

Query sent to backend is "define rule cascades is on delete to a do delete b where b.x =  current.x"
DEFINE
Query sent to backend is "delete a where "foo"::text = a.x"
DELETE
Query sent to backend is "retrieve (a.all)"
---------------
| x           |
---------------
| bar         |
---------------

Query sent to backend is "retrieve (b.all)"
---------------
| x           |
---------------
| bar         |
---------------

Go 
* \q
faerie:aoki (4)> cat footext.c 
#include <ctype.h>
#include <strings.h>

#include "tmp/postgres.h"
#include "utils/log.h"
#include "utils/palloc.h"
#include "utils/builtins.h"

/*
 *	textin		- converts "..." to internal representation
 */
struct varlena *
footext_in(inputText)
	char 	*inputText;
{
	register struct varlena	*result;
	register int		len;

	if (inputText == NULL)
		return(NULL);
	len = strlen(inputText) + sizeof(int32);		/* varlena? */
	result = (struct varlena *) palloc(len);
	result->vl_len = len;
	bcopy(inputText, result->vl_dat, len - sizeof(int32));	/* varlena? */
	return(result);
}

/*
 *	textout		- converts internal representation to "..."
 */
char *
footext_out(vlena)
	struct varlena	*vlena;
{
	register int	len;
	char		*result;

	if (vlena == NULL) {
		result = (char *) palloc(2);
		result[0] = '-';
		result[1] = '\0';
		return(result);
	}
	len = vlena->vl_len - sizeof(int32);			/* varlena? */
	result = (char *) palloc(len + 1);
	bcopy(vlena->vl_dat, result, len);
	result[len] = '\0';
	return(result);
}


	     /* ========== PUBLIC ROUTINES ========== */


/*
 *	texteq		- returns 1 iff arguments are equal
 *	textne		- returns 1 iff arguments are not equal
 */
int32
textfootexteq(arg1, arg2)
	struct varlena	*arg1, *arg2;
{
	register int	len;
	register char	*a1p, *a2p;

	if (arg1 == NULL || arg2 == NULL)
		return((int32) NULL);
	if ((len = arg1->vl_len) != arg2->vl_len)
		return((int32) 0);
	a1p = arg1->vl_dat;
	a2p = arg2->vl_dat;
	/*
	 * Varlenas are stored as the total size (data + size variable)
	 * followed by the data.  The size variable is an int32 so the
	 * length of the data is the total length less sizeof(int32)
	 */
	len -= sizeof(int32);
	while (len-- != 0)
		if (*a1p++ != *a2p++)
			return((int32) 0);
	return((int32) 1);
}
faerie:aoki (5)> exit
exit

script done on Thu Jun 16 00:28:45 1994
--
  Paul M. Aoki  |  CS Div., Dept. of EECS, UCB  |  aoki@CS.Berkeley.EDU
                |  Berkeley, CA 94720           |  ...!uunet!ucbvax!aoki

==============================================================================
   To add/remove yourself to/from the POSTGRES mailing list: send mail with 
   the subject line ADD or DEL to "postgres-request@postgres.Berkeley.EDU"

   If this fails, send mail to "post_questions@postgres.Berkeley.EDU" and
   a human will deal with it.  DO NOT post to the "postgres" mailing list.
==============================================================================
