[Slashdotjp-dev 543] CVS update: slashjp/Slash/DB/MySQL

Back to archive index

Tatsuki SUGIURA sugi****@users*****
2006年 7月 12日 (水) 21:24:21 JST


Index: slashjp/Slash/DB/MySQL/MySQL.pm
diff -u slashjp/Slash/DB/MySQL/MySQL.pm:1.10 slashjp/Slash/DB/MySQL/MySQL.pm:1.11
--- slashjp/Slash/DB/MySQL/MySQL.pm:1.10	Wed Jul 12 20:41:38 2006
+++ slashjp/Slash/DB/MySQL/MySQL.pm	Wed Jul 12 21:24:21 2006
@@ -1,7 +1,7 @@
 # This code is a part of Slash, and is released under the GPL.
 # Copyright 1997-2005 by Open Source Technology Group. See README
 # and COPYING for more information, or see http://slashcode.com/.
-# $Id: MySQL.pm,v 1.10 2006/07/12 11:41:38 sugi Exp $
+# $Id: MySQL.pm,v 1.11 2006/07/12 12:24:21 sugi Exp $
 
 package Slash::DB::MySQL;
 use strict;
@@ -15,11 +15,12 @@
 use URI ();
 use Slash::Custom::ParUserAgent;
 use vars qw($VERSION $_proxy_port);
+use Encode;
 use base 'Slash::DB';
 use base 'Slash::DB::Utility';
 use Slash::Constants ':messages';
 
-($VERSION) = ' $Revision: 1.10 $ ' =~ /\$Revision:\s+([^\s]+)/;
+($VERSION) = ' $Revision: 1.11 $ ' =~ /\$Revision:\s+([^\s]+)/;
 
 # Fry: How can I live my life if I can't tell good from evil?
 
@@ -49,6 +50,9 @@
 	'submission-state'
 		=> sub { $_[0]->sqlSelectMany('code,name', 'code_param', "type='submission-state'") },
 
+	'days_of_week'
+		=> sub { $_[0]->sqlSelectMany('code,name', 'code_param', "type='days_of_week'") },
+
 	'months'
 		=> sub { $_[0]->sqlSelectMany('code,name', 'code_param', "type='months'") },
 
@@ -291,6 +295,27 @@
 }
 
 ########################################################
+# Tell server to send us data in UTF-8 encoding, also
+# tell data base handle to set utf8 flag on all strings
+# (blindly assuming MySQL 4.1 and patched DBD::MySQL for now)
+sub sqlConnect{
+	my($self) = @_;
+	$self->SUPER::sqlConnect();
+	$self->{_dbh}->{mysql_enable_utf8} = 1;
+	$self->{_dbh}->do( "SET NAMES utf8");
+}
+
+########################################################
+# make sure UTF-8 flag is set before we send query to
+# MySQL, assuming all data is actually UTF-8 and only
+# Perl has lost the flag somewhere
+sub sqlDo{
+	my($self, $sql) = @_;
+	$sql = decode_utf8( $sql ) unless $sql =~ /INSERT\s+INTO\s+accesslog_admin|UPDATE\s+users_info\s+SET\s+people\s+=/;
+	$self->SUPER::sqlDo( $sql );
+}
+  
+########################################################
 # Yes, this is ugly, and we can ditch it in about 6 months
 # Turn off autocommit here
 sub sqlTransactionStart {
@@ -318,7 +343,7 @@
 	return -1 unless dbAvailable("write_comments");
 	my $comment_text = $comment->{comment};
 	delete $comment->{comment};
-	$comment->{signature} = md5_hex($comment_text);
+	$comment->{signature} = md5_hex(encode_utf8($comment_text));
 	$comment->{-date} = 'NOW()';
 	$comment->{len} = length($comment_text);
 	$comment->{pointsorig} = $comment->{points} || 0;
@@ -1927,7 +1952,7 @@
 	# To help cut down on duplicates generated by automated routines. For
 	# crapflooders, we will need to look into an alternate methods.
 	# Filters of some sort, maybe?
-	$data->{signature} = md5_hex($data->{story});
+	$data->{signature} = md5_hex(encode_utf8($data->{story}));
 
 	$self->sqlInsert('submissions', $data);
 	my $subid = $self->getLastInsertId;
@@ -6600,7 +6625,7 @@
 sub findCommentsDuplicate {
 	my($self, $sid, $comment) = @_;
 	my $sid_quoted = $self->sqlQuote($sid);
-	my $signature_quoted = $self->sqlQuote(md5_hex($comment));
+	my $signature_quoted = $self->sqlQuote(md5_hex(encode_utf8($comment)));
 	return $self->sqlCount('comments', "sid=$sid_quoted AND signature=$signature_quoted");
 }
 


Slashdotjp-dev メーリングリストの案内
Back to archive index