Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[ljcom] r9774: do not allow this SQL query to crash

Committer: ailyin
do not allow this SQL query to crash
U   trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm	2010-11-30 12:31:15 UTC (rev 9773)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/PaidAccount.pm	2010-12-01 05:01:48 UTC (rev 9774)
@@ -378,10 +378,16 @@
         $add_sql = "DATE_ADD(NOW(), INTERVAL $qtv $units)";
     }
 
-    $dbh->do("INSERT INTO paiduser (userid, paiduntil) VALUES (?, $add_sql)",
-             undef, $userid);
-    if ($dbh->err) {
+    my $affected_rows = int $dbh->do(qq{
+        INSERT IGNORE
+        INTO paiduser
+        (userid, paiduntil)
+        VALUES
+        (?, $add_sql)
+    }, undef, $userid);
 
+    unless ($affected_rows) {
+
         $add_sql = "DATE_ADD(GREATEST(IFNULL(paiduntil, NOW()), NOW()), INTERVAL $qtv $units)"
             unless $units eq 'epoch';
 

Tags: andy, ljcom, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments