cvs: pear /MDB2/MDB2/Driver/Reverse Common.php ibase.php mssql.php mysql.php mysqli.php oci8.php pgsql.php sqlite.php
| From: | Lorenzo Alberton | Date: | Sun, 25 Feb 2007 11:14:34 +0000 |
| Subject: | cvs: pear /MDB2/MDB2/Driver/Reverse Common.php ibase.php mssql.php mysql.php mysqli.php oci8.php pgsql.php sqlite.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-44869@lists.php.net to get a copy of this message | ||
quipo Sun Feb 25 11:14:34 2007 UTC
Modified files:
/pear/MDB2/MDB2/Driver/Reverse Common.php ibase.php mssql.php
mysql.php mysqli.php oci8.php
pgsql.php sqlite.php
Log:
reverted the last commit and implemented a fallback mechanism within getTableIndexDefinition() and
getTableConstraintDefinition() in the Reverse module to ignore the 'idxname_format' option
and use the index name as provided in case of failure before returning an error
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/Common.php?r1=1.34&r2=1.35&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/Common.php diff -u pear/MDB2/MDB2/Driver/Reverse/Common.php:1.34 pear/MDB2/MDB2/Driver/Reverse/Common.php:1.35 --- pear/MDB2/MDB2/Driver/Reverse/Common.php:1.34 Fri Feb 23 20:09:26 2007 +++ pear/MDB2/MDB2/Driver/Reverse/Common.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.34 2007/02/23 20:09:26 quipo Exp $ +// $Id: Common.php,v 1.35 2007/02/25 11:14:34 quipo Exp $ // /** @@ -102,8 +102,6 @@ * * @param string $table name of table that should be used in method * @param string $index name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * The returned array has this structure: * </pre> @@ -119,7 +117,7 @@ * </pre> * @access public */ - function getTableIndexDefinition($table, $index, $format_index_name = true) + function getTableIndexDefinition($table, $index) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -138,8 +136,6 @@ * * @param string $table name of table that should be used in method * @param string $index name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * The returned array has this structure: * <pre> @@ -156,7 +152,7 @@ * </pre> * @access public */ - function getTableConstraintDefinition($table, $index, $format_index_name = true) + function getTableConstraintDefinition($table, $index) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/ibase.php?r1=1.64&r2=1.65&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/ibase.php diff -u pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.64 pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.65 --- pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.64 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/ibase.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.64 2007/02/23 19:57:35 quipo Exp $ +// $Id: ibase.php,v 1.65 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -223,8 +223,6 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ @@ -235,10 +233,6 @@ return $db; } $table = $db->quote(strtoupper($table), 'text'); - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } - $index_name = $db->quote(strtoupper($index_name), 'text'); $query = "SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name, RDB\$INDICES.RDB\$UNIQUE_FLAG AS unique_flag, RDB\$INDICES.RDB\$FOREIGN_KEY AS foreign_key, @@ -247,10 +241,19 @@ LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)=$table - AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=$index_name + AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=%s AND RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE IS NULL ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION;"; - $result = $db->query($query); + $index_name_mdb2 = $db->quote(strtoupper($db->getIndexName($index_name)), 'text'); + $result = $db->queryRow(sprintf($query, $index_name_mdb2)); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } else { + $index_name = $db->quote(strtoupper($index_name), 'text'); + } + $result = $db->query(sprintf($query, $index_name)); if (PEAR::isError($result)) { return $result; } @@ -294,22 +297,17 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } + $table = $db->quote(strtoupper($table), 'text'); - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } - $index_name = $db->quote(strtoupper($index_name), 'text'); $query = "SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name, RDB\$INDICES.RDB\$UNIQUE_FLAG AS unique_flag, RDB\$INDICES.RDB\$FOREIGN_KEY AS foreign_key, @@ -319,9 +317,18 @@ LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)=$table - AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=$index_name + AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=%s ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION;"; - $result = $db->query($query); + $index_name_mdb2 = $db->quote(strtoupper($db->getIndexName($index_name)), 'text'); + $result = $db->queryRow(sprintf($query, $index_name_mdb2)); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } else { + $index_name = $db->quote(strtoupper($index_name), 'text'); + } + $result = $db->query(sprintf($query, $index_name)); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/mssql.php?r1=1.32&r2=1.33&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/mssql.php diff -u pear/MDB2/MDB2/Driver/Reverse/mssql.php:1.32 pear/MDB2/MDB2/Driver/Reverse/mssql.php:1.33 --- pear/MDB2/MDB2/Driver/Reverse/mssql.php:1.32 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/mssql.php Sun Feb 25 11:14:34 2007 @@ -43,7 +43,7 @@ // | Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.32 2007/02/23 19:57:35 quipo Exp $ +// $Id: mssql.php,v 1.33 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -183,21 +183,16 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); //$idxname = $db->quoteIdentifier($index_name, true); @@ -215,10 +210,17 @@ JOIN sysindexkeys ik ON ik.id = i.id AND ik.indid = i.indid JOIN syscolumns c ON c.id = ik.id AND c.colid = ik.colid WHERE OBJECT_NAME(i.id) = '$table' - AND i.name = '$index_name' + AND i.name = '%s' ORDER BY tablename, indexname, ik.keyno"; - $result = $db->query($query); + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $index_name_mdb2)); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $result = $db->query(sprintf($query, $index_name)); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/mysql.php?r1=1.64&r2=1.65&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/mysql.php diff -u pear/MDB2/MDB2/Driver/Reverse/mysql.php:1.64 pear/MDB2/MDB2/Driver/Reverse/mysql.php:1.65 --- pear/MDB2/MDB2/Driver/Reverse/mysql.php:1.64 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/mysql.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.64 2007/02/23 19:57:35 quipo Exp $ +// $Id: mysql.php,v 1.65 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -162,24 +162,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } @@ -230,24 +232,28 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if (strtolower($index_name) != 'primary' && $format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + if (strtolower($index_name) != 'primary') { + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/mysqli.php?r1=1.55&r2=1.56&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/mysqli.php diff -u pear/MDB2/MDB2/Driver/Reverse/mysqli.php:1.55 pear/MDB2/MDB2/Driver/Reverse/mysqli.php:1.56 --- pear/MDB2/MDB2/Driver/Reverse/mysqli.php:1.55 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/mysqli.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.55 2007/02/23 19:57:35 quipo Exp $ +// $Id: mysqli.php,v 1.56 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -216,24 +216,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } @@ -284,24 +286,28 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if (strtolower($index_name) != 'primary' && $format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + if (strtolower($index_name) != 'primary') { + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/oci8.php?r1=1.55&r2=1.56&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/oci8.php diff -u pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.55 pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.56 --- pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.55 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/oci8.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: oci8.php,v 1.55 2007/02/23 19:57:35 quipo Exp $ +// $Id: oci8.php,v 1.56 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -155,30 +155,40 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } - $definition = array(); - + $query = 'SELECT * FROM user_ind_columns'; $query.= ' WHERE (table_name='.$db->quote($table, 'text').' OR table_name='.$db->quote(strtoupper($table), 'text').')'; - $query.= ' AND (index_name='.$db->quote($index_name, 'text').' OR index_name='.$db->quote(strtoupper($index_name), 'text').')'; - $result = $db->query($query); + $query.= ' AND (index_name=%s OR index_name=%s)'; + $index_name_mdb2 = $db->getIndexName($index_name); + $sql = sprintf($query, + $db->quote($index_name_mdb2, 'text'), + $db->quote(strtoupper($index_name_mdb2), 'text') + ); + $result = $db->queryRow($sql); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $sql = sprintf($query, + $db->quote($index_name, 'text'), + $db->quote(strtoupper($index_name), 'text') + ); + $result = $db->query($sql); if (PEAR::isError($result)) { return $result; } + + $definition = array(); while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { $row = array_change_key_case($row, CASE_LOWER); $column_name = $row['column_name']; @@ -211,28 +221,40 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if (strtolower($index_name) != 'primary' && $format_index_name) { - $index_name = $db->getIndexName($index_name); - } + $query = 'SELECT "all".constraint_type, cols.column_name'; $query.= ' FROM all_constraints "all", all_cons_columns cols'; $query.= ' WHERE ("all".table_name='.$db->quote($table, 'text').' OR "all".table_name='.$db->quote(strtoupper($table), 'text').')'; - $query.= ' AND ("all".index_name='.$db->quote($index_name, 'text').' OR "all".index_name='.$db->quote(strtoupper($index_name), 'text').')'; + $query.= ' AND ("all".index_name=%s OR "all".index_name=%s)'; $query.= ' AND "all".constraint_name = cols.constraint_name'; $query.= ' AND "all".owner = '.$db->quote(strtoupper($db->dsn['username']), 'text'); - $result = $db->query($query); + if (strtolower($index_name) != 'primary') { + $index_name_mdb2 = $db->getIndexName($index_name); + $sql = sprintf($query, + $db->quote($index_name_mdb2, 'text'), + $db->quote(strtoupper($index_name_mdb2), 'text') + ); + $result = $db->queryRow($sql); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + } + $sql = sprintf($query, + $db->quote($index_name, 'text'), + $db->quote(strtoupper($index_name), 'text') + ); + $result = $db->query($sql); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/pgsql.php?r1=1.55&r2=1.56&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/pgsql.php diff -u pear/MDB2/MDB2/Driver/Reverse/pgsql.php:1.55 pear/MDB2/MDB2/Driver/Reverse/pgsql.php:1.56 --- pear/MDB2/MDB2/Driver/Reverse/pgsql.php:1.55 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/pgsql.php Sun Feb 25 11:14:34 2007 @@ -43,7 +43,7 @@ // | Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.55 2007/02/23 19:57:35 quipo Exp $ +// $Id: pgsql.php,v 1.56 2007/02/25 11:14:34 quipo Exp $ require_once 'MDB2/Driver/Reverse/Common.php'; @@ -159,26 +159,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } + $query = 'SELECT relname, indkey FROM pg_index, pg_class'; $query.= ' WHERE pg_class.oid = pg_index.indexrelid'; $query.= " AND indisunique != 't' AND indisprimary != 't'"; - $query.= ' AND pg_class.relname = '.$db->quote($index_name, 'text'); - $row = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC); + $query.= ' AND pg_class.relname = %s'; + $index_name_mdb2 = $db->getIndexName($index_name); + $row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); + if (PEAR::isError($row) || empty($row)) { + // fallback to the given $index_name, without transformation + $row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC); + } if (PEAR::isError($row)) { return $row; } @@ -210,26 +210,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } + $query = 'SELECT relname, indisunique, indisprimary, indkey FROM pg_index, pg_class'; $query.= ' WHERE pg_class.oid = pg_index.indexrelid'; $query.= " AND (indisunique = 't' OR indisprimary = 't')"; - $query.= ' AND pg_class.relname = '.$db->quote($index_name, 'text'); - $row = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC); + $query.= ' AND pg_class.relname = %s'; + $index_name_mdb2 = $db->getIndexName($index_name); + $row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); + if (PEAR::isError($row) || empty($row)) { + // fallback to the given $index_name, without transformation + $row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC); + } if (PEAR::isError($row)) { return $row; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/sqlite.php?r1=1.62&r2=1.63&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/sqlite.php diff -u pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.62 pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.63 --- pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.62 Fri Feb 23 19:57:36 2007 +++ pear/MDB2/MDB2/Driver/Reverse/sqlite.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.62 2007/02/23 19:57:36 quipo Exp $ +// $Id: sqlite.php,v 1.63 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -226,29 +226,39 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $query = "SELECT sql FROM sqlite_master WHERE type='index' AND "; if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { - $query.= "LOWER(name)=".$db->quote(strtolower($index_name), 'text')." AND LOWER(tbl_name)=".$db->quote(strtolower($table), 'text'); + $query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text'); } else { - $query.= 'name='.$db->quote($index_name, 'text').' AND tbl_name='.$db->quote($table, 'text'); + $query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text'); + } + $query.= ' AND sql NOT NULL ORDER BY name'; + $index_name_mdb2 = $db->getIndexName($index_name); + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name_mdb2), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name_mdb2, 'text')); + } + $sql = $db->queryOne($qry, 'text'); + if (PEAR::isError($sql) || empty($sql)) { + // fallback to the given $index_name, without transformation + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name, 'text')); + } + $sql = $db->queryOne($qry, 'text'); } - $query.= " AND sql NOT NULL ORDER BY name"; - $sql = $db->queryOne($query, 'text'); if (PEAR::isError($sql)) { return $sql; } @@ -295,35 +305,45 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $query = "SELECT sql FROM sqlite_master WHERE type='index' AND "; if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { - $query.= "LOWER(name)=".$db->quote(strtolower($index_name), 'text')." AND LOWER(tbl_name)=".$db->quote(strtolower($table), 'text'); + $query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text'); } else { - $query.= 'name='.$db->quote($index_name, 'text').' AND tbl_name='.$db->quote($table, 'text'); + $query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text'); + } + $query.= ' AND sql NOT NULL ORDER BY name'; + $index_name_mdb2 = $db->getIndexName($index_name); + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name_mdb2), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name_mdb2, 'text')); + } + $sql = $db->queryOne($qry, 'text'); + if (PEAR::isError($sql) || empty($sql)) { + // fallback to the given $index_name, without transformation + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name, 'text')); + } + $sql = $db->queryOne($qry, 'text'); } - $query.= " AND sql NOT NULL ORDER BY name"; - $sql = $db->queryOne($query, 'text'); if (PEAR::isError($sql)) { return $sql; } if (!$sql) { return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, - 'it was not specified an existing table index', __FUNCTION__); + 'it was not specified an existing table constraint', __FUNCTION__); } $sql = strtolower($sql);
http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/Common.php?r1=1.34&r2=1.35&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/Common.php diff -u pear/MDB2/MDB2/Driver/Reverse/Common.php:1.34 pear/MDB2/MDB2/Driver/Reverse/Common.php:1.35 --- pear/MDB2/MDB2/Driver/Reverse/Common.php:1.34 Fri Feb 23 20:09:26 2007 +++ pear/MDB2/MDB2/Driver/Reverse/Common.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Common.php,v 1.34 2007/02/23 20:09:26 quipo Exp $ +// $Id: Common.php,v 1.35 2007/02/25 11:14:34 quipo Exp $ // /** @@ -102,8 +102,6 @@ * * @param string $table name of table that should be used in method * @param string $index name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * The returned array has this structure: * </pre> @@ -119,7 +117,7 @@ * </pre> * @access public */ - function getTableIndexDefinition($table, $index, $format_index_name = true) + function getTableIndexDefinition($table, $index) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { @@ -138,8 +136,6 @@ * * @param string $table name of table that should be used in method * @param string $index name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * The returned array has this structure: * <pre> @@ -156,7 +152,7 @@ * </pre> * @access public */ - function getTableConstraintDefinition($table, $index, $format_index_name = true) + function getTableConstraintDefinition($table, $index) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/ibase.php?r1=1.64&r2=1.65&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/ibase.php diff -u pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.64 pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.65 --- pear/MDB2/MDB2/Driver/Reverse/ibase.php:1.64 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/ibase.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.64 2007/02/23 19:57:35 quipo Exp $ +// $Id: ibase.php,v 1.65 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -223,8 +223,6 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ @@ -235,10 +233,6 @@ return $db; } $table = $db->quote(strtoupper($table), 'text'); - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } - $index_name = $db->quote(strtoupper($index_name), 'text'); $query = "SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name, RDB\$INDICES.RDB\$UNIQUE_FLAG AS unique_flag, RDB\$INDICES.RDB\$FOREIGN_KEY AS foreign_key, @@ -247,10 +241,19 @@ LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)=$table - AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=$index_name + AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=%s AND RDB\$RELATION_CONSTRAINTS.RDB\$CONSTRAINT_TYPE IS NULL ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION;"; - $result = $db->query($query); + $index_name_mdb2 = $db->quote(strtoupper($db->getIndexName($index_name)), 'text'); + $result = $db->queryRow(sprintf($query, $index_name_mdb2)); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } else { + $index_name = $db->quote(strtoupper($index_name), 'text'); + } + $result = $db->query(sprintf($query, $index_name)); if (PEAR::isError($result)) { return $result; } @@ -294,22 +297,17 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } + $table = $db->quote(strtoupper($table), 'text'); - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } - $index_name = $db->quote(strtoupper($index_name), 'text'); $query = "SELECT RDB\$INDEX_SEGMENTS.RDB\$FIELD_NAME AS field_name, RDB\$INDICES.RDB\$UNIQUE_FLAG AS unique_flag, RDB\$INDICES.RDB\$FOREIGN_KEY AS foreign_key, @@ -319,9 +317,18 @@ LEFT JOIN RDB\$INDICES ON RDB\$INDICES.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME LEFT JOIN RDB\$RELATION_CONSTRAINTS ON RDB\$RELATION_CONSTRAINTS.RDB\$INDEX_NAME = RDB\$INDEX_SEGMENTS.RDB\$INDEX_NAME WHERE UPPER(RDB\$INDICES.RDB\$RELATION_NAME)=$table - AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=$index_name + AND UPPER(RDB\$INDICES.RDB\$INDEX_NAME)=%s ORDER BY RDB\$INDEX_SEGMENTS.RDB\$FIELD_POSITION;"; - $result = $db->query($query); + $index_name_mdb2 = $db->quote(strtoupper($db->getIndexName($index_name)), 'text'); + $result = $db->queryRow(sprintf($query, $index_name_mdb2)); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } else { + $index_name = $db->quote(strtoupper($index_name), 'text'); + } + $result = $db->query(sprintf($query, $index_name)); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/mssql.php?r1=1.32&r2=1.33&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/mssql.php diff -u pear/MDB2/MDB2/Driver/Reverse/mssql.php:1.32 pear/MDB2/MDB2/Driver/Reverse/mssql.php:1.33 --- pear/MDB2/MDB2/Driver/Reverse/mssql.php:1.32 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/mssql.php Sun Feb 25 11:14:34 2007 @@ -43,7 +43,7 @@ // | Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: mssql.php,v 1.32 2007/02/23 19:57:35 quipo Exp $ +// $Id: mssql.php,v 1.33 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -183,21 +183,16 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); //$idxname = $db->quoteIdentifier($index_name, true); @@ -215,10 +210,17 @@ JOIN sysindexkeys ik ON ik.id = i.id AND ik.indid = i.indid JOIN syscolumns c ON c.id = ik.id AND c.colid = ik.colid WHERE OBJECT_NAME(i.id) = '$table' - AND i.name = '$index_name' + AND i.name = '%s' ORDER BY tablename, indexname, ik.keyno"; - $result = $db->query($query); + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $index_name_mdb2)); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $result = $db->query(sprintf($query, $index_name)); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/mysql.php?r1=1.64&r2=1.65&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/mysql.php diff -u pear/MDB2/MDB2/Driver/Reverse/mysql.php:1.64 pear/MDB2/MDB2/Driver/Reverse/mysql.php:1.65 --- pear/MDB2/MDB2/Driver/Reverse/mysql.php:1.64 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/mysql.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysql.php,v 1.64 2007/02/23 19:57:35 quipo Exp $ +// $Id: mysql.php,v 1.65 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -162,24 +162,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } @@ -230,24 +232,28 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if (strtolower($index_name) != 'primary' && $format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + if (strtolower($index_name) != 'primary') { + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/mysqli.php?r1=1.55&r2=1.56&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/mysqli.php diff -u pear/MDB2/MDB2/Driver/Reverse/mysqli.php:1.55 pear/MDB2/MDB2/Driver/Reverse/mysqli.php:1.56 --- pear/MDB2/MDB2/Driver/Reverse/mysqli.php:1.55 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/mysqli.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: mysqli.php,v 1.55 2007/02/23 19:57:35 quipo Exp $ +// $Id: mysqli.php,v 1.56 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -216,24 +216,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } @@ -284,24 +286,28 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if (strtolower($index_name) != 'primary' && $format_index_name) { - $index_name = $db->getIndexName($index_name); - } $table = $db->quoteIdentifier($table, true); - $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = ".$db->quote($index_name)." */"; - $result = $db->query($query); + $query = "SHOW INDEX FROM $table /*!50002 WHERE Key_name = %s */"; + if (strtolower($index_name) != 'primary') { + $index_name_mdb2 = $db->getIndexName($index_name); + $result = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2))); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + } + $result = $db->query(sprintf($query, $db->quote($index_name))); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/oci8.php?r1=1.55&r2=1.56&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/oci8.php diff -u pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.55 pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.56 --- pear/MDB2/MDB2/Driver/Reverse/oci8.php:1.55 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/oci8.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: oci8.php,v 1.55 2007/02/23 19:57:35 quipo Exp $ +// $Id: oci8.php,v 1.56 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -155,30 +155,40 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } - $definition = array(); - + $query = 'SELECT * FROM user_ind_columns'; $query.= ' WHERE (table_name='.$db->quote($table, 'text').' OR table_name='.$db->quote(strtoupper($table), 'text').')'; - $query.= ' AND (index_name='.$db->quote($index_name, 'text').' OR index_name='.$db->quote(strtoupper($index_name), 'text').')'; - $result = $db->query($query); + $query.= ' AND (index_name=%s OR index_name=%s)'; + $index_name_mdb2 = $db->getIndexName($index_name); + $sql = sprintf($query, + $db->quote($index_name_mdb2, 'text'), + $db->quote(strtoupper($index_name_mdb2), 'text') + ); + $result = $db->queryRow($sql); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + $sql = sprintf($query, + $db->quote($index_name, 'text'), + $db->quote(strtoupper($index_name), 'text') + ); + $result = $db->query($sql); if (PEAR::isError($result)) { return $result; } + + $definition = array(); while ($row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) { $row = array_change_key_case($row, CASE_LOWER); $column_name = $row['column_name']; @@ -211,28 +221,40 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if (strtolower($index_name) != 'primary' && $format_index_name) { - $index_name = $db->getIndexName($index_name); - } + $query = 'SELECT "all".constraint_type, cols.column_name'; $query.= ' FROM all_constraints "all", all_cons_columns cols'; $query.= ' WHERE ("all".table_name='.$db->quote($table, 'text').' OR "all".table_name='.$db->quote(strtoupper($table), 'text').')'; - $query.= ' AND ("all".index_name='.$db->quote($index_name, 'text').' OR "all".index_name='.$db->quote(strtoupper($index_name), 'text').')'; + $query.= ' AND ("all".index_name=%s OR "all".index_name=%s)'; $query.= ' AND "all".constraint_name = cols.constraint_name'; $query.= ' AND "all".owner = '.$db->quote(strtoupper($db->dsn['username']), 'text'); - $result = $db->query($query); + if (strtolower($index_name) != 'primary') { + $index_name_mdb2 = $db->getIndexName($index_name); + $sql = sprintf($query, + $db->quote($index_name_mdb2, 'text'), + $db->quote(strtoupper($index_name_mdb2), 'text') + ); + $result = $db->queryRow($sql); + if (!PEAR::isError($result) && !is_null($result)) { + // apply 'idxname_format' only if the query succeeded, otherwise + // fallback to the given $index_name, without transformation + $index_name = $index_name_mdb2; + } + } + $sql = sprintf($query, + $db->quote($index_name, 'text'), + $db->quote(strtoupper($index_name), 'text') + ); + $result = $db->query($sql); if (PEAR::isError($result)) { return $result; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/pgsql.php?r1=1.55&r2=1.56&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/pgsql.php diff -u pear/MDB2/MDB2/Driver/Reverse/pgsql.php:1.55 pear/MDB2/MDB2/Driver/Reverse/pgsql.php:1.56 --- pear/MDB2/MDB2/Driver/Reverse/pgsql.php:1.55 Fri Feb 23 19:57:35 2007 +++ pear/MDB2/MDB2/Driver/Reverse/pgsql.php Sun Feb 25 11:14:34 2007 @@ -43,7 +43,7 @@ // | Lorenzo Alberton <l.alberton@quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: pgsql.php,v 1.55 2007/02/23 19:57:35 quipo Exp $ +// $Id: pgsql.php,v 1.56 2007/02/25 11:14:34 quipo Exp $ require_once 'MDB2/Driver/Reverse/Common.php'; @@ -159,26 +159,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } + $query = 'SELECT relname, indkey FROM pg_index, pg_class'; $query.= ' WHERE pg_class.oid = pg_index.indexrelid'; $query.= " AND indisunique != 't' AND indisprimary != 't'"; - $query.= ' AND pg_class.relname = '.$db->quote($index_name, 'text'); - $row = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC); + $query.= ' AND pg_class.relname = %s'; + $index_name_mdb2 = $db->getIndexName($index_name); + $row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); + if (PEAR::isError($row) || empty($row)) { + // fallback to the given $index_name, without transformation + $row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC); + } if (PEAR::isError($row)) { return $row; } @@ -210,26 +210,26 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } + $query = 'SELECT relname, indisunique, indisprimary, indkey FROM pg_index, pg_class'; $query.= ' WHERE pg_class.oid = pg_index.indexrelid'; $query.= " AND (indisunique = 't' OR indisprimary = 't')"; - $query.= ' AND pg_class.relname = '.$db->quote($index_name, 'text'); - $row = $db->queryRow($query, null, MDB2_FETCHMODE_ASSOC); + $query.= ' AND pg_class.relname = %s'; + $index_name_mdb2 = $db->getIndexName($index_name); + $row = $db->queryRow(sprintf($query, $db->quote($index_name_mdb2, 'text')), null, MDB2_FETCHMODE_ASSOC); + if (PEAR::isError($row) || empty($row)) { + // fallback to the given $index_name, without transformation + $row = $db->queryRow(sprintf($query, $db->quote($index_name, 'text')), null, MDB2_FETCHMODE_ASSOC); + } if (PEAR::isError($row)) { return $row; } http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Driver/Reverse/sqlite.php?r1=1.62&r2=1.63&diff_format=u Index: pear/MDB2/MDB2/Driver/Reverse/sqlite.php diff -u pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.62 pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.63 --- pear/MDB2/MDB2/Driver/Reverse/sqlite.php:1.62 Fri Feb 23 19:57:36 2007 +++ pear/MDB2/MDB2/Driver/Reverse/sqlite.php Sun Feb 25 11:14:34 2007 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: sqlite.php,v 1.62 2007/02/23 19:57:36 quipo Exp $ +// $Id: sqlite.php,v 1.63 2007/02/25 11:14:34 quipo Exp $ // require_once 'MDB2/Driver/Reverse/Common.php'; @@ -226,29 +226,39 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableIndexDefinition($table, $index_name, $format_index_name = true) + function getTableIndexDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $query = "SELECT sql FROM sqlite_master WHERE type='index' AND "; if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { - $query.= "LOWER(name)=".$db->quote(strtolower($index_name), 'text')." AND LOWER(tbl_name)=".$db->quote(strtolower($table), 'text'); + $query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text'); } else { - $query.= 'name='.$db->quote($index_name, 'text').' AND tbl_name='.$db->quote($table, 'text'); + $query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text'); + } + $query.= ' AND sql NOT NULL ORDER BY name'; + $index_name_mdb2 = $db->getIndexName($index_name); + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name_mdb2), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name_mdb2, 'text')); + } + $sql = $db->queryOne($qry, 'text'); + if (PEAR::isError($sql) || empty($sql)) { + // fallback to the given $index_name, without transformation + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name, 'text')); + } + $sql = $db->queryOne($qry, 'text'); } - $query.= " AND sql NOT NULL ORDER BY name"; - $sql = $db->queryOne($query, 'text'); if (PEAR::isError($sql)) { return $sql; } @@ -295,35 +305,45 @@ * * @param string $table name of table that should be used in method * @param string $index_name name of index that should be used in method - * @param boolean $format_index_name if FALSE, the 'idxname_format' option - * is not applied and the index name is used as-is * @return mixed data array on success, a MDB2 error on failure * @access public */ - function getTableConstraintDefinition($table, $index_name, $format_index_name = true) + function getTableConstraintDefinition($table, $index_name) { $db =& $this->getDBInstance(); if (PEAR::isError($db)) { return $db; } - if ($format_index_name) { - $index_name = $db->getIndexName($index_name); - } $query = "SELECT sql FROM sqlite_master WHERE type='index' AND "; if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { - $query.= "LOWER(name)=".$db->quote(strtolower($index_name), 'text')." AND LOWER(tbl_name)=".$db->quote(strtolower($table), 'text'); + $query.= 'LOWER(name)=%s AND LOWER(tbl_name)=' . $db->quote(strtolower($table), 'text'); } else { - $query.= 'name='.$db->quote($index_name, 'text').' AND tbl_name='.$db->quote($table, 'text'); + $query.= 'name=%s AND tbl_name=' . $db->quote($table, 'text'); + } + $query.= ' AND sql NOT NULL ORDER BY name'; + $index_name_mdb2 = $db->getIndexName($index_name); + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name_mdb2), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name_mdb2, 'text')); + } + $sql = $db->queryOne($qry, 'text'); + if (PEAR::isError($sql) || empty($sql)) { + // fallback to the given $index_name, without transformation + if ($db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) { + $qry = sprintf($query, $db->quote(strtolower($index_name), 'text')); + } else { + $qry = sprintf($query, $db->quote($index_name, 'text')); + } + $sql = $db->queryOne($qry, 'text'); } - $query.= " AND sql NOT NULL ORDER BY name"; - $sql = $db->queryOne($query, 'text'); if (PEAR::isError($sql)) { return $sql; } if (!$sql) { return $db->raiseError(MDB2_ERROR_NOT_FOUND, null, null, - 'it was not specified an existing table index', __FUNCTION__); + 'it was not specified an existing table constraint', __FUNCTION__); } $sql = strtolower($sql);