本文整理汇总了PHP中BookPeer::addSelectColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP BookPeer::addSelectColumns方法的具体用法?PHP BookPeer::addSelectColumns怎么用?PHP BookPeer::addSelectColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookPeer
的用法示例。
在下文中一共展示了BookPeer::addSelectColumns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddSelectColumnsAlias
public function testAddSelectColumnsAlias()
{
$c = new Criteria();
BookPeer::addSelectColumns($c, 'foo');
$expected = array('foo.id', 'foo.title', 'foo.isbn', 'foo.price', 'foo.publisher_id', 'foo.author_id');
$this->assertEquals($expected, $c->getSelectColumns(), 'addSelectColumns() uses the second parameter as a table alias');
}
示例2: testDoCount
public function testDoCount()
{
try {
$c = new Criteria();
$c->add(BookPeer::ID, 12, ' BAD SQL');
BookPeer::addSelectColumns($c);
BasePeer::doCount($c);
} catch (PropelException $e) {
$this->assertContains('[SELECT COUNT(*) FROM `book` WHERE book.ID BAD SQL:p1]', $e->getMessage(), 'SQL query is written in the exception message');
}
}
示例3: testApplyLimitDuplicateColumnName
public function testApplyLimitDuplicateColumnName()
{
Propel::setDb('oracle', new DBOracle());
$c = new Criteria();
$c->setDbName('oracle');
BookPeer::addSelectColumns($c);
AuthorPeer::addSelectColumns($c);
$c->setLimit(1);
$params = array();
$sql = BasePeer::createSelectSql($c, $params);
$this->assertEquals('SELECT B.* FROM (SELECT A.*, rownum AS PROPEL_ROWNUM FROM (SELECT book.ID AS book_ID, book.TITLE AS book_TITLE, book.ISBN AS book_ISBN, book.PRICE AS book_PRICE, book.PUBLISHER_ID AS book_PUBLISHER_ID, book.AUTHOR_ID AS book_AUTHOR_ID, author.ID AS author_ID, author.FIRST_NAME AS author_FIRST_NAME, author.LAST_NAME AS author_LAST_NAME, author.EMAIL AS author_EMAIL, author.AGE AS author_AGESELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, author.ID, author.FIRST_NAME, author.LAST_NAME, author.EMAIL, author.AGE FROM book, author) A ) B WHERE B.PROPEL_ROWNUM <= 1', $sql, 'applyLimit() creates a subselect with aliased column names when a duplicate column name is found');
}
示例4: testSubQueryExplicit
public function testSubQueryExplicit()
{
$subCriteria = new BookQuery();
BookPeer::addSelectColumns($subCriteria);
$subCriteria->orderByTitle(Criteria::ASC);
$c = new BookQuery();
BookPeer::addSelectColumns($c, 'subCriteriaAlias');
$c->addSelectQuery($subCriteria, 'subCriteriaAlias', false);
$c->groupBy('subCriteriaAlias.AuthorId');
$sql = "SELECT subCriteriaAlias.ID, subCriteriaAlias.TITLE, subCriteriaAlias.ISBN, subCriteriaAlias.PRICE, subCriteriaAlias.PUBLISHER_ID, subCriteriaAlias.AUTHOR_ID FROM (SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` ORDER BY book.TITLE ASC) AS subCriteriaAlias GROUP BY subCriteriaAlias.AUTHOR_ID";
$params = array();
$this->assertCriteriaTranslation($c, $sql, $params, 'addSubQueryCriteriaInFrom() combines two queries succesfully');
}
示例5: testApplyLimitDuplicateColumnNameWithColumn
public function testApplyLimitDuplicateColumnNameWithColumn()
{
Propel::setDb('oracle', new DBOracle());
$c = new Criteria();
$c->setDbName('oracle');
BookPeer::addSelectColumns($c);
AuthorPeer::addSelectColumns($c);
$c->addAsColumn('BOOK_PRICE', BookPeer::PRICE);
$c->setLimit(1);
$params = array();
$asColumns = $c->getAsColumns();
$sql = BasePeer::createSelectSql($c, $params);
$this->assertEquals('SELECT B.* FROM (SELECT A.*, rownum AS PROPEL_ROWNUM FROM (SELECT book.ID AS ORA_COL_ALIAS_0, book.TITLE AS ORA_COL_ALIAS_1, book.ISBN AS ORA_COL_ALIAS_2, book.PRICE AS ORA_COL_ALIAS_3, book.PUBLISHER_ID AS ORA_COL_ALIAS_4, book.AUTHOR_ID AS ORA_COL_ALIAS_5, author.ID AS ORA_COL_ALIAS_6, author.FIRST_NAME AS ORA_COL_ALIAS_7, author.LAST_NAME AS ORA_COL_ALIAS_8, author.EMAIL AS ORA_COL_ALIAS_9, author.AGE AS ORA_COL_ALIAS_10, book.PRICE AS BOOK_PRICE FROM book, author) A ) B WHERE B.PROPEL_ROWNUM <= 1', $sql, 'applyLimit() creates a subselect with aliased column names when a duplicate column name is found');
$this->assertEquals($asColumns, $c->getAsColumns(), 'createSelectSql supplementary add alias column');
}
示例6: testNeedsSelectAliases
public function testNeedsSelectAliases()
{
$c = new Criteria();
$this->assertFalse(BasePeer::needsSelectAliases($c), 'Empty Criterias dont need aliases');
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(BookPeer::TITLE);
$this->assertFalse(BasePeer::needsSelectAliases($c), 'Criterias with distinct column names dont need aliases');
$c = new Criteria();
BookPeer::addSelectColumns($c);
$this->assertFalse(BasePeer::needsSelectAliases($c), 'Criterias with only the columns of a model dont need aliases');
$c = new Criteria();
$c->addSelectColumn(BookPeer::ID);
$c->addSelectColumn(AuthorPeer::ID);
$this->assertTrue(BasePeer::needsSelectAliases($c), 'Criterias with common column names do need aliases');
}
示例7: testOrderByIgnoreCase
public function testOrderByIgnoreCase()
{
$originalDB = Propel::getDB();
Propel::setDB(null, new DBMySQL());
$criteria = new Criteria();
$criteria->setIgnoreCase(true);
$criteria->addAscendingOrderByColumn(BookPeer::TITLE);
$criteria->addAsColumn(BookPeer::TITLE, 'title');
$params = array();
$sql = BasePeer::createSelectSql($criteria, $params);
$expectedSQL = 'SELECT UPPER(book.TITLE) FROM `book` ORDER BY UPPER(book.TITLE) ASC';
$this->assertEquals($expectedSQL, $sql);
$criteria = new Criteria();
$criteria->setIgnoreCase(true);
$criteria->addAscendingOrderByColumn(BookPeer::TITLE);
BookPeer::addSelectColumns($criteria);
$params = array();
$sql = BasePeer::createSelectSql($criteria, $params);
$expectedSQL = 'SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID, UPPER(book.TITLE) FROM `book` ORDER BY UPPER(book.TITLE) ASC';
$this->assertEquals($expectedSQL, $sql);
Propel::setDB(null, $originalDB);
}
示例8: getBooks
/**
* Gets an array of Book objects which contain a foreign key that references this object.
*
* If this collection has already been initialized with an identical Criteria, it returns the collection.
* Otherwise if this Author has previously been saved, it will retrieve
* related Books from storage. If this Author is new, it will return
* an empty collection or the current collection, the criteria is ignored on a new object.
*
* @param PropelPDO $con
* @param Criteria $criteria
* @return array Book[]
* @throws PropelException
*/
public function getBooks($criteria = null, PropelPDO $con = null)
{
if ($criteria === null) {
$criteria = new Criteria(AuthorPeer::DATABASE_NAME);
} elseif ($criteria instanceof Criteria) {
$criteria = clone $criteria;
}
if ($this->collBooks === null) {
if ($this->isNew()) {
$this->collBooks = array();
} else {
$criteria->add(BookPeer::AUTHOR_ID, $this->id);
BookPeer::addSelectColumns($criteria);
$this->collBooks = BookPeer::doSelect($criteria, $con);
}
} else {
// criteria has no effect for a new object
if (!$this->isNew()) {
// the following code is to determine if a new query is
// called for. If the criteria is the same as the last
// one, just return the collection.
$criteria->add(BookPeer::AUTHOR_ID, $this->id);
BookPeer::addSelectColumns($criteria);
if (!isset($this->lastBookCriteria) || !$this->lastBookCriteria->equals($criteria)) {
$this->collBooks = BookPeer::doSelect($criteria, $con);
}
}
}
$this->lastBookCriteria = $criteria;
return $this->collBooks;
}
示例9: doSelectRS
public static function doSelectRS(Criteria $criteria, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
if (!$criteria->getSelectColumns()) {
$criteria = clone $criteria;
BookPeer::addSelectColumns($criteria);
}
$criteria->setDbName(self::DATABASE_NAME);
return BasePeer::doSelect($criteria, $con);
}
示例10: doSelectJoinAllExceptCategory
/**
* Selects a collection of Article objects pre-filled with all related objects except Category.
*
* @param Criteria $criteria
* @param PropelPDO $con
* @param String $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
* @return array Array of Article objects.
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
*/
public static function doSelectJoinAllExceptCategory(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
{
$criteria = clone $criteria;
// Set the correct dbName if it has not been overridden
// $criteria->getDbName() will return the same object if not set to another value
// so == check is okay and faster
if ($criteria->getDbName() == Propel::getDefaultDB()) {
$criteria->setDbName(self::DATABASE_NAME);
}
ArticlePeer::addSelectColumns($criteria);
$startcol2 = ArticlePeer::NUM_COLUMNS - ArticlePeer::NUM_LAZY_LOAD_COLUMNS;
BookPeer::addSelectColumns($criteria);
$startcol3 = $startcol2 + (BookPeer::NUM_COLUMNS - BookPeer::NUM_LAZY_LOAD_COLUMNS);
$criteria->addJoin(ArticlePeer::BOOK_ID, BookPeer::ID, $join_behavior);
// symfony_behaviors behavior
foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
call_user_func($sf_hook, 'BaseArticlePeer', $criteria, $con);
}
$stmt = BasePeer::doSelect($criteria, $con);
$results = array();
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
$key1 = ArticlePeer::getPrimaryKeyHashFromRow($row, 0);
if (null !== ($obj1 = ArticlePeer::getInstanceFromPool($key1))) {
// We no longer rehydrate the object, since this can cause data loss.
// See http://propel.phpdb.org/trac/ticket/509
// $obj1->hydrate($row, 0, true); // rehydrate
} else {
$cls = ArticlePeer::getOMClass(false);
$obj1 = new $cls();
$obj1->hydrate($row);
ArticlePeer::addInstanceToPool($obj1, $key1);
}
// if obj1 already loaded
// Add objects for joined Book rows
$key2 = BookPeer::getPrimaryKeyHashFromRow($row, $startcol2);
if ($key2 !== null) {
$obj2 = BookPeer::getInstanceFromPool($key2);
if (!$obj2) {
$cls = BookPeer::getOMClass(false);
$obj2 = new $cls();
$obj2->hydrate($row, $startcol2);
BookPeer::addInstanceToPool($obj2, $key2);
}
// if $obj2 already loaded
// Add the $obj1 (Article) to the collection in $obj2 (Book)
$obj2->addArticle($obj1);
}
// if joined row is not null
$results[] = $obj1;
}
$stmt->closeCursor();
return $results;
}
示例11: testOrderByIgnoreCaseWithWhereClause
public function testOrderByIgnoreCaseWithWhereClause()
{
$originalDB = Propel::getDB();
Propel::setDB(null, new DBMySQL());
$criteria = new Criteria();
$criteria->setIgnoreCase(true);
$criteria->addAscendingOrderByColumn(BookPeer::TITLE);
$criteria->add('book.title', false);
BookPeer::addSelectColumns($criteria);
$params = array();
$sql = BasePeer::createSelectSql($criteria, $params);
$expectedSQL = 'SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id, UPPER(book.title) FROM `book` WHERE UPPER(book.title)=UPPER(:p1) ORDER BY UPPER(book.title) ASC';
$this->assertEquals($expectedSQL, $sql);
Propel::setDB(null, $originalDB);
}
示例12: doSelectStmt
public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
{
foreach (sfMixer::getCallables('BaseBookPeer:doSelectStmt:doSelectStmt') as $callable) {
call_user_func($callable, 'BaseBookPeer', $criteria, $con);
}
if ($con === null) {
$con = Propel::getConnection(BookPeer::DATABASE_NAME, Propel::CONNECTION_READ);
}
if (!$criteria->hasSelectClause()) {
$criteria = clone $criteria;
BookPeer::addSelectColumns($criteria);
}
$criteria->setDbName(self::DATABASE_NAME);
return BasePeer::doSelect($criteria, $con);
}
示例13: doSelectStmt
/**
* Prepares the Criteria object and uses the parent doSelect() method to execute a PDOStatement.
*
* Use this method directly if you want to work with an executed statement durirectly (for example
* to perform your own object hydration).
*
* @param Criteria $criteria The Criteria object used to build the SELECT statement.
* @param PropelPDO $con The connection to use
* @throws PropelException Any exceptions caught during processing will be
* rethrown wrapped into a PropelException.
* @return PDOStatement The executed PDOStatement object.
* @see BasePeer::doSelect()
*/
public static function doSelectStmt(Criteria $criteria, PropelPDO $con = null)
{
if ($con === null) {
$con = Propel::getConnection(BookPeer::DATABASE_NAME, Propel::CONNECTION_READ);
}
if (!$criteria->hasSelectClause()) {
$criteria = clone $criteria;
BookPeer::addSelectColumns($criteria);
}
// Set the correct dbName
$criteria->setDbName(self::DATABASE_NAME);
// BasePeer returns a PDOStatement
return BasePeer::doSelect($criteria, $con);
}
示例14: testWithAliasAddsSelectColumns
public function testWithAliasAddsSelectColumns()
{
$c = new TestableModelCriteria('bookstore', 'Book');
BookPeer::addSelectColumns($c);
$c->join('Book.Author a');
$c->with('a');
$expectedColumns = array(BookPeer::ID, BookPeer::TITLE, BookPeer::ISBN, BookPeer::PRICE, BookPeer::PUBLISHER_ID, BookPeer::AUTHOR_ID, 'a.ID', 'a.FIRST_NAME', 'a.LAST_NAME', 'a.EMAIL', 'a.AGE');
$this->assertEquals($expectedColumns, $c->getSelectColumns(), 'with() adds the columns of the related table');
}
示例15: doSelectJoinAllExceptCategory
public static function doSelectJoinAllExceptCategory(Criteria $c, $con = null)
{
$c = clone $c;
if ($c->getDbName() == Propel::getDefaultDB()) {
$c->setDbName(self::DATABASE_NAME);
}
ArticlePeer::addSelectColumns($c);
$startcol2 = ArticlePeer::NUM_COLUMNS - ArticlePeer::NUM_LAZY_LOAD_COLUMNS + 1;
BookPeer::addSelectColumns($c);
$startcol3 = $startcol2 + BookPeer::NUM_COLUMNS;
$c->addJoin(ArticlePeer::BOOK_ID, BookPeer::ID);
$rs = BasePeer::doSelect($c, $con);
$results = array();
while ($rs->next()) {
$omClass = ArticlePeer::getOMClass();
$cls = Propel::import($omClass);
$obj1 = new $cls();
$obj1->hydrate($rs);
$omClass = BookPeer::getOMClass();
$cls = Propel::import($omClass);
$obj2 = new $cls();
$obj2->hydrate($rs, $startcol2);
$newObject = true;
for ($j = 0, $resCount = count($results); $j < $resCount; $j++) {
$temp_obj1 = $results[$j];
$temp_obj2 = $temp_obj1->getBook();
if ($temp_obj2->getPrimaryKey() === $obj2->getPrimaryKey()) {
$newObject = false;
$temp_obj2->addArticle($obj1);
break;
}
}
if ($newObject) {
$obj2->initArticles();
$obj2->addArticle($obj1);
}
$results[] = $obj1;
}
return $results;
}