X-Original-To: pgsql-interfaces-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 50D0C3A1911 for ; Sun, 19 Dec 2004 01:17:07 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 04539-02 for ; Sun, 19 Dec 2004 01:17:00 +0000 (GMT) Received: from hotmail.com (bay10-f27.bay10.hotmail.com [64.4.37.27]) by svr1.postgresql.org (Postfix) with ESMTP id 40EAD3A190C for ; Sun, 19 Dec 2004 01:17:02 +0000 (GMT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sat, 18 Dec 2004 17:17:01 -0800 Message-ID: Received: from 62.178.117.119 by by10fd.bay10.hotmail.msn.com with HTTP; Sun, 19 Dec 2004 01:16:44 GMT X-Originating-IP: [62.178.117.119] X-Originating-Email: [seppwimmer@hotmail.com] X-Sender: seppwimmer@hotmail.com From: "Robert Wimmer" To: pgsql-interfaces@postgresql.org Subject: type text in c functions Date: Sun, 19 Dec 2004 01:16:44 +0000 Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed X-OriginalArrivalTime: 19 Dec 2004 01:17:01.0811 (UTC) FILETIME=[71942430:01C4E568] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.975 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER X-Spam-Level: X-Archive-Number: 200412/43 X-Sequence-Number: 5213 i tried to write a simple typechecking function in c. but it does not work correct -- CODE -- #include #include #include PG_FUNCTION_INFO_V1(text_to_card); Datum text_to_card(PG_FUNCTION_ARGS) { int i,l; int32 ret; text *t = PG_GETARG_TEXT_P(0); l = VARSIZE(t) - VARHDRSZ; for (i = 0; i < l; i++) { if ( (t->vl_dat[i] < '0') || (t->vl_dat[i] > '9')) break; } if (i==l) ret = 0; else ret = i; PG_RETURN_INT32(ret); } --END -- this function should check if it is possible to cast a TEXT in an unsigned INTEGER. if OK it returns 0 otherwise the position in the string where the error occured. ( so you can produce error messages like ERROR[234] text_to_card('paramete') failed at <3>) i assumed - after reading the corresponding header files and docs and google - the type structure of a text as above. i only get zeros and ones as result the algorithm works fine in 'normal' c. is there a possibilty to treat a TEXT parameter like a char array ? thanks and regards sepp _________________________________________________________________ Schaffen Sie das Platzproblem in Ihrem E-Mail-Konto für immer aus der Welt! http://join.msn.com/?pgmarket=de-at&DI=1031&XAPID=1581