Created
October 17, 2014 17:07
-
-
Save 2shortplanks/51ef17828821a9a46974 to your computer and use it in GitHub Desktop.
Pg inserting weirdness
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use DBI; | |
| use Test::More; | |
| { | |
| my $dbh = DBI->connect("dbi:Pg:dbname=circonus;host=wdb3;port=5490",$ENV{USER},$ENV{PASSWORD}, { | |
| pg_enable_utf8 => 1, | |
| }); | |
| my $sth = $dbh->prepare("SELECT length('\x{e2}\x{98}\x{83}') AS snowman"); | |
| $sth->execute; | |
| my $row = $sth->fetchrow_hashref; | |
| my $snowman = $row->{snowman}; | |
| is($snowman, 1); | |
| } | |
| { | |
| my $dbh = DBI->connect("dbi:Pg:dbname=circonus;host=wdb3;port=5490",$ENV{USER},$ENV{PASSWORD}, { | |
| pg_enable_utf8 => 1, | |
| }); | |
| my $sth = $dbh->prepare("SELECT length('\x{e2}\x{98}\x{83}') AS snowman"); | |
| $sth->execute; | |
| my $row = $sth->fetchrow_hashref; | |
| my $snowman = $row->{snowman}; | |
| is($snowman, 1); | |
| } | |
| { | |
| my $dbh = DBI->connect("dbi:Pg:dbname=circonus;host=wdb3;port=5490",$ENV{USER},$ENV{PASSWORD}, { | |
| pg_enable_utf8 => 1, | |
| }); | |
| my $sth = $dbh->prepare("SELECT length('\x{e9}') AS snowman"); | |
| $sth->execute; | |
| my $row = $sth->fetchrow_hashref; | |
| my $snowman = $row->{snowman}; | |
| is($snowman, 1); | |
| } | |
| done_testing; | |
| __END__ | |
| ok 1 | |
| ok 2 | |
| DBD::Pg::st execute failed: ERROR: invalid byte sequence for encoding "UTF8": 0xe9 0x27 0x29 at foo.pl line 36. | |
| DBD::Pg::st fetchrow_hashref failed: no statement executing at foo.pl line 37. | |
| not ok 3 | |
| # Failed test at foo.pl line 39. | |
| # got: undef | |
| # expected: '1' | |
| 1..3 | |
| # Looks like you failed 1 test of 3. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment