/**
  * Updates the index by running first queued deletions, then queued additions
  */
 public function CommitChanges()
 {
     foreach ($this->delete_queue as $sql) {
         $this->connection->query($sql);
     }
     foreach ($this->index_queue as $sql) {
         $this->connection->query($sql);
     }
 }
 /**
  * Gets the id of a user using an up-to-date auto-sign-in cookie if one is found
  * @return int User id if the cookie is found, null otherwise
  */
 public function TryAutoSignIn()
 {
     if (isset($_COOKIE['user']) and is_string($_COOKIE['user']) and $_COOKIE['user']) {
         $cookie = $this->ParseAutoSignInCookie($_COOKIE['user']);
         # Don't assume 'user' cookie was set by this site. Could be hacker value.
         if (isset($cookie['device']) and $cookie['device'] and isset($cookie['token']) and $cookie['token']) {
             $sql = "SELECT COUNT(user_id) AS total, user_id FROM nsa_auto_sign_in \r\n                WHERE device = " . Sql::ProtectNumeric($cookie['device']) . " \r\n                AND token = " . Sql::ProtectString($this->connection, $cookie['token']) . "\r\n                AND expires >= " . gmdate('U');
             $result = $this->connection->query($sql);
             $row = $result->fetch();
             if ($row and $row->total == 1) {
                 return (int) $row->user_id;
             }
         }
     }
     return null;
 }