using $dbh->quote with UTF
using $dbh->quote with UTF
am 18.10.2007 02:04:29 von Len
Hello,
I'm trying to use $dbh->quote with a UTF string, and I'm not having
luck. How can I get it to return a UTF8 string?
Here is my example:
#!/usr/bin/perl -w
use strict;
use DBI;
my $dbh =3D DBI->connect("DBI:mysql:mysql", "root", "");
my $string =3D "test äñèé";
utf8::upgrade($string);
my $sqlutfstring =3D $dbh->quote($string);
print qq~
UTF Quote Test
~;
print $string . " == " . $sqlutfstring;
print qq~
~;
Re: using $dbh->quote with UTF
am 18.10.2007 10:02:28 von Martin.Evans
len@winequest.com wrote:
> Hello,
>
> I'm trying to use $dbh->quote with a UTF string, and I'm not having
> luck. How can I get it to return a UTF8 string?
>
> Here is my example:
>
> #!/usr/bin/perl -w
> use strict;
Add use warnings;
> use DBI;
>
> my $dbh = DBI->connect("DBI:mysql:mysql", "root", "");
> my $string = "test äñèé";
> utf8::upgrade($string);
>
> my $sqlutfstring = $dbh->quote($string);
> print qq~
>
>
>
> UTF Quote Test
>
>
> ~;
> print $string . " == " . $sqlutfstring;
> print qq~
>
>
> ~;
>
>
If you add use warnings I suspect your print will issue:
Wide character in print at xxx, which might have given you the clue that
I believe you should do binmode(STDOUT, ":utf8") before you print.
quote seems to work for me:
perl -e 'use DBI
qw(neat);$h=DBI->connect("dbi:Oracle:XE","xxx","yyy");$x="\x {20ac}";open
OUT, ">x.x";binmode(OUT,":utf8");print OUT $x;close OUT;print neat($x);'
""
and as neat has put double quotes around the Euro, then DBI thinks it is
a unicode character too.
Martin
--
Martin J. Evans
Easysoft Limited
http://www.easysoft.com
Re: using $dbh->quote with UTF
am 20.10.2007 15:50:06 von Len
I added "use warnings;" to my code, but there was no behavior change.
So your suggestion is to NOT use $dbh->quote ad use print neat
instead? Is there a way to use $dbh->quote and get a UTF-8 result?
Re: using $dbh->quote with UTF
am 21.10.2007 18:07:48 von hjp
--rwEMma7ioTxnRzrJ
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
On 2007-10-17 17:04:29 -0700, len@winequest.com wrote:
> I'm trying to use $dbh->quote with a UTF string, and I'm not having
> luck. How can I get it to return a UTF8 string?
[script printing some HTML snipped]
Please explain what you are trying to do. Using the output of quote in
an HTML fragment doesn't seem very useful to me. I can only assume that
you are doing it to demonstrate something but I don't understand what
you are trying to demonstrate.
hp
--=20
_ | Peter J. Holzer | If I wanted to be "academically correct",
|_|_) | Sysadmin WSR | I'd be programming in Java.
| | | hjp@wsr.ac.at | I don't, and I'm not.
__/ | http://www.hjp.at/ | -- Jesse Erlbaum on dbi-users
--rwEMma7ioTxnRzrJ
Content-Type: application/pgp-signature
Content-Disposition: inline
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHG3lUMdFfQa64PCwRAva6AKCLuuYitIWPAdJWZk05Xp7lJZXl4gCf TFzw
P0tkkZTCo5riADIFPzWHLzw=
=08Lf
-----END PGP SIGNATURE-----
--rwEMma7ioTxnRzrJ--
Re: using $dbh->quote with UTF
am 22.10.2007 07:08:57 von Len
Sorry this wasn't clear from the example. Yes printing to HTML was
just an example. What I am trying to do is quote a string, us that to
form a SQL statement, then send that to the mySQL server. When I do
that now, the string has extra characters in it because $dbh->quote is
losing the utf flag.
Re: using $dbh->quote with UTF
am 22.10.2007 17:55:37 von Tim.Bunce
On Sun, Oct 21, 2007 at 10:08:57PM -0700, len@winequest.com wrote:
> Sorry this wasn't clear from the example. Yes printing to HTML was
> just an example. What I am trying to do is quote a string, us that to
> form a SQL statement, then send that to the mySQL server. When I do
> that now, the string has extra characters in it because $dbh->quote is
> losing the utf flag.
Perhaps your DBD::mysql driver is an old version. The latest certainly
has code to pass through the utf8 flag.
Tim.
Re: using $dbh->quote with UTF
am 23.10.2007 09:45:45 von Len
That was it: it was an old version of DBD:mysql. Sorry for wasting
all your time. My PPM thought the latest version was 3.00x. I don't
know why it didn't see 4.00x
(Fwd) RE: using $dbh->quote with UTF
am 23.10.2007 10:30:28 von Tim.Bunce
----- Forwarded message from "Schultz, Len" -----
Subject: RE: using $dbh->quote with UTF
Date: Tue, 23 Oct 2007 01:52:49 -0400
From: "Schultz, Len"
To: Tim Bunce
Hello Tim,
I thought there should be a fix for this. When I run PPM, it says there
is no update available. My current version is:
DBD-mysql 3.0002: up to date
It appears to be an older version. I wonder why PPM isn't finding the
newer version. Do I have to use CPAN? I always have problems when it
tries to run make...
--len
----- End forwarded message -----
----- Forwarded message from "Schultz, Len" -----
Subject: RE: using $dbh->quote with UTF
Date: Tue, 23 Oct 2007 02:12:30 -0400
From: "Schultz, Len"
To: Tim Bunce
Tim,
I used ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-mysql.ppd, and
it worked. For some reason, ppm install DBD::mysql was not finding the
latest version.
Thanks.
--len
----- End forwarded message -----
Re: (Fwd) RE: using $dbh->quote with UTF
am 29.10.2007 21:47:30 von listinfo
[8<]
> When I run PPM, it says there
> is no update available. My current version is:
>
> DBD-mysql 3.0002: up to date> I used ppm install http://theoryx5.uwinnipeg.ca/ppms/DBD-mysql.ppd, and
> it worked. For some reason, ppm install DBD::mysql was not finding the
> latest version.
Probably because you need to add some more current/useful repositories.
ppm repo list
ââââââ¬âââââââ¬âââââââ ââââââââââââââââââââ ââââââ
â id â pkgs â name â
ââââââ¼âââââââ¼âââââââ ââââââââââââââââââââ ââââââ¤
â 1 â 6933 â ActiveState Package Repository â
â 2 â 420 â bribes â
â 3 â 650 â kobes-theoryx5 â
ââââââ´âââââââ´âââââââ ââââââââââââââââââââ ââââââ
(3 enabled repositories)
ppm s DBD::mysql
1: DBD-mysql
A MySQL driver for the Perl5 Database Interface (DBI)
Version: 3.0002
Repo: ActiveState Package Repository
2: DBD-mysql
A MySQL driver for the Perl5 Database Interface (DBI)
Version: 4.005
Repo: kobes-theoryx5
HTH
--
Michael Higgins