PHP Класс Gdn_DatabaseStructure, vanilla

Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$CaptureOnly Whether or not to only capture the sql, rather than execute it. When this property is true then a property called CapturedSql will be added to this class which is an array of all the Sql statements.
$Database The instance of the database singleton.

Защищенные свойства (Protected)

Свойство Тип Описание
$_CharacterEncoding The character encoding to set as default for the table being created.
$_Columns array
$_DatabasePrefix string
$_ExistingColumns The existing columns in the database.
$_TableExists Whether or not this table exists in the database.
$_TableName The name of the table to create or modify.
$_TableStorageEngine The name of the storage engine for this table.

Открытые методы

Метод Описание
__construct ( string $Database = null ) The constructor for this class. Automatically fills $this->ClassName.
column ( string $Name, mixed $Type, boolean $NullDefault = false, string $KeyType = false ) Defines a column to be added to $this->Table().
columnExists ( string $ColumnName ) : boolean Returns whether or not a column exists in the database.
columnTypeString ( mixed $Column ) : string Return the definition string for a column.
columns ( $Name = '' ) : array An associative array of $ColumnName => $ColumnProperties columns for the table.
databasePrefix ( string $DatabasePrefix = '' ) Gets and/or sets the database prefix.
drop ( ) Drops $this->Table() from the database.
dropColumn ( string $Name ) Drops $Name column from $this->Table().
engine ( $Engine, boolean $CheckAvailability = true )
existingColumns ( ) : array Gets the column definitions for the columns in the database.
get ( string $TableName = '' ) : Gdn_DatabaseStructure Load the schema for this table from the database.
getAlterTableThreshold ( ) : integer Get the alter table threshold.
getIssues ( ) : array Get a list of issues that occurred during the last call to {@link Gdn_DatabaseStructure::set()}.
getRowCountEstimate ( string $tableName ) : integer | null Get the estimated number of rows in a table.
primaryKey ( string $Name, string $Type = 'int' ) : Gdn_DatabaseStructure Defines a primary key column on a table.
query ( string $sql, boolean $checkTreshold = false ) : Gdn_Dataset Send a query to the database and return the result.
renameColumn ( string $OldName, string $NewName ) Renames a column in $this->Table().
renameTable ( string $OldName, string $NewName, boolean $UsePrefix = false ) Renames a table in the database.
reset ( ) : Gdn_DatabaseStructure Reset the internal state of this object so that it can be reused.
set ( boolean $Explicit = false, boolean $Drop = false ) Creates the table and columns specified with $this->Table() and $this->Column(). If no table or columns have been specified, this method will throw a fatal error.
setAlterTableThreshold ( integer $alterTableThreshold ) : Gdn_MySQLStructure Set the alterTableThreshold.
table ( string $Name = '', string $CharacterEncoding = '' ) Specifies the name of the table to create or modify.
tableExists ( $TableName = null ) : boolean Whether or not the table exists in the database.
tableName ( ) : string Returns the name of the table being defined in this object.
types ( string $Class = 'all' ) Gets an array of type names allowed in the structure.
view ( string $Name, string $Query ) Specifies the name of the view to create or modify.

Защищенные методы

Метод Описание
_create ( ) Creates the table defined with $this->Table() and $this->Column().
_createColumn ( $Name, $Type, $Null, $Default, $KeyType ) : stdClass
_modify ( boolean $Explicit = false ) Modifies $this->Table() with the columns specified with $this->Column().
addIssue ( string $message, string $sql ) : Gdn_DatabaseStructure Add an issue to the issues list.
executeQuery ( string $sql, boolean $checkThreshold = false ) : boolean Send a query to the database and return the result.

Описание методов

__construct() публичный Метод

The constructor for this class. Automatically fills $this->ClassName.
public __construct ( string $Database = null )
$Database string

_create() защищенный Метод

Creates the table defined with $this->Table() and $this->Column().
protected _create ( )

_createColumn() защищенный Метод

protected _createColumn ( $Name, $Type, $Null, $Default, $KeyType ) : stdClass
$Name
$Type
$Null
$Default
$KeyType
Результат stdClass

_modify() защищенный Метод

Modifies $this->Table() with the columns specified with $this->Column().
protected _modify ( boolean $Explicit = false )
$Explicit boolean If TRUE, this method will remove any columns from the table that were not defined with $this->Column().

addIssue() защищенный Метод

Add an issue to the issues list.
protected addIssue ( string $message, string $sql ) : Gdn_DatabaseStructure
$message string A human readable string for the issue.
$sql string The SQL that didn't happen.
Результат Gdn_DatabaseStructure Returns **this** for chaining.

column() публичный Метод

Defines a column to be added to $this->Table().
public column ( string $Name, mixed $Type, boolean $NullDefault = false, string $KeyType = false )
$Name string The name of the column to create.
$Type mixed The data type of the column to be created. Types with a length speecifty the length in barackets. * If an array of values is provided, the type will be set as "enum" and the array will be assigned as the column's Enum property. * If an array of two values is specified then a "set" or "enum" can be specified (ex. array('set', array('Short', 'Tall', 'Fat', 'Skinny')))
$NullDefault boolean Whether or not nulls are allowed, if not a default can be specified. * TRUE: Nulls are allowed. * FALSE: Nulls are not allowed. * Any other value: Nulls are not allowed, and the specified value will be used as the default.
$KeyType string What type of key is this column on the table? Options are primary, key, and FALSE (not a key).

columnExists() публичный Метод

Returns whether or not a column exists in the database.
public columnExists ( string $ColumnName ) : boolean
$ColumnName string The name of the column to check.
Результат boolean

columnTypeString() публичный Метод

Return the definition string for a column.
public columnTypeString ( mixed $Column ) : string
$Column mixed The column to get the type string from. - object: The column as returned by the database schema. The properties looked at are Type, Length, and Precision. - string
Результат string The type definition string.

columns() публичный Метод

An associative array of $ColumnName => $ColumnProperties columns for the table.
public columns ( $Name = '' ) : array
Результат array

databasePrefix() публичный Метод

Gets and/or sets the database prefix.
public databasePrefix ( string $DatabasePrefix = '' )
$DatabasePrefix string

drop() публичный Метод

Drops $this->Table() from the database.
public drop ( )

dropColumn() публичный Метод

Drops $Name column from $this->Table().
public dropColumn ( string $Name )
$Name string The name of the column to drop from $this->Table().

engine() публичный Метод

public engine ( $Engine, boolean $CheckAvailability = true )
$Engine
$CheckAvailability boolean

executeQuery() защищенный Метод

Send a query to the database and return the result.
protected executeQuery ( string $sql, boolean $checkThreshold = false ) : boolean
$sql string The sql to execute.
$checkThreshold boolean Whether or not to check the alter table threshold before altering the table.
Результат boolean Whether or not the query succeeded.

existingColumns() публичный Метод

Gets the column definitions for the columns in the database.
public existingColumns ( ) : array
Результат array

get() публичный Метод

Load the schema for this table from the database.
public get ( string $TableName = '' ) : Gdn_DatabaseStructure
$TableName string The name of the table to get or blank to get the schema for the current table.
Результат Gdn_DatabaseStructure $this

getAlterTableThreshold() публичный Метод

The alter table threshold is the maximum estimated rows a table can have where alter tables are allowed.
public getAlterTableThreshold ( ) : integer
Результат integer Returns the threshold as an integer. A value of zero means no threshold.

getIssues() публичный Метод

Get a list of issues that occurred during the last call to {@link Gdn_DatabaseStructure::set()}.
public getIssues ( ) : array
Результат array Returns an array of issues.

getRowCountEstimate() публичный Метод

Get the estimated number of rows in a table.
public getRowCountEstimate ( string $tableName ) : integer | null
$tableName string The name of the table to look up, without its prefix.
Результат integer | null Returns the estimated number of rows or **null** if the information doesn't exist.

primaryKey() публичный Метод

Defines a primary key column on a table.
public primaryKey ( string $Name, string $Type = 'int' ) : Gdn_DatabaseStructure
$Name string The name of the column.
$Type string The data type of the column.
Результат Gdn_DatabaseStructure $this.

query() публичный Метод

Send a query to the database and return the result.
Устаревший: since 2.3. Was incorrectly public. Replaced by executeQuery().
public query ( string $sql, boolean $checkTreshold = false ) : Gdn_Dataset
$sql string The sql to execute.
$checkTreshold boolean Should not be used
Результат Gdn_Dataset

renameColumn() публичный Метод

Renames a column in $this->Table().
public renameColumn ( string $OldName, string $NewName )
$OldName string The name of the column to be renamed.
$NewName string The new name for the column being renamed.

renameTable() публичный Метод

Renames a table in the database.
public renameTable ( string $OldName, string $NewName, boolean $UsePrefix = false )
$OldName string The name of the table to be renamed.
$NewName string The new name for the table being renamed.
$UsePrefix boolean A boolean value indicating if $this->_DatabasePrefix should be prefixed before $OldName and $NewName.

reset() публичный Метод

Reset the internal state of this object so that it can be reused.
public reset ( ) : Gdn_DatabaseStructure
Результат Gdn_DatabaseStructure $this

set() публичный Метод

Creates the table and columns specified with $this->Table() and $this->Column(). If no table or columns have been specified, this method will throw a fatal error.
public set ( boolean $Explicit = false, boolean $Drop = false )
$Explicit boolean If TRUE, and the table specified with $this->Table() already exists, this method will remove any columns from the table that were not defined with $this->Column().
$Drop boolean If TRUE, and the table specified with $this->Table() already exists, this method will drop the table before attempting to re-create it.

setAlterTableThreshold() публичный Метод

Set the alterTableThreshold.
public setAlterTableThreshold ( integer $alterTableThreshold ) : Gdn_MySQLStructure
$alterTableThreshold integer
Результат Gdn_MySQLStructure Returns `$this` for fluent calls.

table() публичный Метод

Specifies the name of the table to create or modify.
public table ( string $Name = '', string $CharacterEncoding = '' )
$Name string The name of the table.
$CharacterEncoding string The default character encoding to specify for this table.

tableExists() публичный Метод

Whether or not the table exists in the database.
public tableExists ( $TableName = null ) : boolean
Результат boolean

tableName() публичный Метод

Returns the name of the table being defined in this object.
public tableName ( ) : string
Результат string

types() публичный Метод

Gets an array of type names allowed in the structure.
public types ( string $Class = 'all' )
$Class string The class of types to get. Valid values are: - int: Integer types. - float: Floating point types. - decimal: Precise decimal types. - numeric: float, int and decimal. - string: String types. - date: Date types. - length: Types that have a length. - precision: Types that have a precision. - other: Types that don't fit into any other category on their own. - all: All recognized types.

view() публичный Метод

Specifies the name of the view to create or modify.
public view ( string $Name, string $Query )
$Name string The name of the view.
$Query string Query to create as the view. Typically this can be generated with the $Database object.

Описание свойств

$CaptureOnly публичное свойство

Whether or not to only capture the sql, rather than execute it. When this property is true then a property called CapturedSql will be added to this class which is an array of all the Sql statements.
public $CaptureOnly

$Database публичное свойство

The instance of the database singleton.
public $Database

$_CharacterEncoding защищенное свойство

The character encoding to set as default for the table being created.
protected $_CharacterEncoding

$_Columns защищенное свойство

protected array $_Columns
Результат array

$_DatabasePrefix защищенное свойство

protected string $_DatabasePrefix
Результат string

$_ExistingColumns защищенное свойство

The existing columns in the database.
protected $_ExistingColumns

$_TableExists защищенное свойство

Whether or not this table exists in the database.
protected $_TableExists

$_TableName защищенное свойство

The name of the table to create or modify.
protected $_TableName

$_TableStorageEngine защищенное свойство

The name of the storage engine for this table.
protected $_TableStorageEngine