<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>
/** * Devuelve una lista de $searchClass, tal que: * 1. $searchClass tiene un atributo hasMany $hasManyAttr a la clase $byClass * 2. $searchClass tiene una instancia de $byClass en $hasManyAttr con $byId */ public function findHasManyReverse($searchClass, $hasManyAttr, $byClass, $byId) { $sins = new $searchClass(array(), true); // PHP 5.3 if (!$sins->hasAttribute($hasManyAttr)) { throw new Exception("El atributo hasMany {$hasManyAttr} no existe"); } // tabla de join $relins = new $byClass(array(), true); $joinTableName = YuppConventions::relTableName($sins, $hasManyAttr, $relins); // tabla de esta clase $objTableName = YuppConventions::tableName($sins); // quiero owner_id de la tabla de join, por byId // luego hacer join con la tabla de $this //$cond = Condition::EQ($joinTableName, "byId", $byId); // similar PM.get_many_assoc_lazy YuppLoader::load('core.db.criteria2', 'Query'); $q = new Query(); $q->addFrom($joinTableName, 'ref')->addFrom($objTableName, 'obj')->addProjection('obj', '*')->setCondition(Condition::_AND()->add(Condition::EQA('obj', 'id', 'ref', 'owner_id'))->add(Condition::EQ('ref', 'ref_id', $byId))); $data = $this->findByQuery($q); // PM 760 $result = array(); foreach ($data as $many_attrValues) { if ($many_attrValues['class'] === $byClass) { //echo " la clase es la misma que la declarada<br/>"; $rel_obj = $this->createObjectFromData($byClass, $many_attrValues); } else { //echo " la clase NO es la misma que la declarada<br/>"; $rel_obj = $this->get_mti_object_byData($byClass, $many_attrValues); } $result[] = $rel_obj; } return $result; }