Beispiel #1
0
 /**
  * Gets information about changed records using a type and id and a logid.
  * RedBean Locking shields you from race conditions by comparing the latest
  * cached insert id with a the highest insert id associated with a write action
  * on the same table. If there is any id between these two the record has
  * been changed and RedBean will throw an exception. This function checks for changes.
  * If changes have occurred it will throw an exception. If no changes have occurred
  * it will insert a new change record and return the new change id.
  * This method locks the log table exclusively.
  * @param  string $type
  * @param  integer $id
  * @param  integer $logid
  * @return integer $newchangeid
  */
 public function checkChanges($type, $id, $logid)
 {
     $type = $this->writer->check($type);
     $id = (int) $id;
     $logid = (int) $logid;
     $num = $this->adapter->getCell("\n        SELECT count(*) FROM __log WHERE tbl=\"{$type}\" AND itemid={$id} AND action=2 AND id > {$logid}");
     if ($num) {
         throw new RedBean_Exception_FailedAccessBean("Locked, failed to access (type:{$type}, id:{$id})");
     }
     $this->adapter->exec("INSERT INTO __log (id,action,tbl,itemid) VALUES(NULL, 2,:tbl,:id)", array(":tbl" => $type, ":id" => $id));
     $newid = $this->adapter->getInsertID();
     if ($this->adapter->getCell("select id from __log where tbl=:tbl AND id < {$newid} and id > {$logid} and action=2 and itemid={$id} ", array(":tbl" => $type))) {
         throw new RedBean_Exception_FailedAccessBean("Locked, failed to access II (type:{$type}, id:{$id})");
     }
     return $newid;
 }
 /**
  * Magic method to construct SQL query.
  * Accepts any kind of message and turns it into an SQL statement and
  * adds it to the query string.
  * If camelcase is set to TRUE camelCase transitions will be turned into spaces.
  * Underscores will be replaced with spaces as well.
  * Arguments will be imploded using a comma as glue character and are also added
  * to the query.
  *
  * If capture mode is on, this method returns a reference to itself allowing
  * chaining.
  *
  * If capture mode if off, this method will immediately exceute the resulting
  * SQL query and return a string result.
  *
  * @param string $funcName name of the next SQL statement/keyword
  * @param array  $args     list of statements to be seperated by commas
  *
  * @return string|RedBean_SQLHelper
  */
 public function __call($funcName, $args = array())
 {
     if (self::$flagUseCamelCase) {
         static $funcCache = array();
         if (!isset($funcCache[$funcName])) {
             $funcCache[$funcName] = strtolower(preg_replace('/(?<=[a-z])([A-Z])|([A-Z])(?=[a-z])/', '_$1$2', $funcName));
         }
         $funcName = $funcCache[$funcName];
     }
     $funcName = str_replace('_', ' ', $funcName);
     if ($this->capture) {
         $this->sql .= ' ' . $funcName . ' ' . implode(',', $args);
         return $this;
     } else {
         return $this->adapter->getCell('SELECT ' . $funcName . '(' . implode(',', $args) . ')');
     }
 }
Beispiel #3
0
 /**
  * Magic method to construct SQL query
  * 
  * @param string $funcName name of the next SQL statement/keyword
  * @param array  $args     list of statements to be seperated by commas
  * 
  * @return mixed $result   either self or result depending on mode 
  */
 public function __call($funcName, $args = array())
 {
     $funcName = str_replace('_', ' ', $funcName);
     if ($this->capture) {
         $this->sql .= ' ' . $funcName . ' ' . implode(',', $args);
         return $this;
     } else {
         return $this->adapter->getCell('SELECT ' . $funcName . '(' . implode(',', $args) . ')');
     }
 }
 /**
  * Log queries
  *
  * @param string          $event
  * @param RedBean_Adapter $info
  */
 public function onEvent($event, $info)
 {
     $this->queries[] = $info->getSQL();
 }
 /**
  * Drops all tables in database
  */
 public function wipeAll()
 {
     $this->adapter->exec("\n\t\t\tBEGIN\n\n\t\t\t--Bye Sequences!\n\t\t\tFOR i IN (SELECT us.sequence_name\n\t\t\t\t\t\tFROM USER_SEQUENCES us) LOOP\n\t\t\t\tEXECUTE IMMEDIATE 'drop sequence \"'|| i.sequence_name ||'\"';\n\t\t\tEND LOOP;\n\n\t\t\t--Bye Tables!\n\t\t\tFOR i IN (SELECT ut.table_name\n\t\t\t\t\t\tFROM USER_TABLES ut) LOOP\n\t\t\t\tEXECUTE IMMEDIATE 'drop table \"'|| i.table_name ||'\" CASCADE CONSTRAINTS ';\n\t\t\tEND LOOP;\n\n\t\t\tEND;");
 }