in reply to Re^2: JSON::XS Cyrillic unicode not saving properly
in thread JSON::XS Cyrillic unicode not saving properly
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
use feature qw{ say };
use DBI;
use Encode;
for my $utf8 (1, -1, 0) {
my $string = $utf8 ? 'Кирилл цагаан толгой'
: encode('UTF-8', 'Кирилл цагаан толгой');
my $db = 'DBI'->connect('dbi:Pg:dbname=postgres', "", "");
say $db->{pg_enable_utf8} = $utf8;
$db->do('CREATE TABLE IF NOT EXISTS cyr (t TEXT)');
$db->do('DELETE FROM cyr');
my $insert = $db->prepare('INSERT INTO cyr (t) VALUES (?)');
$insert->execute($string);
my $select = $db->prepare('SELECT t FROM cyr');
$select->execute;
binmode *STDOUT, $utf8 ? ':encoding(UTF-8)' : ':raw';
while (my @row = $select->fetchrow_array) {
say @row;
}
}
The script needs to be saved as UTF-8.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: JSON::XS Cyrillic unicode not saving properly
by cormanaz (Deacon) on Mar 21, 2021 at 20:28 UTC | |
|
Re^4: JSON::XS Cyrillic unicode not saving properly
by cormanaz (Deacon) on Mar 21, 2021 at 23:36 UTC | |
by Anonymous Monk on Mar 22, 2021 at 04:40 UTC | |
by cormanaz (Deacon) on Mar 22, 2021 at 15:29 UTC | |
by cormanaz (Deacon) on Mar 22, 2021 at 15:33 UTC |