1: <?php
2:
3: namespace cli_db\propel\om;
4:
5: use \Criteria;
6: use \Exception;
7: use \ModelCriteria;
8: use \ModelJoin;
9: use \PDO;
10: use \Propel;
11: use \PropelCollection;
12: use \PropelException;
13: use \PropelObjectCollection;
14: use \PropelPDO;
15: use cli_db\propel\Db;
16: use cli_db\propel\DbPeer;
17: use cli_db\propel\DbQuery;
18: use cli_db\propel\Dbxref;
19:
20: /**
21: * Base class that represents a query for the 'db' table.
22: *
23: *
24: *
25: * @method DbQuery orderByDbId($order = Criteria::ASC) Order by the db_id column
26: * @method DbQuery orderByName($order = Criteria::ASC) Order by the name column
27: * @method DbQuery orderByDescription($order = Criteria::ASC) Order by the description column
28: * @method DbQuery orderByUrlprefix($order = Criteria::ASC) Order by the urlprefix column
29: * @method DbQuery orderByUrl($order = Criteria::ASC) Order by the url column
30: *
31: * @method DbQuery groupByDbId() Group by the db_id column
32: * @method DbQuery groupByName() Group by the name column
33: * @method DbQuery groupByDescription() Group by the description column
34: * @method DbQuery groupByUrlprefix() Group by the urlprefix column
35: * @method DbQuery groupByUrl() Group by the url column
36: *
37: * @method DbQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
38: * @method DbQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
39: * @method DbQuery innerJoin($relation) Adds a INNER JOIN clause to the query
40: *
41: * @method DbQuery leftJoinDbxref($relationAlias = null) Adds a LEFT JOIN clause to the query using the Dbxref relation
42: * @method DbQuery rightJoinDbxref($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Dbxref relation
43: * @method DbQuery innerJoinDbxref($relationAlias = null) Adds a INNER JOIN clause to the query using the Dbxref relation
44: *
45: * @method Db findOne(PropelPDO $con = null) Return the first Db matching the query
46: * @method Db findOneOrCreate(PropelPDO $con = null) Return the first Db matching the query, or a new Db object populated from the query conditions when no match is found
47: *
48: * @method Db findOneByName(string $name) Return the first Db filtered by the name column
49: * @method Db findOneByDescription(string $description) Return the first Db filtered by the description column
50: * @method Db findOneByUrlprefix(string $urlprefix) Return the first Db filtered by the urlprefix column
51: * @method Db findOneByUrl(string $url) Return the first Db filtered by the url column
52: *
53: * @method array findByDbId(int $db_id) Return Db objects filtered by the db_id column
54: * @method array findByName(string $name) Return Db objects filtered by the name column
55: * @method array findByDescription(string $description) Return Db objects filtered by the description column
56: * @method array findByUrlprefix(string $urlprefix) Return Db objects filtered by the urlprefix column
57: * @method array findByUrl(string $url) Return Db objects filtered by the url column
58: *
59: * @package propel.generator.cli_db.om
60: */
61: abstract class BaseDbQuery extends ModelCriteria
62: {
63: /**
64: * Initializes internal state of BaseDbQuery object.
65: *
66: * @param string $dbName The dabase name
67: * @param string $modelName The phpName of a model, e.g. 'Book'
68: * @param string $modelAlias The alias for the model in this query, e.g. 'b'
69: */
70: public function __construct($dbName = 'cli_db', $modelName = 'cli_db\\propel\\Db', $modelAlias = null)
71: {
72: parent::__construct($dbName, $modelName, $modelAlias);
73: }
74:
75: /**
76: * Returns a new DbQuery object.
77: *
78: * @param string $modelAlias The alias of a model in the query
79: * @param DbQuery|Criteria $criteria Optional Criteria to build the query from
80: *
81: * @return DbQuery
82: */
83: public static function create($modelAlias = null, $criteria = null)
84: {
85: if ($criteria instanceof DbQuery) {
86: return $criteria;
87: }
88: $query = new DbQuery();
89: if (null !== $modelAlias) {
90: $query->setModelAlias($modelAlias);
91: }
92: if ($criteria instanceof Criteria) {
93: $query->mergeWith($criteria);
94: }
95:
96: return $query;
97: }
98:
99: /**
100: * Find object by primary key.
101: * Propel uses the instance pool to skip the database if the object exists.
102: * Go fast if the query is untouched.
103: *
104: * <code>
105: * $obj = $c->findPk(12, $con);
106: * </code>
107: *
108: * @param mixed $key Primary key to use for the query
109: * @param PropelPDO $con an optional connection object
110: *
111: * @return Db|Db[]|mixed the result, formatted by the current formatter
112: */
113: public function findPk($key, $con = null)
114: {
115: if ($key === null) {
116: return null;
117: }
118: if ((null !== ($obj = DbPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
119: // the object is alredy in the instance pool
120: return $obj;
121: }
122: if ($con === null) {
123: $con = Propel::getConnection(DbPeer::DATABASE_NAME, Propel::CONNECTION_READ);
124: }
125: $this->basePreSelect($con);
126: if ($this->formatter || $this->modelAlias || $this->with || $this->select
127: || $this->selectColumns || $this->asColumns || $this->selectModifiers
128: || $this->map || $this->having || $this->joins) {
129: return $this->findPkComplex($key, $con);
130: } else {
131: return $this->findPkSimple($key, $con);
132: }
133: }
134:
135: /**
136: * Alias of findPk to use instance pooling
137: *
138: * @param mixed $key Primary key to use for the query
139: * @param PropelPDO $con A connection object
140: *
141: * @return Db A model object, or null if the key is not found
142: * @throws PropelException
143: */
144: public function findOneByDbId($key, $con = null)
145: {
146: return $this->findPk($key, $con);
147: }
148:
149: /**
150: * Find object by primary key using raw SQL to go fast.
151: * Bypass doSelect() and the object formatter by using generated code.
152: *
153: * @param mixed $key Primary key to use for the query
154: * @param PropelPDO $con A connection object
155: *
156: * @return Db A model object, or null if the key is not found
157: * @throws PropelException
158: */
159: protected function findPkSimple($key, $con)
160: {
161: $sql = 'SELECT "db_id", "name", "description", "urlprefix", "url" FROM "db" WHERE "db_id" = :p0';
162: try {
163: $stmt = $con->prepare($sql);
164: $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
165: $stmt->execute();
166: } catch (Exception $e) {
167: Propel::log($e->getMessage(), Propel::LOG_ERR);
168: throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
169: }
170: $obj = null;
171: if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
172: $obj = new Db();
173: $obj->hydrate($row);
174: DbPeer::addInstanceToPool($obj, (string) $key);
175: }
176: $stmt->closeCursor();
177:
178: return $obj;
179: }
180:
181: /**
182: * Find object by primary key.
183: *
184: * @param mixed $key Primary key to use for the query
185: * @param PropelPDO $con A connection object
186: *
187: * @return Db|Db[]|mixed the result, formatted by the current formatter
188: */
189: protected function findPkComplex($key, $con)
190: {
191: // As the query uses a PK condition, no limit(1) is necessary.
192: $criteria = $this->isKeepQuery() ? clone $this : $this;
193: $stmt = $criteria
194: ->filterByPrimaryKey($key)
195: ->doSelect($con);
196:
197: return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
198: }
199:
200: /**
201: * Find objects by primary key
202: * <code>
203: * $objs = $c->findPks(array(12, 56, 832), $con);
204: * </code>
205: * @param array $keys Primary keys to use for the query
206: * @param PropelPDO $con an optional connection object
207: *
208: * @return PropelObjectCollection|Db[]|mixed the list of results, formatted by the current formatter
209: */
210: public function findPks($keys, $con = null)
211: {
212: if ($con === null) {
213: $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
214: }
215: $this->basePreSelect($con);
216: $criteria = $this->isKeepQuery() ? clone $this : $this;
217: $stmt = $criteria
218: ->filterByPrimaryKeys($keys)
219: ->doSelect($con);
220:
221: return $criteria->getFormatter()->init($criteria)->format($stmt);
222: }
223:
224: /**
225: * Filter the query by primary key
226: *
227: * @param mixed $key Primary key to use for the query
228: *
229: * @return DbQuery The current query, for fluid interface
230: */
231: public function filterByPrimaryKey($key)
232: {
233:
234: return $this->addUsingAlias(DbPeer::DB_ID, $key, Criteria::EQUAL);
235: }
236:
237: /**
238: * Filter the query by a list of primary keys
239: *
240: * @param array $keys The list of primary key to use for the query
241: *
242: * @return DbQuery The current query, for fluid interface
243: */
244: public function filterByPrimaryKeys($keys)
245: {
246:
247: return $this->addUsingAlias(DbPeer::DB_ID, $keys, Criteria::IN);
248: }
249:
250: /**
251: * Filter the query on the db_id column
252: *
253: * Example usage:
254: * <code>
255: * $query->filterByDbId(1234); // WHERE db_id = 1234
256: * $query->filterByDbId(array(12, 34)); // WHERE db_id IN (12, 34)
257: * $query->filterByDbId(array('min' => 12)); // WHERE db_id >= 12
258: * $query->filterByDbId(array('max' => 12)); // WHERE db_id <= 12
259: * </code>
260: *
261: * @param mixed $dbId The value to use as filter.
262: * Use scalar values for equality.
263: * Use array values for in_array() equivalent.
264: * Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
265: * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
266: *
267: * @return DbQuery The current query, for fluid interface
268: */
269: public function filterByDbId($dbId = null, $comparison = null)
270: {
271: if (is_array($dbId)) {
272: $useMinMax = false;
273: if (isset($dbId['min'])) {
274: $this->addUsingAlias(DbPeer::DB_ID, $dbId['min'], Criteria::GREATER_EQUAL);
275: $useMinMax = true;
276: }
277: if (isset($dbId['max'])) {
278: $this->addUsingAlias(DbPeer::DB_ID, $dbId['max'], Criteria::LESS_EQUAL);
279: $useMinMax = true;
280: }
281: if ($useMinMax) {
282: return $this;
283: }
284: if (null === $comparison) {
285: $comparison = Criteria::IN;
286: }
287: }
288:
289: return $this->addUsingAlias(DbPeer::DB_ID, $dbId, $comparison);
290: }
291:
292: /**
293: * Filter the query on the name column
294: *
295: * Example usage:
296: * <code>
297: * $query->filterByName('fooValue'); // WHERE name = 'fooValue'
298: * $query->filterByName('%fooValue%'); // WHERE name LIKE '%fooValue%'
299: * </code>
300: *
301: * @param string $name The value to use as filter.
302: * Accepts wildcards (* and % trigger a LIKE)
303: * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
304: *
305: * @return DbQuery The current query, for fluid interface
306: */
307: public function filterByName($name = null, $comparison = null)
308: {
309: if (null === $comparison) {
310: if (is_array($name)) {
311: $comparison = Criteria::IN;
312: } elseif (preg_match('/[\%\*]/', $name)) {
313: $name = str_replace('*', '%', $name);
314: $comparison = Criteria::LIKE;
315: }
316: }
317:
318: return $this->addUsingAlias(DbPeer::NAME, $name, $comparison);
319: }
320:
321: /**
322: * Filter the query on the description column
323: *
324: * Example usage:
325: * <code>
326: * $query->filterByDescription('fooValue'); // WHERE description = 'fooValue'
327: * $query->filterByDescription('%fooValue%'); // WHERE description LIKE '%fooValue%'
328: * </code>
329: *
330: * @param string $description The value to use as filter.
331: * Accepts wildcards (* and % trigger a LIKE)
332: * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
333: *
334: * @return DbQuery The current query, for fluid interface
335: */
336: public function filterByDescription($description = null, $comparison = null)
337: {
338: if (null === $comparison) {
339: if (is_array($description)) {
340: $comparison = Criteria::IN;
341: } elseif (preg_match('/[\%\*]/', $description)) {
342: $description = str_replace('*', '%', $description);
343: $comparison = Criteria::LIKE;
344: }
345: }
346:
347: return $this->addUsingAlias(DbPeer::DESCRIPTION, $description, $comparison);
348: }
349:
350: /**
351: * Filter the query on the urlprefix column
352: *
353: * Example usage:
354: * <code>
355: * $query->filterByUrlprefix('fooValue'); // WHERE urlprefix = 'fooValue'
356: * $query->filterByUrlprefix('%fooValue%'); // WHERE urlprefix LIKE '%fooValue%'
357: * </code>
358: *
359: * @param string $urlprefix The value to use as filter.
360: * Accepts wildcards (* and % trigger a LIKE)
361: * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
362: *
363: * @return DbQuery The current query, for fluid interface
364: */
365: public function filterByUrlprefix($urlprefix = null, $comparison = null)
366: {
367: if (null === $comparison) {
368: if (is_array($urlprefix)) {
369: $comparison = Criteria::IN;
370: } elseif (preg_match('/[\%\*]/', $urlprefix)) {
371: $urlprefix = str_replace('*', '%', $urlprefix);
372: $comparison = Criteria::LIKE;
373: }
374: }
375:
376: return $this->addUsingAlias(DbPeer::URLPREFIX, $urlprefix, $comparison);
377: }
378:
379: /**
380: * Filter the query on the url column
381: *
382: * Example usage:
383: * <code>
384: * $query->filterByUrl('fooValue'); // WHERE url = 'fooValue'
385: * $query->filterByUrl('%fooValue%'); // WHERE url LIKE '%fooValue%'
386: * </code>
387: *
388: * @param string $url The value to use as filter.
389: * Accepts wildcards (* and % trigger a LIKE)
390: * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
391: *
392: * @return DbQuery The current query, for fluid interface
393: */
394: public function filterByUrl($url = null, $comparison = null)
395: {
396: if (null === $comparison) {
397: if (is_array($url)) {
398: $comparison = Criteria::IN;
399: } elseif (preg_match('/[\%\*]/', $url)) {
400: $url = str_replace('*', '%', $url);
401: $comparison = Criteria::LIKE;
402: }
403: }
404:
405: return $this->addUsingAlias(DbPeer::URL, $url, $comparison);
406: }
407:
408: /**
409: * Filter the query by a related Dbxref object
410: *
411: * @param Dbxref|PropelObjectCollection $dbxref the related object to use as filter
412: * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
413: *
414: * @return DbQuery The current query, for fluid interface
415: * @throws PropelException - if the provided filter is invalid.
416: */
417: public function filterByDbxref($dbxref, $comparison = null)
418: {
419: if ($dbxref instanceof Dbxref) {
420: return $this
421: ->addUsingAlias(DbPeer::DB_ID, $dbxref->getDbId(), $comparison);
422: } elseif ($dbxref instanceof PropelObjectCollection) {
423: return $this
424: ->useDbxrefQuery()
425: ->filterByPrimaryKeys($dbxref->getPrimaryKeys())
426: ->endUse();
427: } else {
428: throw new PropelException('filterByDbxref() only accepts arguments of type Dbxref or PropelCollection');
429: }
430: }
431:
432: /**
433: * Adds a JOIN clause to the query using the Dbxref relation
434: *
435: * @param string $relationAlias optional alias for the relation
436: * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
437: *
438: * @return DbQuery The current query, for fluid interface
439: */
440: public function joinDbxref($relationAlias = null, $joinType = Criteria::INNER_JOIN)
441: {
442: $tableMap = $this->getTableMap();
443: $relationMap = $tableMap->getRelation('Dbxref');
444:
445: // create a ModelJoin object for this join
446: $join = new ModelJoin();
447: $join->setJoinType($joinType);
448: $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
449: if ($previousJoin = $this->getPreviousJoin()) {
450: $join->setPreviousJoin($previousJoin);
451: }
452:
453: // add the ModelJoin to the current object
454: if ($relationAlias) {
455: $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
456: $this->addJoinObject($join, $relationAlias);
457: } else {
458: $this->addJoinObject($join, 'Dbxref');
459: }
460:
461: return $this;
462: }
463:
464: /**
465: * Use the Dbxref relation Dbxref object
466: *
467: * @see useQuery()
468: *
469: * @param string $relationAlias optional alias for the relation,
470: * to be used as main alias in the secondary query
471: * @param string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
472: *
473: * @return \cli_db\propel\DbxrefQuery A secondary query class using the current class as primary query
474: */
475: public function useDbxrefQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
476: {
477: return $this
478: ->joinDbxref($relationAlias, $joinType)
479: ->useQuery($relationAlias ? $relationAlias : 'Dbxref', '\cli_db\propel\DbxrefQuery');
480: }
481:
482: /**
483: * Exclude object from result
484: *
485: * @param Db $db Object to remove from the list of results
486: *
487: * @return DbQuery The current query, for fluid interface
488: */
489: public function prune($db = null)
490: {
491: if ($db) {
492: $this->addUsingAlias(DbPeer::DB_ID, $db->getDbId(), Criteria::NOT_EQUAL);
493: }
494:
495: return $this;
496: }
497:
498: }
499: