cvs: pear /MDB2/MDB2/Driver/Manager ibase.php
| From: | Lorenzo Alberton | Date: | Sun, 16 Oct 2005 20:56:47 +0000 |
| Subject: | cvs: pear /MDB2/MDB2/Driver/Manager ibase.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35609@lists.php.net to get a copy of this message | ||
quipo Sun Oct 16 16:56:47 2005 EDT
Modified files:
/pear/MDB2/MDB2/Driver/Manager ibase.php
Log:
- fixed many issues with case and quoted identifiers
- in listSequences(), skip system generators
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/ibase.php?r1=1.54&r2=1.55&ty=u Index: pear/MDB2/MDB2/Driver/Manager/ibase.php diff -u pear/MDB2/MDB2/Driver/Manager/ibase.php:1.54 pear/MDB2/MDB2/Driver/Manager/ibase.php:1.55 --- pear/MDB2/MDB2/Driver/Manager/ibase.php:1.54 Sun Oct 16 12:31:52 2005 +++ pear/MDB2/MDB2/Driver/Manager/ibase.php Sun Oct 16 16:56:43 2005 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.54 2005/10/16 16:31:52 lsmith Exp $ +// $Id: ibase.php,v 1.55 2005/10/16 20:56:43 quipo Exp $ require_once 'MDB2/Driver/Manager/Common.php'; @@ -206,6 +206,7 @@ */ function createTable($name, $fields) { + $name = strtoupper($name); $result = parent::createTable($name, $fields); if (PEAR::isError($result)) { return $result; @@ -243,8 +244,10 @@ return $db->raiseError(MDB2_ERROR, null, null, 'checkSupportedChanges: it is not supported changes to field default value'); case 'length': + /* return $db->raiseError(MDB2_ERROR, null, null, 'checkSupportedChanges: it is not supported changes to field default length'); + */ case 'unsigned': case 'type': case 'declaration': @@ -270,6 +273,7 @@ */ function dropTable($name) { + $name = strtoupper($name); $result = $this->_dropAutoincrement($name); if (PEAR::isError($result)) { return $result; @@ -448,7 +452,7 @@ return MDB2_OK; } - $name = $db->quoteIdentifier($name); + $name = $db->quoteIdentifier(strtoupper($name)); return $db->query("ALTER TABLE $name $query"); } @@ -495,7 +499,6 @@ return $db; } $table = strtoupper($table); - $table = $db->quoteIdentifier($table); $query = "SELECT RDB\$FIELD_NAME FROM RDB\$RELATION_FIELDS WHERE UPPER(RDB\$RELATION_NAME)='$table'"; $result = $db->queryCol($query); if (PEAR::isError($result)) { @@ -609,14 +612,34 @@ } } } - $table = $db->quoteIdentifier($table); - $name = $db->quoteIdentifier($name); + $table = $db->quoteIdentifier(strtoupper($table)); + $name = $db->quoteIdentifier(strtoupper($name)); $query .= $query_sort. " INDEX $name ON $table ("; - $query .= implode(', ', array_keys($definition['fields'])) . ')'; + $fields = array(); + foreach (array_keys($definition['fields']) as $field) { + $fields[] = $db->quoteIdentifier($field); + } + $query .= implode(', ', $fields) . ')'; return $db->query($query); } // }}} + // {{{ dropIndex() + + /** + * drop existing index + * + * @param string $table name of table that should be used in method + * @param string $name name of the index to be dropped + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function dropIndex($table, $name) + { + return parent::dropIndex(strtoupper($table), strtoupper($name)); + } + + // }}} // {{{ listTableIndexes() /** @@ -645,6 +668,67 @@ } // }}} + // {{{ createConstraint() + + /** + * create a constraint on a table + * + * @param string $table name of the table on which the constraint is to be created + * @param string $name name of the constraint to be created + * @param array $definition associative array that defines properties of the constraint to be created. + * Currently, only one property named FIELDS is supported. This property + * is also an associative with the names of the constraint fields as array + * constraints. Each entry of this array is set to another type of associative + * array that specifies properties of the constraint that are specific to + * each field. + * + * Example + * array( + * 'fields' => array( + * 'user_name' => array(), + * 'last_login' => array(), + * ) + * ) + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function createConstraint($table, $name, $definition) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + $table = $db->quoteIdentifier(strtoupper($table)); + $name = $db->quoteIdentifier($name); + $query = "ALTER TABLE $table ADD CONSTRAINT $name"; + if (array_key_exists('primary', $definition) && $definition['primary']) { + $query.= ' PRIMARY KEY'; + } + $fields = array(); + foreach (array_keys($definition['fields']) as $field) { + $fields[] = $db->quoteIdentifier($field); + } + $query .= ' ('. implode(', ', $fields) . ')'; + return $db->query($query); + } + + // }}} + // {{{ dropConstraint() + + /** + * drop existing constraint + * + * @param string $table name of table that should be used in method + * @param string $name name of the constraint to be dropped + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function dropConstraint($table, $name) + { + return parent::dropConstraint(strtoupper($table), $name); + } + + // }}} // {{{ listTableConstraints() /** @@ -694,11 +778,11 @@ return $db; } - $sequence_name = $db->getSequenceName($seq_name); - if (PEAR::isError($result = $db->query('CREATE GENERATOR '.strtoupper($sequence_name)))) { + $sequence_name = strtoupper($db->getSequenceName($seq_name)); + if (PEAR::isError($result = $db->query('CREATE GENERATOR '.$sequence_name))) { return $result; } - if (PEAR::isError($result = $db->query('SET GENERATOR '.strtoupper($sequence_name).' TO '.($start-1)))) { + if (PEAR::isError($result = $db->query('SET GENERATOR '.$sequence_name.' TO '.($start-1)))) { if (PEAR::isError($err = $db->dropSequence($seq_name))) { return $db->raiseError(MDB2_ERROR, null, null, 'createSequence: Could not setup sequence start value and then it was not possible to drop it: '. @@ -725,8 +809,9 @@ return $db; } - $sequence_name = $db->getSequenceName($seq_name); - return $db->query('DELETE FROM RDB$GENERATORS WHERE UPPER(RDB$GENERATOR_NAME)=\''.strtoupper($sequence_name).'\''); + $sequence_name = strtoupper($db->getSequenceName($seq_name)); + $query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)='$sequence_name'"; + return $db->query($query); } // }}} @@ -745,14 +830,14 @@ return $db; } - $query = 'SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS'; + $query = 'SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$SYSTEM_FLAG IS NULL'; $table_names = $db->queryCol($query); if (PEAR::isError($table_names)) { return $table_names; } $result = array(); - for ($i = 0, $j = count($table_names); $i < $j; ++$i) { - if ($sqn = $this->_isSequenceName($table_names[$i])) { + foreach ($table_names as $table_name) { + if ($sqn = $this->_isSequenceName($table_name)) { $result[] = $sqn; } }
http://cvs.php.net/diff.php/pear/MDB2/MDB2/Driver/Manager/ibase.php?r1=1.54&r2=1.55&ty=u Index: pear/MDB2/MDB2/Driver/Manager/ibase.php diff -u pear/MDB2/MDB2/Driver/Manager/ibase.php:1.54 pear/MDB2/MDB2/Driver/Manager/ibase.php:1.55 --- pear/MDB2/MDB2/Driver/Manager/ibase.php:1.54 Sun Oct 16 12:31:52 2005 +++ pear/MDB2/MDB2/Driver/Manager/ibase.php Sun Oct 16 16:56:43 2005 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.54 2005/10/16 16:31:52 lsmith Exp $ +// $Id: ibase.php,v 1.55 2005/10/16 20:56:43 quipo Exp $ require_once 'MDB2/Driver/Manager/Common.php'; @@ -206,6 +206,7 @@ */ function createTable($name, $fields) { + $name = strtoupper($name); $result = parent::createTable($name, $fields); if (PEAR::isError($result)) { return $result; @@ -243,8 +244,10 @@ return $db->raiseError(MDB2_ERROR, null, null, 'checkSupportedChanges: it is not supported changes to field default value'); case 'length': + /* return $db->raiseError(MDB2_ERROR, null, null, 'checkSupportedChanges: it is not supported changes to field default length'); + */ case 'unsigned': case 'type': case 'declaration': @@ -270,6 +273,7 @@ */ function dropTable($name) { + $name = strtoupper($name); $result = $this->_dropAutoincrement($name); if (PEAR::isError($result)) { return $result; @@ -448,7 +452,7 @@ return MDB2_OK; } - $name = $db->quoteIdentifier($name); + $name = $db->quoteIdentifier(strtoupper($name)); return $db->query("ALTER TABLE $name $query"); } @@ -495,7 +499,6 @@ return $db; } $table = strtoupper($table); - $table = $db->quoteIdentifier($table); $query = "SELECT RDB\$FIELD_NAME FROM RDB\$RELATION_FIELDS WHERE UPPER(RDB\$RELATION_NAME)='$table'"; $result = $db->queryCol($query); if (PEAR::isError($result)) { @@ -609,14 +612,34 @@ } } } - $table = $db->quoteIdentifier($table); - $name = $db->quoteIdentifier($name); + $table = $db->quoteIdentifier(strtoupper($table)); + $name = $db->quoteIdentifier(strtoupper($name)); $query .= $query_sort. " INDEX $name ON $table ("; - $query .= implode(', ', array_keys($definition['fields'])) . ')'; + $fields = array(); + foreach (array_keys($definition['fields']) as $field) { + $fields[] = $db->quoteIdentifier($field); + } + $query .= implode(', ', $fields) . ')'; return $db->query($query); } // }}} + // {{{ dropIndex() + + /** + * drop existing index + * + * @param string $table name of table that should be used in method + * @param string $name name of the index to be dropped + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function dropIndex($table, $name) + { + return parent::dropIndex(strtoupper($table), strtoupper($name)); + } + + // }}} // {{{ listTableIndexes() /** @@ -645,6 +668,67 @@ } // }}} + // {{{ createConstraint() + + /** + * create a constraint on a table + * + * @param string $table name of the table on which the constraint is to be created + * @param string $name name of the constraint to be created + * @param array $definition associative array that defines properties of the constraint to be created. + * Currently, only one property named FIELDS is supported. This property + * is also an associative with the names of the constraint fields as array + * constraints. Each entry of this array is set to another type of associative + * array that specifies properties of the constraint that are specific to + * each field. + * + * Example + * array( + * 'fields' => array( + * 'user_name' => array(), + * 'last_login' => array(), + * ) + * ) + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function createConstraint($table, $name, $definition) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + $table = $db->quoteIdentifier(strtoupper($table)); + $name = $db->quoteIdentifier($name); + $query = "ALTER TABLE $table ADD CONSTRAINT $name"; + if (array_key_exists('primary', $definition) && $definition['primary']) { + $query.= ' PRIMARY KEY'; + } + $fields = array(); + foreach (array_keys($definition['fields']) as $field) { + $fields[] = $db->quoteIdentifier($field); + } + $query .= ' ('. implode(', ', $fields) . ')'; + return $db->query($query); + } + + // }}} + // {{{ dropConstraint() + + /** + * drop existing constraint + * + * @param string $table name of table that should be used in method + * @param string $name name of the constraint to be dropped + * @return mixed MDB2_OK on success, a MDB2 error on failure + * @access public + */ + function dropConstraint($table, $name) + { + return parent::dropConstraint(strtoupper($table), $name); + } + + // }}} // {{{ listTableConstraints() /** @@ -694,11 +778,11 @@ return $db; } - $sequence_name = $db->getSequenceName($seq_name); - if (PEAR::isError($result = $db->query('CREATE GENERATOR '.strtoupper($sequence_name)))) { + $sequence_name = strtoupper($db->getSequenceName($seq_name)); + if (PEAR::isError($result = $db->query('CREATE GENERATOR '.$sequence_name))) { return $result; } - if (PEAR::isError($result = $db->query('SET GENERATOR '.strtoupper($sequence_name).' TO '.($start-1)))) { + if (PEAR::isError($result = $db->query('SET GENERATOR '.$sequence_name.' TO '.($start-1)))) { if (PEAR::isError($err = $db->dropSequence($seq_name))) { return $db->raiseError(MDB2_ERROR, null, null, 'createSequence: Could not setup sequence start value and then it was not possible to drop it: '. @@ -725,8 +809,9 @@ return $db; } - $sequence_name = $db->getSequenceName($seq_name); - return $db->query('DELETE FROM RDB$GENERATORS WHERE UPPER(RDB$GENERATOR_NAME)=\''.strtoupper($sequence_name).'\''); + $sequence_name = strtoupper($db->getSequenceName($seq_name)); + $query = "DELETE FROM RDB\$GENERATORS WHERE UPPER(RDB\$GENERATOR_NAME)='$sequence_name'"; + return $db->query($query); } // }}} @@ -745,14 +830,14 @@ return $db; } - $query = 'SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS'; + $query = 'SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS WHERE RDB$SYSTEM_FLAG IS NULL'; $table_names = $db->queryCol($query); if (PEAR::isError($table_names)) { return $table_names; } $result = array(); - for ($i = 0, $j = count($table_names); $i < $j; ++$i) { - if ($sqn = $this->_isSequenceName($table_names[$i])) { + foreach ($table_names as $table_name) { + if ($sqn = $this->_isSequenceName($table_name)) { $result[] = $sqn; } }