chiark / gitweb /
Store Unix timestamps in the database, rather than SQL ones.
[odin-cgi] / lib / Odin.pm
index a9bff5ad67bcaf05c1269f39f6f9eaaa837dcbfd..551c51f0e83cc7248baa176513a8df201c1af71b 100644 (file)
@@ -99,12 +99,10 @@ sub open_db (@) {
   my $drv = $db->{Driver}{Name};
   if ($drv eq "Pg") {
     $db->{private_odin_retry_p} = sub { $db->state =~ /^40[0P]01$/ };
-    $db->{private_odin_unixstamp} = sub { "extract(epoch from $_[0])" };
   } elsif ($drv eq "SQLite") {
     $db->{private_odin_retry_p} = sub { $db->err == 5 };
-    $db->{private_odin_unixstamp} = sub { "strftime('%s', $_[0])" };
   } else {
-    fail "unsupported database driver `$drv' (patches welcome)", undef;
+    $db->{private_odin_retry_p} = sub { 0 };
   }
 
   return $db;
@@ -131,10 +129,6 @@ sub xact (&$) {
   die $exc;
 }
 
-sub sql_timestamp ($$) {
-  my ($db, $col) = @_;
-  return $db->{private_odin_unixstamp}->($col);
-}
 
 ###--------------------------------------------------------------------------
 ### Sequence numbers and tagging.
@@ -267,8 +261,9 @@ sub new_shorturl ($) {
        undef, $WHOCMP, $url);
     unless (defined $tag) {
       $tag = encode_tag(next_seq($db, "odin_shorturl_seq"));
-      $db->do("INSERT INTO odin_shorturl (tag, owner, url) VALUES (?, ?, ?)",
-             undef, $tag, $WHO, $url);
+      $db->do("INSERT INTO odin_shorturl (tag, stamp, owner, url)
+              VALUES (?, ?, ?, ?)", undef,
+             $tag, $NOW, $WHO, $url);
     }
   } $db;
   return $tag;
@@ -331,9 +326,9 @@ sub new_pastebin (\%) {
   xact {
     $tag = encode_tag next_seq $db, "odin_pastebin_seq";
     $db->do("INSERT INTO odin_pastebin
-              (tag, edithash, owner, $PASTEBIN_PROPCOLS)
-            VALUES (?, ?, ?, $PASTEBIN_PROPPLACES)", undef,
-           $tag, $hash, $WHO, @{$new}{@PASTEBIN_PROPS});
+              (tag, stamp, edithash, owner, $PASTEBIN_PROPCOLS)
+            VALUES (?, ?, ?, ?, $PASTEBIN_PROPPLACES)", undef,
+           $tag, $NOW, $hash, $WHO, @{$new}{@PASTEBIN_PROPS});
   } $db;
   return $tag, $editkey;
 }