Example #1
0
 /**
  * Performs a DELETE on the database, given a RegionType or Criteria object OR a primary key value.
  *
  * @param mixed               $values Criteria or RegionType 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(RegionTypeTableMap::DATABASE_NAME);
     }
     if ($values instanceof Criteria) {
         // rename for clarity
         $criteria = $values;
     } elseif ($values instanceof \keeko\core\model\RegionType) {
         // 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(RegionTypeTableMap::DATABASE_NAME);
         $criteria->add(RegionTypeTableMap::COL_ID, (array) $values, Criteria::IN);
     }
     $query = RegionTypeQuery::create()->mergeWith($criteria);
     if ($values instanceof Criteria) {
         RegionTypeTableMap::clearInstancePool();
     } elseif (!is_object($values)) {
         // it's a primary key, or an array of pks
         foreach ((array) $values as $singleval) {
             RegionTypeTableMap::removeInstanceFromPool($singleval);
         }
     }
     return $query->delete($con);
 }
Example #2
0
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     ConnectionInterface $con A connection object
  *
  * @throws \Propel\Runtime\Exception\PropelException
  *
  * @return ChildRegionType A model object, or null if the key is not found
  */
 protected function findPkSimple($key, ConnectionInterface $con)
 {
     $sql = 'SELECT `id`, `name`, `area_id` FROM `kk_region_type` WHERE `id` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(\PDO::FETCH_NUM)) {
         /** @var ChildRegionType $obj */
         $obj = new ChildRegionType();
         $obj->hydrate($row);
         RegionTypeTableMap::addInstanceToPool($obj, (string) $key);
     }
     $stmt->closeCursor();
     return $obj;
 }