       1: <?php
       2:
       3: namespace Thelia\Model\om;
       4:
       5: use \BasePeer;
       6: use \Criteria;
       7: use \PDO;
       8: use \PDOStatement;
       9: use \Propel;
      10: use \PropelException;
      11: use \PropelPDO;
      12: use Thelia\Model\AreaPeer;
      13: use Thelia\Model\Country;
      14: use Thelia\Model\CountryI18nPeer;
      15: use Thelia\Model\CountryPeer;
      16: use Thelia\Model\TaxRuleCountryPeer;
      17: use Thelia\Model\map\CountryTableMap;
      18:
      19: /**
      20:  * Base static class for performing query and update operations on the 'country' table.
      21:  *
      22:  *
      23:  *
      24:  * @package propel.generator.Thelia.Model.om
      25:  */
      26: abstract class BaseCountryPeer
      27: {
      28:
      29:     /** the default database name for this class */
      30:     const DATABASE_NAME = 'thelia';
      31:
      32:     /** the table name for this class */
      33:     const TABLE_NAME = 'country';
      34:
      35:     /** the related Propel class for this table */
      36:     const OM_CLASS = 'Thelia\\Model\\Country';
      37:
      38:     /** the related TableMap class for this table */
      39:     const TM_CLASS = 'CountryTableMap';
      40:
      41:     /** The total number of columns. */
      42:     const NUM_COLUMNS = 7;
      43:
      44:     /** The number of lazy-loaded columns. */
      45:     const NUM_LAZY_LOAD_COLUMNS = 0;
      46:
      47:     /** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
      48:     const NUM_HYDRATE_COLUMNS = 7;
      49:
      50:     /** the column name for the id field */
      51:     const ID = 'country.id';
      52:
      53:     /** the column name for the area_id field */
      54:     const AREA_ID = 'country.area_id';
      55:
      56:     /** the column name for the isocode field */
      57:     const ISOCODE = 'country.isocode';
      58:
      59:     /** the column name for the isoalpha2 field */
      60:     const ISOALPHA2 = 'country.isoalpha2';
      61:
      62:     /** the column name for the isoalpha3 field */
      63:     const ISOALPHA3 = 'country.isoalpha3';
      64:
      65:     /** the column name for the created_at field */
      66:     const CREATED_AT = 'country.created_at';
      67:
      68:     /** the column name for the updated_at field */
      69:     const UPDATED_AT = 'country.updated_at';
      70:
      71:     /** The default string format for model objects of the related table **/
      72:     const DEFAULT_STRING_FORMAT = 'YAML';
      73:
      74:     /**
      75:      * An identiy map to hold any loaded instances of Country objects.
      76:      * This must be public so that other peer classes can access this when hydrating from JOIN
      77:      * queries.
      78:      * @var        array Country[]
      79:      */
      80:     public static $instances = array();
      81:
      82:
      83:     // i18n behavior
      84:
      85:     /**
      86:      * The default locale to use for translations
      87:      * @var        string
      88:      */
      89:     const DEFAULT_LOCALE = 'en_US';
      90:     /**
      91:      * holds an array of fieldnames
      92:      *
      93:      * first dimension keys are the type constants
      94:      * e.g. CountryPeer::$fieldNames[CountryPeer::TYPE_PHPNAME][0] = 'Id'
      95:      */
      96:     protected static $fieldNames = array (
      97:         BasePeer::TYPE_PHPNAME => array ('Id', 'AreaId', 'Isocode', 'Isoalpha2', 'Isoalpha3', 'CreatedAt', 'UpdatedAt', ),
      98:         BasePeer::TYPE_STUDLYPHPNAME => array ('id', 'areaId', 'isocode', 'isoalpha2', 'isoalpha3', 'createdAt', 'updatedAt', ),
      99:         BasePeer::TYPE_COLNAME => array (CountryPeer::ID, CountryPeer::AREA_ID, CountryPeer::ISOCODE, CountryPeer::ISOALPHA2, CountryPeer::ISOALPHA3, CountryPeer::CREATED_AT, CountryPeer::UPDATED_AT, ),
     100:         BasePeer::TYPE_RAW_COLNAME => array ('ID', 'AREA_ID', 'ISOCODE', 'ISOALPHA2', 'ISOALPHA3', 'CREATED_AT', 'UPDATED_AT', ),
     101:         BasePeer::TYPE_FIELDNAME => array ('id', 'area_id', 'isocode', 'isoalpha2', 'isoalpha3', 'created_at', 'updated_at', ),
     102:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
     103:     );
     104:
     105:     /**
     106:      * holds an array of keys for quick access to the fieldnames array
     107:      *
     108:      * first dimension keys are the type constants
     109:      * e.g. CountryPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
     110:      */
     111:     protected static $fieldKeys = array (
     112:         BasePeer::TYPE_PHPNAME => array ('Id' => 0, 'AreaId' => 1, 'Isocode' => 2, 'Isoalpha2' => 3, 'Isoalpha3' => 4, 'CreatedAt' => 5, 'UpdatedAt' => 6, ),
     113:         BasePeer::TYPE_STUDLYPHPNAME => array ('id' => 0, 'areaId' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'createdAt' => 5, 'updatedAt' => 6, ),
     114:         BasePeer::TYPE_COLNAME => array (CountryPeer::ID => 0, CountryPeer::AREA_ID => 1, CountryPeer::ISOCODE => 2, CountryPeer::ISOALPHA2 => 3, CountryPeer::ISOALPHA3 => 4, CountryPeer::CREATED_AT => 5, CountryPeer::UPDATED_AT => 6, ),
     115:         BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'AREA_ID' => 1, 'ISOCODE' => 2, 'ISOALPHA2' => 3, 'ISOALPHA3' => 4, 'CREATED_AT' => 5, 'UPDATED_AT' => 6, ),
     116:         BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'area_id' => 1, 'isocode' => 2, 'isoalpha2' => 3, 'isoalpha3' => 4, 'created_at' => 5, 'updated_at' => 6, ),
     117:         BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
     118:     );
     119:
     120:     /**
     121:      * Translates a fieldname to another type
     122:      *
     123:      * @param      string $name field name
     124:      * @param      string $fromType One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     125:      *                         BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     126:      * @param      string $toType   One of the class type constants
     127:      * @return string          translated name of the field.
     128:      * @throws PropelException - if the specified name could not be found in the fieldname mappings.
     129:      */
     130:     public static function translateFieldName($name, $fromType, $toType)
     131:     {
     132:         $toNames = CountryPeer::getFieldNames($toType);
     133:         $key = isset(CountryPeer::$fieldKeys[$fromType][$name]) ? CountryPeer::$fieldKeys[$fromType][$name] : null;
     134:         if ($key === null) {
     135:             throw new PropelException("'$name' could not be found in the field names of type '$fromType'. These are: " . print_r(CountryPeer::$fieldKeys[$fromType], true));
     136:         }
     137:
     138:         return $toNames[$key];
     139:     }
     140:
     141:     /**
     142:      * Returns an array of field names.
     143:      *
     144:      * @param      string $type The type of fieldnames to return:
     145:      *                      One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME
     146:      *                      BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM
     147:      * @return array           A list of field names
     148:      * @throws PropelException - if the type is not valid.
     149:      */
     150:     public static function getFieldNames($type = BasePeer::TYPE_PHPNAME)
     151:     {
     152:         if (!array_key_exists($type, CountryPeer::$fieldNames)) {
     153:             throw new PropelException('Method getFieldNames() expects the parameter $type to be one of the class constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM. ' . $type . ' was given.');
     154:         }
     155:
     156:         return CountryPeer::$fieldNames[$type];
     157:     }
     158:
     159:     /**
     160:      * Convenience method which changes table.column to alias.column.
     161:      *
     162:      * Using this method you can maintain SQL abstraction while using column aliases.
     163:      * <code>
     164:      *      $c->addAlias("alias1", TablePeer::TABLE_NAME);
     165:      *      $c->addJoin(TablePeer::alias("alias1", TablePeer::PRIMARY_KEY_COLUMN), TablePeer::PRIMARY_KEY_COLUMN);
     166:      * </code>
     167:      * @param      string $alias The alias for the current table.
     168:      * @param      string $column The column name for current table. (i.e. CountryPeer::COLUMN_NAME).
     169:      * @return string
     170:      */
     171:     public static function alias($alias, $column)
     172:     {
     173:         return str_replace(CountryPeer::TABLE_NAME.'.', $alias.'.', $column);
     174:     }
     175:
     176:     /**
     177:      * Add all the columns needed to create a new object.
     178:      *
     179:      * Note: any columns that were marked with lazyLoad="true" in the
     180:      * XML schema will not be added to the select list and only loaded
     181:      * on demand.
     182:      *
     183:      * @param      Criteria $criteria object containing the columns to add.
     184:      * @param      string   $alias    optional table alias
     185:      * @throws PropelException Any exceptions caught during processing will be
     186:      *       rethrown wrapped into a PropelException.
     187:      */
     188:     public static function addSelectColumns(Criteria $criteria, $alias = null)
     189:     {
     190:         if (null === $alias) {
     191:             $criteria->addSelectColumn(CountryPeer::ID);
     192:             $criteria->addSelectColumn(CountryPeer::AREA_ID);
     193:             $criteria->addSelectColumn(CountryPeer::ISOCODE);
     194:             $criteria->addSelectColumn(CountryPeer::ISOALPHA2);
     195:             $criteria->addSelectColumn(CountryPeer::ISOALPHA3);
     196:             $criteria->addSelectColumn(CountryPeer::CREATED_AT);
     197:             $criteria->addSelectColumn(CountryPeer::UPDATED_AT);
     198:         } else {
     199:             $criteria->addSelectColumn($alias . '.id');
     200:             $criteria->addSelectColumn($alias . '.area_id');
     201:             $criteria->addSelectColumn($alias . '.isocode');
     202:             $criteria->addSelectColumn($alias . '.isoalpha2');
     203:             $criteria->addSelectColumn($alias . '.isoalpha3');
     204:             $criteria->addSelectColumn($alias . '.created_at');
     205:             $criteria->addSelectColumn($alias . '.updated_at');
     206:         }
     207:     }
     208:
     209:     /**
     210:      * Returns the number of rows matching criteria.
     211:      *
     212:      * @param      Criteria $criteria
     213:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     214:      * @param      PropelPDO $con
     215:      * @return int Number of matching rows.
     216:      */
     217:     public static function doCount(Criteria $criteria, $distinct = false, PropelPDO $con = null)
     218:     {
     219:         // we may modify criteria, so copy it first
     220:         $criteria = clone $criteria;
     221:
     222:         // We need to set the primary table name, since in the case that there are no WHERE columns
     223:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     224:         // tables go into the FROM clause.
     225:         $criteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
     226:
     227:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     228:             $criteria->setDistinct();
     229:         }
     230:
     231:         if (!$criteria->hasSelectClause()) {
     232:             CountryPeer::addSelectColumns($criteria);
     233:         }
     234:
     235:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     236:         $criteria->setDbName(CountryPeer::DATABASE_NAME); // Set the correct dbName
     237:
     238:         if ($con === null) {
     239:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     240:         }
     241:         // BasePeer returns a PDOStatement
     242:         $stmt = BasePeer::doCount($criteria, $con);
     243:
     244:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     245:             $count = (int) $row[0];
     246:         } else {
     247:             $count = 0; // no rows returned; we infer that means 0 matches.
     248:         }
     249:         $stmt->closeCursor();
     250:
     251:         return $count;
     252:     }
     253:     /**
     254:      * Selects one object from the DB.
     255:      *
     256:      * @param      Criteria $criteria object used to create the SELECT statement.
     257:      * @param      PropelPDO $con
     258:      * @return                 Country
     259:      * @throws PropelException Any exceptions caught during processing will be
     260:      *       rethrown wrapped into a PropelException.
     261:      */
     262:     public static function doSelectOne(Criteria $criteria, PropelPDO $con = null)
     263:     {
     264:         $critcopy = clone $criteria;
     265:         $critcopy->setLimit(1);
     266:         $objects = CountryPeer::doSelect($critcopy, $con);
     267:         if ($objects) {
     268:             return $objects[0];
     269:         }
     270:
     271:         return null;
     272:     }
     273:     /**
     274:      * Selects several row from the DB.
     275:      *
     276:      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
     277:      * @param      PropelPDO $con
     278:      * @return array           Array of selected Objects
     279:      * @throws PropelException Any exceptions caught during processing will be
     280:      *       rethrown wrapped into a PropelException.
     281:      */
     282:     public static function doSelect(Criteria $criteria, PropelPDO $con = null)
     283:     {
     284:         return CountryPeer::populateObjects(CountryPeer::doSelectStmt($criteria, $con));
     285:     }
     286:     /**
     287:      * Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
     288:      *
     289:      * Use this method directly if you want to work with an executed statement directly (for example
     290:      * to perform your own object hydration).
     291:      *
     292:      * @param      Criteria $criteria The Criteria object used to build the SELECT statement.
     293:      * @param      PropelPDO $con The connection to use
     294:      * @throws PropelException Any exceptions caught during processing will be
     295:      *       rethrown wrapped into a PropelException.
     296:      * @return PDOStatement The executed PDOStatement object.
     297:      * @see        BasePeer::doSelect()
     298:      */
     299:     public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
     300:     {
     301:         if ($con === null) {
     302:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     303:         }
     304:
     305:         if (!$criteria->hasSelectClause()) {
     306:             $criteria = clone $criteria;
     307:             CountryPeer::addSelectColumns($criteria);
     308:         }
     309:
     310:         // Set the correct dbName
     311:         $criteria->setDbName(CountryPeer::DATABASE_NAME);
     312:
     313:         // BasePeer returns a PDOStatement
     314:         return BasePeer::doSelect($criteria, $con);
     315:     }
     316:     /**
     317:      * Adds an object to the instance pool.
     318:      *
     319:      * Propel keeps cached copies of objects in an instance pool when they are retrieved
     320:      * from the database.  In some cases -- especially when you override doSelect*()
     321:      * methods in your stub classes -- you may need to explicitly add objects
     322:      * to the cache in order to ensure that the same objects are always returned by doSelect*()
     323:      * and retrieveByPK*() calls.
     324:      *
     325:      * @param      Country $obj A Country object.
     326:      * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
     327:      */
     328:     public static function addInstanceToPool($obj, $key = null)
     329:     {
     330:         if (Propel::isInstancePoolingEnabled()) {
     331:             if ($key === null) {
     332:                 $key = (string) $obj->getId();
     333:             } // if key === null
     334:             CountryPeer::$instances[$key] = $obj;
     335:         }
     336:     }
     337:
     338:     /**
     339:      * Removes an object from the instance pool.
     340:      *
     341:      * Propel keeps cached copies of objects in an instance pool when they are retrieved
     342:      * from the database.  In some cases -- especially when you override doDelete
     343:      * methods in your stub classes -- you may need to explicitly remove objects
     344:      * from the cache in order to prevent returning objects that no longer exist.
     345:      *
     346:      * @param      mixed $value A Country object or a primary key value.
     347:      *
     348:      * @return void
     349:      * @throws PropelException - if the value is invalid.
     350:      */
     351:     public static function removeInstanceFromPool($value)
     352:     {
     353:         if (Propel::isInstancePoolingEnabled() && $value !== null) {
     354:             if (is_object($value) && $value instanceof Country) {
     355:                 $key = (string) $value->getId();
     356:             } elseif (is_scalar($value)) {
     357:                 // assume we've been passed a primary key
     358:                 $key = (string) $value;
     359:             } else {
     360:                 $e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or Country object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value,true)));
     361:                 throw $e;
     362:             }
     363:
     364:             unset(CountryPeer::$instances[$key]);
     365:         }
     366:     } // removeInstanceFromPool()
     367:
     368:     /**
     369:      * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
     370:      *
     371:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     372:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     373:      *
     374:      * @param      string $key The key (@see getPrimaryKeyHash()) for this instance.
     375:      * @return   Country Found object or null if 1) no instance exists for specified key or 2) instance pooling has been disabled.
     376:      * @see        getPrimaryKeyHash()
     377:      */
     378:     public static function getInstanceFromPool($key)
     379:     {
     380:         if (Propel::isInstancePoolingEnabled()) {
     381:             if (isset(CountryPeer::$instances[$key])) {
     382:                 return CountryPeer::$instances[$key];
     383:             }
     384:         }
     385:
     386:         return null; // just to be explicit
     387:     }
     388:
     389:     /**
     390:      * Clear the instance pool.
     391:      *
     392:      * @return void
     393:      */
     394:     public static function clearInstancePool($and_clear_all_references = false)
     395:     {
     396:       if ($and_clear_all_references)
     397:       {
     398:         foreach (CountryPeer::$instances as $instance)
     399:         {
     400:           $instance->clearAllReferences(true);
     401:         }
     402:       }
     403:         CountryPeer::$instances = array();
     404:     }
     405:
     406:     /**
     407:      * Method to invalidate the instance pool of all tables related to country
     408:      * by a foreign key with ON DELETE CASCADE
     409:      */
     410:     public static function clearRelatedInstancePool()
     411:     {
     412:         // Invalidate objects in TaxRuleCountryPeer instance pool,
     413:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     414:         TaxRuleCountryPeer::clearInstancePool();
     415:         // Invalidate objects in CountryI18nPeer instance pool,
     416:         // since one or more of them may be deleted by ON DELETE CASCADE/SETNULL rule.
     417:         CountryI18nPeer::clearInstancePool();
     418:     }
     419:
     420:     /**
     421:      * Retrieves a string version of the primary key from the DB resultset row that can be used to uniquely identify a row in this table.
     422:      *
     423:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     424:      * a multi-column primary key, a serialize()d version of the primary key will be returned.
     425:      *
     426:      * @param      array $row PropelPDO resultset row.
     427:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     428:      * @return string A string version of PK or null if the components of primary key in result array are all null.
     429:      */
     430:     public static function getPrimaryKeyHashFromRow($row, $startcol = 0)
     431:     {
     432:         // If the PK cannot be derived from the row, return null.
     433:         if ($row[$startcol] === null) {
     434:             return null;
     435:         }
     436:
     437:         return (string) $row[$startcol];
     438:     }
     439:
     440:     /**
     441:      * Retrieves the primary key from the DB resultset row
     442:      * For tables with a single-column primary key, that simple pkey value will be returned.  For tables with
     443:      * a multi-column primary key, an array of the primary key columns will be returned.
     444:      *
     445:      * @param      array $row PropelPDO resultset row.
     446:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     447:      * @return mixed The primary key of the row
     448:      */
     449:     public static function getPrimaryKeyFromRow($row, $startcol = 0)
     450:     {
     451:
     452:         return (int) $row[$startcol];
     453:     }
     454:
     455:     /**
     456:      * The returned array will contain objects of the default type or
     457:      * objects that inherit from the default.
     458:      *
     459:      * @throws PropelException Any exceptions caught during processing will be
     460:      *       rethrown wrapped into a PropelException.
     461:      */
     462:     public static function populateObjects(PDOStatement $stmt)
     463:     {
     464:         $results = array();
     465:
     466:         // set the class once to avoid overhead in the loop
     467:         $cls = CountryPeer::getOMClass();
     468:         // populate the object(s)
     469:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     470:             $key = CountryPeer::getPrimaryKeyHashFromRow($row, 0);
     471:             if (null !== ($obj = CountryPeer::getInstanceFromPool($key))) {
     472:                 // We no longer rehydrate the object, since this can cause data loss.
     473:                 // See http://www.propelorm.org/ticket/509
     474:                 // $obj->hydrate($row, 0, true); // rehydrate
     475:                 $results[] = $obj;
     476:             } else {
     477:                 $obj = new $cls();
     478:                 $obj->hydrate($row);
     479:                 $results[] = $obj;
     480:                 CountryPeer::addInstanceToPool($obj, $key);
     481:             } // if key exists
     482:         }
     483:         $stmt->closeCursor();
     484:
     485:         return $results;
     486:     }
     487:     /**
     488:      * Populates an object of the default type or an object that inherit from the default.
     489:      *
     490:      * @param      array $row PropelPDO resultset row.
     491:      * @param      int $startcol The 0-based offset for reading from the resultset row.
     492:      * @throws PropelException Any exceptions caught during processing will be
     493:      *       rethrown wrapped into a PropelException.
     494:      * @return array (Country object, last column rank)
     495:      */
     496:     public static function populateObject($row, $startcol = 0)
     497:     {
     498:         $key = CountryPeer::getPrimaryKeyHashFromRow($row, $startcol);
     499:         if (null !== ($obj = CountryPeer::getInstanceFromPool($key))) {
     500:             // We no longer rehydrate the object, since this can cause data loss.
     501:             // See http://www.propelorm.org/ticket/509
     502:             // $obj->hydrate($row, $startcol, true); // rehydrate
     503:             $col = $startcol + CountryPeer::NUM_HYDRATE_COLUMNS;
     504:         } else {
     505:             $cls = CountryPeer::OM_CLASS;
     506:             $obj = new $cls();
     507:             $col = $obj->hydrate($row, $startcol);
     508:             CountryPeer::addInstanceToPool($obj, $key);
     509:         }
     510:
     511:         return array($obj, $col);
     512:     }
     513:
     514:
     515:     /**
     516:      * Returns the number of rows matching criteria, joining the related Area table
     517:      *
     518:      * @param      Criteria $criteria
     519:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     520:      * @param      PropelPDO $con
     521:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     522:      * @return int Number of matching rows.
     523:      */
     524:     public static function doCountJoinArea(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     525:     {
     526:         // we're going to modify criteria, so copy it first
     527:         $criteria = clone $criteria;
     528:
     529:         // We need to set the primary table name, since in the case that there are no WHERE columns
     530:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     531:         // tables go into the FROM clause.
     532:         $criteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
     533:
     534:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     535:             $criteria->setDistinct();
     536:         }
     537:
     538:         if (!$criteria->hasSelectClause()) {
     539:             CountryPeer::addSelectColumns($criteria);
     540:         }
     541:
     542:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     543:
     544:         // Set the correct dbName
     545:         $criteria->setDbName(CountryPeer::DATABASE_NAME);
     546:
     547:         if ($con === null) {
     548:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     549:         }
     550:
     551:         $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
     552:
     553:         $stmt = BasePeer::doCount($criteria, $con);
     554:
     555:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     556:             $count = (int) $row[0];
     557:         } else {
     558:             $count = 0; // no rows returned; we infer that means 0 matches.
     559:         }
     560:         $stmt->closeCursor();
     561:
     562:         return $count;
     563:     }
     564:
     565:
     566:     /**
     567:      * Selects a collection of Country objects pre-filled with their Area objects.
     568:      * @param      Criteria  $criteria
     569:      * @param      PropelPDO $con
     570:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     571:      * @return array           Array of Country objects.
     572:      * @throws PropelException Any exceptions caught during processing will be
     573:      *       rethrown wrapped into a PropelException.
     574:      */
     575:     public static function doSelectJoinArea(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     576:     {
     577:         $criteria = clone $criteria;
     578:
     579:         // Set the correct dbName if it has not been overridden
     580:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     581:             $criteria->setDbName(CountryPeer::DATABASE_NAME);
     582:         }
     583:
     584:         CountryPeer::addSelectColumns($criteria);
     585:         $startcol = CountryPeer::NUM_HYDRATE_COLUMNS;
     586:         AreaPeer::addSelectColumns($criteria);
     587:
     588:         $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
     589:
     590:         $stmt = BasePeer::doSelect($criteria, $con);
     591:         $results = array();
     592:
     593:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     594:             $key1 = CountryPeer::getPrimaryKeyHashFromRow($row, 0);
     595:             if (null !== ($obj1 = CountryPeer::getInstanceFromPool($key1))) {
     596:                 // We no longer rehydrate the object, since this can cause data loss.
     597:                 // See http://www.propelorm.org/ticket/509
     598:                 // $obj1->hydrate($row, 0, true); // rehydrate
     599:             } else {
     600:
     601:                 $cls = CountryPeer::getOMClass();
     602:
     603:                 $obj1 = new $cls();
     604:                 $obj1->hydrate($row);
     605:                 CountryPeer::addInstanceToPool($obj1, $key1);
     606:             } // if $obj1 already loaded
     607:
     608:             $key2 = AreaPeer::getPrimaryKeyHashFromRow($row, $startcol);
     609:             if ($key2 !== null) {
     610:                 $obj2 = AreaPeer::getInstanceFromPool($key2);
     611:                 if (!$obj2) {
     612:
     613:                     $cls = AreaPeer::getOMClass();
     614:
     615:                     $obj2 = new $cls();
     616:                     $obj2->hydrate($row, $startcol);
     617:                     AreaPeer::addInstanceToPool($obj2, $key2);
     618:                 } // if obj2 already loaded
     619:
     620:                 // Add the $obj1 (Country) to $obj2 (Area)
     621:                 $obj2->addCountry($obj1);
     622:
     623:             } // if joined row was not null
     624:
     625:             $results[] = $obj1;
     626:         }
     627:         $stmt->closeCursor();
     628:
     629:         return $results;
     630:     }
     631:
     632:
     633:     /**
     634:      * Returns the number of rows matching criteria, joining all related tables
     635:      *
     636:      * @param      Criteria $criteria
     637:      * @param      boolean $distinct Whether to select only distinct columns; deprecated: use Criteria->setDistinct() instead.
     638:      * @param      PropelPDO $con
     639:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     640:      * @return int Number of matching rows.
     641:      */
     642:     public static function doCountJoinAll(Criteria $criteria, $distinct = false, PropelPDO $con = null, $join_behavior = Criteria::LEFT_JOIN)
     643:     {
     644:         // we're going to modify criteria, so copy it first
     645:         $criteria = clone $criteria;
     646:
     647:         // We need to set the primary table name, since in the case that there are no WHERE columns
     648:         // it will be impossible for the BasePeer::createSelectSql() method to determine which
     649:         // tables go into the FROM clause.
     650:         $criteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
     651:
     652:         if ($distinct && !in_array(Criteria::DISTINCT, $criteria->getSelectModifiers())) {
     653:             $criteria->setDistinct();
     654:         }
     655:
     656:         if (!$criteria->hasSelectClause()) {
     657:             CountryPeer::addSelectColumns($criteria);
     658:         }
     659:
     660:         $criteria->clearOrderByColumns(); // ORDER BY won't ever affect the count
     661:
     662:         // Set the correct dbName
     663:         $criteria->setDbName(CountryPeer::DATABASE_NAME);
     664:
     665:         if ($con === null) {
     666:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     667:         }
     668:
     669:         $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
     670:
     671:         $stmt = BasePeer::doCount($criteria, $con);
     672:
     673:         if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     674:             $count = (int) $row[0];
     675:         } else {
     676:             $count = 0; // no rows returned; we infer that means 0 matches.
     677:         }
     678:         $stmt->closeCursor();
     679:
     680:         return $count;
     681:     }
     682:
     683:     /**
     684:      * Selects a collection of Country objects pre-filled with all related objects.
     685:      *
     686:      * @param      Criteria  $criteria
     687:      * @param      PropelPDO $con
     688:      * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
     689:      * @return array           Array of Country objects.
     690:      * @throws PropelException Any exceptions caught during processing will be
     691:      *       rethrown wrapped into a PropelException.
     692:      */
     693:     public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
     694:     {
     695:         $criteria = clone $criteria;
     696:
     697:         // Set the correct dbName if it has not been overridden
     698:         if ($criteria->getDbName() == Propel::getDefaultDB()) {
     699:             $criteria->setDbName(CountryPeer::DATABASE_NAME);
     700:         }
     701:
     702:         CountryPeer::addSelectColumns($criteria);
     703:         $startcol2 = CountryPeer::NUM_HYDRATE_COLUMNS;
     704:
     705:         AreaPeer::addSelectColumns($criteria);
     706:         $startcol3 = $startcol2 + AreaPeer::NUM_HYDRATE_COLUMNS;
     707:
     708:         $criteria->addJoin(CountryPeer::AREA_ID, AreaPeer::ID, $join_behavior);
     709:
     710:         $stmt = BasePeer::doSelect($criteria, $con);
     711:         $results = array();
     712:
     713:         while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
     714:             $key1 = CountryPeer::getPrimaryKeyHashFromRow($row, 0);
     715:             if (null !== ($obj1 = CountryPeer::getInstanceFromPool($key1))) {
     716:                 // We no longer rehydrate the object, since this can cause data loss.
     717:                 // See http://www.propelorm.org/ticket/509
     718:                 // $obj1->hydrate($row, 0, true); // rehydrate
     719:             } else {
     720:                 $cls = CountryPeer::getOMClass();
     721:
     722:                 $obj1 = new $cls();
     723:                 $obj1->hydrate($row);
     724:                 CountryPeer::addInstanceToPool($obj1, $key1);
     725:             } // if obj1 already loaded
     726:
     727:             // Add objects for joined Area rows
     728:
     729:             $key2 = AreaPeer::getPrimaryKeyHashFromRow($row, $startcol2);
     730:             if ($key2 !== null) {
     731:                 $obj2 = AreaPeer::getInstanceFromPool($key2);
     732:                 if (!$obj2) {
     733:
     734:                     $cls = AreaPeer::getOMClass();
     735:
     736:                     $obj2 = new $cls();
     737:                     $obj2->hydrate($row, $startcol2);
     738:                     AreaPeer::addInstanceToPool($obj2, $key2);
     739:                 } // if obj2 loaded
     740:
     741:                 // Add the $obj1 (Country) to the collection in $obj2 (Area)
     742:                 $obj2->addCountry($obj1);
     743:             } // if joined row not null
     744:
     745:             $results[] = $obj1;
     746:         }
     747:         $stmt->closeCursor();
     748:
     749:         return $results;
     750:     }
     751:
     752:     /**
     753:      * Returns the TableMap related to this peer.
     754:      * This method is not needed for general use but a specific application could have a need.
     755:      * @return TableMap
     756:      * @throws PropelException Any exceptions caught during processing will be
     757:      *       rethrown wrapped into a PropelException.
     758:      */
     759:     public static function getTableMap()
     760:     {
     761:         return Propel::getDatabaseMap(CountryPeer::DATABASE_NAME)->getTable(CountryPeer::TABLE_NAME);
     762:     }
     763:
     764:     /**
     765:      * Add a TableMap instance to the database for this peer class.
     766:      */
     767:     public static function buildTableMap()
     768:     {
     769:       $dbMap = Propel::getDatabaseMap(BaseCountryPeer::DATABASE_NAME);
     770:       if (!$dbMap->hasTable(BaseCountryPeer::TABLE_NAME)) {
     771:         $dbMap->addTableObject(new CountryTableMap());
     772:       }
     773:     }
     774:
     775:     /**
     776:      * The class that the Peer will make instances of.
     777:      *
     778:      *
     779:      * @return string ClassName
     780:      */
     781:     public static function getOMClass($row = 0, $colnum = 0)
     782:     {
     783:         return CountryPeer::OM_CLASS;
     784:     }
     785:
     786:     /**
     787:      * Performs an INSERT on the database, given a Country or Criteria object.
     788:      *
     789:      * @param      mixed $values Criteria or Country object containing data that is used to create the INSERT statement.
     790:      * @param      PropelPDO $con the PropelPDO connection to use
     791:      * @return mixed           The new primary key.
     792:      * @throws PropelException Any exceptions caught during processing will be
     793:      *       rethrown wrapped into a PropelException.
     794:      */
     795:     public static function doInsert($values, PropelPDO $con = null)
     796:     {
     797:         if ($con === null) {
     798:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     799:         }
     800:
     801:         if ($values instanceof Criteria) {
     802:             $criteria = clone $values; // rename for clarity
     803:         } else {
     804:             $criteria = $values->buildCriteria(); // build Criteria from Country object
     805:         }
     806:
     807:
     808:         // Set the correct dbName
     809:         $criteria->setDbName(CountryPeer::DATABASE_NAME);
     810:
     811:         try {
     812:             // use transaction because $criteria could contain info
     813:             // for more than one table (I guess, conceivably)
     814:             $con->beginTransaction();
     815:             $pk = BasePeer::doInsert($criteria, $con);
     816:             $con->commit();
     817:         } catch (PropelException $e) {
     818:             $con->rollBack();
     819:             throw $e;
     820:         }
     821:
     822:         return $pk;
     823:     }
     824:
     825:     /**
     826:      * Performs an UPDATE on the database, given a Country or Criteria object.
     827:      *
     828:      * @param      mixed $values Criteria or Country object containing data that is used to create the UPDATE statement.
     829:      * @param      PropelPDO $con The connection to use (specify PropelPDO connection object to exert more control over transactions).
     830:      * @return int             The number of affected rows (if supported by underlying database driver).
     831:      * @throws PropelException Any exceptions caught during processing will be
     832:      *       rethrown wrapped into a PropelException.
     833:      */
     834:     public static function doUpdate($values, PropelPDO $con = null)
     835:     {
     836:         if ($con === null) {
     837:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     838:         }
     839:
     840:         $selectCriteria = new Criteria(CountryPeer::DATABASE_NAME);
     841:
     842:         if ($values instanceof Criteria) {
     843:             $criteria = clone $values; // rename for clarity
     844:
     845:             $comparison = $criteria->getComparison(CountryPeer::ID);
     846:             $value = $criteria->remove(CountryPeer::ID);
     847:             if ($value) {
     848:                 $selectCriteria->add(CountryPeer::ID, $value, $comparison);
     849:             } else {
     850:                 $selectCriteria->setPrimaryTableName(CountryPeer::TABLE_NAME);
     851:             }
     852:
     853:         } else { // $values is Country object
     854:             $criteria = $values->buildCriteria(); // gets full criteria
     855:             $selectCriteria = $values->buildPkeyCriteria(); // gets criteria w/ primary key(s)
     856:         }
     857:
     858:         // set the correct dbName
     859:         $criteria->setDbName(CountryPeer::DATABASE_NAME);
     860:
     861:         return BasePeer::doUpdate($selectCriteria, $criteria, $con);
     862:     }
     863:
     864:     /**
     865:      * Deletes all rows from the country table.
     866:      *
     867:      * @param      PropelPDO $con the connection to use
     868:      * @return int             The number of affected rows (if supported by underlying database driver).
     869:      * @throws PropelException
     870:      */
     871:     public static function doDeleteAll(PropelPDO $con = null)
     872:     {
     873:         if ($con === null) {
     874:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     875:         }
     876:         $affectedRows = 0; // initialize var to track total num of affected rows
     877:         try {
     878:             // use transaction because $criteria could contain info
     879:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
     880:             $con->beginTransaction();
     881:             $affectedRows += BasePeer::doDeleteAll(CountryPeer::TABLE_NAME, $con, CountryPeer::DATABASE_NAME);
     882:             // Because this db requires some delete cascade/set null emulation, we have to
     883:             // clear the cached instance *after* the emulation has happened (since
     884:             // instances get re-added by the select statement contained therein).
     885:             CountryPeer::clearInstancePool();
     886:             CountryPeer::clearRelatedInstancePool();
     887:             $con->commit();
     888:
     889:             return $affectedRows;
     890:         } catch (PropelException $e) {
     891:             $con->rollBack();
     892:             throw $e;
     893:         }
     894:     }
     895:
     896:     /**
     897:      * Performs a DELETE on the database, given a Country or Criteria object OR a primary key value.
     898:      *
     899:      * @param      mixed $values Criteria or Country object or primary key or array of primary keys
     900:      *              which is used to create the DELETE statement
     901:      * @param      PropelPDO $con the connection to use
     902:      * @return int The number of affected rows (if supported by underlying database driver).  This includes CASCADE-related rows
     903:      *              if supported by native driver or if emulated using Propel.
     904:      * @throws PropelException Any exceptions caught during processing will be
     905:      *       rethrown wrapped into a PropelException.
     906:      */
     907:      public static function doDelete($values, PropelPDO $con = null)
     908:      {
     909:         if ($con === null) {
     910:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     911:         }
     912:
     913:         if ($values instanceof Criteria) {
     914:             // invalidate the cache for all objects of this type, since we have no
     915:             // way of knowing (without running a query) what objects should be invalidated
     916:             // from the cache based on this Criteria.
     917:             CountryPeer::clearInstancePool();
     918:             // rename for clarity
     919:             $criteria = clone $values;
     920:         } elseif ($values instanceof Country) { // it's a model object
     921:             // invalidate the cache for this single object
     922:             CountryPeer::removeInstanceFromPool($values);
     923:             // create criteria based on pk values
     924:             $criteria = $values->buildPkeyCriteria();
     925:         } else { // it's a primary key, or an array of pks
     926:             $criteria = new Criteria(CountryPeer::DATABASE_NAME);
     927:             $criteria->add(CountryPeer::ID, (array) $values, Criteria::IN);
     928:             // invalidate the cache for this object(s)
     929:             foreach ((array) $values as $singleval) {
     930:                 CountryPeer::removeInstanceFromPool($singleval);
     931:             }
     932:         }
     933:
     934:         // Set the correct dbName
     935:         $criteria->setDbName(CountryPeer::DATABASE_NAME);
     936:
     937:         $affectedRows = 0; // initialize var to track total num of affected rows
     938:
     939:         try {
     940:             // use transaction because $criteria could contain info
     941:             // for more than one table or we could emulating ON DELETE CASCADE, etc.
     942:             $con->beginTransaction();
     943:
     944:             $affectedRows += BasePeer::doDelete($criteria, $con);
     945:             CountryPeer::clearRelatedInstancePool();
     946:             $con->commit();
     947:
     948:             return $affectedRows;
     949:         } catch (PropelException $e) {
     950:             $con->rollBack();
     951:             throw $e;
     952:         }
     953:     }
     954:
     955:     /**
     956:      * Validates all modified columns of given Country object.
     957:      * If parameter $columns is either a single column name or an array of column names
     958:      * than only those columns are validated.
     959:      *
     960:      * NOTICE: This does not apply to primary or foreign keys for now.
     961:      *
     962:      * @param      Country $obj The object to validate.
     963:      * @param      mixed $cols Column name or array of column names.
     964:      *
     965:      * @return mixed TRUE if all columns are valid or the error message of the first invalid column.
     966:      */
     967:     public static function doValidate($obj, $cols = null)
     968:     {
     969:         $columns = array();
     970:
     971:         if ($cols) {
     972:             $dbMap = Propel::getDatabaseMap(CountryPeer::DATABASE_NAME);
     973:             $tableMap = $dbMap->getTable(CountryPeer::TABLE_NAME);
     974:
     975:             if (! is_array($cols)) {
     976:                 $cols = array($cols);
     977:             }
     978:
     979:             foreach ($cols as $colName) {
     980:                 if ($tableMap->hasColumn($colName)) {
     981:                     $get = 'get' . $tableMap->getColumn($colName)->getPhpName();
     982:                     $columns[$colName] = $obj->$get();
     983:                 }
     984:             }
     985:         } else {
     986:
     987:         }
     988:
     989:         return BasePeer::doValidate(CountryPeer::DATABASE_NAME, CountryPeer::TABLE_NAME, $columns);
     990:     }
     991:
     992:     /**
     993:      * Retrieve a single object by pkey.
     994:      *
     995:      * @param      int $pk the primary key.
     996:      * @param      PropelPDO $con the connection to use
     997:      * @return Country
     998:      */
     999:     public static function retrieveByPK($pk, PropelPDO $con = null)
    1000:     {
    1001:
    1002:         if (null !== ($obj = CountryPeer::getInstanceFromPool((string) $pk))) {
    1003:             return $obj;
    1004:         }
    1005:
    1006:         if ($con === null) {
    1007:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1008:         }
    1009:
    1010:         $criteria = new Criteria(CountryPeer::DATABASE_NAME);
    1011:         $criteria->add(CountryPeer::ID, $pk);
    1012:
    1013:         $v = CountryPeer::doSelect($criteria, $con);
    1014:
    1015:         return !empty($v) > 0 ? $v[0] : null;
    1016:     }
    1017:
    1018:     /**
    1019:      * Retrieve multiple objects by pkey.
    1020:      *
    1021:      * @param      array $pks List of primary keys
    1022:      * @param      PropelPDO $con the connection to use
    1023:      * @return Country[]
    1024:      * @throws PropelException Any exceptions caught during processing will be
    1025:      *       rethrown wrapped into a PropelException.
    1026:      */
    1027:     public static function retrieveByPKs($pks, PropelPDO $con = null)
    1028:     {
    1029:         if ($con === null) {
    1030:             $con = Propel::getConnection(CountryPeer::DATABASE_NAME, Propel::CONNECTION_READ);
    1031:         }
    1032:
    1033:         $objs = null;
    1034:         if (empty($pks)) {
    1035:             $objs = array();
    1036:         } else {
    1037:             $criteria = new Criteria(CountryPeer::DATABASE_NAME);
    1038:             $criteria->add(CountryPeer::ID, $pks, Criteria::IN);
    1039:             $objs = CountryPeer::doSelect($criteria, $con);
    1040:         }
    1041:
    1042:         return $objs;
    1043:     }
    1044:
    1045: } // BaseCountryPeer
    1046:
    1047: // This is the static code needed to register the TableMap for this table with the main Propel class.
    1048: //
    1049: BaseCountryPeer::buildTableMap();
    1050:
    1051: