本文整理汇总了PHP中R::getWriter方法的典型用法代码示例。如果您正苦于以下问题:PHP R::getWriter方法的具体用法?PHP R::getWriter怎么用?PHP R::getWriter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类R
的用法示例。
在下文中一共展示了R::getWriter方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testBeautifulColumnNames
/**
* Test beautification of column names.
*
* @return void
*/
public function testBeautifulColumnNames()
{
testpack('Beautiful column names');
$town = R::dispense('town');
$town->isCapital = FALSE;
$town->hasTrainStation = TRUE;
$town->name = 'BeautyVille';
$houses = R::dispense('house', 2);
$houses[0]->isForSale = TRUE;
$town->ownHouse = $houses;
R::store($town);
$town = R::load('town', $town->id);
asrt($town->isCapital == FALSE, TRUE);
asrt($town->hasTrainStation == TRUE, TRUE);
asrt($town->name == 'BeautyVille', TRUE);
testpack('Accept datetime objects.');
$cal = R::dispense('calendar');
$cal->when = new DateTime('2000-01-01', new DateTimeZone('Pacific/Nauru'));
asrt($cal->when, '2000-01-01 00:00:00');
testpack('Affected rows test');
$currentDriver = $this->currentlyActiveDriverID;
$toolbox = R::$toolbox;
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$bean = $redbean->dispense('bean');
$bean->prop = 3;
//make test run with strict mode as well
$redbean->store($bean);
$adapter->exec('UPDATE bean SET prop = 2');
asrt($adapter->getAffectedRows(), 1);
testpack('Testing Logger');
R::$adapter->getDatabase()->setLogger(new RedBean_Logger_Default());
asrt(R::$adapter->getDatabase()->getLogger() instanceof RedBean_Logger, TRUE);
asrt(R::$adapter->getDatabase()->getLogger() instanceof RedBean_Logger_Default, TRUE);
$bean = R::dispense('bean');
$bean->property = 1;
$bean->unsetAll(array('property'));
asrt($bean->property, NULL);
asrt($bean->setAttr('property', 2) instanceof RedBean_OODBBean, TRUE);
asrt($bean->property, 2);
asrt(preg_match('/\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d/', R::isoDate()), 1);
asrt(preg_match('/\\d\\d\\d\\d\\-\\d\\d\\-\\d\\d\\s\\d\\d:\\d\\d:\\d\\d/', R::isoDateTime()), 1);
$redbean = R::getRedBean();
$adapter = R::getDatabaseAdapter();
$writer = R::getWriter();
asrt($redbean instanceof RedBean_OODB, TRUE);
asrt($adapter instanceof RedBean_Adapter, TRUE);
asrt($writer instanceof RedBean_QueryWriter, TRUE);
R::setRedBean($redbean);
pass();
//cant really test this
R::setDatabaseAdapter($adapter);
pass();
//cant really test this
R::setWriter($writer);
pass();
//cant really test this
$u1 = R::dispense('user');
$u1->name = 'Gabor';
$u1->login = 'g';
$u2 = R::dispense('user');
$u2->name = 'Eric';
$u2->login = 'e';
R::store($u1);
R::store($u2);
$list = R::getAssoc('select login,' . R::$writer->esc('name') . ' from ' . R::$writer->esc('user') . ' ');
asrt($list['e'], 'Eric');
asrt($list['g'], 'Gabor');
$painting = R::dispense('painting');
$painting->name = 'Nighthawks';
$id = R::store($painting);
testpack('Testing Plugin Cooker');
$cooker = new RedBean_Plugin_Cooker();
$cooker->setToolbox($toolbox);
try {
asrt($cooker->graph('abc'), 'abc');
fail();
} catch (RedBean_Exception_Security $e) {
pass();
}
testpack('Testing SQL Error Types');
foreach ($writer->typeno_sqltype as $code => $text) {
asrt(is_integer($code), TRUE);
asrt(is_string($text), TRUE);
}
foreach ($writer->sqltype_typeno as $text => $code) {
asrt(is_integer($code), TRUE);
asrt(is_string($text), TRUE);
}
testpack('Testing Nowhere Pt. 1 (unfrozen)');
foreach (array('exec', 'getAll', 'getCell', 'getAssoc', 'getRow', 'getCol') as $method) {
R::$method('select * from nowhere');
pass();
//.........这里部分代码省略.........
示例2: get_uniques_for_type
function get_uniques_for_type($type)
{
$list = array();
$writer = R::getWriter();
$adapter = R::getDatabaseAdapter();
global $currentDriver;
switch ($currentDriver) {
case 'mysql':
$table = $writer->esc($type, TRUE);
$columns = $adapter->get('
SELECT
information_schema.key_column_usage.constraint_name,
information_schema.key_column_usage.column_name
FROM
information_schema.table_constraints
INNER JOIN information_schema.key_column_usage
ON (
information_schema.table_constraints.constraint_name = information_schema.key_column_usage.constraint_name
AND information_schema.table_constraints.constraint_schema = information_schema.key_column_usage.constraint_schema
AND information_schema.table_constraints.constraint_catalog = information_schema.key_column_usage.constraint_catalog
)
WHERE
information_schema.table_constraints.table_schema IN (SELECT DATABASE())
AND information_schema.table_constraints.table_name = ?
AND information_schema.table_constraints.constraint_type = \'UNIQUE\'
', array($table));
$uniques = array();
foreach ($columns as $column) {
if (!isset($uniques[$column['constraint_name']])) {
$uniques[$column['constraint_name']] = array();
}
$uniques[$column['constraint_name']][] = $column['column_name'];
}
$list = $uniques;
break;
case 'pgsql':
$table = $writer->esc($type, TRUE);
$columns = $adapter->get('
SELECT
information_schema.key_column_usage.constraint_name,
information_schema.key_column_usage.column_name
FROM
information_schema.table_constraints
INNER JOIN information_schema.key_column_usage
ON (
information_schema.table_constraints.constraint_name = information_schema.key_column_usage.constraint_name
AND information_schema.table_constraints.constraint_schema = information_schema.key_column_usage.constraint_schema
AND information_schema.table_constraints.constraint_catalog = information_schema.key_column_usage.constraint_catalog
)
WHERE
information_schema.table_constraints.table_catalog = current_database()
AND information_schema.key_column_usage.table_schema = ANY( current_schemas( FALSE ) )
AND information_schema.table_constraints.table_name = ?
AND information_schema.table_constraints.constraint_type = \'UNIQUE\'
', array($table));
$uniques = array();
foreach ($columns as $column) {
if (!isset($uniques[$column['constraint_name']])) {
$uniques[$column['constraint_name']] = array();
}
$uniques[$column['constraint_name']][] = $column['column_name'];
}
$list = $uniques;
break;
case 'sqlite':
$uniques = array();
$table = $writer->esc($type, TRUE);
$indexes = $adapter->get("PRAGMA index_list({$table})");
foreach ($indexes as $index) {
if ($index['unique'] == 1) {
$info = $adapter->get("PRAGMA index_info({$index['name']})");
if (!isset($uniques[$index['name']])) {
$uniques[$index['name']] = array();
}
foreach ($info as $piece) {
$uniques[$index['name']][] = $piece['name'];
}
}
}
$list = $uniques;
break;
case 'CUBRID':
try {
$sqlCode = $adapter->get("SHOW CREATE TABLE `{$type}`");
} catch (\Exception $e) {
$sqlCode = '';
}
if (!isset($sqlCode[0])) {
return array();
}
$matches = array();
preg_match_all('/CONSTRAINT\\s+\\[([\\w_]+)\\]\\s+UNIQUE\\s+KEY\\s+\\(([^\\)]+)\\)/', $sqlCode[0]['CREATE TABLE'], $matches);
$list = array();
if (!isset($matches[0])) {
return $list;
}
$max = count($matches[0]);
for ($i = 0; $i < $max; $i++) {
$columns = explode(',', $matches[2][$i]);
foreach ($columns as $key => $column) {
//.........这里部分代码省略.........
示例3: testFastTrackRelations
/**
* Fast track link block code should not affect self-referential N-M relations.
*
* @return void
*/
public function testFastTrackRelations()
{
testpack('Test fast-track linkBlock exceptions');
list($donald, $mickey, $goofy, $pluto) = R::dispense('friend', 4);
$donald->name = 'D';
$mickey->name = 'M';
$goofy->name = 'G';
$pluto->name = 'P';
$donald->sharedFriend = array($mickey, $goofy);
$mickey->sharedFriend = array($pluto, $goofy);
$mickey->sharedBook = array(R::dispense('book'));
R::storeAll(array($mickey, $donald, $goofy, $pluto));
$donald = R::load('friend', $donald->id);
$mickey = R::load('friend', $mickey->id);
$goofy = R::load('friend', $goofy->id);
$pluto = R::load('friend', $pluto->id);
$names = implode(',', R::gatherLabels($donald->sharedFriend));
asrt($names, 'G,M');
$names = implode(',', R::gatherLabels($goofy->sharedFriend));
asrt($names, 'D,M');
$names = implode(',', R::gatherLabels($mickey->sharedFriend));
asrt($names, 'D,G,P');
$names = implode(',', R::gatherLabels($pluto->sharedFriend));
asrt($names, 'M');
// Now in combination with with() conditions...
$donald = R::load('friend', $donald->id);
$names = implode(',', R::gatherLabels($donald->withCondition(' name = ? ', array('M'))->sharedFriend));
asrt($names, 'M');
// Now in combination with with() conditions...
$donald = R::load('friend', $donald->id);
$names = implode(',', R::gatherLabels($donald->with(' ORDER BY name ')->sharedFriend));
asrt($names, 'G,M');
// Now counting
$goofy = R::load('friend', $goofy->id);
asrt((int) $goofy->countShared('friend'), 2);
asrt((int) $donald->countShared('friend'), 2);
asrt((int) $mickey->countShared('friend'), 3);
asrt((int) $pluto->countShared('friend'), 1);
R::unassociate($donald, $mickey);
asrt((int) $donald->countShared('friend'), 1);
asrt(R::areRelated($donald, $mickey), FALSE);
asrt(R::areRelated($mickey, $donald), FALSE);
asrt(R::areRelated($mickey, $goofy), TRUE);
asrt(R::areRelated($goofy, $mickey), TRUE);
R::getWriter()->setUseCache(TRUE);
$mickeysFriends = R::$associationManager->related($mickey, 'friend', TRUE);
asrt(count($mickeysFriends), 2);
$mickeysFriends = R::$associationManager->related($mickey, 'friend', TRUE);
asrt(count($mickeysFriends), 2);
$plutosFriends = R::$associationManager->related($pluto, 'friend', TRUE);
asrt(count($plutosFriends), 1);
$mickeysBooks = R::$associationManager->related($mickey, 'book', TRUE);
asrt(count($mickeysBooks), 1);
R::getWriter()->setUseCache(FALSE);
}