class vB_Database_Alter_MySQL extends vB_Database_Alter

Properties

boolean $init Whether a table has been initialized for altering. from vB_Database_Alter
integer $error_no Number of the latest error from the database. 0 if no error. from vB_Database_Alter
string $error_desc Description of the latest error from the database. from vB_Database_Alter
string $sql The text of the last query that has been run. Helpful for debugging. from vB_Database_Alter
array $table_index_data Array of table index data from vB_Database_Alter
array $table_status_data Array of table status data from vB_Database_Alter
array $table_field_data Array of table field data from vB_Database_Alter
string $table_name Name of the table being altered from vB_Database_Alter
object $db Database object from vB_Database_Alter
$tag from vB_Database_Alter

Methods

__construct(vB_Database $db)

Constructor - checks that the database object has been passed correctly.

bool
fetch_table_info(string $tablename = '')

Public Populates the $table_index_data, $table_status_data and $table_field_data arrays with all relevant information that is obtainable about this database table. Leave $tablename blank to use the table used in the previous call to this functions. The arrays are used by the private and public functions to perform their work. Nothing can be done to a table until this function is invoked.

string
fetch_error()

Public Returns a text value that relates to the error condition, useable to prepare human readable error phrase varname strings

string
fetch_error_message()

Public Returns error description, set manually or by database error handler

string
fetch_table_type()

Public Returns the table type, e.g. ISAM, MYISAM, InnoDB

bool
drop_index(string $fieldname)

Public Drops an index

bool
add_index(string $fieldname, mixed $fields, string $type = '', bool $overwrite = false)

Public Creates an index. Can be single or multi-column index, normal, unique or fulltext

bool
add_field(array $fields, bool $overwrite = false)

Public Adds field. Can be single fields, or multiple fields. If a field already exists, false will be returned so to silently fail on duplicate fields you would want to call this multiple times, creating a field one at a time.

bool
drop_field($fields)

Public Drops field. Can be single fields, or multiple fields. If a field doesn't exist, false will be returned so to silently fail on missing fields you would want to call this multiple times, dropping a field one at a time.

bool
query(string $query, bool $escape = false)

Public Direct write query to the database with error trapping. Useful when a collision isn't important

void
set_error(integer $errno = 0, string $desc = '')

Private Set the $error_no and $error_desc variables

void
init_table_info()

Private Verifies that fetch_table_info() has been called for a valid table and sets current error condition to none

bool
fetch_index_info()

Private Populates $this->table_index_data with index schema relating to $this->table_name

bool
fetch_field_info()

Private Populates $this->table_field_data with column schema relating to $this->table_name

bool
fetch_table_status()

Private Populates $this->table_status_data with table status relating to $this->table_name

bool
convert_table_type(string $type)

Private Converts table type, i.e. from ISAM to MYISAM

alter_field($fields)

No description

add_enum($field, $value, $overwrite = false)

No description

drop_enum($field, $value)

No description

_generate_enum($field, $enums)

No description

Details

in vB_Database_Alter at line 111
__construct(vB_Database $db)

Constructor - checks that the database object has been passed correctly.

Parameters

vB_Database $db The vB_Database object ($db)

in vB_Database_Alter at line 134
bool fetch_table_info(string $tablename = '')

Public Populates the $table_index_data, $table_status_data and $table_field_data arrays with all relevant information that is obtainable about this database table. Leave $tablename blank to use the table used in the previous call to this functions. The arrays are used by the private and public functions to perform their work. Nothing can be done to a table until this function is invoked.

Parameters

string $tablename Name of table

Return Value

bool

in vB_Database_Alter at line 167
string fetch_error()

Public Returns a text value that relates to the error condition, useable to prepare human readable error phrase varname strings

Return Value

string

in vB_Database_Alter at line 197
string fetch_error_message()

Public Returns error description, set manually or by database error handler

Return Value

string

in vB_Database_Alter at line 210
string fetch_table_type()

Public Returns the table type, e.g. ISAM, MYISAM, InnoDB

Return Value

string

at line 478
bool drop_index(string $fieldname)

Public Drops an index

Parameters

string $fieldname Name of index to drop

Return Value

bool

at line 534
bool add_index(string $fieldname, mixed $fields, string $type = '', bool $overwrite = false)

Public Creates an index. Can be single or multi-column index, normal, unique or fulltext

Parameters

string $fieldname Name of index to drop
mixed $fields Name of field to index. Create a multi field index by sending an array of field names
string $type Default is normal. Valid options are 'FULLTEXT' and 'UNIQUE'
bool $overwrite true = delete an existing index, then add. false = return false if index of same name already exists unless it matches exactly

Return Value

bool

at line 714
bool add_field(array $fields, bool $overwrite = false)

Public Adds field. Can be single fields, or multiple fields. If a field already exists, false will be returned so to silently fail on duplicate fields you would want to call this multiple times, creating a field one at a time.

Parameters

array $fields Definition of field to index. Create multiple fields by sending an array of definitions but see note above.
bool $overwrite true = delete an existing field of same name, then create. false = return false if a field of same name already exists

Return Value

bool

at line 813
bool drop_field($fields)

Public Drops field. Can be single fields, or multiple fields. If a field doesn't exist, false will be returned so to silently fail on missing fields you would want to call this multiple times, dropping a field one at a time.

Parameters

$fields

Return Value

bool

at line 791
bool query(string $query, bool $escape = false)

Public Direct write query to the database with error trapping. Useful when a collision isn't important

Parameters

string $query Direct query string to perform
bool $escape true: escape_string $query false: use as-is

Return Value

bool

in vB_Database_Alter at line 282
void set_error(integer $errno = 0, string $desc = '')

Private Set the $error_no and $error_desc variables

Parameters

integer $errno Errorcode - use values defined at top of class file
string $desc Description of error. Manually set or returned by database error handler

Return Value

void

in vB_Database_Alter at line 297
void init_table_info()

Private Verifies that fetch_table_info() has been called for a valid table and sets current error condition to none

.. in other words verify that fetchTableInfo returns true before proceeding on

Return Value

void

at line 336
bool fetch_index_info()

Private Populates $this->table_index_data with index schema relating to $this->table_name

Return Value

bool

at line 376
bool fetch_field_info()

Private Populates $this->table_field_data with column schema relating to $this->table_name

Return Value

bool

at line 411
bool fetch_table_status()

Private Populates $this->table_status_data with table status relating to $this->table_name

Return Value

bool

at line 444
bool convert_table_type(string $type)

Private Converts table type, i.e. from ISAM to MYISAM

Parameters

string $type

Return Value

bool

at line 627
alter_field($fields)

Parameters

$fields

at line 859
add_enum($field, $value, $overwrite = false)

Parameters

$field
$value
$overwrite

at line 906
drop_enum($field, $value)

Parameters

$field
$value

at line 952
_generate_enum($field, $enums)

Parameters

$field
$enums