From: Andrey Kutejko Date: Sat, 27 Jul 2013 12:36:47 +0000 (+0300) Subject: simplify export of indexes X-Git-Tag: 0.6~65 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=2cb3d1d88e3866f7e0d307f5160b9fd8ae6c7293;p=ipf-legacy-orm.git simplify export of indexes --- diff --git a/ipf/orm.php b/ipf/orm.php index a34f2c3..cdc1bef 100644 --- a/ipf/orm.php +++ b/ipf/orm.php @@ -99,11 +99,9 @@ final class IPF_ORM const ATTR_MAX_COLUMN_LEN = 18; const ATTR_FIELD_CASE = 102; - const ATTR_IDXNAME_FORMAT = 103; const ATTR_CMPNAME_FORMAT = 118; const ATTR_DBNAME_FORMAT = 117; const ATTR_TBLCLASS_FORMAT = 119; - const ATTR_TBLNAME_FORMAT = 120; const ATTR_EXPORT = 140; const ATTR_DECIMAL_PLACES = 141; diff --git a/ipf/orm/configurable.php b/ipf/orm/configurable.php index 4ef9932..a2d82bc 100644 --- a/ipf/orm/configurable.php +++ b/ipf/orm/configurable.php @@ -81,13 +81,6 @@ abstract class IPF_ORM_Configurable if ($value != 0 && $value != CASE_LOWER && $value != CASE_UPPER) throw new IPF_ORM_Exception('Field case attribute should be either 0, CASE_LOWER or CASE_UPPER constant.'); break; - case IPF_ORM::ATTR_IDXNAME_FORMAT: - case IPF_ORM::ATTR_TBLNAME_FORMAT: - if ($this instanceof IPF_ORM_Table) { - throw new IPF_ORM_Exception('index name format attributes cannot be set' - . 'at table level (only at connection or global level).'); - } - break; default: throw new IPF_ORM_Exception("Unknown attribute."); } diff --git a/ipf/orm/export.php b/ipf/orm/export.php index a6d1ef6..e6fb191 100644 --- a/ipf/orm/export.php +++ b/ipf/orm/export.php @@ -17,6 +17,11 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module 'string' => '' ); + protected function getIndexName($name) + { + return $name . '_idx'; + } + public function dropDatabase($database) { $this->conn->execute($this->dropDatabaseSql($database)); @@ -44,7 +49,7 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module public function dropIndexSql($table, $name) { - $name = $this->conn->quoteIdentifier($this->conn->formatter->getIndexName($name)); + $name = $this->conn->quoteIdentifier($this->getIndexName($name)); return 'DROP INDEX ' . $name; } @@ -128,7 +133,7 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module public function createConstraintSql($table, $name, $definition) { $table = $this->conn->quoteIdentifier($table); - $name = $this->conn->quoteIdentifier($this->conn->formatter->getIndexName($name)); + $name = $this->conn->quoteIdentifier($this->getIndexName($name)); $query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $name; if (isset($definition['primary']) && $definition['primary']) { diff --git a/ipf/orm/export/mysql.php b/ipf/orm/export/mysql.php index 27d6edb..34af481 100644 --- a/ipf/orm/export/mysql.php +++ b/ipf/orm/export/mysql.php @@ -386,9 +386,7 @@ class IPF_ORM_Export_Mysql extends IPF_ORM_Export public function createIndexSql($table, $name, array $definition) { - $table = $table; - $name = $this->conn->formatter->getIndexName($name); - $name = $this->conn->quoteIdentifier($name); + $name = $this->conn->quoteIdentifier($this->getIndexName($name)); $type = ''; if (isset($definition['type'])) { switch (strtolower($definition['type'])) { @@ -408,7 +406,7 @@ class IPF_ORM_Export_Mysql extends IPF_ORM_Export public function getIndexDeclaration($name, array $definition) { - $name = $this->conn->formatter->getIndexName($name); + $name = $this->getIndexName($name); $type = ''; if (isset($definition['type'])) { switch (strtolower($definition['type'])) { @@ -484,7 +482,7 @@ class IPF_ORM_Export_Mysql extends IPF_ORM_Export public function dropIndexSql($table, $name) { $table = $this->conn->quoteIdentifier($table); - $name = $this->conn->quoteIdentifier($this->conn->formatter->getIndexName($name)); + $name = $this->conn->quoteIdentifier($this->getIndexName($name)); return 'DROP INDEX ' . $name . ' ON ' . $table; } diff --git a/ipf/orm/formatter.php b/ipf/orm/formatter.php index c61eb4d..6ff634d 100644 --- a/ipf/orm/formatter.php +++ b/ipf/orm/formatter.php @@ -18,17 +18,5 @@ class IPF_ORM_Formatter extends IPF_ORM_Connection_Module } return $text; } - - public function getIndexName($idx) - { - return sprintf($this->conn->getAttribute(IPF_ORM::ATTR_IDXNAME_FORMAT), - preg_replace('/[^a-z0-9_\$]/i', '_', $idx)); - } - - public function getTableName($table) - { - return sprintf($this->conn->getAttribute(IPF_ORM::ATTR_TBLNAME_FORMAT), - $table); - } } diff --git a/ipf/orm/manager.php b/ipf/orm/manager.php index b206559..e209a00 100644 --- a/ipf/orm/manager.php +++ b/ipf/orm/manager.php @@ -13,8 +13,6 @@ class IPF_ORM_Manager extends IPF_ORM_Configurable implements Countable, Iterato { $this->attributes = array( IPF_ORM::ATTR_LOAD_REFERENCES => true, - IPF_ORM::ATTR_IDXNAME_FORMAT => "%s_idx", - IPF_ORM::ATTR_TBLNAME_FORMAT => "%s", IPF_ORM::ATTR_PORTABILITY => IPF_ORM::PORTABILITY_ALL, IPF_ORM::ATTR_EXPORT => IPF_ORM::EXPORT_ALL, IPF_ORM::ATTR_DECIMAL_PLACES => 2, diff --git a/ipf/orm/table.php b/ipf/orm/table.php index 90834c5..73ce2a4 100644 --- a/ipf/orm/table.php +++ b/ipf/orm/table.php @@ -980,7 +980,7 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable public function setTableName($tableName) { - $this->setOption('tableName', $this->_conn->formatter->getTableName($tableName)); + $this->setOption('tableName', $tableName); } public function getTemplate($template)