本文整理汇总了PHP中propel\tests\bookstore\map\BookTableMap::addSelectColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP BookTableMap::addSelectColumns方法的具体用法?PHP BookTableMap::addSelectColumns怎么用?PHP BookTableMap::addSelectColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类propel\tests\bookstore\map\BookTableMap
的用法示例。
在下文中一共展示了BookTableMap::addSelectColumns方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testAddSelectColumnsAlias
public function testAddSelectColumnsAlias()
{
$c = new Criteria();
BookTableMap::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(BookTableMap::ID, 12, ' BAD SQL');
BookTableMap::addSelectColumns($c);
$c->doCount();
$this->fail('Missing expected exception on BAD SQL');
} catch (PropelException $e) {
$this->assertContains($this->getSql('[SELECT COUNT(*) FROM `book` WHERE book.ID BAD SQL:p1]'), $e->getMessage(), 'SQL query is written in the exception message');
}
}
示例3: testApplyLimitDuplicateColumnNameWithColumn
public function testApplyLimitDuplicateColumnNameWithColumn()
{
Propel::getServiceContainer()->setAdapter('oracle', new OracleAdapter());
$c = new Criteria();
$c->setDbName('oracle');
BookTableMap::addSelectColumns($c);
AuthorTableMap::addSelectColumns($c);
$c->addAsColumn('BOOK_PRICE', BookTableMap::COL_PRICE);
$c->setLimit(1);
$params = [];
$asColumns = $c->getAsColumns();
$sql = $c->createSelectSql($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');
}
示例4: testApplyLimitDuplicateColumnNameWithColumn
public function testApplyLimitDuplicateColumnNameWithColumn()
{
Propel::getServiceContainer()->setAdapter('oracle', new OracleAdapter());
$c = new Criteria();
$c->setDbName('oracle');
BookTableMap::addSelectColumns($c);
AuthorTableMap::addSelectColumns($c);
$c->addAsColumn('BOOK_PRICE', BookTableMap::PRICE);
$c->setLimit(1);
$params = array();
$asColumns = $c->getAsColumns();
$sql = $c->createSelectSql($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');
}
示例5: testNeedsSelectAliases
public function testNeedsSelectAliases()
{
$c = new Criteria();
$this->assertFalse($c->needsSelectAliases(), 'Empty Criterias don\'t need aliases');
$c = new Criteria();
$c->addSelectColumn(BookTableMap::COL_ID);
$c->addSelectColumn(BookTableMap::COL_TITLE);
$this->assertFalse($c->needsSelectAliases(), 'Criterias with distinct column names don\'t need aliases');
$c = new Criteria();
BookTableMap::addSelectColumns($c);
$this->assertFalse($c->needsSelectAliases(), 'Criterias with only the columns of a model don\'t need aliases');
$c = new Criteria();
$c->addSelectColumn(BookTableMap::COL_ID);
$c->addSelectColumn(AuthorTableMap::COL_ID);
$this->assertTrue($c->needsSelectAliases(), 'Criterias with common column names do need aliases');
}
示例6: testSubQueryExplicit
public function testSubQueryExplicit()
{
$subCriteria = new BookQuery();
BookTableMap::addSelectColumns($subCriteria);
$subCriteria->orderByTitle(Criteria::ASC);
$c = new BookQuery();
BookTableMap::addSelectColumns($c, 'subCriteriaAlias');
$c->addSelectQuery($subCriteria, 'subCriteriaAlias', false);
$c->groupBy('subCriteriaAlias.AuthorId');
if (in_array($this->getDriver(), array('mysql'))) {
$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";
} else {
$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 successfully');
}
示例7: testSubQueryExplicit
public function testSubQueryExplicit()
{
$subCriteria = new BookQuery();
BookTableMap::addSelectColumns($subCriteria);
$subCriteria->orderByTitle(Criteria::ASC);
$c = new BookQuery();
BookTableMap::addSelectColumns($c, 'subCriteriaAlias');
$c->addSelectQuery($subCriteria, 'subCriteriaAlias', false);
$c->groupBy('subCriteriaAlias.AuthorId');
if ($this->isDb('pgsql')) {
$sql = $this->getSql("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,subCriteriaAlias.id,subCriteriaAlias.title,subCriteriaAlias.isbn,subCriteriaAlias.price,subCriteriaAlias.publisher_id");
} else {
$sql = $this->getSql("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 successfully');
}
示例8: testWithAliasAddsSelectColumns
public function testWithAliasAddsSelectColumns()
{
$c = new TestableModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
BookTableMap::addSelectColumns($c);
$c->join('Propel\\Tests\\Bookstore\\Book.Author a');
$c->with('a');
$expectedColumns = array(BookTableMap::COL_ID, BookTableMap::COL_TITLE, BookTableMap::COL_ISBN, BookTableMap::COL_PRICE, BookTableMap::COL_PUBLISHER_ID, BookTableMap::COL_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');
}
示例9: testOrderByIgnoreCase
public function testOrderByIgnoreCase()
{
$originalDB = Propel::getServiceContainer()->getAdapter();
Propel::getServiceContainer()->setAdapter(Propel::getServiceContainer()->getDefaultDatasource(), new MysqlAdapter());
$criteria = new Criteria();
$criteria->setIgnoreCase(true);
$criteria->addAscendingOrderByColumn(BookTableMap::TITLE);
BookTableMap::addSelectColumns($criteria);
$params = array();
$sql = $criteria->createSelectSql($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::getServiceContainer()->setAdapter(Propel::getServiceContainer()->getDefaultDatasource(), $originalDB);
}
示例10: testWithAliasAddsSelectColumns
public function testWithAliasAddsSelectColumns()
{
$c = new TestableModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
BookTableMap::addSelectColumns($c);
$c->join('Propel\\Tests\\Bookstore\\Book.Author a');
$c->with('a');
$expectedColumns = array(BookTableMap::ID, BookTableMap::TITLE, BookTableMap::ISBN, BookTableMap::PRICE, BookTableMap::PUBLISHER_ID, BookTableMap::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');
}
示例11: testOrderByIgnoreCase
public function testOrderByIgnoreCase()
{
$originalDB = Propel::getServiceContainer()->getAdapter();
Propel::getServiceContainer()->setAdapter(Propel::getServiceContainer()->getDefaultDatasource(), new MysqlAdapter());
Propel::getServiceContainer()->setDefaultDatasource('bookstore');
$criteria = new Criteria();
$criteria->setIgnoreCase(true);
$criteria->addAscendingOrderByColumn(BookTableMap::COL_TITLE);
BookTableMap::addSelectColumns($criteria);
$params = [];
$sql = $criteria->createSelectSql($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::getServiceContainer()->setAdapter(Propel::getServiceContainer()->getDefaultDatasource(), $originalDB);
}