/** * @covers Zend\Db\Sql\Sql::__construct */ public function test__construct() { $sql = new Sql($this->mockAdapter); $this->assertFalse($sql->hasTable()); $sql->setTable('foo'); $this->assertSame('foo', $sql->getTable()); $this->setExpectedException('Zend\\Db\\Sql\\Exception\\InvalidArgumentException', 'Table must be a string or instance of TableIdentifier.'); $sql->setTable(null); }
public function insertSocialMedia(SocialMediaEntity $socMedEnt) { $select = $this->sql->select(); $select->where(array("username" => $socMedEnt->getUsername(), "social_id" => $socMedEnt->getSocialId())); $result = $this->hydrateResult(new SocialMediaEntity(), $select); if ($result->count() == 0) { $hydrator = new ClassMethods(); $data = $hydrator->extract($socMedEnt); $action = $this->sql->insert(); $action->values($data); $statement = $this->sql->prepareStatementForSqlObject($action); // echo "<hr>"; echo $action->getSqlString($this->dbAdapter->getPlatform()); echo "<hr>asdf"; $statement->execute(); $sql = new Sql($this->dbAdapter); $sql->setTable('blvd'); $update = $sql->update(); $update->set(array("last_social_media_datetime" => $data['date_created']))->where(array("id" => $socMedEnt->getBlvdId())); $statement = $sql->prepareStatementForSqlObject($update); $r = $statement->execute(); echo $action->getSqlString($this->dbAdapter->getPlatform()); } elseif (false) { $hydrator = new ClassMethods(); $data = $hydrator->extract($socMedEnt); $update = $this->sql->update(); $update->set(array("date_created" => $data['date_created']))->where(array("username" => $socMedEnt->getUsername(), "social_id" => $socMedEnt->getSocialId())); $statement = $this->sql->prepareStatementForSqlObject($update); $r = $statement->execute(); //echo "<hr>"; echo $update->getSqlString($this->dbAdapter->getPlatform()); echo "<hr>asdf"; return $r; } return false; }
/** * Funcao que retorna o objeto Sql ja com o adaptador e o nome da tabela * preparado pronto para criar sua consulta * @return \Zend\Db\Sql\Sql */ public function getSqlStatement() { $sqlObject = new Sql($this->dbAdapter); $sqlObject->setTable($this->tableName); return $sqlObject; }