/** * Parses the FROM clause. * * @return void * @throws SparqlParserException */ protected function parseFrom() { $this->_fastForward(); if (strtolower(current($this->tokens)) != 'named') { if ($this->iriCheck(current($this->tokens)) || $this->qnameCheck(current($this->tokens))) { $this->query->addFrom(new Resource(substr(current($this->tokens), 1, -1))); } else { if ($this->varCheck(current($this->tokens))) { $this->query->addFrom(current($this->tokens)); } else { throw new SparqlParserException("Variable, Iri or qname expected in FROM ", null, key($this->tokens)); } } $this->query->addFrom(current($this->tokens)); } else { $this->_fastForward(); if ($this->iriCheck(current($this->tokens)) || $this->qnameCheck(current($this->tokens))) { $this->query->addFromNamed(new Resource(substr(current($this->tokens), 1, -1))); } else { if ($this->varCheck(current($this->tokens))) { $this->query->addFromNamed(current($this->tokens)); } else { throw new SparqlParserException("Variable, Iri or qname expected in FROM NAMED ", null, key($this->tokens)); } } } }
<pre> <?php include_once "core.db.criteria2.Condition.class.php"; include_once "core.db.criteria2.ComplexCondition.class.php"; include_once "core.db.criteria2.CompareCondition.class.php"; include_once "core.db.criteria2.BinaryInfixCondition.class.php"; include_once "core.db.criteria2.UnaryPrefixCondition.class.php"; include_once "core.db.criteria2.Query.class.php"; include_once "core.db.criteria2.Select.class.php"; include_once "../core.db.DatabaseMySQL.class.php"; $q = new Query(); $q->addFrom('Persona', 'p')->addFrom('Empleado', 'e')->setCondition(Condition::_AND()->add(Condition::EQ('p', "nombre", "Carlos"))->add(Condition::GT('p', "edad", 5))->add(Condition::EQA('p', "nombre", 'p', "nombre2"))); $db = new DatabaseMySQL(); echo $db->evaluateQuery($q); //echo Condition::EQ("per", "nombre", "Carlox")->evaluate(); //echo Condition::EQA("per", "nombre", "per", "nombre2")->evaluate(); /* $sel = new Select(); $sel->addProjection("per", "name"); $sel->addProjection("per", "age"); $sel->addAvg("per", "age"); echo $sel->evaluate(); */ $q = new Query(); $q->addAggregation(SelectAggregation::AGTN_DISTINTC, 'datos', 'nombre')->addFrom('Persona', 'datos')->setCondition(Condition::GT('p', "edad", 5)); echo $db->evaluateQuery($q); ?> </pre>
/** * Se usa solo desde PO::aRemoveFrom y PO::aRemoveAllFrom. * * ES COMO LO CONTRARIO DE SAVE_ASSOC, pero para solo un registro. save_assoc( PersistentObject &$owner, PersistentObject &$child, $ownerAttr ) * Elimina la asociacion hasMany entre los objetos. (marca como eliminada o borra fisicamente el registro en la tabla de join correspondiente a la relacion entre los objetos). * attr1 es un atributo de obj1 * attr2 es un atributo de obj2 * attr1 y attr2 corresponden a los roles de la misma asociacion entre obj1 y obj2 * attr1 y/o attr2 debe(n) ser hasMany * logical indica si la baja es fisica o logica. */ public function remove_assoc($obj1, $obj2, $attr1, $attr2, $logical = false) { Logger::getInstance()->pm_log("PM::remove_assoc"); // TODO: Si la relacion es A(1)<->(*)B (bidireccional) deberia setear en NULL el atributo A y A_id de B. // Veo cual es el owner: $owner =& $obj1; $ownerAttr =& $attr1; $child =& $obj2; if ($obj1->getClass() != $obj2->getClass() && $obj2->isOwnerOf($attr1)) { $owner =& $obj2; $ownerAttr =& $attr2; $child =& $obj1; } Logger::getInstance()->log('PM::remove_assoc owner ' . $owner->getClass() . ', child ' . $child->getClass()); // Para eliminar no me interesa el tipo de relacion (si esta instanciada bidireccional o unidireccional). // Quiero eliminar el que tenga ownerid y childid de los objetos que me pasaron. // (obs: entonces no permito mas de una relacion entre 2 instancias!) ); // El id de la superclase, es igual que el id de la clase declarada en el hasMany, y el mismo que la instancia final // Por eso uso el id del objeto directamente $ref_id = $child->getId(); Logger::getInstance()->log('PM::remove_assoc owner_id ' . $owner->getId() . ', ref_id ' . $ref_id); // se pasan instancias... para poder pedir el withtable q se setea en tiempo de ejecucion!!!! // $tableName = YuppConventions::relTableName($owner, $ownerAttr, $child); // Necesito el id del registro para poder eliminarlo... // esto es porque no tengo un deleteWhere y solo tengo un delete por id... (TODO) YuppLoader::load("core.db.criteria2", "Query"); $q = new Query(); $q->addFrom($tableName, "ref")->addProjection("ref", "id")->setCondition(Condition::_AND()->add(Condition::EQ("ref", "owner_id", $owner->getId()))->add(Condition::EQ("ref", "ref_id", $ref_id))); $data = $this->dal->query($q); $id = $data[0]['id']; // Se que hay solo un registro... // TODO: podria no haber ninguno, OJO! hay que tener en cuenta ese caso. $this->dal->deleteFromTable($tableName, $id, $logical); }