Пример #1
0
 /**
  * Tests FUSE and lists, FUSE enforces no more than
  * 3 sugar cubes in coffee.
  *
  * @return void
  */
 public function testCoffeeWithSugarAndFUSE()
 {
     $coffee = R::dispense('coffee');
     $coffee->size = 'XL';
     $coffee->ownSugar = R::dispense('sugar', 5);
     $id = R::store($coffee);
     $coffee = R::load('coffee', $id);
     asrt(count($coffee->ownSugar), 3);
     $coffee->ownSugar = R::dispense('sugar', 2);
     $id = R::store($coffee);
     $coffee = R::load('coffee', $id);
     asrt(count($coffee->ownSugar), 2);
     $cocoa = R::dispense('cocoa');
     $cocoa->name = 'Fair Cocoa';
     list($taste1, $taste2) = R::dispense('taste', 2);
     $taste1->name = 'sweet';
     $taste2->name = 'bitter';
     $cocoa->ownTaste = array($taste1, $taste2);
     R::store($cocoa);
     $cocoa->name = 'Koko';
     R::store($cocoa);
     if (method_exists(R::getDatabaseAdapter()->getDatabase(), 'getPDO')) {
         $pdo = R::getDatabaseAdapter()->getDatabase()->getPDO();
         $driver = new RPDO($pdo);
         pass();
         asrt($pdo->getAttribute(\PDO::ATTR_ERRMODE), \PDO::ERRMODE_EXCEPTION);
         asrt($pdo->getAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE), \PDO::FETCH_ASSOC);
         asrt(strval($driver->GetCell('select 123')), '123');
     }
     $a = new SQL();
     $a->setSqlState('test');
     $b = strval($a);
     asrt(strpos($b, '[test] - ') === 0, TRUE);
 }
Пример #2
0
Файл: rb.php Проект: WTer/NJB
 /**
  * This method runs the actual SQL query and binds a list of parameters to the query.
  * slots. The result of the query will be stored in the protected property
  * $rs (always array). The number of rows affected (result of rowcount, if supported by database)
  * is stored in protected property $affectedRows. If the debug flag is set
  * this function will send debugging output to screen buffer.
  *
  * @param string $sql      the SQL string to be send to database server
  * @param array  $bindings the values that need to get bound to the query slots
  *
  * @return void
  */
 protected function runQuery($sql, $bindings, $options = array())
 {
     $this->connect();
     if ($this->loggingEnabled && $this->logger) {
         $this->logger->log($sql, $bindings);
     }
     try {
         if (strpos('pgsql', $this->dsn) === 0) {
             if (defined('\\PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT')) {
                 $statement = $this->pdo->prepare($sql, array(\PDO::PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT => TRUE));
             } else {
                 $statement = $this->pdo->prepare($sql);
             }
         } else {
             $statement = $this->pdo->prepare($sql);
         }
         $this->bindParams($statement, $bindings);
         $statement->execute();
         $this->queryCounter++;
         $this->affectedRows = $statement->rowCount();
         if ($statement->columnCount()) {
             $fetchStyle = isset($options['fetchStyle']) ? $options['fetchStyle'] : NULL;
             if (isset($options['noFetch']) && $options['noFetch']) {
                 $this->resultArray = array();
                 return $statement;
             }
             $this->resultArray = $statement->fetchAll($fetchStyle);
             if ($this->loggingEnabled && $this->logger) {
                 $this->logger->log('resultset: ' . count($this->resultArray) . ' rows');
             }
         } else {
             $this->resultArray = array();
         }
     } catch (\PDOException $e) {
         //Unfortunately the code field is supposed to be int by default (php)
         //So we need a property to convey the SQL State code.
         $err = $e->getMessage();
         if ($this->loggingEnabled && $this->logger) {
             $this->logger->log('An error occurred: ' . $err);
         }
         $exception = new SQL($err, 0);
         $exception->setSQLState($e->getCode());
         throw $exception;
     }
 }
Пример #3
0
 public function get($sql, $values = array())
 {
     $exception = new SQL('Just a trouble maker');
     $exception->setSQLState($this->sqlState);
     throw $exception;
 }