/** * Test BIG INT primary key support. * * @return void */ public function testBigIntSupport() { R::nuke(); $createPageTableSQL = ' CREATE TABLE page ( id BIGSERIAL PRIMARY KEY, book_id BIGSERIAL, magazine_id BIGSERIAL, title VARCHAR(255) )'; $createBookTableSQL = ' CREATE TABLE book ( id BIGSERIAL PRIMARY KEY, title VARCHAR(255) )'; $createPagePageTableSQL = ' CREATE TABLE page_page ( id BIGSERIAL PRIMARY KEY, page_id BIGSERIAL, page2_id BIGSERIAL ) '; R::exec($createBookTableSQL); R::exec($createPageTableSQL); R::exec($createPagePageTableSQL); //insert some records $book1ID = '2223372036854775808'; $book2ID = '2223372036854775809'; $page1ID = '1223372036854775808'; $page2ID = '1223372036854775809'; $page3ID = '1223372036854775890'; $pagePage1ID = '3223372036854775808'; R::exec("ALTER SEQUENCE book_id_seq RESTART WITH {$book1ID}"); R::exec("ALTER SEQUENCE page_id_seq RESTART WITH {$page1ID}"); R::exec("ALTER SEQUENCE page_page_id_seq RESTART WITH {$pagePage1ID}"); $insertBook1SQL = "\n\t\t\tINSERT INTO book (title) VALUES( 'book 1' );\n\t\t"; $insertBook2SQL = "\n\t\t\tINSERT INTO book (title) VALUES( 'book 2' );\n\t\t"; $insertPage1SQL = "\n\t\t\tINSERT INTO page (id, book_id, title, magazine_id) VALUES( '{$page1ID}', '{$book1ID}', 'page 1 of book 1', '{$book2ID}' );\n\t\t"; $insertPage2SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page2ID}', '{$book1ID}', 'page 2 of book 1' );\n\t\t"; $insertPage3SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page3ID}', '{$book2ID}', 'page 1 of book 2' );\n\t\t"; $insertPagePage1SQL = "\n\t\t\tINSERT INTO page_page (id, page_id, page2_id) VALUES( '{$pagePage1ID}', '{$page2ID}', '{$page3ID}' );\n\t\t"; R::exec($insertBook1SQL); R::exec($insertBook2SQL); R::exec($insertPage1SQL); R::exec($insertPage2SQL); R::exec($insertPage3SQL); R::exec($insertPagePage1SQL); //basic tour of basic functions.... $book1 = R::load('book', $book1ID); asrt($book1->id, $book1ID); asrt($book1->title, 'book 1'); $book2 = R::load('book', $book2ID); asrt($book2->id, $book2ID); asrt($book2->title, 'book 2'); asrt(count($book1->ownPage), 2); asrt(count($book1->fresh()->with('LIMIT 1')->ownPage), 1); asrt(count($book1->fresh()->withCondition(' title = ? ', array('page 2 of book 1'))->ownPage), 1); asrt(count($book2->ownPage), 1); asrt($book2->fresh()->countOwn('page'), 1); $page1 = R::load('page', $page1ID); asrt(count($page1->sharedPage), 0); asrt($page1->fetchAs('book')->magazine->id, $book2ID); $page2 = R::load('page', $page2ID); asrt(count($page2->sharedPage), 1); asrt($page2->fresh()->countShared('page'), 1); $page3 = R::findOne('page', ' title = ? ', array('page 1 of book 2')); asrt($page3->id, $page3ID); asrt($page3->book->id, $book2ID); R::each($page2->fresh(), 'book', function ($page, $book) use($page2ID, $book1ID) { asrt($page->id, $page2ID); asrt($book->id, $book1ID); }); }
/** * Test Read-support. * * @return void */ public function testUUIDReadSupport() { R::nuke(); $createPageTableSQL = ' CREATE TABLE `page` ( id CHAR( 40 ), book_id CHAR( 40 ), magazine_id CHAR( 40 ), title VARCHAR(255), PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci '; $createBookTableSQL = ' CREATE TABLE `book` ( id CHAR( 40 ), title VARCHAR(255), PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci '; $createPagePageTableSQL = ' CREATE TABLE `page_page` ( id CHAR( 40 ), page_id CHAR( 40 ), page2_id CHAR( 40 ), PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci '; R::exec($createBookTableSQL); R::exec($createPageTableSQL); R::exec($createPagePageTableSQL); //insert some records $book1ID = '6ccd780c-baba-1026-9564-0040f4311e21'; $book2ID = '6ccd780c-baba-1026-9564-0040f4311e22'; $page1ID = '6ccd780c-baba-1026-9564-0040f4311e23'; $page2ID = '6ccd780c-baba-1026-9564-0040f4311e24'; $page3ID = '6ccd780c-baba-1026-9564-0040f4311e25'; $pagePage1ID = '6ccd780c-baba-1026-9564-0040f4311e26'; $insertBook1SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book1ID}', 'book 1' );\n\t\t"; $insertBook2SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book2ID}', 'book 2' );\n\t\t"; $insertPage1SQL = "\n\t\t\tINSERT INTO page (id, book_id, title, magazine_id) VALUES( '{$page1ID}', '{$book1ID}', 'page 1 of book 1', '{$book2ID}' );\n\t\t"; $insertPage2SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page2ID}', '{$book1ID}', 'page 2 of book 1' );\n\t\t"; $insertPage3SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page3ID}', '{$book2ID}', 'page 1 of book 2' );\n\t\t"; $insertPagePage1SQL = "\n\t\t\tINSERT INTO page_page (id, page_id, page2_id) VALUES( '{$pagePage1ID}', '{$page2ID}', '{$page3ID}' );\n\t\t"; R::exec($insertBook1SQL); R::exec($insertBook2SQL); R::exec($insertPage1SQL); R::exec($insertPage2SQL); R::exec($insertPage3SQL); R::exec($insertPagePage1SQL); //basic tour of basic functions.... $book1 = R::load('book', $book1ID); asrt($book1->id, $book1ID); asrt($book1->title, 'book 1'); $book2 = R::load('book', $book2ID); asrt($book2->id, $book2ID); asrt($book2->title, 'book 2'); asrt(count($book1->ownPage), 2); asrt(count($book1->fresh()->with('LIMIT 1')->ownPage), 1); asrt(count($book1->fresh()->withCondition(' title = ? ', array('page 2 of book 1'))->ownPage), 1); asrt(count($book2->ownPage), 1); asrt($book2->fresh()->countOwn('page'), 1); $page1 = R::load('page', $page1ID); asrt(count($page1->sharedPage), 0); asrt($page1->fetchAs('book')->magazine->id, $book2ID); $page2 = R::load('page', $page2ID); asrt(count($page2->sharedPage), 1); asrt($page2->fresh()->countShared('page'), 1); $page3 = R::findOne('page', ' title = ? ', array('page 1 of book 2')); asrt($page3->id, $page3ID); asrt($page3->book->id, $book2ID); R::each($page2->fresh(), 'book', function ($page, $book) use($page2ID, $book1ID) { asrt($page->id, $page2ID); asrt($book->id, $book1ID); }); }
/** * Test BIG INT primary key support. * * @return void */ public function testBigIntSupport() { R::nuke(); $createPageTableSQL = ' CREATE TABLE `page` ( id BIGINT(20) UNSIGNED NOT NULL, book_id BIGINT(20) UNSIGNED NOT NULL, magazine_id BIGINT(20) UNSIGNED NOT NULL, title VARCHAR(255), PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT = 1223372036854775808'; $createBookTableSQL = ' CREATE TABLE `book` ( id BIGINT(20) UNSIGNED NOT NULL, title VARCHAR(255), PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT = 2223372036854775808'; $createPagePageTableSQL = ' CREATE TABLE `page_page` ( id BIGINT(20) UNSIGNED NOT NULL, page_id BIGINT(20) UNSIGNED NOT NULL, page2_id BIGINT(20) UNSIGNED NOT NULL, PRIMARY KEY ( id ) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci AUTO_INCREMENT = 3223372036854775808'; R::exec($createBookTableSQL); R::exec($createPageTableSQL); R::exec($createPagePageTableSQL); //insert some records $book1ID = '2223372036854775808'; $book2ID = '2223372036854775809'; $page1ID = '1223372036854775808'; $page2ID = '1223372036854775809'; $page3ID = '1223372036854775890'; $pagePage1ID = '3223372036854775808'; $insertBook1SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book1ID}', 'book 1' );\n\t\t"; $insertBook2SQL = "\n\t\t\tINSERT INTO book (id, title) VALUES( '{$book2ID}', 'book 2' );\n\t\t"; $insertPage1SQL = "\n\t\t\tINSERT INTO page (id, book_id, title, magazine_id) VALUES( '{$page1ID}', '{$book1ID}', 'page 1 of book 1', '{$book2ID}' );\n\t\t"; $insertPage2SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page2ID}', '{$book1ID}', 'page 2 of book 1' );\n\t\t"; $insertPage3SQL = "\n\t\t\tINSERT INTO page (id, book_id, title) VALUES( '{$page3ID}', '{$book2ID}', 'page 1 of book 2' );\n\t\t"; $insertPagePage1SQL = "\n\t\t\tINSERT INTO page_page (id, page_id, page2_id) VALUES( '{$pagePage1ID}', '{$page2ID}', '{$page3ID}' );\n\t\t"; R::exec($insertBook1SQL); R::exec($insertBook2SQL); R::exec($insertPage1SQL); R::exec($insertPage2SQL); R::exec($insertPage3SQL); R::exec($insertPagePage1SQL); //basic tour of basic functions.... $book1 = R::load('book', $book1ID); asrt($book1->id, $book1ID); asrt($book1->title, 'book 1'); $book2 = R::load('book', $book2ID); asrt($book2->id, $book2ID); asrt($book2->title, 'book 2'); asrt(count($book1->ownPage), 2); asrt(count($book1->fresh()->with('LIMIT 1')->ownPage), 1); asrt(count($book1->fresh()->withCondition(' title = ? ', array('page 2 of book 1'))->ownPage), 1); asrt(count($book2->ownPage), 1); asrt($book2->fresh()->countOwn('page'), 1); $page1 = R::load('page', $page1ID); asrt(count($page1->sharedPage), 0); asrt($page1->fetchAs('book')->magazine->id, $book2ID); $page2 = R::load('page', $page2ID); asrt(count($page2->sharedPage), 1); asrt($page2->fresh()->countShared('page'), 1); $page3 = R::findOne('page', ' title = ? ', array('page 1 of book 2')); asrt($page3->id, $page3ID); asrt($page3->book->id, $book2ID); R::each($page2->fresh(), 'book', function ($page, $book) use($page2ID, $book1ID) { asrt($page->id, $page2ID); asrt($book->id, $book1ID); }); }
/** * Test variations and cache 2. * * @return void */ public function testPreloadingVariationsAndCache2() { R::$writer->setUseCache(FALSE); $villages = R::dispense('village', 3); foreach ($villages as $v) { $v->ownBuilding = R::dispense('building', 3); } foreach ($villages as $v) { foreach ($v->ownBuilding as $b) { $b->ownFurniture = R::dispense('furniture', 2); } } $armies = R::dispense('army', 3); $villages[0]->sharedArmy = array($armies[1], $armies[2]); $villages[1]->sharedArmy = array($armies[0], $armies[1]); $villages[2]->sharedArmy = array($armies[2]); $soldiers = R::dispense('soldier', 4); $armies[0]->sharedSoldier = array($soldiers[0], $soldiers[1], $soldiers[2]); $armies[1]->sharedSoldier = array($soldiers[2], $soldiers[1]); $armies[2]->sharedSoldier = array($soldiers[2]); $counter = 0; foreach ($villages as $v) { $v->name = $counter++; } $counter = 0; foreach ($armies as $a) { $a->name = $counter++; } $counter = 0; foreach ($soldiers as $s) { $s->name = $counter++; } $buildings = R::dispense('building', 4); $villages[0]->ownBuilding = array($buildings[0]); $villages[1]->ownBuilding = array($buildings[1], $buildings[2]); $villages[2]->ownBuilding = array($buildings[3]); $counter = 0; foreach ($buildings as $b) { $b->name = $counter++; } $books = R::dispense('book', 5); $counter = 0; foreach ($books as $b) { $b->name = $counter++; } $buildings[0]->ownBook = array($books[0], $books[1]); $buildings[1]->ownBook = array($books[2]); $buildings[2]->ownBook = array($books[3], $books[4]); $world = R::dispense('world'); $world->name = 'w1'; $villages[1]->world = $world; R::storeAll($villages); $towns = R::find('village'); $counter = 0; R::each($towns, array('sharedArmy' => 'army', 'sharedArmy.sharedSoldier' => array('soldier', array(' ORDER BY soldier.name DESC ', array())), 'ownBuilding' => array('building', array(' ORDER BY building.name DESC ', array())), 'ownBuilding.ownBook' => 'book', 'world'), function ($t, $a, $s, $b, $x, $w) use(&$counter) { if ($counter === 0) { asrt($w, NULL); asrt((string) $t->name, '0'); asrt(count($t->sharedArmy), 2); $list = array(); foreach ($a as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '1,2'); $list = array(); foreach ($s as $item) { $list[] = $item->name; } asrt(implode(',', $list), '2,1'); $list = array(); foreach ($b as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '0'); $list = array(); foreach ($x as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '0,1'); $first = reset($a); asrt($first->getMeta('type'), 'army'); $first = reset($s); asrt($first->getMeta('type'), 'soldier'); $first = reset($b); asrt($first->getMeta('type'), 'building'); $first = reset($x); asrt($first->getMeta('type'), 'book'); } elseif ($counter === 1) { asrt($w->name, 'w1'); asrt((string) $t->name, '1'); asrt(count($t->sharedArmy), 2); $list = array(); foreach ($a as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '0,1'); $list = array(); foreach ($s as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '0,1,2'); $list = array(); foreach ($b as $item) { $list[] = $item->name; } asrt(implode(',', $list), '2,1'); $list = array(); foreach ($x as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '2,3,4'); $first = reset($a); asrt($first->getMeta('type'), 'army'); $first = reset($s); asrt($first->getMeta('type'), 'soldier'); $first = reset($b); asrt($first->getMeta('type'), 'building'); $first = reset($x); asrt($first->getMeta('type'), 'book'); } elseif ($counter === 2) { asrt($w, NULL); asrt((string) $t->name, '2'); asrt(count($t->sharedArmy), 1); $list = array(); foreach ($a as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '2'); $list = array(); foreach ($s as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '2'); $list = array(); foreach ($b as $item) { $list[] = $item->name; } sort($list); asrt(implode(',', $list), '3'); asrt(count($x), 0); $first = reset($a); asrt($first->getMeta('type'), 'army'); $first = reset($s); asrt($first->getMeta('type'), 'soldier'); $first = reset($b); asrt($first->getMeta('type'), 'building'); } $counter++; }); }