public function beforeCall($proxied, $method, $args, &$alternateReturn)
 {
     // we only query on the write DB if it's a write query, OR we've performed a write
     // by some other means
     if ($method == 'query') {
         if (isset($args[0])) {
             $sql = $args[0];
             $code = isset($args[1]) ? $args[1] : E_USER_ERROR;
             if (in_array(strtolower(substr($sql, 0, strpos($sql, ' '))), $this->writeQueries) || $this->writePerformed) {
                 $alternateReturn = $this->writeDb->query($sql, $code);
                 $this->writePerformed = true;
                 return false;
             }
         }
     } else {
         $i = call_user_func_array(array($this->writeDb, $method), $args);
         // capture a call to manipulate, which basically performs a bunch of write queries
         // at once
         if ($method == 'manipulate') {
             $this->writePerformed = true;
         }
         $alternateReturn = $i;
         return false;
     }
 }
 /**
  * Execute the given SQL query.
  * This abstract function must be defined by subclasses as part of the actual implementation.
  * It should return a subclass of SS_Query as the result.
  *
  * @param string $sql The SQL query to execute
  * @param int $errorLevel The level of error reporting to enable for the query
  * @return SS_Query
  */
 public function query($sql, $errorLevel = E_USER_ERROR)
 {
     return $this->database->query($sql, $errorLevel);
 }