public function getSocial() { //RECUPERA CONEXAO BANCO DE DADOS TTransaction::open('my_bd_site'); //TABELA exposition_gallery $criteria = new TCriteria(); $criteria->setProperty('order', 'nome ASC'); // instancia a instrução de SELECT $sql = new TSqlSelect(); $sql->addColumn('*'); $sql->setEntity('social'); // atribui o critério passado como parâmetro $sql->setCriteria($criteria); // obtém transação ativa if ($conn = TTransaction::get()) { // registra mensagem de log TTransaction::log($sql->getInstruction()); // executa a consulta no banco de dados $result = $conn->Query($sql->getInstruction()); $this->results = array(); if ($result) { // percorre os resultados da consulta, retornando um objeto while ($row = $result->fetchObject()) { // armazena no array $this->results; $this->results[] = $row; } } } TTransaction::close(); return $this->results; }
function count(TCriteria $criteria) { $sql = new TSqlSelect(); $sql->addColumn(' count(*) '); $sql->setEntity(constant($this->class . '::TABLENAME')); $sql->setCriteria($criteria); if ($conn = TTransaction::get()) { TTransaction::log($sql->getInstruction()); $result = $conn->query($sql->getInstruction()); if ($result) { $row = $result->fetch(); } return $row[0]; } else { throw new Exception('Não há transação ativa!'); } }
private function getUsuario() { try { //RECUPERA CONEXAO BANCO DE DADOS TTransaction2::open('my_bd_site'); //TABELA exposition_gallery $criteria = new TCriteria(); $criteria->add(new TFilter(' usuario ', ' = ', "{$this->usuario}")); // instancia a instrução de SELECT $sql = new TSqlSelect(); $sql->addColumn("usuario"); $sql->addColumn("senha"); $sql->addColumn("nome"); $sql->setEntity('usuario'); // atribui o critério passado como parâmetro $sql->setCriteria($criteria); // obtém transação ativa if ($conn = TTransaction2::get()) { // registra mensagem de log TTransaction2::log($sql->getInstruction()); // executa a consulta no banco de dados $result = $conn->Query($sql->getInstruction()); $this->results = array(); if ($result) { // percorre os resultados da consulta, retornando um objeto while ($row = $result->fetchObject()) { // armazena no array $this->results; $this->results[] = $row; } } } TTransaction2::close(); } catch (Exception $e) { $this->results = NULL; } }
/** * Return the amount of objects that satisfy a given criteria * @param $criteria An TCriteria object, specifiyng the filters * @return An Integer containing the amount of objects that satisfy the criteria */ public function count(TCriteria $criteria = NULL) { if (!$criteria) { $criteria = isset($this->criteria) ? $this->criteria : new TCriteria(); } // creates a SELECT statement $sql = new TSqlSelect(); $sql->addColumn('count(*)'); $sql->setEntity($this->getEntity()); // assign the criteria to the SELECT statement $sql->setCriteria($criteria); // get the connection of the active transaction if ($conn = TTransaction::get()) { // register the operation in the LOG file TTransaction::log($sql->getInstruction()); // executes the SELECT statement $result = $conn->Query($sql->getInstruction()); if ($result) { $row = $result->fetch(); } // returns the result return $row[0]; } else { // if there's no active transaction opened throw new Exception(TAdiantiCoreTranslator::translate('No active transactions') . ': ' . __METHOD__ . ' ' . $this->getEntity()); } }
include_once "app.ado/{$classe}.class.php"; } } //Criar critéria de seleção e dados $criteria1 = new TCriteria(); //Selecionar todos as meninas que estão na terceira serie $criteria1->add(new TFilter('sexo', '=', 'F')); $criteria1->add(new TFilter('serie', '=', '3')); // Selecionar dados dos meninos de 4 seria $criteria2 = new TCriteria(); $criteria2->add(new TFilter('sexo', '=', 'M')); $criteria2->add(new TFilter('seria', '=', '4')); //Agrora juntamos os dois criterios Utilizados //O operador lógico OR. O resultado tem de conter //Os dados dos meninos ou das meninas $criteria = new TCriteria(); $criteria->add(new $criteria1(), TExpression::OR_OPERATOR); $criteria->add(new $criteria2(), TExpression::OR_OPERATOR); //Definir o ordenamento da consulta $criteria->setProperty('order', 'nome'); //Criar Instrução SELECT $sql = new TSqlSelect(); //definir o nome da entidade $sql->setEntity('aluno'); //Acrecentar colunas a consulta $sql->addColumn('*'); // Definir Critério de seleção de dado $sql->setCriteria($criteria); //Processar a intrução SQL echo $sql->getInstruction(); echo "<br>\n";
public function load($id) { // instancia instrução de SELECT $sql = new TSqlSelect(); $sql->setEntity($this->getEntity()); $sql->addColumn('*'); // cria critério de seleção baseado no ID $criteria = new TCriteria(); $criteria->add(new TFilter('id', '=', $id)); // define o critério de seleção de dados $sql->setCriteria($criteria); // obtém transação ativa if ($conn = TTransaction::get()) { // cria mensagem de log e executa a consulta TTransaction::log($sql->getInstruction()); $result = $conn->Query($sql->getInstruction()); // se retornou algum dado if ($result) { // retorna os dados em forma de objeto $object = $result->fetchObject(get_class($this)); } return $object; } else { // se não tiver transação, retorna uma exceção throw new Exception('Não há transação ativa!!'); } }
public function loadCriteria($criteria) { // cria instrução SQL $sql = new TSqlSelect(); $sql->addEntity($this->getEntity()); $sql->addColumn('*'); //$criteria = new TCriteria; //$criteria->add(new TFilter('codigo', '=', $codigo)); $sql->setCriteria($criteria); if ($conn = TTransaction::get()) { $result = $conn->query($sql->getInstruction()); if ($result) { $object = $result->fetchObject(get_class($this)); } return $object; } else { throw new Exception('Não há transação ativa'); } }
/** * Load an Active Record Object from the database * @param $id The object ID * @return The Active Record Object * @exception Exception if there's no active transaction opened */ public function load($id) { // creates a SELECT instruction $sql = new TSqlSelect(); $sql->setEntity($this->getEntity()); $sql->addColumn('*'); // discover the primary key name $pk = $this->getPrimaryKey(); // creates a select criteria based on the ID $criteria = new TCriteria(); $criteria->add(new TFilter($pk, '=', $id)); // define the select criteria $sql->setCriteria($criteria); // get the connection of the active transaction if ($conn = TTransaction::get()) { // register the operation in the LOG file TTransaction::log($sql->getInstruction()); $result = $conn->Query($sql->getInstruction()); // if there's a result if ($result) { // returns the data as an object of this class $object = $result->fetchObject(get_class($this)); } return $object; } else { // if there's no active transaction opened throw new Exception(TAdiantiCoreTranslator::translate('No active transactions') . ': ' . __METHOD__ . ' ' . $this->getEntity()); } }
function count(TCriteria $criteria) { // instancia instrução de SELECT $sql = new TSqlSelect(); $sql->addColumn('count(*)'); $sql->setEntity(constant($this->class . '::TABLENAME')); // atribui o critério passado como parâmetro $sql->setCriteria($criteria); // obtém transação ativa if ($conn = TTransaction::get()) { // registra mensagem de log TTransaction::log($sql->getInstruction()); // executa instrução de SELECT $result = $conn->Query($sql->getInstruction()); if ($result) { $row = $result->fetch(); } // retorna o resultado return $row[0]; } else { // se não tiver transação, retorna uma exceção throw new Exception('Não há transação ativa!!'); } }
/** * Método count() * Conta o número de ocorrencias que satisfazem o critério de seleção * * @access public * @param $criteria Criteria de Selecção * @throws Exception Não há transação ativa * @return Número de Ocorrencias */ function count(TCriteria $criteria) { $sql = new TSqlSelect(); $sql->addColumn(' count(*) '); $sql->addEntity($this->entity[0]); $sql->setCriteria($criteria); //RECUPERA CONEXAO BANCO DE DADOS TTransaction::open('my_bd_site'); if ($conn = TTransaction::get()) { $result = $conn->query($sql->getInstruction()); if ($result) { $row = $result->fetch(); } TTransaction::close(); return $row[0]; } else { throw new Exception('Não há transação ativa!'); } }
/** * Método loadCriteria * Recupera (retorna) um objeto da base de dados através de um Critério e instancia ele na memória * * @access public * @param $criteria Critério de seleção * @throws Exception Não há transação ativa * @return object Objeto da base de dados */ public function loadCriteria($criteria) { // cria instrução SQL $sql = new TSqlSelect(); $sql->addEntity($this->getEntity()); $sql->addColumn('*'); //$criteria = new TCriteria; //$criteria->addFilter('codigo', '=', $codigo); $criteria->addFilter('excluido', '=', 0); $sql->setCriteria($criteria); //RECUPERA CONEXAO BANCO DE DADOS TTransaction::open('my_bd_site'); if ($conn = TTransaction::get()) { $result = $conn->query($sql->getInstruction()); if ($result) { $object = $result->fetchObject(get_class($this)); } TTransaction::close(); return $object; } else { throw new Exception('Não há transação ativa'); } }
function count(TCriteria $criteria) { $sql = new TSqlSelect(); $sql->addColumn(' count(*) '); $sql->addEntity($this->entity[0]); $sql->setCriteria($criteria); if ($conn = TTransaction2::get()) { if ($result) { $row = $result->fetch(); } return $row[0]; } else { throw new Exception('Não há transação ativa!'); } }
/** * Load an Active Record Object from the database * @param $id The object ID * @return The Active Record Object * @exception Exception if there's no active transaction opened */ public function load($id) { // get the Active Record class name $class = get_class($this); // discover the primary key name $pk = $this->getPrimaryKey(); if (defined("{$class}::OBJECTCACHE") and constant("{$class}::OBJECTCACHE") == TRUE and extension_loaded('apc')) { if ($fetched_object_array = apc_fetch($class . '[' . $id . ']')) { $fetched_object = clone $this; $fetched_object->fromArray($fetched_object_array); TTransaction::log($class . '[' . $id . '] loaded from cache'); return $fetched_object; } } // creates a SELECT instruction $sql = new TSqlSelect(); $sql->setEntity($this->getEntity()); $sql->addColumn('*'); // creates a select criteria based on the ID $criteria = new TCriteria(); $criteria->add(new TFilter($pk, '=', $id)); // define the select criteria $sql->setCriteria($criteria); // get the connection of the active transaction if ($conn = TTransaction::get()) { // register the operation in the LOG file TTransaction::log($sql->getInstruction()); $result = $conn->Query($sql->getInstruction()); // if there's a result if ($result) { // returns the data as an object of this class $object = $result->fetchObject(get_class($this)); } return $object; } else { // if there's no active transaction opened throw new Exception(TAdiantiCoreTranslator::translate('No active transactions') . ': ' . __METHOD__ . ' ' . $this->getEntity()); } }