本文整理汇总了PHP中BookPeer::doSelectOne方法的典型用法代码示例。如果您正苦于以下问题:PHP BookPeer::doSelectOne方法的具体用法?PHP BookPeer::doSelectOne怎么用?PHP BookPeer::doSelectOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BookPeer
的用法示例。
在下文中一共展示了BookPeer::doSelectOne方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testScenarioUsingQuery
//.........这里部分代码省略.........
$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);
$this->assertNotNull($phoenix, "book 'phoenix' has been re-fetched from db");
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc1->getId());
$blc1 = BookClubListPeer::doSelectOne($crit);
$this->assertNotNull($blc1, 'BookClubList 1 has been re-fetched from db');
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc2->getId());
$blc2 = BookClubListPeer::doSelectOne($crit);
$this->assertNotNull($blc2, 'BookClubList 2 has been re-fetched from db');
$relCount = $phoenix->countBookListRels();
$this->assertEquals(2, $relCount, "book 'phoenix' has 2 BookListRels");
$relCount = $blc1->countBookListRels();
$this->assertEquals(2, $relCount, 'BookClubList 1 has 2 BookListRels');
$relCount = $blc2->countBookListRels();
$this->assertEquals(1, $relCount, 'BookClubList 2 has 1 BookListRel');
// Cleanup (tests DELETE)
// ----------------------
// Removing books that were just created
// First finding book by PK (=$phoenix_id) ....
$hp = BookQuery::create()->findPk($phoenix_id);
$this->assertNotNull($hp, 'Could find just-created book');
// Attempting to delete [multi-table] by found pk
$c = new Criteria();
$c->add(BookPeer::ID, $hp->getId());
// The only way for cascading to work currently
// is to specify the author_id and publisher_id (i.e. the fkeys
// have to be in the criteria).
$c->add(AuthorPeer::ID, $hp->getAuthor()->getId());
$c->add(PublisherPeer::ID, $hp->getPublisher()->getId());
$c->setSingleRecord(true);
BookPeer::doDelete($c);
// Checking to make sure correct records were removed.
$this->assertEquals(3, AuthorPeer::doCount(new Criteria()), 'Correct records were removed from author table');
$this->assertEquals(3, PublisherPeer::doCount(new Criteria()), 'Correct records were removed from publisher table');
$this->assertEquals(3, BookPeer::doCount(new Criteria()), 'Correct records were removed from book table');
// Attempting to delete books by complex criteria
BookQuery::create()->filterByISBN("043935806X")->orWhere('Book.ISBN = ?', "0380977427")->orWhere('Book.ISBN = ?', "0140422161")->delete();
// Attempting to delete book [id = $td_id]
$td->delete();
// Attempting to delete authors
AuthorQuery::create()->filterById($stephenson_id)->delete();
AuthorQuery::create()->filterById($byron_id)->delete();
$grass->delete();
// Attempting to delete publishers
PublisherQuery::create()->filterById($morrow_id)->delete();
PublisherQuery::create()->filterById($penguin_id)->delete();
$vintage->delete();
// These have to be deleted manually also since we have onDelete
// set to SETNULL in the foreign keys in book. Is this correct?
$rowling->delete();
$scholastic->delete();
$blc1->delete();
$blc2->delete();
$this->assertEquals(array(), AuthorPeer::doSelect(new Criteria()), 'no records in [author] table');
$this->assertEquals(array(), PublisherPeer::doSelect(new Criteria()), 'no records in [publisher] table');
$this->assertEquals(array(), BookPeer::doSelect(new Criteria()), 'no records in [book] table');
$this->assertEquals(array(), ReviewPeer::doSelect(new Criteria()), 'no records in [review] table');
$this->assertEquals(array(), MediaPeer::doSelect(new Criteria()), 'no records in [media] table');
$this->assertEquals(array(), BookClubListPeer::doSelect(new Criteria()), 'no records in [book_club_list] table');
$this->assertEquals(array(), BookListRelPeer::doSelect(new Criteria()), 'no records in [book_x_list] table');
}
示例2: testLobSetting_WriteMode
public function testLobSetting_WriteMode()
{
$blob_path = $this->getLobFile('tin_drum.gif');
$blob2_path = $this->getLobFile('propel.gif');
$clob_path = $this->getLobFile('tin_drum.txt');
$book = BookPeer::doSelectOne(new Criteria());
$m1 = new Media();
$m1->setBook($book);
$m1->setCoverImage(file_get_contents($blob_path));
$m1->setExcerpt(file_get_contents($clob_path));
$m1->save();
MediaPeer::clearInstancePool();
// make sure we have the latest from the db:
$m2 = MediaPeer::retrieveByPK($m1->getId());
// now attempt to assign a temporary stream, opened in 'w' mode, to the db
$stream = fopen("php://memory", 'w');
fwrite($stream, file_get_contents($blob2_path));
$m2->setCoverImage($stream);
$m2->save();
fclose($stream);
$m2->reload();
$this->assertEquals(md5(file_get_contents($blob2_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w' mode");
$stream2 = fopen("php://memory", 'w+');
fwrite($stream2, file_get_contents($blob_path));
rewind($stream2);
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($stream2)), "Expecting setup to be correct");
$m2->setCoverImage($stream2);
$m2->save();
$m2->reload();
$this->assertEquals(md5(file_get_contents($blob_path)), md5(stream_get_contents($m2->getCoverImage())), "Expected contents to match when setting stream w/ 'w+' mode");
}
示例3: boolTest
print "Making sure BookClubList 1 was saved: ";
print boolTest(!is_null($blc1->getId()));
// 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();
print "Making sure BookClubList 2 was saved: ";
print boolTest(!is_null($blc2->getId()));
// 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);
print "Making sure book 'phoenix' has been re-fetched from db: ";
print boolTest(!empty($phoenix));
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc1->getId());
$blc1 = BookClubListPeer::doSelectOne($crit);
print "Making sure BookClubList 1 has been re-fetched from db: ";
print boolTest(!empty($blc1));
$crit = new Criteria();
$crit->add(BookClubListPeer::ID, $blc2->getId());
$blc2 = BookClubListPeer::doSelectOne($crit);
print "Making sure BookClubList 2 has been re-fetched from db: ";
print boolTest(!empty($blc2));
$relCount = $phoenix->countBookListRels();
print "Making sure book 'phoenix' has 2 BookListRels: ";
print boolTest($relCount == 2);
示例4: 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.");
}
示例5: testCopyInto_Deep
/**
* Test copyInto method.
*/
public function testCopyInto_Deep()
{
// Test a "normal" object
$c = new Criteria();
$c->add(BookPeer::TITLE, 'Harry%', Criteria::LIKE);
$book = BookPeer::doSelectOne($c);
$reviews = $book->getReviews();
$b2 = $book->copy(true);
$this->assertType('Book', $b2);
$this->assertNull($b2->getId());
$r2 = $b2->getReviews();
$this->assertEquals(count($reviews), count($r2));
// Test a one-to-one object
$emp = BookstoreEmployeePeer::doSelectOne(new Criteria());
$e2 = $emp->copy(true);
$this->assertType('BookstoreEmployee', $e2);
$this->assertNull($e2->getId());
$this->assertEquals($emp->getBookstoreEmployeeAccount()->getLogin(), $e2->getBookstoreEmployeeAccount()->getLogin());
}
示例6: testDoDelete_ByObj
/**
* Test deleting a row by passing the generated object to doDelete().
*/
public function testDoDelete_ByObj()
{
// 1) get an arbitrary book
$book = BookPeer::doSelectOne(new Criteria());
$bookId = $book->getId();
// 2) now delete that book
BookPeer::doDelete($book);
// 3) now make sure it's gone
$obj = BookPeer::retrieveByPK($bookId);
$this->assertNull($obj, "Expect NULL when retrieving on no matching Book.");
}
示例7: getBook
public function getBook(PropelPDO $con = null)
{
if ($this->aBook === null && $this->book_id !== null) {
$c = new Criteria(BookPeer::DATABASE_NAME);
$c->add(BookPeer::ID, $this->book_id);
$this->aBook = BookPeer::doSelectOne($c, $con);
}
return $this->aBook;
}
示例8: testSpeed
//.........这里部分代码省略.........
$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);
$crit->addAscendingOrderByColumn(BookPeer::TITLE);
$results = BookPeer::doSelect($crit);
// Perform a lookup & update!
// --------------------------
$qs_lookup = BookPeer::retrieveByPk($qs_id);
$new_title = "Quicksilver (" . crc32(uniqid(rand())) . ")";
$qs_lookup->setTitle($new_title);
$qs_lookup->save();
$qs_lookup2 = BookPeer::retrieveByPk($qs_id);
// Test some basic DATE / TIME stuff
// ---------------------------------
// that's the control timestamp.
$control = strtotime('2004-02-29 00:00:00');
// should be two in the db
$r = ReviewPeer::doSelectOne(new Criteria());
$r_id = $r->getId();
$r->setReviewDate($control);
$r->save();
$r2 = ReviewPeer::retrieveByPk($r_id);
// Testing the DATE/TIME columns
// -----------------------------
// that's the control timestamp.
$control = strtotime('2004-02-29 00:00:00');
// should be two in the db
$r = ReviewPeer::doSelectOne(new Criteria());
$r_id = $r->getId();
$r->setReviewDate($control);
$r->save();
$r2 = ReviewPeer::retrieveByPk($r_id);
// Testing the column validators
// -----------------------------
$bk1 = new Book();
$bk1->setTitle("12345");
// min length is 10
$ret = $bk1->validate();
// Unique validator
$bk2 = new Book();
$bk2->setTitle("Don Juan");
$ret = $bk2->validate();
// Now trying some more complex validation.
$auth1 = new Author();
$auth1->setFirstName("Hans");
// last name required; will fail
$bk1->setAuthor($auth1);
$rev1 = new Review();
$rev1->setReviewDate("08/09/2001");
// will fail: reviewed_by column required
示例9: populateOpinionFavorite
public static function populateOpinionFavorite($con = null)
{
if ($con === null) {
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
}
$con->beginTransaction();
$book1 = BookPeer::doSelectOne(new Criteria(), $con);
$reader1 = new BookReader();
$reader1->save($con);
$bo = new BookOpinion();
$bo->setBook($book1);
$bo->setBookReader($reader1);
$bo->save($con);
$rf = new ReaderFavorite();
$rf->setBookOpinion($bo);
$rf->save($con);
$con->commit();
}
示例10: testIneffectualUpdateUsingBookObject
public function testIneffectualUpdateUsingBookObject()
{
$con = Propel::getConnection(BookPeer::DATABASE_NAME);
$c = new Criteria();
$book = BookPeer::doSelectOne($c, $con);
$count = $con->getQueryCount();
$book->setTitle($book->getTitle());
$book->setISBN($book->getISBN());
try {
$rowCount = BookPeer::doUpdate($book, $con);
$this->assertEquals(0, $rowCount, 'BookPeer::doUpdate() should indicate zero rows updated');
} catch (Exception $ex) {
$this->fail('BookPeer::doUpdate() threw an exception');
}
$this->assertEquals($count, $con->getQueryCount(), 'BookPeer::doUpdate() does not execute any queries when there are no changes');
}