]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
simplify export of indexes
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 12:36:47 +0000 (15:36 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 12:36:47 +0000 (15:36 +0300)
ipf/orm.php
ipf/orm/configurable.php
ipf/orm/export.php
ipf/orm/export/mysql.php
ipf/orm/formatter.php
ipf/orm/manager.php
ipf/orm/table.php

index a34f2c3004138cb71ab6b2a1775e865e48b7e10a..cdc1bef8584911b56e2beaeb0672b538494da195 100644 (file)
@@ -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;
 
index 4ef99325bbec33d3c25cd7c9c59fafbd9bb422ba..a2d82bc8f3011c0ca88e3db524bebb571d14b4ed 100644 (file)
@@ -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.");
         }
index a6d1ef6e30d589def4f26386b6568ce8afec5ebd..e6fb1918c4c7020bd0484125efe5a664bd540e4c 100644 (file)
@@ -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']) {
index 27d6edbea4f260d1f320ff196591eec2bffe1d3b..34af481d0193d61602d1e45f203a100f3d2b9e37 100644 (file)
@@ -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;
     }
 
index c61eb4d10ebbe01ed0b385af1c12104ab3428c9a..6ff634d0c4d63f7f8c9050f6afa22115b61c7952 100644 (file)
@@ -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);
-    }
 }
 
index b206559d0d5308d6077968a695501e3db7b16087..e209a00e82bb78801ca05b8940066031919d2982 100644 (file)
@@ -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,
index 90834c5228f07b846b25598217d96e69999eaa37..73ce2a40a99598624028353323fdd4aa8202fc75 100644 (file)
@@ -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)