Beispiel #1
0
 /**
  * @param	string	$sql
  * @param	string	$type
  * @param	string	$stategy
  * @param	mixed	$values 
  * @return	DbRequest
  */
 public function createRequest($sql, $type = null, $strategy = null, $values = null)
 {
     $request = new DbRequest($sql, $type, $strategy);
     if (null !== $values) {
         if (is_scalar($values)) {
             $values = array($values);
         } else {
             if (!is_array($values)) {
                 $paramType = gettype($values);
                 $err = "values must be a scalar of an array -({$paramType})";
                 throw new InvalidArgumentException($err);
             }
         }
         $request->setValues($values);
     }
     return $request;
 }
 /**
  * DbRequest::isResultBuffer:	true
  * DbRequest::getResultType:	name (MYSQLI_ASSOC)
  * DbRequest::getCallback		throws an exception
  * 
  * @depends	testInitialState
  * @return	null
  */
 public function testExecuteProfileF()
 {
     $driver = $this->getDriver();
     $adapter = $this->getAdapter();
     $sql = $this->getSql();
     $request = new DbRequest($sql);
     $request->setValues(array(1, 2, 3));
     $errMsg = "error has occured";
     $func = function ($row) use($errMsg) {
         throw new Exception($errMsg, 99);
     };
     $request->setCallback($func);
     $response = new DbResponse();
     $result = $adapter->execute($driver, $request, $response);
     $this->assertSame($response, $result);
     $this->assertTrue($response->isError());
     $stack = $response->getErrorStack();
     $this->assertEquals(3, $stack->count());
     $error = $stack->current();
     $idx = 0;
     $expected = "error has occured -(0)";
     $this->assertEquals(99, $error->getCode());
     $this->assertEquals($expected, $error->getMessage());
     $idx = 1;
     $expected = "error has occured -(1)";
     $stack->next();
     $error = $stack->current();
     $this->assertEquals(99, $error->getCode());
     $this->assertEquals($expected, $error->getMessage());
     $expected = "error has occured -(2)";
     $stack->next();
     $error = $stack->current();
     $this->assertEquals(99, $error->getCode());
     $this->assertEquals($expected, $error->getMessage());
 }