--- MySQL.pm_org	2024-04-02 14:45:26.000000000 +0900
+++ MySQL.pm_patch	2024-10-05 17:15:36.900236567 +0900
@@ -1107,7 +1107,8 @@ sub _put_tokens {
     $self->{needs_cleanup} = 1;
 
     my $sql = "UPDATE bayes_token SET spam_count = GREATEST(spam_count + ?, 0),
-                                      ham_count = GREATEST(ham_count + ?, 0)
+                                      ham_count = GREATEST(ham_count + ?, 0),
+                                      tokenstring = ?
                 WHERE id = ?
                   AND token = ?";
 
@@ -1121,12 +1122,15 @@ sub _put_tokens {
 
     $sth->bind_param(1, $spam_count);
     $sth->bind_param(2, $ham_count);
-    $sth->bind_param(3, $self->{_userid});
-    # 4, update token in foreach loop
+    $sth->bind_param(4, $self->{_userid});
+    # 5, update token in foreach loop
 
     my $error_p = 0;
-    foreach my $token (keys %{$tokens}) {
-      $sth->bind_param(4, $token, DBI::SQL_BINARY);
+    while (my ($token, $value) = each(%{$tokens})){
+      $sth->bind_param(3, $value);
+      $sth->bind_param(5, $token, DBI::SQL_BINARY);
+      my $hextoken = unpack("H*", $token);
+      dbg("bayes: Database store Key Update: $hextoken, Value: $value"); 
       my $rc = $sth->execute();
 
       unless ($rc) {
@@ -1144,11 +1148,12 @@ sub _put_tokens {
   }
   else {
     my $sql = "INSERT INTO bayes_token
-               (id, token, spam_count, ham_count, atime)
-               VALUES (?,?,?,?,?)
+               (id, token, spam_count, ham_count, atime, tokenstring)
+               VALUES (?,?,?,?,?,?)
                ON DUPLICATE KEY UPDATE spam_count = GREATEST(spam_count + ?, 0),
                                        ham_count = GREATEST(ham_count + ?, 0),
-                                       atime = GREATEST(atime, ?)";
+                                       atime = GREATEST(atime, ?),
+                                       tokenstring = ?";
 
     my $sth = $self->{_dbh}->prepare_cached($sql);
 
@@ -1163,15 +1168,19 @@ sub _put_tokens {
     $sth->bind_param(3, $spam_count);
     $sth->bind_param(4, $ham_count);
     $sth->bind_param(5, $atime);
-    $sth->bind_param(6, $spam_count);
-    $sth->bind_param(7, $ham_count);
-    $sth->bind_param(8, $atime);
+    $sth->bind_param(7, $spam_count);
+    $sth->bind_param(8, $ham_count);
+    $sth->bind_param(9, $atime);
 
     my $error_p = 0;
     my $new_tokens = 0;
     my $need_atime_update_p = 0;
-    foreach my $token (keys %{$tokens}) {
+    while (my ($token, $value) = each(%{$tokens})){
       $sth->bind_param(2, $token, DBI::SQL_BINARY);
+      $sth->bind_param(6, $value);
+      $sth->bind_param(10, $value);
+      my $hextoken = unpack("H*", $token);
+      dbg("bayes: Database store Key Insert: $hextoken, Value: $value"); 
       my $rc = $sth->execute();
 
       if (!$rc) {
