Esempio n. 1
0
 public function testAddOrEmptyCriteria()
 {
     $table1 = "myTable1";
     $column1 = "myColumn1";
     $value1 = "myValue1";
     $key1 = "{$table1}.{$column1}";
     $this->c->addOr($key1, $value1, Criteria::EQUAL);
     $expect = "SELECT  FROM myTable1 WHERE myTable1.myColumn1=:p1";
     $params = array();
     $result = $this->c->createSelectSql($params);
     $expect_params = array(array('table' => 'myTable1', 'column' => 'myColumn1', 'value' => 'myValue1'));
     $this->assertEquals($expect, $result, 'addOr() called on an empty Criteria adds a criterion to the criteria');
     $this->assertEquals($expect_params, $params, 'addOr() called on an empty Criteria adds a criterion to the criteria');
 }
Esempio n. 2
0
 public function testCombineCriterionOrLessSimple()
 {
     $this->c->addCond('cond1', "INVOICE.COST1", "1000", Criteria::GREATER_EQUAL);
     $this->c->addCond('cond2', "INVOICE.COST2", "2000", Criteria::LESS_EQUAL);
     $this->c->add("INVOICE.COST3", "8000", Criteria::GREATER_EQUAL);
     $this->c->combine(['cond1', 'cond2'], Criteria::LOGICAL_OR);
     $this->c->addOr("INVOICE.COST4", "9000", Criteria::LESS_EQUAL);
     $expect = $this->getSql("SELECT  FROM INVOICE WHERE INVOICE.COST3>=:p1 AND ((INVOICE.COST1>=:p2 OR INVOICE.COST2<=:p3) OR INVOICE.COST4<=:p4)");
     $expect_params = [['table' => 'INVOICE', 'column' => 'COST3', 'value' => '8000'], ['table' => 'INVOICE', 'column' => 'COST1', 'value' => '1000'], ['table' => 'INVOICE', 'column' => 'COST2', 'value' => '2000'], ['table' => 'INVOICE', 'column' => 'COST4', 'value' => '9000']];
     $params = [];
     $result = $this->c->createSelectSql($params);
     $this->assertEquals($expect, $result);
     $this->assertEquals($expect_params, $params);
 }
 /**
  * Performs a DELETE on the database, given a DiaporamaVersion or Criteria object OR a primary key value.
  *
  * @param mixed               $values Criteria or DiaporamaVersion object or primary key or array of primary keys
  *              which is used to create the DELETE statement
  * @param ConnectionInterface $con the connection to use
  * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
  *                if supported by native driver or if emulated using Propel.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doDelete($values, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(DiaporamaVersionTableMap::DATABASE_NAME);
     }
     if ($values instanceof Criteria) {
         // rename for clarity
         $criteria = $values;
     } elseif ($values instanceof \Diaporamas\Model\DiaporamaVersion) {
         // it's a model object
         // create criteria based on pk values
         $criteria = $values->buildPkeyCriteria();
     } else {
         // it's a primary key, or an array of pks
         $criteria = new Criteria(DiaporamaVersionTableMap::DATABASE_NAME);
         // primary key is composite; we therefore, expect
         // the primary key passed to be an array of pkey values
         if (count($values) == count($values, COUNT_RECURSIVE)) {
             // array is not multi-dimensional
             $values = array($values);
         }
         foreach ($values as $value) {
             $criterion = $criteria->getNewCriterion(DiaporamaVersionTableMap::ID, $value[0]);
             $criterion->addAnd($criteria->getNewCriterion(DiaporamaVersionTableMap::VERSION, $value[1]));
             $criteria->addOr($criterion);
         }
     }
     $query = DiaporamaVersionQuery::create()->mergeWith($criteria);
     if ($values instanceof Criteria) {
         DiaporamaVersionTableMap::clearInstancePool();
     } elseif (!is_object($values)) {
         // it's a primary key, or an array of pks
         foreach ((array) $values as $singleval) {
             DiaporamaVersionTableMap::removeInstanceFromPool($singleval);
         }
     }
     return $query->delete($con);
 }