91 if (!is_array($fields) || empty($fields)) {
93 'missing any fields', __FUNCTION__);
95 foreach ($fields as $field_name => $field) {
96 $query = $db->getDeclaration($field[
'type'], $field_name, $field);
102 return implode(
', ', $query_fields);
123 $seq_pattern =
'/^'.preg_replace(
'/%s/',
'([a-z0-9_]+)', $db->options[
'seqname_format']).
'$/i';
124 $seq_name = preg_replace($seq_pattern,
'\\1', $sqn);
125 if ($seq_name && !strcasecmp($sqn, $db->getSequenceName($seq_name))) {
151 $idx_pattern =
'/^'.preg_replace(
'/%s/',
'([a-z0-9_]+)', $db->options[
'idxname_format']).
'$/i';
152 $idx_name = preg_replace($idx_pattern,
'\\1', $idx);
153 if ($idx_name && !strcasecmp($idx, $db->getIndexName($idx_name))) {
177 'method not implemented', __FUNCTION__);
198 'method not implemented', __FUNCTION__);
221 'no valid table name specified', __FUNCTION__);
223 if (empty($fields)) {
225 'no fields specified for table "'.$name.
'"', __FUNCTION__);
229 return $query_fields;
232 $query_fields.=
', PRIMARY KEY ('.implode(
', ', array_keys(
$options[
'primary'])).
')';
235 $name = $db->quoteIdentifier($name,
true);
237 if (!empty(
$options[
'temporary'])) {
240 $result .=
" TABLE $name ($query_fields)";
331 $name = $db->quoteIdentifier($name,
true);
332 return $db->exec(
"DROP TABLE $name");
436 'method not implemented', __FUNCTION__);
456 'method not implementedd', __FUNCTION__);
476 'method not implemented', __FUNCTION__);
499 'method not implemented', __FUNCTION__);
520 'method not implemented', __FUNCTION__);
541 'method not implemented', __FUNCTION__);
561 'method not implemented', __FUNCTION__);
584 'method not implemented', __FUNCTION__);
605 'method not implemented', __FUNCTION__);
650 $table = $db->quoteIdentifier($table,
true);
651 $name = $db->quoteIdentifier($db->getIndexName($name),
true);
652 $query =
"CREATE INDEX $name ON $table";
654 foreach (array_keys($definition[
'fields']) as $field) {
655 $fields[] = $db->quoteIdentifier($field,
true);
657 $query .=
' ('. implode(
', ', $fields) .
')';
679 $name = $db->quoteIdentifier($db->getIndexName($name),
true);
680 return $db->exec(
"DROP INDEX $name");
701 'method not implemented', __FUNCTION__);
735 $table = $db->quoteIdentifier($table,
true);
736 $name = $db->quoteIdentifier($db->getIndexName($name),
true);
737 $query =
"ALTER TABLE $table ADD CONSTRAINT $name";
738 if (!empty($definition[
'primary'])) {
740 } elseif (!empty($definition[
'unique'])) {
744 foreach (array_keys($definition[
'fields']) as $field) {
745 $fields[] = $db->quoteIdentifier($field,
true);
747 $query .=
' ('. implode(
', ', $fields) .
')';
770 $table = $db->quoteIdentifier($table,
true);
771 $name = $db->quoteIdentifier($db->getIndexName($name),
true);
772 return $db->exec(
"ALTER TABLE $table DROP CONSTRAINT $name");
793 'method not implemented', __FUNCTION__);
815 'method not implemented', __FUNCTION__);
836 'method not implemented', __FUNCTION__);
859 'method not implemented', __FUNCTION__);
dropTable($name)
drop an existing table
listFunctions()
list all functions in the current database
const MDB2_ERROR_UNSUPPORTED
_getTemporaryTableQuery()
A method to return the required SQL string that fits between CREATE ...
listUsers()
list all users
getFieldDeclarationList($fields)
Get declaration of a number of field in bulk.
createIndex($table, $name, $definition)
Get the stucture of a field into an array.
dropSequence($name)
drop existing sequence
listSequences($database=null)
list all sequences in the current database
listTableFields($table)
list all fields in a table in the current database
dropDatabase($database)
drop an existing database
createDatabase($database)
create a new database
dropIndex($table, $name)
drop existing index
if(!is_array($argv)) $options
createConstraint($table, $name, $definition)
create a constraint on a table
const MDB2_ERROR_NEED_MORE_DATA
listDatabases()
list all databases
listTableTriggers($table=null)
list all triggers in the database that reference a given table
listTableIndexes($table)
list all indexes in a table
alterTable($name, $changes, $check)
alter an existing table
_fixSequenceName($sqn, $check=false)
Removes any formatting in an sequence name using the 'seqname_format' option.
createSequence($seq_name, $start=1)
create sequence
listViews($database=null)
list all views in the current database
listTableViews($table)
list the views in the database that reference a given table
const MDB2_ERROR_CANNOT_CREATE
createTable($name, $fields, $options=array())
create a new table
_fixIndexName($idx)
Removes any formatting in an index name using the 'idxname_format' option.
dropConstraint($table, $name, $primary=false)
drop existing constraint
& getDBInstance()
Get the instance of MDB2 associated with the module instance.
listTableConstraints($table)
list all constraints in a table
_getCreateTableQuery($name, $fields, $options=array())
Create a basic SQL query for a new table creation.
listTables($database=null)
list all tables in the current database
isError($data, $code=null)
Tell whether a value is a PEAR error.