agora inbox for postgres@postgres.berkeley.edu  
help / color / mirror / Atom feed
Re-sending - could someone please help ?
2+ messages / 2 participants
[nested] [flat]

* Re-sending - could someone please help ?
@ 1994-12-12 07:13 SRIRAMK@charlie.usd.edu
  1994-12-12 07:52 ` Re: Re-sending - could someone please help ? Paul M. Aoki <aoki@cs.berkeley.edu>
  0 siblings, 1 reply; 2+ messages in thread

From: SRIRAMK@charlie.usd.edu @ 1994-12-12 07:13 UTC (permalink / raw)
  To: legacy; +Cc: SRIRAMK@charlie.usd.edu

From:	CHARLI::SRIRAMK       8-DEC-1994 01:50:45.65
To:	SMTP%"postgres@postgres.berkeley.edu"
CC:	SRIRAMK
Subj:	GetAttributeByName  for string values


Hi, 

My function given below * no longer returns an error * after I used
the third parameter for GetAttributeByName as suggested in response
to my earlier e-mail.  However, GetAttributeByName  does not display
any string attribute values while it successfully does for integer type 
attributes .

Can anybody tell what's wrong ?

The following is a simplified example - it is part of a method that 
returns a bool.

/*  method_folder.c  - to display attribute values */


#include "/home/coyote/postgres/src/backend/tmp/libpq.h"
#include <utils/builtins.h>
#include <tmp/libpq-fe.h>

bool method_folder(t)
TUPLE t;

{
    char folder_name[100];
    bool isnull; 
 
/* Display of a string attribute as below doesn't work */
/* Nothing gets displayed */
  
    printf("Print : %s\n", GetAttributeByName(t,"fldrname",&isnull));


/* Display of an integer attribute with the same syntax as shown below 
    works */
    
    printf("Print cnt: %d\n", (int) GetAttributeByName(t,"msgcnt",&isnull));
}


I used the following command to define the function :

  define function method_folder (language = "c", returntype = bool) arg is 
  (FOLDERS) as "/home/coyote/postgres/final/method_folder.o"  \g

I ran the function with the command :

  retrieve (FOLDERS.all) where method_folder(FOLDERS) \g

==============================================================================
   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.
==============================================================================
              URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres/



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

* Re: Re-sending - could someone please help ?
  1994-12-12 07:13 Re-sending - could someone please help ? SRIRAMK@charlie.usd.edu
@ 1994-12-12 07:52 ` Paul M. Aoki <aoki@cs.berkeley.edu>
  0 siblings, 0 replies; 2+ messages in thread

From: Paul M. Aoki @ 1994-12-12 07:52 UTC (permalink / raw)
  To: SRIRAMK@charlie.usd.edu; +Cc: legacy

SRIRAMK@charlie.usd.edu writes:
> /* Display of a string attribute as below doesn't work */
> /* Nothing gets displayed */
>     printf("Print : %s\n", GetAttributeByName(t,"fldrname",&isnull));

postgres has no "string" type.

when using user-defined functions (executed within the server) you
have to know what the internal representation of the type is in order
to print it out.  that should be pretty obvious.

if you have defined your own "string" type, then i don't know what's
going on here.

if you are using "text", then you should understand that "text" is
defined as a 4-byte length field followed by the string (which is
*NOT* NUL-delimited, so it is not a C string).  on a sun or other
big-endian computer, the first byte of the length field is very likely
to be 0, which is what would end a C string.  so printf("%s") thinks
it's an empty string.

if you are using "char16", then the internal representation is simply
a 16-byte string that is, again, *NOT* NUL-delimited.

hence, "%s" is a bad idea for both "char16" and "text".  for "char16",
"%.16s" works.  for "text", you can do something like

	struct varlena *v;

	v = GetAttributeByName(blah blah);
	printf("%.*s\n", v->vl_len, v->vl_dat);
--
  Paul M. Aoki          |  University of California at Berkeley
  aoki@CS.Berkeley.EDU  |  Dept. of EECS, Computer Science Division (#1776) 
                        |  Berkeley, CA 94720-1776

==============================================================================
   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.
==============================================================================
              URL: http://s2k-ftp.CS.Berkeley.EDU:8000/postgres/



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


end of thread, other threads:[~1994-12-12 07:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1994-12-12 07:13 Re-sending - could someone please help ? SRIRAMK@charlie.usd.edu
1994-12-12 07:52 ` Paul M. Aoki <aoki@cs.berkeley.edu>

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