Documentation

Alter extends AbstractStructure
in package

Schema ALTER table class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2021 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

http://www.popphp.org/license New BSD License

version
5.3.0

Table of Contents

BACKTICK  = 'BACKTICK'
Constants for id quote types
BRACKET  = 'BRACKET'
DOUBLE_QUOTE  = 'DOUBLE_QUOTE'
MYSQL  = 'MYSQL'
Constants for database types
NO_QUOTE  = 'NO_QUOTE'
PGSQL  = 'PGSQL'
SQLITE  = 'SQLITE'
SQLSRV  = 'SQLSRV'
$closeQuote  : string
ID close quote
$columns  : array<string|int, mixed>
Columns to be added or modified
$constraints  : array<string|int, mixed>
Constraints to be added
$currentColumn  : string
Current column
$currentConstraint  : string
Current constraint
$db  : AbstractAdapter
Database object
$dbType  : int
Database type
$dropColumns  : array<string|int, mixed>
Columns to be dropped
$dropConstraints  : array<string|int, mixed>
Constraints to be dropped
$dropIndices  : array<string|int, mixed>
Indices to be dropped
$existingColumns  : array<string|int, mixed>
Existing columns in the table
$idQuoteType  : string
ID quote type
$indices  : array<string|int, mixed>
Indices to be created
$info  : array<string|int, mixed>
Table info
$openQuote  : string
ID open quote
$parameterCount  : int
Parameter count
$placeholder  : string
SQL placeholder
$table  : string
Table name
__construct()  : mixed
Constructor
__toString()  : string
Render the table schema to string
addColumn()  : AbstractStructure
Add a column
addColumnAttribute()  : AbstractStructure
Add a custom column attribute
after()  : Alter
Set the AFTER column (MySQL-only))
bigInt()  : AbstractStructure
Add a BIGINT column
blob()  : AbstractStructure
Add a BLOB column
char()  : AbstractStructure
Add a CHAR column
column()  : AbstractStructure
Set the current column
constraint()  : AbstractStructure
Set the current constraint
date()  : AbstractStructure
Add a DATE column
datetime()  : AbstractStructure
Add a DATETIME column
db()  : AbstractAdapter
Get the current database adapter object (alias method)
decimal()  : AbstractStructure
Add a DECIMAL column
decrementParameterCount()  : static
Decrement parameter count
defaultIs()  : AbstractStructure
Set the current column's default value
double()  : AbstractStructure
Add a DOUBLE column
dropColumn()  : Alter
Drop a column
dropConstraint()  : Alter
Drop a constraint
dropIndex()  : Alter
Drop an index
float()  : AbstractStructure
Add a FLOAT column
foreignKey()  : AbstractStructure
Create a FOREIGN KEY constraint
getCloseQuote()  : string
Get close quote
getColumn()  : string
Get the current column
getConstraint()  : string
Get the current constraint
getDb()  : AbstractAdapter
Get the current database adapter object
getDbType()  : int
Get the current database type
getIdQuoteType()  : int
Get the quote ID type
getIncrement()  : array<string|int, mixed>
Get the increment column(s)
getInfo()  : array<string|int, mixed>
Get the table info
getOpenQuote()  : string
Get open quote
getParameter()  : string
Get parameter placeholder value
getParameterCount()  : int
Get parameter count
getPlaceholder()  : string
Get the SQL placeholder
getPrimary()  : array<string|int, mixed>
Get the primary key column(s)
getTable()  : string
Get the table name
hasColumn()  : bool
Determine if the table has a column
hasIncrement()  : bool
Determine if the table has an increment column
hasPrimary()  : bool
Determine if the table has a primary key column
increment()  : AbstractStructure
Set the current column as an increment column
incrementParameterCount()  : static
Increment parameter count
index()  : AbstractStructure
Create an index
int()  : AbstractStructure
Add an INT column
integer()  : AbstractStructure
Add an INTEGER column
isMysql()  : bool
Determine if the DB type is MySQL
isParameter()  : bool
Check if value is parameter placeholder
isPgsql()  : bool
Determine if the DB type is PostgreSQL
isSqlite()  : bool
Determine if the DB type is SQLite
isSqlsrv()  : bool
Determine if the DB type is SQL Server
longBlob()  : AbstractStructure
Add a LONGBLOB column
longText()  : AbstractStructure
Add a LONGTEXT column
mediumBlob()  : AbstractStructure
Add a MEDIUMBLOB column
mediumInt()  : AbstractStructure
Add a MEDIUMINT column
mediumText()  : AbstractStructure
Add a MEDIUMTEXT column
modifyColumn()  : Alter
Modify a column
notNullable()  : AbstractStructure
Set the current column as NOT nullable
nullable()  : AbstractStructure
Set the current column as nullable
numeric()  : AbstractStructure
Add a NUMERIC column
on()  : AbstractStructure
Assign FOREIGN KEY reference table column
onDelete()  : AbstractStructure
Assign FOREIGN KEY ON DELETE action
primary()  : AbstractStructure
Create a PRIMARY KEY index
quote()  : string
Quote the value (if it is not a numeric value)
quoteId()  : string
Quote the identifier
real()  : AbstractStructure
Add a REAL column
references()  : AbstractStructure
Assign FOREIGN KEY reference table
render()  : string
Render the table schema
renderToStatements()  : array<string|int, mixed>
Render the table schema to an array of statements
setIdQuoteType()  : AbstractSql
Set the quote ID type
setPlaceholder()  : AbstractSql
Set the placeholder
smallInt()  : AbstractStructure
Add a SMALLINT column
text()  : AbstractStructure
Add a TEXT column
time()  : AbstractStructure
Add a TIME column
timestamp()  : AbstractStructure
Add a TIMESTAMP column
tinyInt()  : AbstractStructure
Add a TINYINT column
tinyText()  : AbstractStructure
Add a TINYTEXT column
unique()  : AbstractStructure
Create a UNIQUE index
unsigned()  : AbstractStructure
Set the current column as unsigned
varchar()  : AbstractStructure
Add a VARCHAR column
year()  : AbstractStructure
Add a YEAR column
getColumnSchema()  : string
Format column schema
init()  : void
Initialize SQL object
initQuoteType()  : void
Initialize quite type

Constants

BACKTICK

Constants for id quote types

public mixed BACKTICK = 'BACKTICK'

DOUBLE_QUOTE

public mixed DOUBLE_QUOTE = 'DOUBLE_QUOTE'

MYSQL

Constants for database types

public mixed MYSQL = 'MYSQL'

Properties

$closeQuote

ID close quote

protected string $closeQuote = null

$columns

Columns to be added or modified

protected array<string|int, mixed> $columns = []

$constraints

Constraints to be added

protected array<string|int, mixed> $constraints = []

$currentConstraint

Current constraint

protected string $currentConstraint = null

$dropColumns

Columns to be dropped

protected array<string|int, mixed> $dropColumns = []

$dropConstraints

Constraints to be dropped

protected array<string|int, mixed> $dropConstraints = []

$dropIndices

Indices to be dropped

protected array<string|int, mixed> $dropIndices = []

$existingColumns

Existing columns in the table

protected array<string|int, mixed> $existingColumns = []

$idQuoteType

ID quote type

protected string $idQuoteType = 'NO_QUOTE'

$indices

Indices to be created

protected array<string|int, mixed> $indices = []

$info

Table info

protected array<string|int, mixed> $info = []

$openQuote

ID open quote

protected string $openQuote = null

$parameterCount

Parameter count

protected int $parameterCount = 0

$placeholder

SQL placeholder

protected string $placeholder = null

Methods

__construct()

Constructor

public __construct(string $table, AbstractAdapter $db) : mixed

Instantiate the ALTER table object

Parameters
$table : string
$db : AbstractAdapter
Return values
mixed

__toString()

Render the table schema to string

public __toString() : string
Return values
string

addColumn()

Add a column

public addColumn(string $name, string $type[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$type : string
$size : mixed = null
$precision : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

after()

Set the AFTER column (MySQL-only))

public after(string $column) : Alter
Parameters
$column : string
Return values
Alter

bigInt()

Add a BIGINT column

public bigInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

char()

Add a CHAR column

public char(string $name[, int $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : int = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

decimal()

Add a DECIMAL column

public decimal(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$precision : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

decrementParameterCount()

Decrement parameter count

public decrementParameterCount() : static
Return values
static

double()

Add a DOUBLE column

public double(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$precision : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

dropColumn()

Drop a column

public dropColumn(string $name) : Alter
Parameters
$name : string
Return values
Alter

dropConstraint()

Drop a constraint

public dropConstraint(string $name) : Alter
Parameters
$name : string
Return values
Alter

dropIndex()

Drop an index

public dropIndex(string $name) : Alter
Parameters
$name : string
Return values
Alter

float()

Add a FLOAT column

public float(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$precision : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

getCloseQuote()

Get close quote

public getCloseQuote() : string
Return values
string

getColumn()

Get the current column

public getColumn() : string
Return values
string

getConstraint()

Get the current constraint

public getConstraint() : string
Return values
string

getDbType()

Get the current database type

public getDbType() : int
Return values
int

getIdQuoteType()

Get the quote ID type

public getIdQuoteType() : int
Return values
int

getIncrement()

Get the increment column(s)

public getIncrement([bool $quote = false ]) : array<string|int, mixed>
Parameters
$quote : bool = false
Return values
array<string|int, mixed>

getInfo()

Get the table info

public getInfo() : array<string|int, mixed>
Return values
array<string|int, mixed>

getOpenQuote()

Get open quote

public getOpenQuote() : string
Return values
string

getParameter()

Get parameter placeholder value

public getParameter(mixed $value[, string $column = null ]) : string
Parameters
$value : mixed
$column : string = null
Return values
string

getParameterCount()

Get parameter count

public getParameterCount() : int
Return values
int

getPlaceholder()

Get the SQL placeholder

public getPlaceholder() : string
Return values
string

getPrimary()

Get the primary key column(s)

public getPrimary([bool $quote = false ]) : array<string|int, mixed>
Parameters
$quote : bool = false
Return values
array<string|int, mixed>

getTable()

Get the table name

public getTable() : string
Return values
string

hasColumn()

Determine if the table has a column

public hasColumn(string $name) : bool
Parameters
$name : string
Return values
bool

hasIncrement()

Determine if the table has an increment column

public hasIncrement() : bool
Return values
bool

hasPrimary()

Determine if the table has a primary key column

public hasPrimary() : bool
Return values
bool

incrementParameterCount()

Increment parameter count

public incrementParameterCount() : static
Return values
static

int()

Add an INT column

public int(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

integer()

Add an INTEGER column

public integer(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

isMysql()

Determine if the DB type is MySQL

public isMysql() : bool
Return values
bool

isParameter()

Check if value is parameter placeholder

public isParameter(mixed $value[, string $column = null ]) : bool
Parameters
$value : mixed
$column : string = null
Return values
bool

isPgsql()

Determine if the DB type is PostgreSQL

public isPgsql() : bool
Return values
bool

isSqlite()

Determine if the DB type is SQLite

public isSqlite() : bool
Return values
bool

isSqlsrv()

Determine if the DB type is SQL Server

public isSqlsrv() : bool
Return values
bool

mediumInt()

Add a MEDIUMINT column

public mediumInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

modifyColumn()

Modify a column

public modifyColumn(string $oldName, string $newName[, string $type = null ][, mixed $size = null ][, mixed $precision = null ]) : Alter
Parameters
$oldName : string
$newName : string
$type : string = null
$size : mixed = null
$precision : mixed = null
Return values
Alter

numeric()

Add a NUMERIC column

public numeric(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$precision : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

quote()

Quote the value (if it is not a numeric value)

public quote(string $value[, bool $force = false ]) : string
Parameters
$value : string
$force : bool = false
Return values
string

quoteId()

Quote the identifier

public quoteId(string $identifier) : string
Parameters
$identifier : string
Return values
string

real()

Add a REAL column

public real(string $name[, mixed $size = null ][, mixed $precision = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$precision : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

render()

Render the table schema

public render() : string
Return values
string

renderToStatements()

Render the table schema to an array of statements

public renderToStatements() : array<string|int, mixed>
Return values
array<string|int, mixed>

setIdQuoteType()

Set the quote ID type

public setIdQuoteType([string $type = self::NO_QUOTE ]) : AbstractSql
Parameters
$type : string = self::NO_QUOTE
Return values
AbstractSql

smallInt()

Add a SMALLINT column

public smallInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

tinyInt()

Add a TINYINT column

public tinyInt(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

varchar()

Add a VARCHAR column

public varchar(string $name[, int $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : int = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

year()

Add a YEAR column

public year(string $name[, mixed $size = null ][, array<string|int, mixed> $attributes = [] ]) : AbstractStructure
Parameters
$name : string
$size : mixed = null
$attributes : array<string|int, mixed> = []
Return values
AbstractStructure

getColumnSchema()

Format column schema

protected getColumnSchema(string $name, array<string|int, mixed> $column) : string
Parameters
$name : string
$column : array<string|int, mixed>
Return values
string

init()

Initialize SQL object

protected init(string $adapter) : void
Parameters
$adapter : string
Return values
void

initQuoteType()

Initialize quite type

protected initQuoteType() : void
Return values
void

Search results