[SQL] Problem with LATIN1 characters from Perl-DBI

2004-09-07 Thread Andreas Joseph Krogh
Hi.
I have a database created with -E LATIN1. Inserting norwegian characters lik 
'ø' works perfectly from JDBC, but from Perl, it stores the word 'søker' as 
'søker'(UNICODE).

perl --version:
This is perl, v5.8.3 built for i386-linux-thread-multi
A Mandrake-10 Linux system.

I first had the problem printing out LATIN1 chars to stdout too, but solved 
that by using the pragma
use encoding 'ISO-8859-1';

I've tried:
$dbh->do("set CLIENT_ENCODING TO 'ISO-8859-1'") 
or die("Couldn't set encoding to ISO-8859-1");
but that didn't work.

Any hints anyone?

-- 
Andreas Joseph Krogh <[EMAIL PROTECTED]>
Senior Software Developer / Manager
gpg public_key: http://dev.officenet.no/~andreak/public_key.asc
+-+
OfficeNet AS| Two tomatoes in a fridge. One tomato says   |
Hoffsveien 17   | to the other, "It's cold in here, isn't it?"|
PO. Box 425 Skøyen  | The other tomato says, "F**king hell,   |
0213 Oslo   | a talking tomato!"  |
NORWAY  | |
Phone : +47 22 13 01 00 | |
Direct: +47 22 13 10 03 | |
Mobile: +47 909  56 963 | |
+-+



pgpl5sdpAFxjq.pgp
Description: PGP signature


Re: [SQL] Problem with LATIN1 characters from Perl-DBI

2004-09-07 Thread Andreas Joseph Krogh
On Tuesday 07 September 2004 14:06, you wrote:
> Hi.
> I have a database created with -E LATIN1. Inserting norwegian characters
> lik 'ø' works perfectly from JDBC, but from Perl, it stores the word
> 'søker' as 'søker'(UNICODE).
>
> perl --version:
> This is perl, v5.8.3 built for i386-linux-thread-multi
> A Mandrake-10 Linux system.
>
> I first had the problem printing out LATIN1 chars to stdout too, but solved
> that by using the pragma
> use encoding 'ISO-8859-1';
>
> I've tried:
> $dbh->do("set CLIENT_ENCODING TO 'ISO-8859-1'")
> or die("Couldn't set encoding to ISO-8859-1");
> but that didn't work.
>
> Any hints anyone?

Replying to my self:

I fixed it by using the following:
use encoding 'ISO-8859-1';
use Unicode::MapUTF8 qw(to_utf8 from_utf8 utf8_supported_charset);

$tmp_text = from_utf8({ -string => $plain_text, -charset => 'ISO-8859-1' });
$retval = $insert_stmt->execute($tmp_text);

The problem was that the contents of $plain_text was obtained by some library 
which returned text in utf8. When printing it out to stdout, the 'use 
encoding' pragma took care of the conversion, but that didn't work for 
inserting the contents of $plain_text into the database. So I must convert it 
to latin1 using the from_utf8 subroutine *before* inserting it into the DB.

-- 
Andreas Joseph Krogh <[EMAIL PROTECTED]>
Senior Software Developer / Manager
gpg public_key: http://dev.officenet.no/~andreak/public_key.asc
+-+
OfficeNet AS| Two tomatoes in a fridge. One tomato says   |
Hoffsveien 17   | to the other, "It's cold in here, isn't it?"|
PO. Box 425 Skøyen  | The other tomato says, "F**king hell,   |
0213 Oslo   | a talking tomato!"  |
NORWAY  | |
Phone : +47 22 13 01 00 | |
Direct: +47 22 13 10 03 | |
Mobile: +47 909  56 963 | |
+-+



pgpjEketBA8Lk.pgp
Description: PGP signature


[SQL] Problem with returning setof record

2004-09-07 Thread oliverp21
Hello,

Here is a simple function I created for a test.

create function ttt() returns setof record as '
declare
r record;
begin
for r in select * from utilisateurs.menus loop
   return next r;
end loop;
return;
end;
' language 'plpgsql';

When I try to use it, it returns to me :

select ttt();
 set-valued function called in context that cannot accept a set
:  PL/pgSQL function "ttt" line 5 at return next

Anyone has an idea ?

Best regards,
Patrice OLIVER

---(end of broadcast)---
TIP 4: Don't 'kill -9' the postmaster


Re: [SQL] Problem with returning setof record

2004-09-07 Thread Richard Huxton
[EMAIL PROTECTED] wrote:
Hello,
Here is a simple function I created for a test.
create function ttt() returns setof record as '

When I try to use it, it returns to me :
select ttt();
 set-valued function called in context that cannot accept a set
:  PL/pgSQL function "ttt" line 5 at return next
Anyone has an idea ?
You need to treat it like a table:
  SELECT * FROM ttt();
Also, I'm not sure you can return a setof anonymous record types (unless 
you can specify the structure in the select).
Try CREATE FUNCTION...RETURNS SETOF utilisateurs.menus

If there's no appropriate table you can use CREATE TYPE to create a 
structure.
--
  Richard Huxton
  Archonet Ltd

---(end of broadcast)---
TIP 1: subscribe and unsubscribe commands go to [EMAIL PROTECTED]