Documentation

Alter extends AbstractStructure
in package

Schema ALTER table class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

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

license

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

version
6.5.0

Table of Contents

Constants

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'

Properties

$aggregateFunctions  : array<string|int, mixed>
Supported standard SQL aggregate functions
$closeQuote  : string|null
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|null
Current column
$currentConstraint  : string|null
Current constraint
$dateTimeFunctions  : array<string|int, mixed>
Supported standard SQL date-time functions
$db  : AbstractAdapter|null
Database object
$dbType  : string|null
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
$mathFunctions  : array<string|int, mixed>
Supported standard SQL math functions
$openQuote  : string|null
ID open quote
$parameterCount  : int
Parameter count
$placeholder  : string|null
SQL placeholder
$stringFunctions  : array<string|int, mixed>
Supported standard SQL string functions
$table  : string|null
Table name

Methods

__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|null
Get the current database adapter object (alias method)
decimal()  : AbstractStructure
Add a DECIMAL column
decrementParameterCount()  : AbstractSql
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|null
Get close quote
getColumn()  : string|null
Get the current column
getConstraint()  : string|null
Get the current constraint
getDb()  : AbstractAdapter|null
Get the current database adapter object
getDbType()  : string|null
Get the current database type
getIdQuoteType()  : string
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|null
Get open quote
getParameter()  : string
Get parameter placeholder value
getParameterCount()  : int
Get parameter count
getPlaceholder()  : string|null
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()  : AbstractSql
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
isSupportedFunction()  : bool
Check if value contains a standard SQL supported function
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()  : float|int|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

$aggregateFunctions

Supported standard SQL aggregate functions

protected static array<string|int, mixed> $aggregateFunctions = ['AVG', 'COUNT', 'MAX', 'MIN', 'SUM']

$closeQuote

ID close quote

protected string|null $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|null $currentConstraint = null

$dateTimeFunctions

Supported standard SQL date-time functions

protected static array<string|int, mixed> $dateTimeFunctions = ['CURRENT_DATE', 'CURRENT_TIMESTAMP', 'CURRENT_TIME', 'CURDATE', 'CURTIME', 'DATE', 'DATETIME', 'DAY', 'EXTRACT', 'GETDATE', 'HOUR', 'LOCALTIME', 'LOCALTIMESTAMP', 'MINUTE', 'MONTH', 'NOW', 'SECOND', 'TIME', 'TIMEDIFF', 'TIMESTAMP', 'UNIX_TIMESTAMP', 'YEAR']

$dbType

Database type

protected string|null $dbType = 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 = []

$mathFunctions

Supported standard SQL math functions

protected static array<string|int, mixed> $mathFunctions = ['ABS', 'RAND', 'SQRT', 'POW', 'POWER', 'EXP', 'LN', 'LOG', 'LOG10', 'GREATEST', 'LEAST', 'DIV', 'MOD', 'ROUND', 'TRUNC', 'CEIL', 'CEILING', 'FLOOR', 'COS', 'ACOS', 'ACOSH', 'SIN', 'SINH', 'ASIN', 'ASINH', 'TAN', 'TANH', 'ATANH', 'ATAN2']

$openQuote

ID open quote

protected string|null $openQuote = null

$parameterCount

Parameter count

protected int $parameterCount = 0

$placeholder

SQL placeholder

protected string|null $placeholder = null

$stringFunctions

Supported standard SQL string functions

protected static array<string|int, mixed> $stringFunctions = ['CONCAT', 'FORMAT', 'INSTR', 'LCASE', 'LEFT', 'LENGTH', 'LOCATE', 'LOWER', 'LPAD', 'LTRIM', 'POSITION', 'QUOTE', 'REGEXP', 'REPEAT', 'REPLACE', 'REVERSE', 'RIGHT', 'RPAD', 'RTRIM', 'SPACE', 'STRCMP', 'SUBSTRING', 'SUBSTR', 'TRIM', 'UCASE', 'UPPER']

Methods

__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

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|null
Return values
string|null

getColumn()

Get the current column

public getColumn() : string|null
Return values
string|null

getConstraint()

Get the current constraint

public getConstraint() : string|null
Return values
string|null

getDbType()

Get the current database type

public getDbType() : string|null
Return values
string|null

getIdQuoteType()

Get the quote ID type

public getIdQuoteType() : string
Return values
string

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|null
Return values
string|null

getParameter()

Get parameter placeholder value

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

getParameterCount()

Get parameter count

public getParameterCount() : int
Return values
int

getPlaceholder()

Get the SQL placeholder

public getPlaceholder() : string|null
Return values
string|null

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

index()

Create an index

public index(string|array<string|int, mixed> $column[, string|null $name = null ][, string $type = 'index' ]) : AbstractStructure
Parameters
$column : string|array<string|int, mixed>
$name : string|null = null
$type : string = 'index'
Return values
AbstractStructure

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|null $column = null ]) : bool
Parameters
$value : mixed
$column : string|null = 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

isSupportedFunction()

Check if value contains a standard SQL supported function

public static isSupportedFunction(string $value) : bool
Parameters
$value : string
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|null $type = null ][, mixed $size = null ][, mixed $precision = null ]) : Alter
Parameters
$oldName : string
$newName : string
$type : string|null = 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

primary()

Create a PRIMARY KEY index

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

quote()

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

public quote([string|null $value = null ][, bool $force = false ]) : float|int|string
Parameters
$value : string|null = null
$force : bool = false
Return values
float|int|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

unique()

Create a UNIQUE index

public unique([string|array<string|int, mixed>|null $column = null ][, string|null $name = null ]) : AbstractStructure
Parameters
$column : string|array<string|int, mixed>|null = null
$name : string|null = null
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

initQuoteType()

Initialize quite type

protected initQuoteType() : void

        
On this page

Search results