本文整理汇总了PHP中DB::requireField方法的典型用法代码示例。如果您正苦于以下问题:PHP DB::requireField方法的具体用法?PHP DB::requireField怎么用?PHP DB::requireField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB::requireField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: requireField
/**
* Add the field to the underlying database.
*
* @see DBField::requireField()
*/
public function requireField()
{
//@todo change this to use Link rather than basic varchar
$parts = array('datatype' => 'varchar', 'precision' => 50, 'character set' => 'utf8', 'default' => 0, 'arrayValue' => $this->arrayValue);
$values = array('type' => 'varchar', 'parts' => $parts);
DB::requireField($this->tableName, $this->name, $values);
}
示例2: requireField
public function requireField()
{
$fields = $this->compositeDatabaseFields();
if ($fields) {
foreach ($fields as $name => $type) {
\DB::requireField($this->tableName, $this->name . $name, $type);
}
}
}
示例3: requireField
public function requireField()
{
// HACK: MSSQL does not support double so we're usinf float instead
// @todo This should go into MSSQLDatabase ideally somehow
if (DB::getConn() instanceof MySQLDatabase) {
DB::requireField($this->tableName, $this->name, "double");
} else {
DB::requireField($this->tableName, $this->name, "float");
}
}
示例4: requireField
/**
* (non-PHPdoc)
* @see DBField::requireField()
*/
public function requireField()
{
$parts = array('datatype' => 'varchar', 'precision' => 9, 'character set' => 'utf8', 'collate' => 'utf8_general_ci', 'arrayValue' => $this->arrayValue);
$values = array('type' => 'varchar', 'parts' => $parts);
// Add support for both SS DB API 3.2 and <3.2
if (method_exists('DB', 'require_field')) {
DB::require_field($this->tableName, $this->name, $values);
} else {
DB::requireField($this->tableName, $this->name, $values);
}
}
示例5: requireField
/**
* (non-PHPdoc)
* @see DBField::requireField()
*/
function requireField() {
$parts = array(
'datatype'=>'varchar',
'precision'=>$this->size,
'character set'=>'utf8',
'collate'=>'utf8_general_ci',
'arrayValue'=>$this->arrayValue
);
$values = array(
'type' => 'varchar',
'parts' => $parts
);
DB::requireField($this->tableName, $this->name, $values);
}
示例6: requireField
/**
* Compose the requirements for this field
*
* Note: Issue with this approach is if the same name is used in different relations,
* believe this is a limitation with SilverStripe anyway.
* many_many = array('Name' => 'SomeClass')
* belongs_many_many = array('Name' => 'SomeOtherClass')
*
* @return void
*/
public function requireField()
{
//Get the type of object for this relation and pass to OrientDatabase::linkset() effectively
//@todo @has_many same treatment for has_many
//@todo @belongs_many_many same treatment for belongs_many_many
$relationClass = null;
//Does the tableName always match the class name?
$manyMany = Config::inst()->get($this->tableName, 'many_many', Config::UNINHERITED);
if (isset($manyMany[$this->name])) {
$relationClass = $manyMany[$this->name];
}
$belongsManyMany = Config::inst()->get($this->tableName, 'belongs_many_many', Config::UNINHERITED);
if (isset($belongsManyMany[$this->name])) {
$relationClass = $belongsManyMany[$this->name];
}
//If the relation class cannot be found do not create the linkset at all
if (!$relationClass) {
return;
}
$parts = array('datatype' => 'linkset', 'precision' => null, 'null' => null, 'default' => null, 'arrayValue' => null, 'relationClass' => $relationClass);
$values = array('type' => 'linkset', 'parts' => $parts);
DB::requireField($this->tableName, $this->name, $values);
}
示例7: augmentDatabase
function augmentDatabase()
{
$classTable = $this->owner->class;
// Build a list of suffixes whose tables need versioning
$allSuffixes = array();
foreach (Versioned::$versionableExtensions as $versionableExtension => $suffixes) {
if ($this->owner->hasExtension($versionableExtension) && singleton($versionableExtension)->stat('enabled')) {
$allSuffixes = array_merge($allSuffixes, (array) $suffixes);
foreach ((array) $suffixes as $suffix) {
$allSuffixes[$suffix] = $versionableExtension;
}
}
}
// Add the default table with an empty suffix to the list (table name = class name)
array_push($allSuffixes, '');
foreach ($allSuffixes as $key => $suffix) {
// check that this is a valid suffix
if (!is_int($key)) {
continue;
}
if ($suffix) {
$table = "{$classTable}_{$suffix}";
} else {
$table = $classTable;
}
if ($fields = $this->owner->databaseFields()) {
$indexes = $this->owner->databaseIndexes();
if ($this->owner->parentClass() == "DataObject") {
$rootTable = true;
}
if ($suffix && ($ext = $this->owner->extInstance($allSuffixes[$suffix]))) {
if (!$ext->isVersionedTable($table)) {
continue;
}
$fields = $ext->fieldsInExtraTables($suffix);
$indexes = $fields['indexes'];
$fields = $fields['db'];
}
// Create tables for other stages
foreach ($this->stages as $stage) {
// Extra tables for _Live, etc.
if ($stage != $this->defaultStage) {
DB::requireTable("{$table}_{$stage}", $fields, $indexes);
/*
if(!DB::query("SELECT * FROM {$table}_$stage")->value()) {
$fieldList = implode(", ",array_keys($fields));
DB::query("INSERT INTO `{$table}_$stage` (ID,$fieldList)
SELECT ID,$fieldList FROM `$table`");
}
*/
}
// Version fields on each root table (including Stage)
if (isset($rootTable)) {
$stageTable = $stage == $this->defaultStage ? $table : "{$table}_{$stage}";
DB::requireField($stageTable, "Version", "int(11) not null default '0'");
}
}
// Create table for all versions
$versionFields = array_merge(array("RecordID" => "Int", "Version" => "Int", "WasPublished" => "Boolean", "AuthorID" => "Int", "PublisherID" => "Int"), (array) $fields);
$versionIndexes = array_merge(array('RecordID_Version' => '(RecordID, Version)', 'RecordID' => true, 'Version' => true, 'AuthorID' => true, 'PublisherID' => true), (array) $indexes);
DB::requireTable("{$table}_versions", $versionFields, $versionIndexes);
/*
if(!DB::query("SELECT * FROM {$table}_versions")->value()) {
$fieldList = implode(", ",array_keys($fields));
DB::query("INSERT INTO `{$table}_versions` ($fieldList, RecordID, Version)
SELECT $fieldList, ID AS RecordID, 1 AS Version FROM `$table`");
}
*/
} else {
DB::dontRequireTable("{$table}_versions");
foreach ($this->stages as $stage) {
if ($stage != $this->defaultStage) {
DB::dontrequireTable("{$table}_{$stage}");
}
}
}
}
}
示例8: requireField
function requireField()
{
DB::requireField($this->tableName, $this->name, "float");
}
示例9: requireField
public function requireField()
{
$parts = array('datatype' => 'longblob', 'arrayValue' => $this->arrayValue);
$values = array('type' => 'longblob', 'parts' => $parts);
DB::requireField($this->tableName, $this->name, $values, $this->default);
}
示例10: requireField
function requireField() {
DB::requireField($this->tableName, $this->name, "tinyint(1) unsigned not null default '{$this->defaultVal}'");
}
示例11: requireField
public function requireField()
{
$parts = array('datatype' => 'year', 'precision' => 4, 'arrayValue' => $this->arrayValue);
$values = array('type' => 'year', 'parts' => $parts);
DB::requireField($this->tableName, $this->name, $values);
}
示例12: requireField
/**
* Add the field to the underlying database.
*/
public function requireField()
{
DB::requireField($this->tableName, $this->name, 'mediumblob');
}
示例13: augmentDatabase
function augmentDatabase()
{
$classTable = $this->owner->class;
$isRootClass = $this->owner->class == ClassInfo::baseDataClass($this->owner->class);
// Build a list of suffixes whose tables need versioning
$allSuffixes = array();
foreach (Versioned::$versionableExtensions as $versionableExtension => $suffixes) {
if ($this->owner->hasExtension($versionableExtension) && singleton($versionableExtension)->stat('enabled')) {
$allSuffixes = array_merge($allSuffixes, (array) $suffixes);
foreach ((array) $suffixes as $suffix) {
$allSuffixes[$suffix] = $versionableExtension;
}
}
}
// Add the default table with an empty suffix to the list (table name = class name)
array_push($allSuffixes, '');
foreach ($allSuffixes as $key => $suffix) {
// check that this is a valid suffix
if (!is_int($key)) {
continue;
}
if ($suffix) {
$table = "{$classTable}_{$suffix}";
} else {
$table = $classTable;
}
if ($fields = $this->owner->databaseFields()) {
$indexes = $this->owner->databaseIndexes();
if ($suffix && ($ext = $this->owner->extInstance($allSuffixes[$suffix]))) {
if (!$ext->isVersionedTable($table)) {
continue;
}
$fields = $ext->fieldsInExtraTables($suffix);
$indexes = $fields['indexes'];
$fields = $fields['db'];
}
// Create tables for other stages
foreach ($this->stages as $stage) {
// Extra tables for _Live, etc.
if ($stage != $this->defaultStage) {
DB::requireTable("{$table}_{$stage}", $fields, $indexes);
}
// Version fields on each root table (including Stage)
if ($isRootClass) {
$stageTable = $stage == $this->defaultStage ? $table : "{$table}_{$stage}";
DB::requireField($stageTable, "Version", "int(11) not null default '0'");
}
}
if ($isRootClass) {
// Create table for all versions
$versionFields = array_merge(array("RecordID" => "Int", "Version" => "Int", "WasPublished" => "Boolean", "AuthorID" => "Int", "PublisherID" => "Int"), (array) $fields);
$versionIndexes = array_merge(array('RecordID_Version' => '(RecordID, Version)', 'RecordID' => true, 'Version' => true, 'AuthorID' => true, 'PublisherID' => true), (array) $indexes);
} else {
// Create fields for any tables of subclasses
$versionFields = array_merge(array("RecordID" => "Int", "Version" => "Int"), (array) $fields);
$versionIndexes = array_merge(array('RecordID_Version' => '(RecordID, Version)', 'RecordID' => true, 'Version' => true), (array) $indexes);
}
DB::requireTable("{$table}_versions", $versionFields, $versionIndexes);
} else {
DB::dontRequireTable("{$table}_versions");
foreach ($this->stages as $stage) {
if ($stage != $this->defaultStage) {
DB::dontrequireTable("{$table}_{$stage}");
}
}
}
}
}
示例14: requireField
function requireField()
{
$parts = array('datatype' => 'date', 'arrayValue' => $this->arrayValue);
$values = array('type' => 'date', 'parts' => $parts);
DB::requireField($this->tableName, $this->name, $values);
}
示例15: requireField
function requireField()
{
$values = array('type' => 'set', 'parts' => array('enums' => $this->enum, 'character set' => 'utf8', 'collate' => 'utf8_general_ci', 'default' => Convert::raw2sql($this->default), 'table' => $this->tableName, 'arrayValue' => $this->arrayValue));
DB::requireField($this->tableName, $this->name, $values);
}