Esempio n. 1
0
 /**
  * The primary method a driver needs to implement is the execute method, which takes an array of query options.
  * The options in the array varies, but the key type will always be supplied, which will be either SELECT, UPDATE,
  * INSERT, REPLACE or DELETE.
  *
  * @param array $options An array of options that were generated through use of the Query class.
  * @return object It is expected to return an instance of an \Queryer\Driver\DatabaseDriverResult class.
  * @see \Queryer\Query, \Queryer\Driver\DatabaseDriverResult
  */
 public function execute(array $options)
 {
     $query = self::generateQuery($options);
     $query = DatabaseTools::replaceVariables($query, $options['variables']);
     $result = $this->sqlite->query($query);
     return new Sqlite3DriverResult($result, $this->sqlite->changes(), $this->sqlite->lastInsertRowID(), $result === false ? $this->sqlite->lastErrorCode() : null, $result === false ? $this->sqlite->lastErrorMsg() : null, $query);
 }
 /**
  * Tests to ensure a DatabaseException is thrown when an unknown datatype is specified.
  *
  * @expectedException \Queryer\Exception\DatabaseException
  * @expectedExceptionCode \Queryer\Exception\DatabaseException::UNKNOWN_DATATYPE
  */
 public function testUnknownType()
 {
     DatabaseTools::replaceVariables('{someunknowntype:imnotthevariableyouwant}', array('imnotthevariableyouwant' => 1));
 }
Esempio n. 3
0
 /**
  * Tests the execute method.
  */
 public function testExecute()
 {
     $query = Query::select()->expr('user_id')->from('users')->where('user_id = {int:user_id}')->replace(array('user_id' => 100));
     // Set everything...
     $this->mysqliMocker->affected_rows = 100;
     $this->mysqliMocker->insert_id = 321;
     $this->mysqliMocker->errno = 322;
     $this->mysqliMocker->error = "ERROR";
     $userId = 32143;
     $this->mysqliMocker->setQueryReturn(true);
     $result = $this->mysqlDriver->execute($query->getOptions());
     $this->assertEquals(DatabaseTools::replaceVariables(MysqlDriver::generateQuery($query->getOptions()), array('user_id' => 100)), $this->mysqliMocker->getQueryInvokedWith());
     $this->assertEquals($this->mysqliMocker->affected_rows, $result->getAffectedRows());
     $this->assertEquals($this->mysqliMocker->insert_id, $result->getInsertId());
     $this->assertEquals($this->mysqliMocker->errno, $result->getErrorCode());
     $this->assertEquals($this->mysqliMocker->error, $result->getErrorMessage());
 }