/**
  * Crea la tabla temporal en el gestor relacional
  *
  * @access	private
  * @param	string $tableName
  * @param	string $schemaName
  * @param	DbBase $db
  */
 private function _createTemporaryTable($tableName, $schemaName, $db = null)
 {
     if (method_exists($this, '_tableDefinition') == true) {
         $tableDefinition = $this->_tableDefinition();
         if (!isset($tableDefinition['attributes'])) {
             throw new ActiveRecordException('Los atributos en la definición de la entidad no son correctos');
         }
         if (!isset($tableDefinition['indexes'])) {
             $tableDefinition['indexes'] = array();
         }
         if ($db == null) {
             $db = DbPool::getConnection();
         }
         if ($db->createTable($tableName, $schemaName, $tableDefinition['attributes'], $tableDefinition['indexes'], array('temporary' => true)) == false) {
             throw new Exception("No se pudo crear la tabla temporal '{$tableName}'");
         }
         $this->_dumpLock = true;
         foreach ($tableDefinition['attributes'] as $attributeName => $definition) {
             if (isset($this->{$attributeName}) == false) {
                 $this->{$attributeName} = '';
             }
         }
         $this->_dumpLock = false;
     } else {
         throw new ActiveRecordException('No ha definido el metodo "_tableDefinition" para obtener la definición de la tabla temporal');
     }
 }
Exemplo n.º 2
0
 /**
  * Ejecuta la consulta
  *
  * @return	ActiveRecordResultset
  */
 public function execute()
 {
     $sqlStatement = $this->getSQLString();
     if ($this->_connection == null) {
         $this->_connection = DbPool::getConnection();
     }
     $resultResource = $this->_connection->query($sqlStatement);
     $count = $this->_connection->numRows($resultResource);
     if ($count > 0) {
         $rowObject = new ActiveRecordRow();
         $rowObject->setConnection($this->_connection);
         return new ActiveRecordResultset($rowObject, $resultResource, $sqlStatement);
     } else {
         return new ActiveRecordResultset(new stdClass(), false, $sqlStatement);
     }
 }