void addField(
string
$name, string
$generictype, [int
$size = 0], [int
$flags = 0], [mixed
$default = NULL]
)
|
|
Add a field to the table definition.
Parameters:
|
string |
$name: |
The name of the field |
|
string |
$generictype: |
The datatype of the field (should be one of the generic types supported by ATK). |
|
int |
$size: |
The size of the field (if appropriate) |
|
int |
$flags: |
The DDL_ flags for this field. |
|
mixed |
$default: |
The default value to be used when inserting new rows. |
void addFields(
array
$meta
)
|
|
Add multiple fields at once using the given metadata.
NOTE: defaults are not supported yet!
Parameters:
|
array |
$meta: |
The fields meta data. |
Build one or more ALTER TABLE queries and return them as an array of strings.
The default implementation assumes that multiple fields can be added with one single ALTER TABLE statement. If a database needs to be supported which doesn't have this ability, then an override for this function should be implemented in the appropriate atk<database>ddl class.
API Tags:
| Return: | array of ALTER TABLE queries. |
Redefined in descendants as:
String buildConstraints(
)
|
|
Convert all constraints to a string that can be used in a CREATE TABLE statement.
API Tags:
| Return: | containing constraints to be used in a CREATE or ALTER TABLE statement |
Build a CREATE TABLE query and return it as a string.
API Tags:
| Return: | CREATE TABLE query. |
Redefined in descendants as:
Build a DROP TABLE query and return it as a string.
API Tags:
| Return: | DROP TABLE query. |
void buildField(
string
$name, string
$generictype, [int
$size = 0], [int
$flags = 0], [mixed
$default = NULL]
)
|
|
Generate a string for a field, to be used inside a CREATE TABLE statement.
This function tries to be generic, so it will work in the largest number of databases. Databases that won't work with this syntax, should override this method in the database specific ddl class.
Parameters:
|
string |
$name: |
The name of the field |
|
string |
$generictype: |
The datatype of the field (should be one of the generic types supported by ATK). |
|
int |
$size: |
The size of the field (if appropriate) |
|
int |
$flags: |
The DDL_ flags for this field. |
|
mixed |
$default: |
The default value to be used when inserting new rows. |
Redefined in descendants as:
Convert all fields to a string that can be used in a CREATE or ALTER TABLE statement.
API Tags:
| Return: | containing fields to be used in a CREATE or ALTER TABLE statement |
void buildPrimaryKey(
[array
$fieldlist = array()]
)
|
|
Generate a string that defines the primary key, for use inside the CREATE TABLE statement.
This function will be overrided by the database specific subclasses of atkDDL.
Parameters:
|
array |
$fieldlist: |
An array of fields that define the primary key. |
string buildView(
string
$name, string
$select, string
$with_check_option
)
|
|
Build CREATE VIEW query
Parameters:
|
string |
$name: |
- name of view |
|
string |
$select: |
- SQL SELECT statement |
|
string |
$with_check_option: |
- use SQL WITH CHECK OPTION |
API Tags:
| Return: | CREATE VIEW query string |
Redefined in descendants as:
string calculateDecimalFieldSize(
string
$size
)
|
|
Calculate the correct field size for decimal fields We should add the decimals to the size, since size is specified including the decimals.
Parameters:
|
string |
$size: |
Current size |
API Tags:
atkDDL &create(
[String
$database = NULL]
)
|
|
Static factory method for creating a new atkDDL instance. This static method will determine the database type (mysql, oci, etc) and instantiate the correct DDL class.
Parameters:
|
String |
$database: |
The database driver to use |
API Tags:
| Return: | instance of db specific DDL driver |
boolean createIndex(
string
$name, array
$definition
)
|
|
Create an index
Parameters:
|
string |
$name: |
Index name |
|
array |
$definition: |
associative array that defines properties of the index to be created. example array('fields' => array('user_id' => array('sorting' => 'ascending' 'length' => 3 ), 'lastname' => array() ) ) |
void dropField(
string
$name
)
|
|
Drop a field from the table definition.
Parameters:
|
string |
$name: |
The name of the field |
boolean dropIndex(
string
$name
)
|
|
Drop an existing index
Parameters:
bool dropSequence(
string
$name
)
|
|
Drop sequence
Parameters:
|
string |
$name: |
Sequence name |
Redefined in descendants as:
string dropView(
string
$name
)
|
|
Build DROP VIEW query
Parameters:
|
string |
$name: |
- name of view |
API Tags:
| Return: | CREATE VIEW query string |
Redefined in descendants as:
Build and execute ALTER TABLE queries.
Note that more than one query might be performed, depending on the number of fields added, and the database capabilities (some databases are capable of adding several fields in one ALTER TABLE query, others aren't and need to perform multiple queries).
API Tags:
| Return: | if the table was altered successfully false if anything went wrong, or if no table could be altered. |
Build and execute the CREATE TABLE query.
API Tags:
| Return: | if the table was created successfully false if anything went wrong, or if no table could be created. |
true executeCreateView(
string
$name, string
$select, string
$with_check_option
)
|
|
Build and execute CREATE VIEW query
Parameters:
|
string |
$name: |
- name of view |
|
string |
$select: |
- SQL SELECT statement |
|
string |
$with_check_option: |
- use SQL WITH CHECK OPTION |
API Tags:
| Return: | if view create successfully false if error take place |
Build and execute the DROP TABLE query.
API Tags:
| Return: | if the table was dropped successfully false if anything went wrong, or if no table could be dropped. |
true executeDropView(
string
$name
)
|
|
Build and execute DROP VIEW query
Parameters:
|
string |
$name: |
- name of view |
API Tags:
| Return: | if view create successfully false if error take place |
void getGenericType(
string
$type
)
|
|
Convert an database specific type to an ATK generic datatype.
This function will be overrided by the database specific subclasses of atkDb.
Parameters:
|
string |
$type: |
The database specific datatype to convert. |
API Tags:
Redefined in descendants as:
string getIndexName(
string
$name
)
|
|
Get Indexname
Parameters:
void getType(
string
$generictype
)
|
|
Convert an ATK generic datatype to a database specific type.
This function will be overrided by the database specific subclasses of atkDb. Note: in all derived subclasses, the following types *must* be supported: number, decimal, string, date, text, datetime, time, boolean. If the database does not have a proper field type, consider using a varchar or number to store the value.
Parameters:
|
string |
$generictype: |
The datatype to convert. |
API Tags:
Redefined in descendants as:
void loadMetaData(
array
$tablemeta
)
|
|
Set all table data at once using the given table meta data, retrieved using the metadata function of the db instance.
Parameters:
|
array |
$tablemeta: |
table meta data array |
Redefined in descendants as:
-
atkMysqlDDL::loadMetaData()
: Set all table data at once using the given table meta data, retrieved using the metadata function of the db instance.
true needsQuotes(
string
$generictype
)
|
|
Method to determine whether quotes are needed around the values for a given generic datatype.
Parameters:
|
string |
$generictype: |
The type of field. |
API Tags:
| Return: | if quotes should be put around values for the given type of field. false if quotes should not be used. |
true needsSize(
string
$generictype
)
|
|
Method to determine whether a given generic field type needs to have a size defined.
Parameters:
|
string |
$generictype: |
The type of field. |
API Tags:
| Return: | if a size should be specified for the given field type. false if a size does not have to be specified. |
Redefined in descendants as:
bool renameSequence(
string
$name, string
$new_name
)
|
|
Rename sequence
Parameters:
|
string |
$name: |
The current sequence name |
|
string |
$new_name: |
The new sequence name |
Redefined in descendants as:
bool renameTable(
string
$name, string
$new_name
)
|
|
Rename table name
Parameters:
|
string |
$name: |
Table name |
|
string |
$new_name: |
New table name |
Redefined in descendants as:
void setTable(
string
$tablename
)
|
|
Set the name of the table.
Parameters:
|
string |
$tablename: |
The name of the table |
An _buildConstraintsArray(
)
|
|
Convert all constraints to an array that can be used in a CREATE or ALTER TABLE statement.
API Tags:
| Return: | array of constraints |
| Access: | private |
void _buildFieldsArray(
)
|
|
Convert all fields to string that can be used in a CREATE or ALTER TABLE statement. Fields will be returned in an array. (INTERNAL USE ONLY)
API Tags: