Forge
extends Forge
in package
Forge for SQLSRV
Table of Contents
- $_drop_table_if : string
- DROP TABLE IF statement
- $charset : string
- Character set used.
- $checkDatabaseExistStr : string
- CHECK DATABASE EXIST statement
- $createDatabaseIfStr : string
- CREATE DATABASE IF statement
- $createDatabaseStr : string
- CREATE DATABASE IF statement
- $createTableIfStr : string
- CREATE TABLE IF statement
- $createTableKeys : bool
- CREATE TABLE keys flag
- $createTableStr : string
- CREATE TABLE statement
- $db : BaseConnection
- The active database connection.
- $default : string|false
- DEFAULT value representation in CREATE/ALTER TABLE statements
- $dropConstraintStr : string
- DROP CONSTRAINT statement
- $dropDatabaseStr : string|false
- DROP DATABASE statement
- $dropTableIfStr : string|bool
- DROP TABLE IF EXISTS statement
- $fields : array<string|int, mixed>
- List of fields.
- $foreignKeys : array<string|int, mixed>
- List of foreign keys.
- $keys : array<string|int, mixed>
- List of keys.
- $primaryKeys : array<string|int, mixed>
- List of primary keys.
- $renameTableStr : string
- RENAME TABLE statement
- $uniqueKeys : array<string|int, mixed>
- List of unique keys.
- $unsigned : array<string|int, mixed>
- UNSIGNED support
- __construct() : mixed
- Constructor.
- addColumn() : bool
- Column Add
- addField() : Forge
- Add Field
- addForeignKey() : Forge
- Add Foreign Key
- addKey() : Forge
- Add Key
- addPrimaryKey() : Forge
- Add Primary Key
- addUniqueKey() : Forge
- Add Unique Key
- createDatabase() : bool
- Create database
- createTable() : mixed
- Create Table
- dropColumn() : mixed
- Column Drop
- dropDatabase() : bool
- Drop database
- dropForeignKey() : bool|BaseResult|Query|false|mixed
- Foreign Key Drop
- dropTable() : mixed
- Drop Table
- getConnection() : ConnectionInterface
- Provides access to the forge's current database connection.
- modifyColumn() : bool
- Column Modify
- renameTable() : mixed
- Rename Table
- reset() : void
- Reset
- _alterTable() : string|array<string|int, string>|false
- ALTER TABLE
- _attributeAutoIncrement() : void
- Field attribute AUTO_INCREMENT
- _attributeDefault() : null|void
- Field attribute DEFAULT
- _attributeType() : void
- Field attribute TYPE
- _attributeUnique() : void
- Field attribute UNIQUE
- _attributeUnsigned() : null|void
- Field attribute UNSIGNED
- _createTable() : mixed
- Create Table
- _createTableAttributes() : string
- CREATE TABLE attributes
- _dropIndex() : mixed
- Drop index for table
- _dropTable() : string
- Drop Table
- _processColumn() : string
- Process column
- _processFields() : array<string|int, mixed>
- Process fields
- _processForeignKeys() : string
- Process foreign keys
- _processIndexes() : array<string|int, mixed>|string
- Process indexes
- _processPrimaryKeys() : string
- Process primary keys
- databaseExists() : bool
- Determine if a database exists
Properties
$_drop_table_if
DROP TABLE IF statement
protected
string
$_drop_table_if
= "IF EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE"
$charset
Character set used.
protected
string
$charset
= ''
$checkDatabaseExistStr
CHECK DATABASE EXIST statement
protected
string
$checkDatabaseExistStr
= 'IF DB_ID( %s ) IS NOT NULL SELECT 1'
$createDatabaseIfStr
CREATE DATABASE IF statement
protected
string
$createDatabaseIfStr
= "DECLARE @DBName VARCHAR(255) = '%s'
DECLARE @SQL VARCHAR(max) = 'IF DB_ID( ''' + @DBName + ''' ) IS NULL CREATE DATABASE ' + @DBName
EXEC( @SQL )"
Tags
$createDatabaseStr
CREATE DATABASE IF statement
protected
string
$createDatabaseStr
= 'CREATE DATABASE %s '
Tags
$createTableIfStr
CREATE TABLE IF statement
protected
string
$createTableIfStr
= "IF NOT EXISTS (SELECT * FROM sysobjects WHERE ID = object_id(N'%s') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
CREATE TABLE"
$createTableKeys
CREATE TABLE keys flag
protected
bool
$createTableKeys
= false
Whether table keys are created from within the CREATE TABLE statement.
$createTableStr
CREATE TABLE statement
protected
string
$createTableStr
= "%s %s (%s
) "
$db
The active database connection.
protected
BaseConnection
$db
$default
DEFAULT value representation in CREATE/ALTER TABLE statements
protected
string|false
$default
= ' DEFAULT '
$dropConstraintStr
DROP CONSTRAINT statement
protected
string
$dropConstraintStr
= 'ALTER TABLE %s DROP CONSTRAINT %s'
$dropDatabaseStr
DROP DATABASE statement
protected
string|false
$dropDatabaseStr
= 'DROP DATABASE %s'
$dropTableIfStr
DROP TABLE IF EXISTS statement
protected
string|bool
$dropTableIfStr
= 'DROP TABLE IF EXISTS'
$fields
List of fields.
protected
array<string|int, mixed>
$fields
= []
$foreignKeys
List of foreign keys.
protected
array<string|int, mixed>
$foreignKeys
= []
$keys
List of keys.
protected
array<string|int, mixed>
$keys
= []
$primaryKeys
List of primary keys.
protected
array<string|int, mixed>
$primaryKeys
= []
$renameTableStr
RENAME TABLE statement
protected
string
$renameTableStr
= 'EXEC sp_rename %s , %s ;'
While the below statement would work, it returns an error. Also MS recommends dropping and dropping and re-creating the table.
Tags
$uniqueKeys
List of unique keys.
protected
array<string|int, mixed>
$uniqueKeys
= []
$unsigned
UNSIGNED support
protected
array<string|int, mixed>
$unsigned
= ['TINYINT' => 'SMALLINT', 'SMALLINT' => 'INT', 'INT' => 'BIGINT', 'REAL' => 'FLOAT']
Methods
__construct()
Constructor.
public
__construct(BaseConnection $db) : mixed
Parameters
- $db : BaseConnection
Return values
mixed —addColumn()
Column Add
public
addColumn(string $table, string|array<string|int, mixed> $field) : bool
Parameters
- $table : string
-
Table name
- $field : string|array<string|int, mixed>
-
Column definition
Tags
Return values
bool —addField()
Add Field
public
addField(array<string|int, mixed>|string $field) : Forge
Parameters
- $field : array<string|int, mixed>|string
Return values
Forge —addForeignKey()
Add Foreign Key
public
addForeignKey([string $fieldName = '' ][, string $tableName = '' ][, string $tableField = '' ][, string $onUpdate = '' ][, string $onDelete = '' ]) : Forge
Parameters
- $fieldName : string = ''
- $tableName : string = ''
- $tableField : string = ''
- $onUpdate : string = ''
- $onDelete : string = ''
Tags
Return values
Forge —addKey()
Add Key
public
addKey(string|array<string|int, mixed> $key[, bool $primary = false ][, bool $unique = false ]) : Forge
Parameters
- $key : string|array<string|int, mixed>
- $primary : bool = false
- $unique : bool = false
Return values
Forge —addPrimaryKey()
Add Primary Key
public
addPrimaryKey(string|array<string|int, mixed> $key) : Forge
Parameters
- $key : string|array<string|int, mixed>
Return values
Forge —addUniqueKey()
Add Unique Key
public
addUniqueKey(string|array<string|int, mixed> $key) : Forge
Parameters
- $key : string|array<string|int, mixed>
Return values
Forge —createDatabase()
Create database
public
createDatabase(string $dbName[, bool $ifNotExists = false ]) : bool
Parameters
- $dbName : string
- $ifNotExists : bool = false
-
Whether to add IF NOT EXISTS condition
Tags
Return values
bool —createTable()
Create Table
public
createTable(string $table[, bool $ifNotExists = false ][, array<string|int, mixed> $attributes = [] ]) : mixed
Parameters
- $table : string
-
Table name
- $ifNotExists : bool = false
-
Whether to add IF NOT EXISTS condition
- $attributes : array<string|int, mixed> = []
-
Associative array of table attributes
Tags
Return values
mixed —dropColumn()
Column Drop
public
dropColumn(string $table, string|array<string|int, mixed> $columnName) : mixed
Parameters
- $table : string
-
Table name
- $columnName : string|array<string|int, mixed>
-
Column name Array or comma separated
Tags
Return values
mixed —dropDatabase()
Drop database
public
dropDatabase(string $dbName) : bool
Parameters
- $dbName : string
Tags
Return values
bool —dropForeignKey()
Foreign Key Drop
public
dropForeignKey(string $table, string $foreignName) : bool|BaseResult|Query|false|mixed
Parameters
- $table : string
-
Table name
- $foreignName : string
-
Foreign name
Tags
Return values
bool|BaseResult|Query|false|mixed —dropTable()
Drop Table
public
dropTable(string $tableName[, bool $ifExists = false ][, bool $cascade = false ]) : mixed
Parameters
- $tableName : string
-
Table name
- $ifExists : bool = false
-
Whether to add an IF EXISTS condition
- $cascade : bool = false
-
Whether to add an CASCADE condition
Tags
Return values
mixed —getConnection()
Provides access to the forge's current database connection.
public
getConnection() : ConnectionInterface
Return values
ConnectionInterface —modifyColumn()
Column Modify
public
modifyColumn(string $table, string|array<string|int, mixed> $field) : bool
Parameters
- $table : string
-
Table name
- $field : string|array<string|int, mixed>
-
Column definition
Tags
Return values
bool —renameTable()
Rename Table
public
renameTable(string $tableName, string $newTableName) : mixed
Parameters
- $tableName : string
-
Old table name
- $newTableName : string
-
New table name
Tags
Return values
mixed —reset()
Reset
public
reset() : void
Resets table creation vars
Return values
void —_alterTable()
ALTER TABLE
protected
_alterTable(string $alterType, string $table, mixed $field) : string|array<string|int, string>|false
Parameters
- $alterType : string
-
ALTER type
- $table : string
-
Table name
- $field : mixed
-
Column definition
Return values
string|array<string|int, string>|false —_attributeAutoIncrement()
Field attribute AUTO_INCREMENT
protected
_attributeAutoIncrement(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : void
Parameters
- $attributes : array<string|int, mixed>
- $field : array<string|int, mixed>
Return values
void —_attributeDefault()
Field attribute DEFAULT
protected
_attributeDefault(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : null|void
Parameters
- $attributes : array<string|int, mixed>
- $field : array<string|int, mixed>
Return values
null|void —_attributeType()
Field attribute TYPE
protected
_attributeType(array<string|int, mixed> &$attributes) : void
Performs a data type mapping between different databases.
Parameters
- $attributes : array<string|int, mixed>
Return values
void —_attributeUnique()
Field attribute UNIQUE
protected
_attributeUnique(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : void
Parameters
- $attributes : array<string|int, mixed>
- $field : array<string|int, mixed>
Return values
void —_attributeUnsigned()
Field attribute UNSIGNED
protected
_attributeUnsigned(array<string|int, mixed> &$attributes, array<string|int, mixed> &$field) : null|void
Depending on the unsigned property value:
- TRUE will always set $field['unsigned'] to 'UNSIGNED'
- FALSE will always set $field['unsigned'] to ''
- array(TYPE) will set $field['unsigned'] to 'UNSIGNED', if $attributes['TYPE'] is found in the array
- array(TYPE => UTYPE) will change $field['type'], from TYPE to UTYPE in case of a match
Parameters
- $attributes : array<string|int, mixed>
- $field : array<string|int, mixed>
Return values
null|void —_createTable()
Create Table
protected
_createTable(string $table, bool $ifNotExists, array<string|int, mixed> $attributes) : mixed
Parameters
- $table : string
-
Table name
- $ifNotExists : bool
-
Whether to add 'IF NOT EXISTS' condition
- $attributes : array<string|int, mixed>
-
Associative array of table attributes
Return values
mixed —_createTableAttributes()
CREATE TABLE attributes
protected
_createTableAttributes(array<string|int, mixed> $attributes) : string
Parameters
- $attributes : array<string|int, mixed>
-
Associative array of table attributes
Return values
string —_dropIndex()
Drop index for table
protected
_dropIndex(string $table, object $indexData) : mixed
Parameters
- $table : string
- $indexData : object
Return values
mixed —_dropTable()
Drop Table
protected
_dropTable(string $table, bool $ifExists, bool $cascade) : string
Generates a platform-specific DROP TABLE string
Parameters
- $table : string
-
Table name
- $ifExists : bool
-
Whether to add an IF EXISTS condition
- $cascade : bool
Tags
Return values
string —_processColumn()
Process column
protected
_processColumn(array<string|int, mixed> $field) : string
Parameters
- $field : array<string|int, mixed>
Return values
string —_processFields()
Process fields
protected
_processFields([bool $createTable = false ]) : array<string|int, mixed>
Parameters
- $createTable : bool = false
Return values
array<string|int, mixed> —_processForeignKeys()
Process foreign keys
protected
_processForeignKeys(string $table) : string
Parameters
- $table : string
-
Table name
Return values
string —_processIndexes()
Process indexes
protected
_processIndexes(string $table) : array<string|int, mixed>|string
Parameters
- $table : string
Return values
array<string|int, mixed>|string —_processPrimaryKeys()
Process primary keys
protected
_processPrimaryKeys(string $table) : string
Parameters
- $table : string
-
Table name
Return values
string —databaseExists()
Determine if a database exists
private
databaseExists(string $dbName) : bool
Parameters
- $dbName : string