Re: [PATCH][RESUBMIT] mysql_db_quote + UTF8 flagged strings
"Ruslan U. Zakirov" <[email protected]>
| Newsgroups | gmane.comp.db.mysql.perl |
|---|---|
| Message-ID | <[email protected]> |
Rudy Lippan wrote: > On Wed, 25 Aug 2004, Ruslan U. Zakirov wrote: > > >>Attached patch fix problems for users of perl5.8.x when somebody try >>quote strings with UTF8 flag enabled: > > > After a quick look over, it looks good, so I'll put this in the next version. > Do you, by chance, have a test script to go with the patch? > > > >>PS. May be PERL_VERSION check should be changed to right values, I don't >>know when exactly UTF8 flag was introduced. > > > We will find out in testing, right :) > > > Thank you, > > Rudy lippan. > > -- MySQL Perl Mailing List For list archives: http://lists.mysql.com/perl To unsubscribe: http://lists.mysql.com/[email protected]
mysql_quote_utf_fix.patch
(application/aegis-patch, 3.4 KB)
diff -Nru DBD-mysql-2.9003/dbdimp.c DBD-mysql-2.9003-my/dbdimp.c
--- DBD-mysql-2.9003/dbdimp.c 2003-10-17 21:20:50.000000000 +0400
+++ DBD-mysql-2.9003-my/dbdimp.c 2004-05-03 21:12:41.000000000 +0400
@@ -2449,6 +2449,10 @@
*sptr++ = '\0'; /* Never hurts NUL terminating a Perl
* string ...
*/
+#if ((PERL_REVISION >= 5) && (PERL_VERSION >= 8))
+ if(SvUTF8(str))
+ SvUTF8_on(result);
+#endif
}
return result;
}
diff -Nru DBD-mysql-2.9003/MANIFEST DBD-mysql-2.9003-my/MANIFEST
--- DBD-mysql-2.9003/MANIFEST 2003-06-16 10:07:07.000000000 +0400
+++ DBD-mysql-2.9003-my/MANIFEST 2004-08-25 17:28:04.000000000 +0400
@@ -28,6 +28,7 @@
t/insertid.t
t/mysql.dbtest
t/mysql.mtest
+t/40quote.t
dbdimp.h
constants.h
lib/Mysql.pm
diff -Nru DBD-mysql-2.9003/t/40listfields.t DBD-mysql-2.9003-my/t/40listfields.t
--- DBD-mysql-2.9003/t/40listfields.t 2003-10-22 22:29:35.000000000 +0400
+++ DBD-mysql-2.9003-my/t/40listfields.t 2004-08-25 17:42:05.000000000 +0400
@@ -133,18 +133,4 @@
or !$verbose or printf("NUM_OF_FIELDS is %s, not zero.\n",
$cursor->{'NUM_OF_FIELDS'});
Test($state or (undef $cursor) or 1);
-
- #
- # Test different flavours of quote. Need to work around a bug in
- # DBI 1.02 ...
- #
- my $quoted;
- if (!$state) {
- $quoted = eval { $dbh->quote(0, DBI::SQL_INTEGER()) };
- }
- Test($state or $@ or $quoted eq 0);
- if (!$state) {
- $quoted = eval { $dbh->quote('abc', DBI::SQL_VARCHAR()) };
- }
- Test($state or $@ or $quoted eq q{'abc'});
}
diff -Nru DBD-mysql-2.9003/t/40quote.t DBD-mysql-2.9003-my/t/40quote.t
--- DBD-mysql-2.9003/t/40quote.t 1970-01-01 03:00:00.000000000 +0300
+++ DBD-mysql-2.9003-my/t/40quote.t 2004-08-25 17:54:16.000000000 +0400
@@ -0,0 +1,72 @@
+#!/usr/local/bin/perl
+#
+# This is a test for quote call
+#
+
+
+#
+# Make -w happy
+#
+$test_dsn = '';
+$test_user = '';
+$test_password = '';
+
+
+#
+# Include lib.pl
+#
+use DBI;
+use vars qw($verbose);
+
+$mdriver = "";
+foreach $file ("lib.pl", "t/lib.pl") {
+ do $file; if ($@) { print STDERR "Error while executing lib.pl: $@\n";
+ exit 10;
+ }
+ if ($mdriver ne '') {
+ last;
+ }
+}
+
+sub ServerError() {
+ print STDERR ("Cannot connect: ", $DBI::errstr, "\n",
+ "\tEither your server is not up and running or you have no\n",
+ "\tpermissions for acessing the DSN $test_dsn.\n",
+ "\tThis test requires a running server and write permissions.\n",
+ "\tPlease make sure your server is running and you have\n",
+ "\tpermissions, then retry.\n");
+ exit 10;
+}
+
+#
+# Main loop; leave this untouched, put tests after creating
+# the new table.
+#
+while (Testing()) {
+ #
+ # Connect to the database
+ Test($state or $dbh = DBI->connect($test_dsn, $test_user, $test_password))
+ or ServerError();
+
+ # Test different flavours of quote. Need to work around a bug in
+ # DBI 1.02 ...
+ #
+
+ my $quoted;
+ if (!$state) {
+ $quoted = eval { $dbh->quote(0, DBI::SQL_INTEGER()) };
+ }
+ Test($state or $@ or $quoted eq 0);
+ if (!$state) {
+ $quoted = eval { $dbh->quote('abc', DBI::SQL_VARCHAR()) };
+ }
+ Test($state or $@ or $quoted eq q{'abc'});
+
+ eval { require Encode; };
+ unless( $@ ) {
+ if (!$state) {
+ $quoted = eval { $dbh->quote("\x{442}\x{435}\x{441}\x{442}", DBI::SQL_VARCHAR()) };
+ }
+ Test($state or $@ or (Encode::is_utf8($quoted) and $quoted eq "'\x{442}\x{435}\x{441}\x{442}'"));
+ }
+}