本文整理汇总了PHP中BookPeer::doSelect方法的典型用法代码示例。如果您正苦于以下问题:PHP BookPeer::doSelect方法的具体用法?PHP BookPeer::doSelect怎么用?PHP BookPeer::doSelect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookPeer
的用法示例。
在下文中一共展示了BookPeer::doSelect方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
/**
* This is run after each unit test. It empties the database.
*/
protected function tearDown()
{
BookstoreDataPopulator::depopulate();
$this->assertEquals(0, count(BookPeer::doSelect(new Criteria())), "Expect book table to be empty.");
$this->assertEquals(0, count(AuthorPeer::doSelect(new Criteria())), "Expect author table to be empty.");
$this->assertEquals(0, count(PublisherPeer::doSelect(new Criteria())), "Expect publisher table to be empty.");
$this->assertEquals(0, count(ReviewPeer::doSelect(new Criteria())), "Expect review table to be empty.");
$this->assertEquals(0, count(MediaPeer::doSelect(new Criteria())), "Expect media table to be empty.");
$this->assertEquals(0, count(BookstoreEmployeePeer::doSelect(new Criteria())), "Expect bookstore_employee table to be empty.");
$this->assertEquals(0, count(BookstoreEmployeeAccountPeer::doSelect(new Criteria())), "Expect bookstore_employee_account table to be empty.");
$this->assertEquals(0, count(BookstoreSalePeer::doSelect(new Criteria())), "Expect bookstore_sale table to be empty.");
BookPeer::clearInstancePool();
$this->assertEquals(0, count(BookPeer::$instances), "Expected 0 Book instances after clearInstancePool()");
AuthorPeer::clearInstancePool();
$this->assertEquals(0, count(AuthorPeer::$instances), "Expected 0 Author instances after clearInstancePool()");
PublisherPeer::clearInstancePool();
$this->assertEquals(0, count(PublisherPeer::$instances), "Expected 0 Publisher instances after clearInstancePool()");
ReviewPeer::clearInstancePool();
$this->assertEquals(0, count(ReviewPeer::$instances), "Expected 0 Review instances after clearInstancePool()");
MediaPeer::clearInstancePool();
$this->assertEquals(0, count(MediaPeer::$instances), "Expected 0 Media instances after clearInstancePool()");
BookstoreEmployeePeer::clearInstancePool();
$this->assertEquals(0, count(BookstoreEmployeePeer::$instances), "Expected 0 BookstoreEmployee instances after clearInstancePool()");
BookstoreEmployeeAccountPeer::clearInstancePool();
$this->assertEquals(0, count(BookstoreEmployeeAccountPeer::$instances), "Expected 0 BookstoreEmployeeAccount instances after clearInstancePool()");
BookstoreSalePeer::clearInstancePool();
$this->assertEquals(0, count(BookstoreSalePeer::$instances), "Expected 0 BookstoreSale instances after clearInstancePool()");
parent::tearDown();
}
示例2: runHydrate
function runHydrate($i)
{
$c = new Criteria();
$c->add(BookPeer::PRICE, $i, Criteria::GREATER_THAN);
$c->setLimit(5);
$books = BookPeer::doSelect($c, $this->con);
foreach ($books as $book) {
}
}
示例3: testGetLastQueryMoreThanTenArgs
public function testGetLastQueryMoreThanTenArgs()
{
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
$c = new Criteria();
$c->add(BookPeer::ID, array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), Criteria::IN);
$books = BookPeer::doSelect($c, $con);
$expected = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` WHERE book.ID IN (1,1,1,1,1,1,1,1,1,1,1,1)";
$this->assertEquals($expected, $con->getLastExecutedQuery(), 'PropelPDO correctly replaces arguments in queries');
}
示例4: testScenarioUsingQuery
//.........这里部分代码省略.........
$rev1 = new Review();
$rev1->setReviewDate("08/09/2001");
// will fail: reviewed_by column required
$bk1->addReview($rev1);
$ret2 = $bk1->validate();
$this->assertFalse($ret2, 'validation failed');
$failures2 = $bk1->getValidationFailures();
$this->assertEquals(3, count($failures2), '3 validation messages were returned');
$expectedKeys = array(AuthorPeer::LAST_NAME, BookPeer::TITLE, ReviewPeer::REVIEWED_BY);
$this->assertEquals($expectedKeys, array_keys($failures2), 'correct columns failed');
$bk2 = new Book();
$bk2->setTitle("12345678901");
// passes
$auth2 = new Author();
$auth2->setLastName("Blah");
//passes
$auth2->setEmail("some@body.com");
//passes
$auth2->setAge(50);
//passes
$bk2->setAuthor($auth2);
$rev2 = new Review();
$rev2->setReviewedBy("Me!");
// passes
$rev2->setStatus("new");
// passes
$bk2->addReview($rev2);
$ret3 = $bk2->validate();
$this->assertTrue($ret3, 'complex validation can pass');
// Testing doCount() functionality
// -------------------------------
// old way
$c = new Criteria();
$records = BookPeer::doSelect($c);
$count = BookPeer::doCount($c);
$this->assertEquals($count, count($records), 'correct number of results');
// new way
$count = BookQuery::create()->count();
$this->assertEquals($count, count($records), 'correct number of results');
// Test many-to-many relationships
// ---------------
// init book club list 1 with 2 books
$blc1 = new BookClubList();
$blc1->setGroupLeader("Crazyleggs");
$blc1->setTheme("Happiness");
$brel1 = new BookListRel();
$brel1->setBook($phoenix);
$brel2 = new BookListRel();
$brel2->setBook($dj);
$blc1->addBookListRel($brel1);
$blc1->addBookListRel($brel2);
$blc1->save();
$this->assertNotNull($blc1->getId(), 'BookClubList 1 was saved');
// init book club list 2 with 1 book
$blc2 = new BookClubList();
$blc2->setGroupLeader("John Foo");
$blc2->setTheme("Default");
$brel3 = new BookListRel();
$brel3->setBook($phoenix);
$blc2->addBookListRel($brel3);
$blc2->save();
$this->assertNotNull($blc2->getId(), 'BookClubList 2 was saved');
// re-fetch books and lists from db to be sure that nothing is cached
$crit = new Criteria();
$crit->add(BookPeer::ID, $phoenix->getId());
$phoenix = BookPeer::doSelectOne($crit);
示例5: retrieveByPKs
public static function retrieveByPKs($pks, $con = null)
{
if ($con === null) {
$con = Propel::getConnection(self::DATABASE_NAME);
}
$objs = null;
if (empty($pks)) {
$objs = array();
} else {
$criteria = new Criteria();
$criteria->add(BookPeer::ID, $pks, Criteria::IN);
$objs = BookPeer::doSelect($criteria, $con);
}
return $objs;
}
示例6: testDebugLog
public function testDebugLog()
{
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
$config = Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT);
// save data to return to normal state after test
$logger = $con->getLogger();
$testLog = new myLogger();
$con->setLogger($testLog);
$logEverything = array('PropelPDO::exec', 'PropelPDO::query', 'PropelPDO::beginTransaction', 'PropelPDO::commit', 'PropelPDO::rollBack', 'DebugPDOStatement::execute');
Propel::getConfiguration(PropelConfiguration::TYPE_OBJECT)->setParameter("debugpdo.logging.methods", $logEverything, false);
$con->useDebug(true);
// test transaction log
$con->beginTransaction();
$this->assertEquals('log: Begin transaction', $testLog->latestMessage, 'PropelPDO logs begin transation in debug mode');
$con->commit();
$this->assertEquals('log: Commit transaction', $testLog->latestMessage, 'PropelPDO logs commit transation in debug mode');
$con->beginTransaction();
$con->rollBack();
$this->assertEquals('log: Rollback transaction', $testLog->latestMessage, 'PropelPDO logs rollback transation in debug mode');
$con->beginTransaction();
$testLog->latestMessage = '';
$con->beginTransaction();
$this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested begin transation in debug mode');
$con->commit();
$this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested commit transation in debug mode');
$con->beginTransaction();
$con->rollBack();
$this->assertEquals('', $testLog->latestMessage, 'PropelPDO does not log nested rollback transation in debug mode');
$con->rollback();
// test query log
$con->beginTransaction();
$c = new Criteria();
$c->add(BookPeer::TITLE, 'Harry%s', Criteria::LIKE);
$books = BookPeer::doSelect($c, $con);
$latestExecutedQuery = "SELECT book.id, book.title, book.isbn, book.price, book.publisher_id, book.author_id FROM `book` WHERE book.title LIKE 'Harry%s'";
$this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs queries and populates bound parameters in debug mode');
BookPeer::doDeleteAll($con);
$latestExecutedQuery = "DELETE FROM `book`";
$this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs deletion queries in debug mode');
$latestExecutedQuery = 'DELETE FROM book WHERE 1=1';
$con->exec($latestExecutedQuery);
$this->assertEquals('log: ' . $latestExecutedQuery, $testLog->latestMessage, 'PropelPDO logs exec queries in debug mode');
$con->commit();
// return to normal state after test
$con->setLogger($logger);
$config->setParameter("debugpdo.logging.methods", array('PropelPDO::exec', 'PropelPDO::query', 'DebugPDOStatement::execute'));
}
示例7: boolTest
// is to specify the author_id and publisher_id (i.e. the fkeys
// have to be in the criteria).
$c->add(AuthorPeer::ID, $hp->getId());
$c->add(PublisherPeer::ID, $hp->getId());
$c->setSingleRecord(true);
BookPeer::doDelete($c);
print boolTest(true);
print "Checking to make sure correct records were removed.\n";
print "\tFrom author table: ";
$res = AuthorPeer::doSelect(new Criteria());
print boolTest(count($res) === 3);
print "\tFrom publisher table: ";
$res2 = PublisherPeer::doSelect(new Criteria());
print boolTest(count($res2) === 3);
print "\tFrom book table: ";
$res3 = BookPeer::doSelect(new Criteria());
print boolTest(count($res3) === 3);
print "Attempting to delete books by complex criteria: ";
$c = new Criteria();
$cn = $c->getNewCriterion(BookPeer::ISBN, "043935806X");
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0380977427"));
$cn->addOr($c->getNewCriterion(BookPeer::ISBN, "0140422161"));
$c->add($cn);
BookPeer::doDelete($c);
print boolTest(true);
print "Attempting to delete book [id = {$td_id}]: ";
$td->delete();
print boolTest(true);
print "Attempting to delete author [id = {$stephenson_id}]: ";
AuthorPeer::doDelete($stephenson_id);
print boolTest(true);
示例8: testSetJoinConditionNamedCondition
public function testSetJoinConditionNamedCondition()
{
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
$c = new ModelCriteria('bookstore', 'Book');
$c->join('Book.Author', Criteria::INNER_JOIN);
$c->condition('cond1', 'Book.Title = Author.FirstName');
$c->setJoinCondition('Author', 'cond1');
$books = BookPeer::doSelect($c, $con);
$expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` INNER JOIN `author` ON book.TITLE = author.FIRST_NAME";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'setJoinCondition() can override a previous join condition with a named condition');
}
示例9: testJoinAliasQuery
public function testJoinAliasQuery()
{
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
$c = new ModelCriteria('bookstore', 'Book', 'b');
$c->join('b.Author a');
$c->where('a.FirstName = ?', 'Leo');
$books = BookPeer::doSelect($c, $con);
$expectedSQL = "SELECT book.ID, book.TITLE, book.ISBN, book.PRICE, book.PUBLISHER_ID, book.AUTHOR_ID FROM `book` INNER JOIN author a ON (book.AUTHOR_ID=a.ID) WHERE a.FIRST_NAME = 'Leo'";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'join() allows the use of relation alias in where()');
$c = new ModelCriteria('bookstore', 'BookstoreEmployee', 'be');
$c->join('be.Supervisor sup');
$c->join('sup.Subordinate sub');
$c->where('sub.Name = ?', 'Foo');
$employees = BookstoreEmployeePeer::doSelect($c, $con);
$expectedSQL = "SELECT bookstore_employee.ID, bookstore_employee.CLASS_KEY, bookstore_employee.NAME, bookstore_employee.JOB_TITLE, bookstore_employee.SUPERVISOR_ID FROM `bookstore_employee` INNER JOIN bookstore_employee sup ON (bookstore_employee.SUPERVISOR_ID=sup.ID) INNER JOIN bookstore_employee sub ON (sup.ID=sub.SUPERVISOR_ID) WHERE sub.NAME = 'Foo'";
$this->assertEquals($expectedSQL, $con->getLastExecutedQuery(), 'join() allows the use of relation alias in further joins()');
}
示例10: testObjectInstances
public function testObjectInstances()
{
$sample = BookPeer::doSelectOne(new Criteria());
$samplePk = $sample->getPrimaryKey();
// 1) make sure consecutive calls to retrieveByPK() return the same object.
$b1 = BookPeer::retrieveByPK($samplePk);
$b2 = BookPeer::retrieveByPK($samplePk);
$sampleval = md5(microtime());
$this->assertTrue($b1 === $b2, "Expected object instances to match for calls with same retrieveByPK() method signature.");
// 2) make sure that calls to doSelect also return references to the same objects.
$allbooks = BookPeer::doSelect(new Criteria());
foreach ($allbooks as $testb) {
if ($testb->getPrimaryKey() == $b1->getPrimaryKey()) {
$this->assertTrue($testb === $b1, "Expected same object instance from doSelect() as from retrieveByPK()");
}
}
// 3) test fetching related objects
$book = BookPeer::retrieveByPK($samplePk);
$bookauthor = $book->getAuthor();
$author = AuthorPeer::retrieveByPK($bookauthor->getId());
$this->assertTrue($bookauthor === $author, "Expected same object instance when calling fk object accessor as retrieveByPK()");
// 4) test a doSelectJoin()
$morebooks = BookPeer::doSelectJoinAuthor(new Criteria());
for ($i = 0, $j = 0; $j < count($morebooks); $i++, $j++) {
$testb1 = $allbooks[$i];
$testb2 = $allbooks[$j];
$this->assertTrue($testb1 === $testb2, "Expected the same objects from consecutive doSelect() calls.");
// we could probably also test this by just verifying that $book & $testb are the same
if ($testb1->getPrimaryKey() === $book) {
$this->assertTrue($book->getAuthor() === $testb1->getAuthor(), "Expected same author object in calls to pkey-matching books.");
}
}
// 5) test creating a new object, saving it, and then retrieving that object (should all be same instance)
$b = new BookstoreEmployee();
$b->setName("Testing");
$b->setJobTitle("Testing");
$b->save();
$empId = $b->getId();
$this->assertSame($b, BookstoreEmployeePeer::retrieveByPK($empId), "Expected newly saved object to be same instance as pooled.");
}
示例11: testDoDeleteAll_SetNull
/**
* Test the doDeleteAll() method when onDelete="SETNULL".
*/
public function testDoDeleteAll_SetNull()
{
$c = new Criteria();
$c->add(BookPeer::AUTHOR_ID, null, Criteria::NOT_EQUAL);
// 1) make sure there are some books with valid authors
$this->assertTrue(count(BookPeer::doSelect($c)) > 0, "Expect some book.author_id columns that are not NULL.");
// 2) delete all the authors
AuthorPeer::doDeleteAll();
// 3) now verify that the book.author_id columns are all nul
$this->assertEquals(0, count(BookPeer::doSelect($c)), "Expect all book.author_id columns to be NULL.");
}
示例12: testSpeed
public function testSpeed()
{
// Add publisher records
// ---------------------
$scholastic = new Publisher();
$scholastic->setName("Scholastic");
// do not save, will do later to test cascade
$morrow = new Publisher();
$morrow->setName("William Morrow");
$morrow->save();
$morrow_id = $morrow->getId();
$penguin = new Publisher();
$penguin->setName("Penguin");
$penguin->save();
$penguin_id = $penguin->getId();
$vintage = new Publisher();
$vintage->setName("Vintage");
$vintage->save();
$vintage_id = $vintage->getId();
// Add author records
// ------------------
$rowling = new Author();
$rowling->setFirstName("J.K.");
$rowling->setLastName("Rowling");
// no save()
$stephenson = new Author();
$stephenson->setFirstName("Neal");
$stephenson->setLastName("Stephenson");
$stephenson->save();
$stephenson_id = $stephenson->getId();
$byron = new Author();
$byron->setFirstName("George");
$byron->setLastName("Byron");
$byron->save();
$byron_id = $byron->getId();
$grass = new Author();
$grass->setFirstName("Gunter");
$grass->setLastName("Grass");
$grass->save();
$grass_id = $grass->getId();
// Add book records
// ----------------
$phoenix = new Book();
$phoenix->setTitle("Harry Potter and the Order of the Phoenix");
$phoenix->setISBN("043935806X");
// cascading save (Harry Potter)
$phoenix->setAuthor($rowling);
$phoenix->setPublisher($scholastic);
$phoenix->save();
$phoenix_id = $phoenix->getId();
$qs = new Book();
$qs->setISBN("0380977427");
$qs->setTitle("Quicksilver");
$qs->setAuthor($stephenson);
$qs->setPublisher($morrow);
$qs->save();
$qs_id = $qs->getId();
$dj = new Book();
$dj->setISBN("0140422161");
$dj->setTitle("Don Juan");
$dj->setAuthor($byron);
$dj->setPublisher($penguin);
$dj->save();
$dj_id = $qs->getId();
$td = new Book();
$td->setISBN("067972575X");
$td->setTitle("The Tin Drum");
$td->setAuthor($grass);
$td->setPublisher($vintage);
$td->save();
$td_id = $td->getId();
// Add review records
// ------------------
$r1 = new Review();
$r1->setBook($phoenix);
$r1->setReviewedBy("Washington Post");
$r1->setRecommended(true);
$r1->setReviewDate(time());
$r1->save();
$r1_id = $r1->getId();
$r2 = new Review();
$r2->setBook($phoenix);
$r2->setReviewedBy("New York Times");
$r2->setRecommended(false);
$r2->setReviewDate(time());
$r2->save();
$r2_id = $r2->getId();
// Perform a "complex" search
// --------------------------
$crit = new Criteria();
$crit->add(BookPeer::TITLE, 'Harry%', Criteria::LIKE);
$results = BookPeer::doSelect($crit);
$crit2 = new Criteria();
$crit2->add(BookPeer::ISBN, array("0380977427", "0140422161"), Criteria::IN);
$results = BookPeer::doSelect($crit2);
// Perform a "limit" search
// ------------------------
$crit = new Criteria();
$crit->setLimit(2);
$crit->setOffset(1);
//.........这里部分代码省略.........
示例13: 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;
}