クラス yii\db\sqlite\Schema
Schema は、SQLite (2/3) データベースからメタデータを取得するためのクラスです。
パブリックプロパティ
パブリックメソッド
保護されたメソッド
定数
定数 | 値 | 説明 | 定義元 |
---|---|---|---|
SCHEMA_CACHE_VERSION | 1 | キャッシュされた値のデータ形式が変更された場合に、キャッシュされた値の非互換性を検出するためのスキーマキャッシュバージョン。 | yii\db\Schema |
TYPE_BIGINT | 'bigint' | yii\db\Schema | |
TYPE_BIGPK | 'bigpk' | yii\db\Schema | |
TYPE_BINARY | 'binary' | yii\db\Schema | |
TYPE_BOOLEAN | 'boolean' | yii\db\Schema | |
TYPE_CHAR | 'char' | yii\db\Schema | |
TYPE_DATE | 'date' | yii\db\Schema | |
TYPE_DATETIME | 'datetime' | yii\db\Schema | |
TYPE_DECIMAL | 'decimal' | yii\db\Schema | |
TYPE_DOUBLE | 'double' | yii\db\Schema | |
TYPE_FLOAT | 'float' | yii\db\Schema | |
TYPE_INTEGER | 'integer' | yii\db\Schema | |
TYPE_JSON | 'json' | yii\db\Schema | |
TYPE_MONEY | 'money' | yii\db\Schema | |
TYPE_PK | 'pk' | yii\db\Schema | |
TYPE_SMALLINT | 'smallint' | yii\db\Schema | |
TYPE_STRING | 'string' | yii\db\Schema | |
TYPE_TEXT | 'text' | yii\db\Schema | |
TYPE_TIME | 'time' | yii\db\Schema | |
TYPE_TIMESTAMP | 'timestamp' | yii\db\Schema | |
TYPE_TINYINT | 'tinyint' | yii\db\Schema | |
TYPE_UBIGPK | 'ubigpk' | yii\db\Schema | |
TYPE_UPK | 'upk' | yii\db\Schema |
プロパティの詳細
列名をクォートするために使用する文字。開始文字と終了文字が異なる場合は、2 文字の配列を使用できます。
スキーマ、テーブルなどの名前をクォートするために使用する文字。開始文字と終了文字が異なる場合は、2 文字の配列を使用できます。
このトランザクションに使用するトランザクション分離レベル。これは、yii\db\Transaction::READ_UNCOMMITTED または yii\db\Transaction::SERIALIZABLE のいずれかです。
物理的なカラム型 (キー) から抽象的なカラム型 (値) へのマッピング
'tinyint' => self::TYPE_TINYINT,
'bit' => self::TYPE_SMALLINT,
'boolean' => self::TYPE_BOOLEAN,
'bool' => self::TYPE_BOOLEAN,
'smallint' => self::TYPE_SMALLINT,
'mediumint' => self::TYPE_INTEGER,
'int' => self::TYPE_INTEGER,
'integer' => self::TYPE_INTEGER,
'bigint' => self::TYPE_BIGINT,
'float' => self::TYPE_FLOAT,
'double' => self::TYPE_DOUBLE,
'real' => self::TYPE_FLOAT,
'decimal' => self::TYPE_DECIMAL,
'numeric' => self::TYPE_DECIMAL,
'tinytext' => self::TYPE_TEXT,
'mediumtext' => self::TYPE_TEXT,
'longtext' => self::TYPE_TEXT,
'text' => self::TYPE_TEXT,
'varchar' => self::TYPE_STRING,
'string' => self::TYPE_STRING,
'char' => self::TYPE_CHAR,
'blob' => self::TYPE_BINARY,
'datetime' => self::TYPE_DATETIME,
'year' => self::TYPE_DATE,
'date' => self::TYPE_DATE,
'time' => self::TYPE_TIME,
'timestamp' => self::TYPE_TIMESTAMP,
'enum' => self::TYPE_STRING,
]
メソッドの詳細
定義元: yii\base\BaseObject::__call()
クラスメソッドではない名前付きメソッドを呼び出します。
このメソッドは、未知のメソッドが呼び出されたときに暗黙的に呼び出されるPHPのマジックメソッドであるため、直接呼び出さないでください。
public mixed __call ( $name, $params ) | ||
$name | string |
メソッド名 |
$params | array |
メソッドのパラメータ |
return | mixed |
メソッドの戻り値 |
---|---|---|
throws | yii\base\UnknownMethodException |
未知のメソッドを呼び出すとき |
public function __call($name, $params)
{
throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()");
}
定義元: yii\base\BaseObject::__construct()
コンストラクタ。
デフォルトの実装では、次の2つの処理を行います。
- 与えられた構成
$config
でオブジェクトを初期化します。 - init()を呼び出します。
このメソッドが子クラスでオーバーライドされている場合は、次のことを推奨します。
- コンストラクタの最後のパラメータは、ここでの
$config
のように構成配列であること。 - コンストラクタの最後に親の実装を呼び出すこと。
public void __construct ( $config = [] ) | ||
$config | array |
オブジェクトのプロパティを初期化するために使用される名前と値のペア |
public function __construct($config = [])
{
if (!empty($config)) {
Yii::configure($this, $config);
}
$this->init();
}
定義元: yii\base\BaseObject::__get()
オブジェクトプロパティの値を返します。
このメソッドは、$value = $object->property;
を実行するときに暗黙的に呼び出されるPHPのマジックメソッドであるため、直接呼び出さないでください。
関連項目 __set()。
public mixed __get ( $name ) | ||
$name | string |
プロパティ名 |
return | mixed |
プロパティの値 |
---|---|---|
throws | yii\base\UnknownPropertyException |
プロパティが定義されていない場合 |
throws | yii\base\InvalidCallException |
プロパティが書き込み専用の場合 |
public function __get($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter();
} elseif (method_exists($this, 'set' . $name)) {
throw new InvalidCallException('Getting write-only property: ' . get_class($this) . '::' . $name);
}
throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '::' . $name);
}
定義元: yii\base\BaseObject::__isset()
プロパティが設定されているか (つまり、定義されていて null でないか) を確認します。
このメソッドは、isset($object->property)
を実行するときに暗黙的に呼び出されるPHPのマジックメソッドであるため、直接呼び出さないでください。
プロパティが定義されていない場合、falseが返されることに注意してください。
public boolean __isset ( $name ) | ||
$name | string |
プロパティ名またはイベント名 |
return | boolean |
指定されたプロパティが設定されているかどうか(nullではない)。 |
---|
public function __isset($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter() !== null;
}
return false;
}
定義元: yii\base\BaseObject::__set()
オブジェクトプロパティの値を設定します。
このメソッドは、$object->property = $value;
を実行するときに暗黙的に呼び出されるPHPのマジックメソッドであるため、直接呼び出さないでください。
関連項目 __get()。
public void __set ( $name, $value ) | ||
$name | string |
プロパティ名またはイベント名 |
$value | mixed |
プロパティの値 |
throws | yii\base\UnknownPropertyException |
プロパティが定義されていない場合 |
---|---|---|
throws | yii\base\InvalidCallException |
プロパティが読み取り専用の場合 |
public function __set($name, $value)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter($value);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '::' . $name);
} else {
throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '::' . $name);
}
}
定義元: yii\base\BaseObject::__unset()
オブジェクトプロパティを null に設定します。
このメソッドは、unset($object->property)
を実行するときに暗黙的に呼び出されるPHPのマジックメソッドであるため、直接呼び出さないでください。
プロパティが定義されていない場合、このメソッドは何もしないことに注意してください。プロパティが読み取り専用の場合、例外がスローされます。
public void __unset ( $name ) | ||
$name | string |
プロパティ名 |
throws | yii\base\InvalidCallException |
プロパティが読み取り専用の場合。 |
---|
public function __unset($name)
{
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
$this->$setter(null);
} elseif (method_exists($this, 'get' . $name)) {
throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '::' . $name);
}
}
定義元: yii\base\BaseObject::canGetProperty()
プロパティが読み取り可能かどうかを示す値を返します。
プロパティが読み取り可能であるのは、次のいずれかの場合です。
- クラスが指定された名前に関連付けられたゲッターメソッドを持っている場合(この場合、プロパティ名は大文字と小文字を区別しません)。
- クラスが指定された名前のメンバー変数を持っている場合(
$checkVars
が true の場合)。
参照: canSetProperty()。
public boolean canGetProperty ( $name, $checkVars = true ) | ||
$name | string |
プロパティ名 |
$checkVars | boolean |
メンバー変数をプロパティとして扱うかどうか |
return | boolean |
プロパティが読み取り可能かどうか |
---|
public function canGetProperty($name, $checkVars = true)
{
return method_exists($this, 'get' . $name) || $checkVars && property_exists($this, $name);
}
定義元: yii\base\BaseObject::canSetProperty()
プロパティを設定可能かどうかを示す値を返します。
プロパティが書き込み可能であるのは、次のいずれかの場合です。
- クラスが指定された名前に関連付けられたセッターメソッドを持っている場合(この場合、プロパティ名は大文字と小文字を区別しません)。
- クラスが指定された名前のメンバー変数を持っている場合(
$checkVars
が true の場合)。
参照: canGetProperty()。
public boolean canSetProperty ( $name, $checkVars = true ) | ||
$name | string |
プロパティ名 |
$checkVars | boolean |
メンバー変数をプロパティとして扱うかどうか |
return | boolean |
プロパティが書き込み可能かどうか |
---|
public function canSetProperty($name, $checkVars = true)
{
return method_exists($this, 'set' . $name) || $checkVars && property_exists($this, $name);
}
::class
を使用してください。
定義元: yii\base\BaseObject::className()
このクラスの完全修飾名を返します。
public static string className ( ) | ||
return | string |
このクラスの完全修飾名。 |
---|
public static function className()
{
return get_called_class();
}
定義元: yii\db\Schema::convertException()
可能であれば、DB例外をより具体的な例外に変換します。
public yii\db\Exception convertException ( Exception $e, $rawSql ) | ||
$e | 例外 | |
$rawSql | string |
例外を発生させた SQL |
public function convertException(\Exception $e, $rawSql)
{
if ($e instanceof Exception) {
return $e;
}
$exceptionClass = '\yii\db\Exception';
foreach ($this->exceptionMap as $error => $class) {
if (strpos($e->getMessage(), $error) !== false) {
$exceptionClass = $class;
}
}
$message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
return new $exceptionClass($message, $errorInfo, $e->getCode(), $e);
}
定義元: yii\db\Schema::createColumnSchema()
データベースの列スキーマを作成します。
このメソッドは、DBMS固有のカラムスキーマを作成するために子クラスでオーバーライドできます。
protected yii\db\ColumnSchema createColumnSchema ( ) | ||
return | yii\db\ColumnSchema |
カラムスキーマのインスタンス。 |
---|---|---|
throws | yii\base\InvalidConfigException |
カラムスキーマクラスを作成できない場合。 |
protected function createColumnSchema()
{
return Yii::createObject($this->columnSchemaClass);
}
型と値の精度を指定して、カラムスキーマビルダーインスタンスを作成します。
このメソッドは、DBMS固有のカラムスキーマビルダーを作成するために子クラスでオーバーライドできます。
public yii\db\sqlite\ColumnSchemaBuilder createColumnSchemaBuilder ( $type, $length = null ) | ||
$type | string |
カラムの型。 yii\db\sqlite\ColumnSchemaBuilder::$type を参照してください。 |
$length | integer|string|array|null |
カラムの長さまたは精度。yii\db\sqlite\ColumnSchemaBuilder::$length を参照してください。 |
return | yii\db\sqlite\ColumnSchemaBuilder |
カラムスキーマビルダーのインスタンス |
---|
public function createColumnSchemaBuilder($type, $length = null)
{
return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]);
}
MySQLデータベースのクエリビルダーを作成します。
このメソッドは、DBMS固有のクエリビルダーを作成するために子クラスでオーバーライドできます。
public yii\db\sqlite\QueryBuilder createQueryBuilder ( ) | ||
return | yii\db\sqlite\QueryBuilder |
クエリビルダーのインスタンス |
---|
public function createQueryBuilder()
{
return Yii::createObject(QueryBuilder::className(), [$this->db]);
}
定義元: yii\db\Schema::createSavepoint()
新しいセーブポイントを作成します。
public void createSavepoint ( $name ) | ||
$name | string |
セーブポイント名 |
public function createSavepoint($name)
{
$this->db->createCommand("SAVEPOINT $name")->execute();
}
テーブルの列メタデータを収集します。
protected boolean findColumns ( $table ) | ||
$table | yii\db\TableSchema |
テーブルメタデータ |
return | boolean |
テーブルがデータベースに存在するかどうか |
---|
protected function findColumns($table)
{
$sql = 'PRAGMA table_info(' . $this->quoteSimpleTableName($table->name) . ')';
$columns = $this->db->createCommand($sql)->queryAll();
if (empty($columns)) {
return false;
}
foreach ($columns as $info) {
$column = $this->loadColumnSchema($info);
$table->columns[$column->name] = $column;
if ($column->isPrimaryKey) {
$table->primaryKey[] = $column->name;
}
}
if (count($table->primaryKey) === 1 && !strncasecmp($table->columns[$table->primaryKey[0]]->dbType, 'int', 3)) {
$table->sequenceName = '';
$table->columns[$table->primaryKey[0]]->autoIncrement = true;
}
return true;
}
指定されたテーブルの外部キー列の詳細を収集します。
protected void findConstraints ( $table ) | ||
$table | yii\db\TableSchema |
テーブルメタデータ |
protected function findConstraints($table)
{
$sql = 'PRAGMA foreign_key_list(' . $this->quoteSimpleTableName($table->name) . ')';
$keys = $this->db->createCommand($sql)->queryAll();
foreach ($keys as $key) {
$id = (int) $key['id'];
if (!isset($table->foreignKeys[$id])) {
$table->foreignKeys[$id] = [$key['table'], $key['from'] => $key['to']];
} else {
// composite FK
$table->foreignKeys[$id][$key['from']] = $key['to'];
}
}
}
定義元: yii\db\Schema::findSchemaNames()
データベース内のすべてのスキーマ名(デフォルトのスキーマを含むが、システムスキーマを除く)を返します。
デフォルトの実装は単に例外をスローするため、この機能をサポートするには、このメソッドを子クラスでオーバーライドする必要があります。
protected array findSchemaNames ( ) | ||
return | array |
データベース内のすべてのスキーマ名 (システムスキーマを除く)。 |
---|---|---|
throws | yii\base\NotSupportedException |
このメソッドがDBMSでサポートされていない場合。 |
protected function findSchemaNames()
{
throw new NotSupportedException(get_class($this) . ' does not support fetching all schema names.');
}
データベース内のすべてのテーブル名を返します。
デフォルトの実装は単に例外をスローするため、この機能をサポートするには、このメソッドを子クラスでオーバーライドする必要があります。
protected array findTableNames ( $schema = '' ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマまたはデフォルトスキーマを意味します。 |
return | array |
データベース内のすべてのテーブル名。名前にはスキーマ名のプレフィックスはありません。 |
---|---|---|
throws | yii\base\NotSupportedException |
このメソッドがDBMSでサポートされていない場合。 |
protected function findTableNames($schema = '')
{
$sql = "SELECT DISTINCT tbl_name FROM sqlite_master WHERE tbl_name<>'sqlite_sequence' ORDER BY tbl_name";
return $this->db->createCommand($sql)->queryColumn();
}
指定されたテーブルのすべての一意インデックスを返します。
各配列要素は次の構造を持ちます
[
'IndexName1' => ['col1' [, ...]],
'IndexName2' => ['col2' [, ...]],
]
public array findUniqueIndexes ( $table ) | ||
$table | yii\db\TableSchema |
テーブルメタデータ |
return | array |
指定されたテーブルのすべてのユニークインデックス。 |
---|
public function findUniqueIndexes($table)
{
$sql = 'PRAGMA index_list(' . $this->quoteSimpleTableName($table->name) . ')';
$indexes = $this->db->createCommand($sql)->queryAll();
$uniqueIndexes = [];
foreach ($indexes as $index) {
$indexName = $index['name'];
$indexInfo = $this->db->createCommand('PRAGMA index_info(' . $this->quoteValue($index['name']) . ')')->queryAll();
if ($index['unique']) {
$uniqueIndexes[$indexName] = [];
foreach ($indexInfo as $row) {
$uniqueIndexes[$indexName][] = $row['name'];
}
}
}
return $uniqueIndexes;
}
定義元: yii\db\Schema::getCacheKey()
指定されたテーブル名のキャッシュキーを返します。
protected mixed getCacheKey ( $name ) | ||
$name | string |
テーブル名。 |
return | mixed |
キャッシュキー。 |
---|
protected function getCacheKey($name)
{
return [
__CLASS__,
$this->db->dsn,
$this->db->username,
$this->getRawTableName($name),
];
}
protected string getCacheTag ( ) | ||
return | string |
キャッシュタグ名 |
---|
protected function getCacheTag()
{
return md5(serialize([
__CLASS__,
$this->db->dsn,
$this->db->username,
]));
}
定義元: yii\db\Schema::getColumnPhpType()
抽象DBタイプからPHPタイプを抽出します。
protected string getColumnPhpType ( $column ) | ||
$column | yii\db\ColumnSchema |
カラムスキーマ情報 |
return | string |
PHPの型名 |
---|
protected function getColumnPhpType($column)
{
static $typeMap = [
// abstract type => php type
self::TYPE_TINYINT => 'integer',
self::TYPE_SMALLINT => 'integer',
self::TYPE_INTEGER => 'integer',
self::TYPE_BIGINT => 'integer',
self::TYPE_BOOLEAN => 'boolean',
self::TYPE_FLOAT => 'double',
self::TYPE_DOUBLE => 'double',
self::TYPE_BINARY => 'resource',
self::TYPE_JSON => 'array',
];
if (isset($typeMap[$column->type])) {
if ($column->type === 'bigint') {
return PHP_INT_SIZE === 8 && !$column->unsigned ? 'integer' : 'string';
} elseif ($column->type === 'integer') {
return PHP_INT_SIZE === 4 && $column->unsigned ? 'string' : 'integer';
}
return $typeMap[$column->type];
}
return 'string';
}
定義元: yii\db\Schema::getLastInsertID()
最後に挿入された行またはシーケンスの値のIDを返します。
参考: https://www.php.net/manual/en/function.PDO-lastInsertId.php。
public string getLastInsertID ( $sequenceName = '' ) | ||
$sequenceName | string |
シーケンスオブジェクトの名前(一部のDBMSで必要) |
return | string |
最後に挿入された行のID、またはシーケンスオブジェクトから取得された最後の値 |
---|---|---|
throws | yii\base\InvalidCallException |
DB接続がアクティブでない場合 |
public function getLastInsertID($sequenceName = '')
{
if ($this->db->isActive) {
return $this->db->pdo->lastInsertId($sequenceName === '' ? null : $this->quoteTableName($sequenceName));
}
throw new InvalidCallException('DB Connection is not active.');
}
定義元: yii\db\Schema::getPdoType()
指定されたPHPデータ値のPDO型を決定します。
public integer getPdoType ( $data ) | ||
$data | mixed |
PDO型を判定するデータ |
return | 整数 |
PDO型 |
---|
public function getPdoType($data)
{
static $typeMap = [
// php type => PDO type
'boolean' => \PDO::PARAM_BOOL,
'integer' => \PDO::PARAM_INT,
'string' => \PDO::PARAM_STR,
'resource' => \PDO::PARAM_LOB,
'NULL' => \PDO::PARAM_NULL,
];
$type = gettype($data);
return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR;
}
public yii\db\QueryBuilder getQueryBuilder ( ) | ||
return | yii\db\QueryBuilder |
この接続のクエリビルダー。 |
---|
public function getQueryBuilder()
{
if ($this->_builder === null) {
$this->_builder = $this->createQueryBuilder();
}
return $this->_builder;
}
定義元: yii\db\Schema::getRawTableName()
指定されたテーブル名の実際の名前を返します。
このメソッドは、指定されたテーブル名から中括弧を取り除き、パーセント文字 '%' を yii\db\Connection::$tablePrefix に置き換えます。
public string getRawTableName ( $name ) | ||
$name | string |
変換するテーブル名 |
return | string |
指定されたテーブル名の実際の名前 |
---|
public function getRawTableName($name)
{
if (strpos($name, '{{') !== false) {
$name = preg_replace('/\\{\\{(.*?)\\}\\}/', '\1', $name);
return str_replace('%', $this->db->tablePrefix, $name);
}
return $name;
}
定義元: yii\db\ConstraintFinderTrait::getSchemaChecks()
データベース内のすべてのテーブルのチェック制約を返します。
public \yii\db\CheckConstraint[][] getSchemaChecks ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$refresh | boolean |
利用可能な最新のテーブルスキーマを取得するかどうか。これがfalseの場合、利用可能であればキャッシュされたデータが返される可能性があります。 |
return | \yii\db\CheckConstraint[][] |
データベース内のすべてのテーブルのチェック制約。各配列要素は、yii\db\CheckConstraint またはその子クラスの配列です。 |
---|
public function getSchemaChecks($schema = '', $refresh = false)
{
return $this->getSchemaMetadata($schema, 'checks', $refresh);
}
定義元: yii\db\ConstraintFinderTrait::getSchemaDefaultValues()
データベース内のすべてのテーブルのデフォルト値制約を返します。
public yii\db\DefaultValueConstraint[] getSchemaDefaultValues ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$refresh | boolean |
利用可能な最新のテーブルスキーマを取得するかどうか。これがfalseの場合、利用可能であればキャッシュされたデータが返される可能性があります。 |
return | yii\db\DefaultValueConstraint[] |
データベース内のすべてのテーブルのデフォルト値制約。各配列要素は、yii\db\DefaultValueConstraint またはその子クラスの配列です。 |
---|
public function getSchemaDefaultValues($schema = '', $refresh = false)
{
return $this->getSchemaMetadata($schema, 'defaultValues', $refresh);
}
定義元: yii\db\ConstraintFinderTrait::getSchemaForeignKeys()
データベース内のすべてのテーブルの外部キーを返します。
public \yii\db\ForeignKeyConstraint[][] getSchemaForeignKeys ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$refresh | boolean |
利用可能な最新のテーブルスキーマを取得するかどうか。これがfalseの場合、利用可能であればキャッシュされたデータが返される可能性があります。 |
return | \yii\db\ForeignKeyConstraint[][] |
データベース内のすべてのテーブルの外部キー。各配列要素は、yii\db\ForeignKeyConstraintまたはその子クラスの配列です。 |
---|
public function getSchemaForeignKeys($schema = '', $refresh = false)
{
return $this->getSchemaMetadata($schema, 'foreignKeys', $refresh);
}
定義元: yii\db\ConstraintFinderTrait::getSchemaIndexes()
データベース内のすべてのテーブルのインデックスを返します。
public \yii\db\IndexConstraint[][] getSchemaIndexes ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$refresh | boolean |
利用可能な最新のテーブルスキーマを取得するかどうか。これがfalseの場合、利用可能であればキャッシュされたデータが返される可能性があります。 |
return | \yii\db\IndexConstraint[][] |
データベース内のすべてのテーブルのインデックス。各配列要素は、yii\db\IndexConstraintまたはその子クラスの配列です。 |
---|
public function getSchemaIndexes($schema = '', $refresh = false)
{
return $this->getSchemaMetadata($schema, 'indexes', $refresh);
}
定義元: yii\db\ConstraintFinderTrait::getSchemaMetadata()
指定されたスキーマ内のすべてのテーブルについて、指定されたタイプのメタデータを返します。
protected abstract array getSchemaMetadata ( $schema, $type, $refresh ) | ||
$schema | string |
メタデータのスキーマ。デフォルトは空文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$type | string |
メタデータタイプ。 |
$refresh | boolean |
最新の利用可能なテーブルメタデータを取得するかどうか。これが |
return | array |
メタデータの配列。 |
---|
abstract protected function getSchemaMetadata($schema, $type, $refresh);
定義元: yii\db\Schema::getSchemaNames()
データベース内のすべてのスキーマ名(システムスキーマを除く)を返します。
public string[] getSchemaNames ( $refresh = false ) | ||
$refresh | boolean |
最新の利用可能なスキーマ名を取得するかどうか。これがfalseの場合、以前に取得したスキーマ名(利用可能な場合)が返されます。 |
return | string[] |
データベース内のすべてのスキーマ名 (システムスキーマを除く)。 |
---|
public function getSchemaNames($refresh = false)
{
if ($this->_schemaNames === null || $refresh) {
$this->_schemaNames = $this->findSchemaNames();
}
return $this->_schemaNames;
}
定義元: yii\db\ConstraintFinderTrait::getSchemaPrimaryKeys()
データベース内のすべてのテーブルの主キーを返します。
public yii\db\Constraint[] getSchemaPrimaryKeys ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$refresh | boolean |
最新の利用可能なテーブルスキーマを取得するかどうか。これが |
return | yii\db\Constraint[] |
データベース内のすべてのテーブルの主キー。各配列要素は、yii\db\Constraintまたはその子クラスのインスタンスです。 |
---|
public function getSchemaPrimaryKeys($schema = '', $refresh = false)
{
return $this->getSchemaMetadata($schema, 'primaryKey', $refresh);
}
定義元: yii\db\ConstraintFinderTrait::getSchemaUniques()
データベース内のすべてのテーブルの一意性制約を返します。
public \yii\db\Constraint[][] getSchemaUniques ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$refresh | boolean |
利用可能な最新のテーブルスキーマを取得するかどうか。これがfalseの場合、利用可能であればキャッシュされたデータが返される可能性があります。 |
return | \yii\db\Constraint[][] |
データベース内のすべてのテーブルの一意制約。各配列要素は、yii\db\Constraintまたはその子クラスの配列です。 |
---|
public function getSchemaUniques($schema = '', $refresh = false)
{
return $this->getSchemaMetadata($schema, 'uniques', $refresh);
}
定義元: yii\db\Schema::getServerVersion()
\version_compare() で比較可能な文字列としてサーバーのバージョンを返します。
public string getServerVersion ( ) | ||
return | string |
文字列としてのサーバーバージョン。 |
---|
public function getServerVersion()
{
if ($this->_serverVersion === null) {
$this->_serverVersion = $this->db->getSlavePdo(true)->getAttribute(\PDO::ATTR_SERVER_VERSION);
}
return $this->_serverVersion;
}
定義元: yii\db\ConstraintFinderTrait::getTableChecks()
指定されたテーブルのチェック制約情報を取得します。
public yii\db\CheckConstraint[] getTableChecks ( $name, $refresh = false ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$refresh | boolean |
情報がキャッシュに見つかった場合でも、リロードするかどうか。 |
return | yii\db\CheckConstraint[] |
テーブルチェック制約。 |
---|
public function getTableChecks($name, $refresh = false)
{
return $this->getTableMetadata($name, 'checks', $refresh);
}
定義元: yii\db\ConstraintFinderTrait::getTableDefaultValues()
指定されたテーブルのデフォルト値制約情報を取得します。
public yii\db\DefaultValueConstraint[] getTableDefaultValues ( $name, $refresh = false ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$refresh | boolean |
情報がキャッシュに見つかった場合でも、リロードするかどうか。 |
return | yii\db\DefaultValueConstraint[] |
テーブルのデフォルト値制約。 |
---|
public function getTableDefaultValues($name, $refresh = false)
{
return $this->getTableMetadata($name, 'defaultValues', $refresh);
}
定義元: yii\db\ConstraintFinderTrait::getTableForeignKeys()
指定されたテーブルの外部キー情報を取得します。
public yii\db\ForeignKeyConstraint[] getTableForeignKeys ( $name, $refresh = false ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$refresh | boolean |
情報がキャッシュに見つかった場合でも、リロードするかどうか。 |
return | yii\db\ForeignKeyConstraint[] |
テーブルの外部キー。 |
---|
public function getTableForeignKeys($name, $refresh = false)
{
return $this->getTableMetadata($name, 'foreignKeys', $refresh);
}
定義場所: yii\db\ConstraintFinderTrait::getTableIndexes()
指定されたテーブルのインデックス情報を取得します。
public yii\db\IndexConstraint[] getTableIndexes ( $name, $refresh = false ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$refresh | boolean |
情報がキャッシュに見つかった場合でも、リロードするかどうか。 |
return | yii\db\IndexConstraint[] |
テーブルのインデックス。 |
---|
public function getTableIndexes($name, $refresh = false)
{
return $this->getTableMetadata($name, 'indexes', $refresh);
}
定義場所: yii\db\ConstraintFinderTrait::getTableMetadata()
指定されたテーブルについて、指定されたタイプのメタデータを返します。
protected abstract mixed getTableMetadata ( $name, $type, $refresh ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$type | string |
メタデータタイプ。 |
$refresh | boolean |
キャッシュに見つかった場合でも、テーブルメタデータをリロードするかどうか。 |
return | mixed |
メタデータ。 |
---|
abstract protected function getTableMetadata($name, $type, $refresh);
定義場所: yii\db\Schema::getTableNameParts()
完全なテーブル名をパーツに分割します。
protected array getTableNameParts ( $name ) | ||
$name | string |
protected function getTableNameParts($name)
{
return explode('.', $name);
}
定義場所: yii\db\Schema::getTableNames()
データベース内のすべてのテーブル名を返します。
public string[] getTableNames ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空文字列で、現在のまたはデフォルトのスキーマ名を意味します。空でない場合、返されるテーブル名にはスキーマ名がプレフィックスとして付与されます。 |
$refresh | boolean |
利用可能な最新のテーブル名を取得するかどうか。これが false の場合、以前に取得されたテーブル名(利用可能な場合)が返されます。 |
return | string[] |
データベース内のすべてのテーブル名。 |
---|
public function getTableNames($schema = '', $refresh = false)
{
if (!isset($this->_tableNames[$schema]) || $refresh) {
$this->_tableNames[$schema] = $this->findTableNames($schema);
}
return $this->_tableNames[$schema];
}
定義場所: yii\db\ConstraintFinderTrait::getTablePrimaryKey()
指定されたテーブルの主キーを取得します。
public yii\db\Constraint|null getTablePrimaryKey ( $name, $refresh = false ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$refresh | boolean |
情報がキャッシュに見つかった場合でも、リロードするかどうか。 |
return | yii\db\Constraint|null |
テーブルのプライマリキー。テーブルにプライマリキーがない場合は |
---|
public function getTablePrimaryKey($name, $refresh = false)
{
return $this->getTableMetadata($name, 'primaryKey', $refresh);
}
定義場所: yii\db\Schema::getTableSchema()
指定されたテーブルのメタデータを取得します。
public yii\db\TableSchema|null getTableSchema ( $name, $refresh = false ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$refresh | boolean |
キャッシュに見つかった場合でも、テーブルスキーマをリロードするかどうか。 |
return | yii\db\TableSchema|null |
テーブルのメタデータ。指定された名前のテーブルが存在しない場合は |
---|
public function getTableSchema($name, $refresh = false)
{
return $this->getTableMetadata($name, 'schema', $refresh);
}
定義場所: yii\db\Schema::getTableSchemas()
データベース内のすべてのテーブルのメタデータを返します。
public yii\db\TableSchema[] getTableSchemas ( $schema = '', $refresh = false ) | ||
$schema | string |
テーブルのスキーマ。デフォルトは空の文字列で、現在のスキーマ名またはデフォルトのスキーマ名を意味します。 |
$refresh | boolean |
最新の利用可能なテーブルスキーマを取得するかどうか。これが |
return | yii\db\TableSchema[] |
データベース内のすべてのテーブルのメタデータ。各配列要素は、yii\db\TableSchema またはその子クラスのインスタンスです。 |
---|
public function getTableSchemas($schema = '', $refresh = false)
{
return $this->getSchemaMetadata($schema, 'schema', $refresh);
}
定義場所: yii\db\ConstraintFinderTrait::getTableUniques()
指定されたテーブルの一意性制約情報を取得します。
public yii\db\Constraint[] getTableUniques ( $name, $refresh = false ) | ||
$name | string |
テーブル名。テーブル名にはスキーマ名が含まれる場合があります。テーブル名を引用符で囲まないでください。 |
$refresh | boolean |
情報がキャッシュに見つかった場合でも、リロードするかどうか。 |
return | yii\db\Constraint[] |
テーブルの一意制約。 |
---|
public function getTableUniques($name, $refresh = false)
{
return $this->getTableMetadata($name, 'uniques', $refresh);
}
定義場所: yii\base\BaseObject::hasMethod()
メソッドが定義されているかどうかを示す値を返します。
デフォルトの実装は、php関数 method_exists()
の呼び出しです。phpのマジックメソッド __call()
を実装した場合は、このメソッドをオーバーライドできます。
public boolean hasMethod ( $name ) | ||
$name | string |
メソッド名 |
return | boolean |
メソッドが定義されているかどうか |
---|
public function hasMethod($name)
{
return method_exists($this, $name);
}
定義場所: yii\base\BaseObject::hasProperty()
プロパティが定義されているかどうかを示す値を返します。
プロパティが定義されるのは、
- クラスに、指定された名前に関連付けられたゲッターまたはセッターメソッドがある場合(この場合、プロパティ名は大小文字を区別しません)。
- クラスが指定された名前のメンバー変数を持っている場合(
$checkVars
が true の場合)。
参照
public boolean hasProperty ( $name, $checkVars = true ) | ||
$name | string |
プロパティ名 |
$checkVars | boolean |
メンバー変数をプロパティとして扱うかどうか |
return | boolean |
プロパティが定義されているかどうか |
---|
public function hasProperty($name, $checkVars = true)
{
return $this->canGetProperty($name, $checkVars) || $this->canSetProperty($name, false);
}
public void init ( ) |
public function init()
{
}
INSERT コマンドを実行し、主キーの値を返します。
public array|false insert ( $table, $columns ) | ||
$table | string |
新しい行が挿入されるテーブル。 |
$columns | array |
テーブルに挿入されるカラムデータ(name => value)。 |
return | array|false |
主キーの値。またはコマンドが失敗した場合は false。 |
---|
public function insert($table, $columns)
{
$command = $this->db->createCommand()->insert($table, $columns);
if (!$command->execute()) {
return false;
}
$tableSchema = $this->getTableSchema($table);
$result = [];
foreach ($tableSchema->primaryKey as $name) {
if ($tableSchema->columns[$name]->autoIncrement) {
$result[$name] = $this->getLastInsertID($tableSchema->sequenceName);
break;
}
$result[$name] = isset($columns[$name]) ? $columns[$name] : $tableSchema->columns[$name]->defaultValue;
}
return $result;
}
定義元: yii\db\Schema::isReadQuery()
SQL ステートメントが読み取り目的であるかどうかを示す値を返します。
public boolean isReadQuery ( $sql ) | ||
$sql | string |
SQLステートメント |
return | boolean |
SQLステートメントが読み取り目的であるかどうか。 |
---|
public function isReadQuery($sql)
{
$pattern = '/^\s*(SELECT|SHOW|DESCRIBE)\b/i';
return preg_match($pattern, $sql) > 0;
}
列情報をyii\db\ColumnSchemaオブジェクトにロードします。
protected yii\db\ColumnSchema loadColumnSchema ( $info ) | ||
$info | array |
カラム情報 |
return | yii\db\ColumnSchema |
カラムスキーマオブジェクト |
---|
protected function loadColumnSchema($info)
{
$column = $this->createColumnSchema();
$column->name = $info['name'];
$column->allowNull = !$info['notnull'];
$column->isPrimaryKey = $info['pk'] != 0;
$column->dbType = strtolower($info['type']);
$column->unsigned = strpos($column->dbType, 'unsigned') !== false;
$column->type = self::TYPE_STRING;
if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) {
$type = strtolower($matches[1]);
if (isset($this->typeMap[$type])) {
$column->type = $this->typeMap[$type];
}
if (!empty($matches[2])) {
$values = explode(',', $matches[2]);
$column->size = $column->precision = (int) $values[0];
if (isset($values[1])) {
$column->scale = (int) $values[1];
}
if ($column->size === 1 && ($type === 'tinyint' || $type === 'bit')) {
$column->type = 'boolean';
} elseif ($type === 'bit') {
if ($column->size > 32) {
$column->type = 'bigint';
} elseif ($column->size === 32) {
$column->type = 'integer';
}
}
}
}
$column->phpType = $this->getColumnPhpType($column);
if (!$column->isPrimaryKey) {
if ($info['dflt_value'] === 'null' || $info['dflt_value'] === '' || $info['dflt_value'] === null) {
$column->defaultValue = null;
} elseif ($column->type === 'timestamp' && $info['dflt_value'] === 'CURRENT_TIMESTAMP') {
$column->defaultValue = new Expression('CURRENT_TIMESTAMP');
} else {
$value = trim($info['dflt_value'], "'\"");
$column->defaultValue = $column->phpTypecast($value);
}
}
return $column;
}
protected void loadTableChecks ( $tableName ) | ||
$tableName |
protected function loadTableChecks($tableName)
{
$sql = $this->db->createCommand('SELECT `sql` FROM `sqlite_master` WHERE name = :tableName', [
':tableName' => $tableName,
])->queryScalar();
/** @var $code SqlToken[]|SqlToken[][]|SqlToken[][][] */
$code = (new SqlTokenizer($sql))->tokenize();
$pattern = (new SqlTokenizer('any CREATE any TABLE any()'))->tokenize();
if (!$code[0]->matches($pattern, 0, $firstMatchIndex, $lastMatchIndex)) {
return [];
}
$createTableToken = $code[0][$lastMatchIndex - 1];
$result = [];
$offset = 0;
while (true) {
$pattern = (new SqlTokenizer('any CHECK()'))->tokenize();
if (!$createTableToken->matches($pattern, $offset, $firstMatchIndex, $offset)) {
break;
}
$checkSql = $createTableToken[$offset - 1]->getSql();
$name = null;
$pattern = (new SqlTokenizer('CONSTRAINT any'))->tokenize();
if (isset($createTableToken[$firstMatchIndex - 2]) && $createTableToken->matches($pattern, $firstMatchIndex - 2)) {
$name = $createTableToken[$firstMatchIndex - 1]->content;
}
$result[] = new CheckConstraint([
'name' => $name,
'expression' => $checkSql,
]);
}
return $result;
}
protected void loadTableDefaultValues ( $tableName ) | ||
$tableName | ||
throws | yii\base\NotSupportedException |
このメソッドが呼び出された場合。 |
---|
protected function loadTableDefaultValues($tableName)
{
throw new NotSupportedException('SQLite does not support default value constraints.');
}
protected void loadTableForeignKeys ( $tableName ) | ||
$tableName |
protected function loadTableForeignKeys($tableName)
{
$foreignKeys = $this->db->createCommand('PRAGMA FOREIGN_KEY_LIST (' . $this->quoteValue($tableName) . ')')->queryAll();
$foreignKeys = $this->normalizePdoRowKeyCase($foreignKeys, true);
$foreignKeys = ArrayHelper::index($foreignKeys, null, 'table');
ArrayHelper::multisort($foreignKeys, 'seq', SORT_ASC, SORT_NUMERIC);
$result = [];
foreach ($foreignKeys as $table => $foreignKey) {
$result[] = new ForeignKeyConstraint([
'columnNames' => ArrayHelper::getColumn($foreignKey, 'from'),
'foreignTableName' => $table,
'foreignColumnNames' => ArrayHelper::getColumn($foreignKey, 'to'),
'onDelete' => isset($foreignKey[0]['on_delete']) ? $foreignKey[0]['on_delete'] : null,
'onUpdate' => isset($foreignKey[0]['on_update']) ? $foreignKey[0]['on_update'] : null,
]);
}
return $result;
}
protected void loadTableIndexes ( $tableName ) | ||
$tableName |
protected function loadTableIndexes($tableName)
{
return $this->loadTableConstraints($tableName, 'indexes');
}
protected void loadTablePrimaryKey ( $tableName ) | ||
$tableName |
protected function loadTablePrimaryKey($tableName)
{
return $this->loadTableConstraints($tableName, 'primaryKey');
}
指定されたテーブルのメタデータをロードします。
protected yii\db\TableSchema|null loadTableSchema ( $name ) | ||
$name | string |
テーブル名 |
return | yii\db\TableSchema|null |
DBMS依存のテーブルメタデータ。テーブルが存在しない場合は |
---|
protected function loadTableSchema($name)
{
$table = new TableSchema();
$table->name = $name;
$table->fullName = $name;
if ($this->findColumns($table)) {
$this->findConstraints($table);
return $table;
}
return null;
}
protected void loadTableUniques ( $tableName ) | ||
$tableName |
protected function loadTableUniques($tableName)
{
return $this->loadTableConstraints($tableName, 'uniques');
}
定義元: yii\db\Schema::normalizePdoRowKeyCase()
PDOのキーが大文字に設定されている場合、行の配列キーのケースを小文字に変更します。
protected array normalizePdoRowKeyCase ( array $row, $multiple ) | ||
$row | array |
行の配列または行の配列の配列。 |
$multiple | boolean |
複数の行または単一行が渡されたかどうか。 |
return | array |
正規化された行または行。 |
---|
protected function normalizePdoRowKeyCase(array $row, $multiple)
{
if ($this->db->getSlavePdo(true)->getAttribute(\PDO::ATTR_CASE) !== \PDO::CASE_UPPER) {
return $row;
}
if ($multiple) {
return array_map(function (array $row) {
return array_change_key_case($row, CASE_LOWER);
}, $row);
}
return array_change_key_case($row, CASE_LOWER);
}
定義元: yii\db\Schema::quoteColumnName()
クエリで使用するために列名をクォートします。
カラム名にプレフィックスが含まれている場合、プレフィックスも適切にクォートされます。カラム名がすでにクォートされているか、'('、'[['または'{{'が含まれている場合、このメソッドは何もしません。
こちらも参照: quoteSimpleColumnName()。
public string quoteColumnName ( $name ) | ||
$name | string |
カラム名 |
return | string |
適切にクォートされたカラム名 |
---|
public function quoteColumnName($name)
{
if (strpos($name, '(') !== false || strpos($name, '[[') !== false) {
return $name;
}
if (($pos = strrpos($name, '.')) !== false) {
$prefix = $this->quoteTableName(substr($name, 0, $pos)) . '.';
$name = substr($name, $pos + 1);
} else {
$prefix = '';
}
if (strpos($name, '{{') !== false) {
return $name;
}
return $prefix . $this->quoteSimpleColumnName($name);
}
定義元: yii\db\Schema::quoteSimpleColumnName()
クエリで使用するために単純な列名をクォートします。
単純なカラム名は、プレフィックスなしのカラム名のみを含める必要があります。カラム名がすでにクォートされているか、アスタリスク文字'*'である場合、このメソッドは何もしません。
public string quoteSimpleColumnName ( $name ) | ||
$name | string |
カラム名 |
return | string |
適切にクォートされたカラム名 |
---|
public function quoteSimpleColumnName($name)
{
if (is_string($this->columnQuoteCharacter)) {
$startingCharacter = $endingCharacter = $this->columnQuoteCharacter;
} else {
list($startingCharacter, $endingCharacter) = $this->columnQuoteCharacter;
}
return $name === '*' || strpos($name, $startingCharacter) !== false ? $name : $startingCharacter . $name . $endingCharacter;
}
定義元: yii\db\Schema::quoteSimpleTableName()
クエリで使用するために単純なテーブル名をクォートします。
シンプルなテーブル名には、スキーマのプレフィックスを含まず、テーブル名のみが含まれるべきです。テーブル名がすでにクォートされている場合、このメソッドは何もしません。
public string quoteSimpleTableName ( $name ) | ||
$name | string |
テーブル名 |
return | string |
適切にクォートされたテーブル名 |
---|
public function quoteSimpleTableName($name)
{
if (is_string($this->tableQuoteCharacter)) {
$startingCharacter = $endingCharacter = $this->tableQuoteCharacter;
} else {
list($startingCharacter, $endingCharacter) = $this->tableQuoteCharacter;
}
return strpos($name, $startingCharacter) !== false ? $name : $startingCharacter . $name . $endingCharacter;
}
定義元: yii\db\Schema::quoteTableName()
クエリで使用するためにテーブル名をクォートします。
テーブル名にスキーマのプレフィックスが含まれている場合、プレフィックスも適切にクォートされます。テーブル名がすでにクォートされているか、'(' または '{{' を含む場合、このメソッドは何もしません。
public string quoteTableName ( $name ) | ||
$name | string |
テーブル名 |
return | string |
適切にクォートされたテーブル名 |
---|
public function quoteTableName($name)
{
if (strncmp($name, '(', 1) === 0 && strpos($name, ')') === strlen($name) - 1) {
return $name;
}
if (strpos($name, '{{') !== false) {
return $name;
}
if (strpos($name, '.') === false) {
return $this->quoteSimpleTableName($name);
}
$parts = $this->getTableNameParts($name);
foreach ($parts as $i => $part) {
$parts[$i] = $this->quoteSimpleTableName($part);
}
return implode('.', $parts);
}
public string quoteValue ( $str ) | ||
$str | string |
クォートされる文字列 |
return | string |
適切にクォートされた文字列 |
---|
public function quoteValue($str)
{
if (!is_string($str)) {
return $str;
}
if (mb_stripos((string)$this->db->dsn, 'odbc:') === false && ($value = $this->db->getSlavePdo(true)->quote($str)) !== false) {
return $value;
}
// the driver doesn't support quote (e.g. oci)
return "'" . addcslashes(str_replace("'", "''", $str), "\000\n\r\\\032") . "'";
}
スキーマを更新します。
このメソッドは、キャッシュされたすべてのテーブルスキーマをクリーンアップし、後でデータベーススキーマの変更を反映して再作成できるようにします。
public void refresh ( ) |
public function refresh()
{
/* @var $cache CacheInterface */
$cache = is_string($this->db->schemaCache) ? Yii::$app->get($this->db->schemaCache, false) : $this->db->schemaCache;
if ($this->db->enableSchemaCache && $cache instanceof CacheInterface) {
TagDependency::invalidate($cache, $this->getCacheTag());
}
$this->_tableNames = [];
$this->_tableMetadata = [];
}
定義元: yii\db\Schema::refreshTableSchema()
特定のテーブルのスキーマを更新します。
このメソッドは、キャッシュされたテーブルスキーマをクリーンアップし、後でデータベーススキーマの変更を反映して再作成できるようにします。
public void refreshTableSchema ( $name ) | ||
$name | string |
テーブル名。 |
public function refreshTableSchema($name)
{
$rawName = $this->getRawTableName($name);
unset($this->_tableMetadata[$rawName]);
$this->_tableNames = [];
/* @var $cache CacheInterface */
$cache = is_string($this->db->schemaCache) ? Yii::$app->get($this->db->schemaCache, false) : $this->db->schemaCache;
if ($this->db->enableSchemaCache && $cache instanceof CacheInterface) {
$cache->delete($this->getCacheKey($rawName));
}
}
定義元: yii\db\Schema::releaseSavepoint()
既存のセーブポイントを解放します。
public void releaseSavepoint ( $name ) | ||
$name | string |
セーブポイント名 |
public function releaseSavepoint($name)
{
$this->db->createCommand("RELEASE SAVEPOINT $name")->execute();
}
定義元: yii\db\Schema::resolveTableName()
テーブル名とスキーマ名(存在する場合)を解決します。
protected yii\db\TableSchema resolveTableName ( $name ) | ||
$name | string |
テーブル名 |
return | yii\db\TableSchema |
解決されたテーブル、スキーマなどの名前を持つ yii\db\TableSchema。 |
---|---|---|
throws | yii\base\NotSupportedException |
このメソッドがDBMSでサポートされていない場合。 |
protected function resolveTableName($name)
{
throw new NotSupportedException(get_class($this) . ' does not support resolving table names.');
}
定義元: yii\db\Schema::rollBackSavepoint()
以前に作成したセーブポイントまでロールバックします。
public void rollBackSavepoint ( $name ) | ||
$name | string |
セーブポイント名 |
public function rollBackSavepoint($name)
{
$this->db->createCommand("ROLLBACK TO SAVEPOINT $name")->execute();
}
定義元: yii\db\Schema::setTableMetadata()
指定されたテーブルについて、指定されたタイプのメタデータを設定します。
protected void setTableMetadata ( $name, $type, $data ) | ||
$name | string |
テーブル名。 |
$type | string |
メタデータタイプ。 |
$data | mixed |
メタデータ。 |
protected function setTableMetadata($name, $type, $data)
{
$this->_tableMetadata[$this->getRawTableName($name)][$type] = $data;
}
現在のトランザクションの分離レベルを設定します。
参照: https://www.sqlite.org/pragma.html#pragma_read_uncommitted。
public void setTransactionIsolationLevel ( $level ) | ||
$level | string |
このトランザクションに使用するトランザクション分離レベル。これは、yii\db\Transaction::READ_UNCOMMITTED または yii\db\Transaction::SERIALIZABLE のいずれかです。 |
throws | yii\base\NotSupportedException |
サポートされていない分離レベルが使用された場合。SQLite は SERIALIZABLE と READ UNCOMMITTED のみをサポートします。 |
---|
public function setTransactionIsolationLevel($level)
{
switch ($level) {
case Transaction::SERIALIZABLE:
$this->db->createCommand('PRAGMA read_uncommitted = False;')->execute();
break;
case Transaction::READ_UNCOMMITTED:
$this->db->createCommand('PRAGMA read_uncommitted = True;')->execute();
break;
default:
throw new NotSupportedException(get_class($this) . ' only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.');
}
}
public boolean supportsSavepoint ( ) | ||
return | boolean |
この DBMS が セーブポイント をサポートしているかどうか。 |
---|
public function supportsSavepoint()
{
return $this->db->enableSavepoint;
}
定義元: yii\db\Schema::unquoteSimpleColumnName()
単純な列名のクォートを解除します。
シンプルなカラム名には、プレフィックスを含まず、カラム名のみが含まれるべきです。カラム名がクォートされていないか、アスタリスク文字 '*' の場合、このメソッドは何もしません。
public string unquoteSimpleColumnName ( $name ) | ||
$name | string |
カラム名。 |
return | string |
クォートされていないカラム名。 |
---|
public function unquoteSimpleColumnName($name)
{
if (is_string($this->columnQuoteCharacter)) {
$startingCharacter = $this->columnQuoteCharacter;
} else {
$startingCharacter = $this->columnQuoteCharacter[0];
}
return strpos($name, $startingCharacter) === false ? $name : substr($name, 1, -1);
}
定義元: yii\db\Schema::unquoteSimpleTableName()
単純なテーブル名のクォートを解除します。
単純なテーブル名は、スキーマのプレフィックスなしでテーブル名のみを含んでいる必要があります。テーブル名がクォートされていない場合、このメソッドは何もしません。
public string unquoteSimpleTableName ( $name ) | ||
$name | string |
テーブル名。 |
return | string |
クォートされていないテーブル名。 |
---|
public function unquoteSimpleTableName($name)
{
if (is_string($this->tableQuoteCharacter)) {
$startingCharacter = $this->tableQuoteCharacter;
} else {
$startingCharacter = $this->tableQuoteCharacter[0];
}
return strpos($name, $startingCharacter) === false ? $name : substr($name, 1, -1);
}
サインアップ または ログイン してコメントしてください。