本文整理汇总了PHP中RedBeanPHP\Facade::getCell方法的典型用法代码示例。如果您正苦于以下问题:PHP Facade::getCell方法的具体用法?PHP Facade::getCell怎么用?PHP Facade::getCell使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\Facade
的用法示例。
在下文中一共展示了Facade::getCell方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testRebuilder
/**
* Test SQLite table rebuilding.
*
* @return void
*/
public function testRebuilder()
{
$toolbox = R::getToolBox();
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$book = R::dispense('book');
$page = R::dispense('page');
$book->xownPage[] = $page;
$id = R::store($book);
$book = R::load('book', $id);
asrt(count($book->xownPage), 1);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
R::trash($book);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
$book = R::dispense('book');
$page = R::dispense('page');
$book->xownPage[] = $page;
$id = R::store($book);
$book = R::load('book', $id);
asrt(count($book->xownPage), 1);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 1);
$book->added = 2;
R::store($book);
$book->added = 'added';
R::store($book);
R::trash($book);
asrt((int) R::getCell('SELECT COUNT(*) FROM page'), 0);
}
示例2: testSQLFilters
/**
* Test whether we can use SQL filters and
* whether they are being applied properly for
* different types of SELECT queries in the QueryWriter.
*/
public function testSQLFilters()
{
R::nuke();
AQueryWriter::setSQLFilters(array(QueryWriter::C_SQLFILTER_READ => array('book' => array('title' => ' LOWER(book.title) ')), QueryWriter::C_SQLFILTER_WRITE => array('book' => array('title' => ' UPPER(?) '))));
$book = R::dispense('book');
$book->title = 'story';
R::store($book);
asrt(R::getCell('SELECT title FROM book WHERE id = ?', array($book->id)), 'STORY');
$book = $book->fresh();
asrt($book->title, 'story');
$library = R::dispense('library');
$library->sharedBookList[] = $book;
R::store($library);
$library = $library->fresh();
$books = $library->sharedBookList;
$book = reset($books);
asrt($book->title, 'story');
$otherBook = R::dispense('book');
$otherBook->sharedBook[] = $book;
R::store($otherBook);
$otherBook = $otherBook->fresh();
$books = $otherBook->sharedBookList;
$book = reset($books);
asrt($book->title, 'story');
$links = $book->ownBookBookList;
$link = reset($links);
$link->shelf = 'x13';
AQueryWriter::setSQLFilters(array(QueryWriter::C_SQLFILTER_READ => array('book' => array('title' => ' LOWER(book.title) '), 'book_book' => array('shelf' => ' LOWER(book_book.shelf) ')), QueryWriter::C_SQLFILTER_WRITE => array('book' => array('title' => ' UPPER(?) '), 'book_book' => array('shelf' => ' UPPER(?) '))));
R::store($link);
asrt(R::getCell('SELECT shelf FROM book_book WHERE id = ?', array($link->id)), 'X13');
$otherBook = $otherBook->fresh();
unset($book->sharedBookList[$otherBook->id]);
R::store($book);
AQueryWriter::setSQLFilters(array());
}
示例3: testAddingForeignKey
/**
* Test adding foreign keys.
*
* @return void
*/
public function testAddingForeignKey()
{
R::nuke();
$sql = '
CREATE TABLE book (
id INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY ( id )
)
ENGINE = InnoDB
';
R::exec($sql);
$sql = '
CREATE TABLE page (
id INT( 11 ) UNSIGNED NOT NULL AUTO_INCREMENT,
book_id INT( 11 ) UNSIGNED NOT NULL,
PRIMARY KEY ( id )
)
ENGINE = InnoDB
';
R::exec($sql);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" AND DELETE_RULE = "CASCADE"');
asrt((int) $numOfFKS, 0);
$writer = R::getWriter();
//Can we add a foreign key with cascade?
$writer->addFK('page', 'book', 'book_id', 'id', TRUE);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" AND DELETE_RULE = "CASCADE"');
asrt((int) $numOfFKS, 1);
//dont add it twice
$writer->addFK('page', 'book', 'book_id', 'id', TRUE);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" AND DELETE_RULE = "CASCADE"');
asrt((int) $numOfFKS, 1);
//even if different
$writer->addFK('page', 'book', 'book_id', 'id', FALSE);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" ');
asrt((int) $numOfFKS, 1);
//Now add non-dep key
R::nuke();
$sql = '
CREATE TABLE book (
id INT( 11 ) UNSIGNED NULL AUTO_INCREMENT,
PRIMARY KEY ( id )
)
ENGINE = InnoDB
';
R::exec($sql);
$sql = '
CREATE TABLE page (
id INT( 11 ) UNSIGNED AUTO_INCREMENT,
book_id INT( 11 ) UNSIGNED NULL,
PRIMARY KEY ( id )
)
ENGINE = InnoDB
';
R::exec($sql);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" AND DELETE_RULE = "CASCADE"');
asrt((int) $numOfFKS, 0);
//even if different
$writer->addFK('page', 'book', 'book_id', 'id', FALSE);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" AND DELETE_RULE = "CASCADE"');
asrt((int) $numOfFKS, 0);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" AND DELETE_RULE = "SET NULL"');
asrt((int) $numOfFKS, 1);
$writer->addFK('page', 'book', 'book_id', 'id', TRUE);
$numOfFKS = R::getCell('
SELECT COUNT(*)
FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS
WHERE TABLE_NAME = "page" ');
}
示例4: testCommonUsageFacade
/**
* Test common Facade usage scenarios.
*
* @return void
*/
public function testCommonUsageFacade()
{
$toolbox = R::getToolBox();
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$a = new AssociationManager($toolbox);
asrt(R::getRedBean() instanceof OODB, TRUE);
asrt(R::getToolBox() instanceof ToolBox, TRUE);
asrt(R::getDatabaseAdapter() instanceof Adapter, TRUE);
asrt(R::getWriter() instanceof QueryWriter, TRUE);
$book = R::dispense("book");
asrt($book instanceof OODBBean, TRUE);
$book->title = "a nice book";
$id = R::store($book);
asrt($id > 0, TRUE);
$book = R::load("book", (int) $id);
asrt($book->title, "a nice book");
asrt(R::load('book', 999)->title, NULL);
R::freeze(TRUE);
try {
R::load('bookies', 999);
fail();
} catch (\Exception $e) {
pass();
}
R::freeze(FALSE);
$author = R::dispense("author");
$author->name = "me";
R::store($author);
$book9 = R::dispense("book");
$author9 = R::dispense("author");
$author9->name = "mr Nine";
$a9 = R::store($author9);
$book9->author_id = $a9;
$bk9 = R::store($book9);
$book9 = R::load("book", $bk9);
$author = R::load("author", $book9->author_id);
asrt($author->name, "mr Nine");
R::trash($author);
R::trash($book9);
pass();
$book2 = R::dispense("book");
$book2->title = "second";
R::store($book2);
$book3 = R::dispense("book");
$book3->title = "third";
R::store($book3);
asrt(count(R::find("book")), 3);
asrt(count(R::findAll("book")), 3);
asrt(count(R::findAll("book", " LIMIT 2")), 2);
asrt(count(R::find("book", " id=id ")), 3);
asrt(count(R::find("book", " title LIKE ?", array("third"))), 1);
asrt(count(R::find("book", " title LIKE ?", array("%d%"))), 2);
// Find without where clause
asrt(count(R::findAll('book', ' order by id')), 3);
R::trash($book3);
R::trash($book2);
asrt(count(R::getAll("SELECT * FROM book ")), 1);
asrt(count(R::getCol("SELECT title FROM book ")), 1);
asrt((int) R::getCell("SELECT 123 "), 123);
$book = R::dispense("book");
$book->title = "not so original title";
$author = R::dispense("author");
$author->name = "Bobby";
R::store($book);
$aid = R::store($author);
$author = R::findOne("author", " name = ? ", array("Bobby"));
}
示例5: setGetSpatial
/**
* Stored and reloads spatial data to see if the
* value is preserved correctly.
*
* @return void
*/
protected function setGetSpatial($data)
{
R::nuke();
$place = R::dispense('place');
$place->location = $data;
R::store($place);
asrt(R::getCell('SELECT AsText(location) FROM place LIMIT 1'), $data);
}
示例6: testSelects
/**
* Test selecting.
*
* @return void
*/
public function testSelects()
{
$rooms = R::dispense('room', 2);
$rooms[0]->kind = 'suite';
$rooms[1]->kind = 'classic';
$rooms[0]->number = 6;
$rooms[1]->number = 7;
R::store($rooms[0]);
R::store($rooms[1]);
$rooms = R::getAssoc('SELECT * FROM room WHERE id < -999');
asrt(is_array($rooms), TRUE);
asrt(count($rooms), 0);
$rooms = R::getAssoc('SELECT ' . R::getWriter()->esc('number') . ', kind FROM room ORDER BY kind ASC');
foreach ($rooms as $key => $room) {
asrt($key === 6 || $key === 7, TRUE);
asrt($room == 'classic' || $room == 'suite', TRUE);
}
$rooms = R::getDatabaseAdapter()->getAssoc('SELECT kind FROM room');
foreach ($rooms as $key => $room) {
asrt($room == 'classic' || $room == 'suite', TRUE);
asrt($room, $key);
}
$rooms = R::getAssoc('SELECT `number`, kind FROM rooms2 ORDER BY kind ASC');
asrt(count($rooms), 0);
asrt(is_array($rooms), TRUE);
// GetCell should return NULL in case of exception
asrt(NULL, R::getCell('SELECT dream FROM fantasy'));
}
示例7: testTransactionInFacade
//.........这里部分代码省略.........
fail();
} catch (\Exception $e) {
pass();
}
testpack('Test Camelcase 2 underscore');
$names = array('oneACLRoute' => 'one_acl_route', 'ALLUPPERCASE' => 'alluppercase', 'clientServerArchitecture' => 'client_server_architecture', 'camelCase' => 'camel_case', 'peer2peer' => 'peer2peer', 'fromUs4You' => 'from_us4_you', 'lowercase' => 'lowercase', 'a1A2b' => 'a1a2b');
$bean = R::dispense('bean');
foreach ($names as $name => $becomes) {
$bean->{$name} = 1;
asrt(isset($bean->{$becomes}), TRUE);
}
testpack('Misc Tests');
R::debug(1);
flush();
ob_start();
R::exec('SELECT 123');
$out = ob_get_contents();
ob_end_clean();
flush();
pass();
asrt(strpos($out, 'SELECT 123') !== FALSE, TRUE);
R::debug(0);
flush();
ob_start();
R::exec('SELECT 123');
$out = ob_get_contents();
ob_end_clean();
flush();
pass();
asrt($out, '');
R::debug(0);
pass();
testpack('test to string override');
$band = R::dispense('band');
$str = strval($band);
asrt($str, 'bigband');
testpack('test whether we can use isset/set in model');
$band->setProperty('property1', 123);
asrt($band->property1, 123);
asrt($band->checkProperty('property1'), TRUE);
asrt($band->checkProperty('property2'), FALSE);
$band = new \Model_Band();
$bean = R::dispense('band');
$bean->property3 = 123;
$band->loadBean($bean);
$bean->property4 = 345;
$band->setProperty('property1', 123);
asrt($band->property1, 123);
asrt($band->checkProperty('property1'), TRUE);
asrt($band->checkProperty('property2'), FALSE);
asrt($band->property3, 123);
asrt($band->property4, 345);
testpack('Can we pass a\\PDO object to Setup?');
$pdo = new \PDO('sqlite:test.db');
R::addDatabase('pdo', $pdo);
R::selectDatabase('pdo');
R::getCell('SELECT 123;');
testpack('Test array interface of beans');
$bean = R::dispense('bean');
$bean->hello = 'hi';
$bean->world = 'planet';
asrt($bean['hello'], 'hi');
asrt(isset($bean['hello']), TRUE);
asrt(isset($bean['bye']), FALSE);
$bean['world'] = 'sphere';
asrt($bean->world, 'sphere');
foreach ($bean as $key => $el) {
if ($el == 'sphere' || $el == 'hi' || $el == 0) {
pass();
} else {
fail();
}
if ($key == 'hello' || $key == 'world' || $key == 'id') {
pass();
} else {
fail();
}
}
asrt(count($bean), 3);
unset($bean['hello']);
asrt(count($bean), 2);
asrt(count(R::dispense('countable')), 1);
// Otherwise untestable...
$bean->setBeanHelper(new SimpleFacadeBeanHelper());
R::getRedBean()->setBeanHelper(new SimpleFacadeBeanHelper());
pass();
// Test whether properties like owner and shareditem are still possible
testpack('Test Bean Interface for Lists');
$bean = R::dispense('bean');
// Must not be list, because first char after own is lowercase
asrt(is_array($bean->owner), FALSE);
// Must not be list, because first char after shared is lowercase
asrt(is_array($bean->shareditem), FALSE);
asrt(is_array($bean->own), FALSE);
asrt(is_array($bean->shared), FALSE);
asrt(is_array($bean->own_item), FALSE);
asrt(is_array($bean->shared_item), FALSE);
asrt(is_array($bean->{'own item'}), FALSE);
asrt(is_array($bean->{'shared Item'}), FALSE);
}
示例8: testScenarios
//.........这里部分代码省略.........
asrt(count($t3->sharedBook), 2);
// Nuke an own-array, replace entire array at once without getting first
$page2->id = 0;
$page2->title = 'yet another page 2';
$page4->id = 0;
$page4->title = 'yet another page 4';
$book = R::load('book', $id);
$book->ownPage = array($page2, $page4);
R::store($book);
$book = R::load('book', $id);
asrt(count($book->ownPage), 2);
asrt(reset($book->ownPage)->title, 'yet another page 2');
asrt(end($book->ownPage)->title, 'yet another page 4');
testids($book->ownPage);
// Test with alias format
$book3->cover = $page6;
$idb3 = R::store($book3);
$book3 = R::load('book', $idb3);
$justACover = $book3->fetchAs('page')->cover;
asrt($book3->cover instanceof OODBBean, TRUE);
asrt($justACover->title, 'cover1');
// No page property
asrt(isset($book3->page), FALSE);
// Test doubling and other side effects ... should not occur..
$book3->sharedTopic = array($topic1, $topic2);
$book3 = R::load('book', R::store($book3));
$book3->sharedTopic = array();
$book3 = R::load('book', R::store($book3));
asrt(count($book3->sharedTopic), 0);
$book3->sharedTopic[] = $topic1;
$book3 = R::load('book', R::store($book3));
// Added only one, not more?
asrt(count($book3->sharedTopic), 1);
asrt(intval(R::getCell("select count(*) from book_topic where book_id = {$idb3}")), 1);
// Add the same
$book3->sharedTopic[] = $topic1;
$book3 = R::load('book', R::store($book3));
asrt(count($book3->sharedTopic), 1);
asrt(intval(R::getCell("select count(*) from book_topic where book_id = {$idb3}")), 1);
$book3->sharedTopic['differentkey'] = $topic1;
$book3 = R::load('book', R::store($book3));
asrt(count($book3->sharedTopic), 1);
asrt(intval(R::getCell("select count(*) from book_topic where book_id = {$idb3}")), 1);
// Ugly assign, auto array generation
$book3->ownPage[] = $page1;
$book3 = R::load('book', R::store($book3));
asrt(count($book3->ownPage), 1);
asrt(intval(R::getCell("select count(*) from page where book_id = {$idb3} ")), 1);
$book3 = R::load('book', $idb3);
$book3->ownPage = array();
// No change until saved
asrt(intval(R::getCell("select count(*) from page where book_id = {$idb3} ")), 1);
$book3 = R::load('book', R::store($book3));
asrt(intval(R::getCell("select count(*) from page where book_id = {$idb3} ")), 0);
asrt(count($book3->ownPage), 0);
$book3 = R::load('book', $idb3);
/**
* Why do I need to do this ---> why does trash() not set id -> 0?
* Because you unset() so trash is done on origin not bean
*/
$page1->id = 0;
$page2->id = 0;
$page3->id = 0;
$book3->ownPage[] = $page1;
$book3->ownPage[] = $page2;
$book3->ownPage[] = $page3;
示例9: runOnce
/**
* Run tests
*/
private function runOnce($n = TRUE)
{
$books = R::dispense('book', 10);
$pages = R::dispense('page', 10);
$readers = R::dispense('reader', 10);
$texts = R::dispense('text', 10);
$i = 0;
foreach ($books as $book) {
$book->name = 'book-' . $i++;
}
$i = 0;
foreach ($pages as $page) {
$page->name = 'page-' . $i++;
}
$i = 0;
foreach ($readers as $reader) {
$reader->name = 'reader-' . $i++;
}
$i = 0;
foreach ($texts as $text) {
$text->content = 'lorem ipsum -' . $i++;
}
foreach ($texts as $text) {
$pages[array_rand($pages)]->ownText[] = $text;
}
foreach ($pages as $page) {
$books[array_rand($books)]->ownPage[] = $page;
}
foreach ($readers as $reader) {
$books[array_rand($books)]->sharedReader[] = $reader;
}
$i = $noOfReaders = $noOfPages = $noOfTexts = 0;
foreach ($books as $key => $book) {
$i++;
$noOfPages += count($book->ownPage);
$noOfReaders += count($book->sharedReader);
foreach ($book->ownPage as $page) {
$noOfTexts += count($page->ownText);
}
$arr = R::exportAll($book);
echo "\nIntermediate info: " . json_encode($arr) . ": Totals = {$i},{$noOfPages},{$noOfReaders},{$noOfTexts} ";
$this->compare($book, $arr[0]);
$copiedBook = R::dup($book);
$copiedBookArray = R::exportAll($copiedBook);
$this->compare($book, $copiedBookArray[0]);
$copiedBookArrayII = $copiedBook->export();
$this->compare($book, $copiedBookArrayII);
$copyFromCopy = R::dup($copiedBook);
$copyFromCopyArray = R::exportAll($copyFromCopy);
$this->compare($book, $copyFromCopyArray[0]);
$copyFromCopyArrayII = $copyFromCopy->export();
$this->compare($book, $copyFromCopyArrayII);
$id = R::store($book);
$copiedBook = R::dup($book);
R::store($book);
//should not be damaged
$copiedBookArray = R::exportAll($copiedBook);
$originalBookArray = R::exportAll($book);
$this->compare($copiedBook, $copiedBookArray[0]);
$this->compare($book, $originalBookArray[0]);
$book = R::load('book', $id);
$this->compare($book, $originalBookArray[0]);
$copiedBook = R::dup($book);
$this->compare($copiedBook, $copiedBook->export());
R::store($copiedBook);
$this->compare($copiedBook, $copiedBook->export());
$copyFromCopy = R::dup($copiedBook);
$this->compare($copyFromCopy, $copyFromCopy->export());
R::store($copyFromCopy);
$newPage = R::dispense('page');
$newPage->name = 'new';
$copyFromCopy->ownPage[] = $newPage;
$modifiedCopy = R::dup($copyFromCopy);
$exportMod = R::exportAll($modifiedCopy);
$this->compare($modifiedCopy, $exportMod[0]);
asrt(count($modifiedCopy->ownPage), count($copiedBook->ownPage) + 1);
R::store($modifiedCopy);
if ($n) {
asrt((int) R::getCell('SELECT count(*) FROM book'), $i * 4);
asrt((int) R::getCell('SELECT count(*) FROM page'), $noOfPages * 4 + $i);
asrt((int) R::getCell('SELECT count(*) FROM text'), $noOfTexts * 4);
asrt((int) R::getCell('SELECT count(*) FROM book_reader'), $noOfReaders * 4);
asrt((int) R::getCell('SELECT count(*) FROM reader'), $noOfReaders);
}
}
if ($n) {
asrt($noOfTexts, 10);
asrt($noOfReaders, 10);
asrt($noOfPages, 10);
asrt($i, 10);
}
}
示例10: testAddingForeignKey
/**
* Test adding foreign keys.
*
* @return void
*/
public function testAddingForeignKey()
{
R::nuke();
$database = R::getCell('SELECT current_database()');
$sql = 'CREATE TABLE book (
id SERIAL PRIMARY KEY
)';
R::exec($sql);
$sql = 'CREATE TABLE page (
id SERIAL PRIMARY KEY,
book_id INTEGER
)';
R::exec($sql);
$writer = R::getWriter();
$sql = "\n\t\t\tSELECT \n\t\t\t\tCOUNT(*) \n\t\t\tFROM information_schema.key_column_usage AS k \n\t\t\tLEFT JOIN information_schema.table_constraints AS c ON c.constraint_name = k.constraint_name \n\t\t\tWHERE k.table_catalog = '{$database}'\n\t\t\t\tAND k.table_schema = 'public' \n\t\t\t\tAND k.table_name = 'page' \n\t\t\t\tAND c.constraint_type = 'FOREIGN KEY'";
$numFKS = R::getCell($sql);
asrt((int) $numFKS, 0);
$writer->addFK('page', 'page', 'book_id', 'id', TRUE);
$sql = "\n\t\t\tSELECT \n\t\t\t\tCOUNT(*) \n\t\t\tFROM information_schema.key_column_usage AS k \n\t\t\tLEFT JOIN information_schema.table_constraints AS c ON c.constraint_name = k.constraint_name \n\t\t\tWHERE k.table_catalog = '{$database}'\n\t\t\t\tAND k.table_schema = 'public' \n\t\t\t\tAND k.table_name = 'page' \n\t\t\t\tAND c.constraint_type = 'FOREIGN KEY'";
$numFKS = R::getCell($sql);
asrt((int) $numFKS, 1);
//dont add twice
$writer->addFK('page', 'page', 'book_id', 'id', TRUE);
$sql = "\n\t\t\tSELECT \n\t\t\t\tCOUNT(*) \n\t\t\tFROM information_schema.key_column_usage AS k \n\t\t\tLEFT JOIN information_schema.table_constraints AS c ON c.constraint_name = k.constraint_name \n\t\t\tWHERE k.table_catalog = '{$database}'\n\t\t\t\tAND k.table_schema = 'public' \n\t\t\t\tAND k.table_name = 'page' \n\t\t\t\tAND c.constraint_type = 'FOREIGN KEY'";
$numFKS = R::getCell($sql);
asrt((int) $numFKS, 1);
//even if it is different
$writer->addFK('page', 'page', 'book_id', 'id', FALSE);
$sql = "\n\t\t\tSELECT \n\t\t\t\tCOUNT(*) \n\t\t\tFROM information_schema.key_column_usage AS k \n\t\t\tLEFT JOIN information_schema.table_constraints AS c ON c.constraint_name = k.constraint_name \n\t\t\tWHERE k.table_catalog = '{$database}'\n\t\t\t\tAND k.table_schema = 'public' \n\t\t\t\tAND k.table_name = 'page' \n\t\t\t\tAND c.constraint_type = 'FOREIGN KEY'";
$numFKS = R::getCell($sql);
asrt((int) $numFKS, 1);
R::nuke();
$sql = 'CREATE TABLE book (
id SERIAL PRIMARY KEY
)';
R::exec($sql);
$sql = 'CREATE TABLE page (
id SERIAL PRIMARY KEY,
book_id INTEGER
)';
R::exec($sql);
$writer = R::getWriter();
$sql = "\n\t\t\tSELECT \n\t\t\t\tCOUNT(*) \n\t\t\tFROM information_schema.key_column_usage AS k \n\t\t\tLEFT JOIN information_schema.table_constraints AS c ON c.constraint_name = k.constraint_name \n\t\t\tWHERE k.table_catalog = '{$database}'\n\t\t\t\tAND k.table_schema = 'public' \n\t\t\t\tAND k.table_name = 'page' \n\t\t\t\tAND c.constraint_type = 'FOREIGN KEY'";
$numFKS = R::getCell($sql);
asrt((int) $numFKS, 0);
$writer->addFK('page', 'page', 'book_id', 'id', FALSE);
$sql = "\n\t\t\tSELECT \n\t\t\t\tCOUNT(*) \n\t\t\tFROM information_schema.key_column_usage AS k \n\t\t\tLEFT JOIN information_schema.table_constraints AS c ON c.constraint_name = k.constraint_name \n\t\t\tWHERE k.table_catalog = '{$database}'\n\t\t\t\tAND k.table_schema = 'public' \n\t\t\t\tAND k.table_name = 'page' \n\t\t\t\tAND c.constraint_type = 'FOREIGN KEY'";
$numFKS = R::getCell($sql);
asrt((int) $numFKS, 1);
}
示例11: beforeCreate
public function beforeCreate()
{
$pos = R::getCell("SELECT MAX(position) FROM setting");
$this->set('position', (int) $pos + 1);
}
示例12: beforeCreate
public function beforeCreate()
{
if (is_null($this->get('position'))) {
$this->set('position', (int) R::getCell("SELECT MAX(position) FROM " . $this->getTableName()) + 1);
}
}