]> git.andy128k.dev Git - ipf-legacy-orm.git/commitdiff
delete buggy sequences
authorAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 06:39:26 +0000 (09:39 +0300)
committerAndrey Kutejko <andy128k@gmail.com>
Sat, 27 Jul 2013 06:39:26 +0000 (09:39 +0300)
14 files changed:
ipf/orm.php
ipf/orm/configurable.php
ipf/orm/connection.php
ipf/orm/connection/unitofwork.php
ipf/orm/export.php
ipf/orm/export/mysql.php
ipf/orm/formatter.php
ipf/orm/import/schema.php
ipf/orm/manager.php
ipf/orm/record.php
ipf/orm/relation/parser.php
ipf/orm/sequence.php [deleted file]
ipf/orm/sequence/mysql.php [deleted file]
ipf/orm/table.php

index 43bbc49962845b4322bd52ba4483df53c49e135d..a216def34e2c8b3bdb478db76e2a84b3ea4e7d30 100644 (file)
@@ -101,8 +101,6 @@ final class IPF_ORM
     const ATTR_QUOTE_IDENTIFIER     = 101;
     const ATTR_FIELD_CASE           = 102;
     const ATTR_IDXNAME_FORMAT       = 103;
-    const ATTR_SEQNAME_FORMAT       = 104;
-    const ATTR_SEQCOL_NAME          = 105;
     const ATTR_CMPNAME_FORMAT       = 118;
     const ATTR_DBNAME_FORMAT        = 117;
     const ATTR_TBLCLASS_FORMAT      = 119;
@@ -118,7 +116,6 @@ final class IPF_ORM
     const ATTR_DEF_TABLESPACE       = 115;
     const ATTR_EMULATE_DATABASE     = 116;
     const ATTR_USE_NATIVE_ENUM      = 117;
-    const ATTR_DEFAULT_SEQUENCE     = 133;
 
     //const ATTR_FETCHMODE                = 118;
     const ATTR_NAME_PREFIX              = 121;
@@ -167,7 +164,6 @@ final class IPF_ORM
 
     const HYDRATE_NONE              = 4;
     const IDENTIFIER_AUTOINC        = 1;
-    const IDENTIFIER_SEQUENCE       = 2;
     const IDENTIFIER_NATURAL        = 3;
     const IDENTIFIER_COMPOSITE      = 4;
     const MODEL_LOADING_AGGRESSIVE   = 1;
index b629ec0fc168a51e160d07e3869cdefe631a23bc..ce12e9429bc5c78427cb25a54f68e23d9884057e 100644 (file)
@@ -67,7 +67,6 @@ abstract class IPF_ORM_Configurable
             case IPF_ORM::ATTR_DEFAULT_TABLE_TYPE:
             case IPF_ORM::ATTR_EMULATE_DATABASE:
             case IPF_ORM::ATTR_USE_NATIVE_ENUM:
-            case IPF_ORM::ATTR_DEFAULT_SEQUENCE:
             case IPF_ORM::ATTR_EXPORT:
             case IPF_ORM::ATTR_DECIMAL_PLACES:
             case IPF_ORM::ATTR_LOAD_REFERENCES:
@@ -78,21 +77,15 @@ abstract class IPF_ORM_Configurable
             case IPF_ORM::ATTR_RECURSIVE_MERGE_FIXTURES;
             case IPF_ORM::ATTR_SINGULARIZE_IMPORT;
 
-                break;
-            case IPF_ORM::ATTR_SEQCOL_NAME:
-                if ( ! is_string($value)) {
-                    throw new IPF_ORM_Exception('Sequence column name attribute only accepts string values');
-                }
                 break;
             case IPF_ORM::ATTR_FIELD_CASE:
                 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_SEQNAME_FORMAT:
             case IPF_ORM::ATTR_IDXNAME_FORMAT:
             case IPF_ORM::ATTR_TBLNAME_FORMAT:
                 if ($this instanceof IPF_ORM_Table) {
-                    throw new IPF_ORM_Exception('Sequence / index name format attributes cannot be set'
+                    throw new IPF_ORM_Exception('index name format attributes cannot be set'
                                                . 'at table level (only at connection or global level).');
                 }
                 break;
index 06c5306fb260c82652f10a1f5e94d4933c457c7a..1107baddd57c38ab2d41b707789f1d95fb7f7bd0 100644 (file)
@@ -15,7 +15,6 @@ abstract class IPF_ORM_Connection extends IPF_ORM_Configurable implements Counta
                              'dataDict'    => false,
                              'export'      => false,
                              'import'      => false,
-                             'sequence'    => false,
                              'unitOfWork'  => false,
                              'formatter'   => false,
                              'util'        => false,
@@ -682,7 +681,7 @@ abstract class IPF_ORM_Connection extends IPF_ORM_Configurable implements Counta
 
     public function lastInsertId($table = null, $field = null)
     {
-        return $this->sequence->lastInsertId($table, $field);
+        return $this->getDbh()->lastInsertId();
     }
 
     public function beginTransaction($savepoint = null)
index ad766460c2494fc8da03a0ef319c3accd6f887c7..07fa2600be317977a123607ea7bffe78d284c497 100644 (file)
@@ -397,16 +397,6 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module
 
         $identifier = (array) $table->getIdentifier();
 
-        $seq = $record->getTable()->sequenceName;
-
-        if ( ! empty($seq)) {
-            $id = $this->conn->sequence->nextId($seq);
-            $seqName = $table->getIdentifier();
-            $fields[$seqName] = $id;
-
-            $record->assignIdentifier($id);
-        }
-
         $this->conn->insert($table, $fields);
 
         if (empty($seq) && count($identifier) == 1 && $identifier[0] == $table->getIdentifier() &&
@@ -415,7 +405,7 @@ class IPF_ORM_Connection_UnitOfWork extends IPF_ORM_Connection_Module
                 $seq = $table->getTableName() . '_' . $identifier[0];
             }
 
-            $id = $this->conn->sequence->lastInsertId($seq);
+            $id = $this->conn->lastInsertId($seq);
 
             if ( ! $id) {
                 throw new IPF_ORM_Exception("Couldn't get last insert identifier.");
index 66c813c93f266ac05726177c984a6a6a1f6f46b6..005aab60ff18c0fbcf4b400b0f0ce58f7da8b944 100644 (file)
@@ -62,16 +62,6 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
         return $this->dropConstraint($table, $name);
     }
 
-    public function dropSequence($sequenceName)
-    {
-        $this->conn->exec($this->dropSequenceSql($sequenceName));
-    }
-
-    public function dropSequenceSql($sequenceName)
-    {
-        throw new IPF_ORM_Exception('Drop sequence not supported by this driver.');
-    }
-
     public function createDatabase($database)
     {
         $this->conn->execute($this->createDatabaseSql($database));
@@ -128,16 +118,6 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
         return $sql;
     }
 
-    public function createSequence($seqName, $start = 1, array $options = array())
-    {
-        return $this->conn->execute($this->createSequenceSql($seqName, $start = 1, $options));
-    }
-
-    public function createSequenceSql($seqName, $start = 1, array $options = array())
-    {
-        throw new IPF_ORM_Exception('Create sequence not supported by this driver.');
-    }
-
     public function createConstraint($table, $name, $definition)
     {
         $sql = $this->createConstraintSql($table, $name, $definition);
@@ -444,7 +424,6 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
              if ( ! isset($connections[$connectionName])) {
                  $connections[$connectionName] = array(
                      'create_tables'    => array(),
-                     'create_sequences' => array(),
                      'create_indexes'   => array(),
                      'alters'           => array()
                  );
@@ -463,14 +442,6 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
                      continue;
                  }
 
-                 // If create sequence statement
-                 if (substr($query, 0, strlen('CREATE SEQUENCE')) == 'CREATE SEQUENCE') {
-                     $connections[$connectionName]['create_sequences'][] = $query;
-
-                     unset($sql[$key]);
-                     continue;
-                 }
-
                  // If create index statement
                  if (preg_grep("/CREATE .* INDEX/", array($query))) {
                      $connections[$connectionName]['create_indexes'][] =  $query;
@@ -492,7 +463,7 @@ class IPF_ORM_Export extends IPF_ORM_Connection_Module
          // Loop over all the sql again to merge everything together so it is in the correct order
          $build = array();
          foreach ($connections as $connectionName => $sql) {
-             $build[$connectionName] = array_merge($sql['create_tables'], $sql['create_sequences'], $sql['create_indexes'], $sql['alters']);
+             $build[$connectionName] = array_merge($sql['create_tables'], $sql['create_indexes'], $sql['alters']);
          }
 
          if ( ! $groupByConnection) {
index a5cabf803841807528d065f9e71b31e766e11df6..fb90b11ffb3ab5ff97943a1517be4bdcde51500c 100644 (file)
@@ -237,68 +237,6 @@ class IPF_ORM_Export_Mysql extends IPF_ORM_Export
         return 'ALTER TABLE ' . $name . ' ' . $query;
     }
 
-    public function createSequence($sequenceName, $start = 1, array $options = array())
-    {
-        $sequenceName   = $this->conn->quoteIdentifier($sequenceName, true);
-        $seqcolName     = $this->conn->quoteIdentifier($this->conn->getAttribute(IPF_ORM::ATTR_SEQCOL_NAME), true);
-
-        $optionsStrings = array();
-
-        if (isset($options['comment']) && ! empty($options['comment'])) {
-            $optionsStrings['comment'] = 'COMMENT = ' . $this->conn->quote($options['comment'], 'string');
-        }
-
-        if (isset($options['charset']) && ! empty($options['charset'])) {
-            $optionsStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset'];
-
-            if (isset($options['collate'])) {
-                $optionsStrings['charset'] .= ' COLLATE ' . $options['collate'];
-            }
-        }
-
-        $type = false;
-
-        if (isset($options['type'])) {
-            $type = $options['type'];
-        } else {
-            $type = $this->conn->getAttribute(IPF_ORM::ATTR_DEFAULT_TABLE_TYPE);
-        }
-        if ($type) {
-            $optionsStrings[] = 'ENGINE = ' . $type;
-        }
-
-
-        try {
-            $query  = 'CREATE TABLE ' . $sequenceName
-                    . ' (' . $seqcolName . ' BIGINT NOT NULL AUTO_INCREMENT, PRIMARY KEY ('
-                    . $seqcolName . ')) ' . implode($optionsStrings, ' ');
-
-            $res    = $this->conn->exec($query);
-        } catch(IPF_ORM_Exception $e) {
-            throw new IPF_ORM_Exception('could not create sequence table');
-        }
-
-        if ($start == 1 && $res == 1)
-            return true;
-
-        $query  = 'INSERT INTO ' . $sequenceName
-                . ' (' . $seqcolName . ') VALUES (' . ($start - 1) . ')';
-
-        $res    = $this->conn->exec($query);
-
-        if ($res == 1)
-            return true;
-
-        // Handle error
-        try {
-            $result = $this->conn->exec('DROP TABLE ' . $sequenceName);
-        } catch(IPF_ORM_Exception $e) {
-            throw new IPF_ORM_Exception('could not drop inconsistent sequence table');
-        }
-
-
-    }
-
     public function createIndexSql($table, $name, array $definition)
     {
         $table  = $table;
@@ -444,4 +382,4 @@ class IPF_ORM_Export_Mysql extends IPF_ORM_Export
 
         return $this->conn->exec('ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $name);
     }
-}
\ No newline at end of file
+}
index 078f655bae883706b749ebb492a058f61d2066a1..456fb2aa15f5cebe14398a455ef341804f35b60d 100644 (file)
@@ -89,17 +89,6 @@ class IPF_ORM_Formatter extends IPF_ORM_Connection_Module
         }
     }
 
-    public function fixSequenceName($sqn)
-    {
-        $seqPattern = '/^'.preg_replace('/%s/', '([a-z0-9_]+)',  $this->conn->getAttribute(IPF_ORM::ATTR_SEQNAME_FORMAT)).'$/i';
-        $seqName    = preg_replace($seqPattern, '\\1', $sqn);
-
-        if ($seqName && ! strcasecmp($sqn, $this->getSequenceName($seqName))) {
-            return $seqName;
-        }
-        return $sqn;
-    }
-
     public function fixIndexName($idx)
     {
         $indexPattern   = '/^'.preg_replace('/%s/', '([a-z0-9_]+)', $this->conn->getAttribute(IPF_ORM::ATTR_IDXNAME_FORMAT)).'$/i';
@@ -110,12 +99,6 @@ class IPF_ORM_Formatter extends IPF_ORM_Connection_Module
         return $idx;
     }
 
-    public function getSequenceName($sqn)
-    {
-        return sprintf($this->conn->getAttribute(IPF_ORM::ATTR_SEQNAME_FORMAT),
-            preg_replace('/[^a-z0-9_\$.]/i', '_', $sqn));
-    }
-
     public function getIndexName($idx)
     {
         return sprintf($this->conn->getAttribute(IPF_ORM::ATTR_IDXNAME_FORMAT),
index 163db9fd5647ad7ff327dbdf3f890a2f209e926c..551b9fdf3a1be5e7c3c23793880de6be20d4c123 100644 (file)
@@ -35,7 +35,6 @@ class IPF_ORM_Import_Schema
             'scale',
             'values',
             'comment',
-            'sequence',
             'protected',
             'zerofill',
             'owner',
@@ -190,7 +189,6 @@ class IPF_ORM_Import_Schema
                     $colDesc['primary'] = isset($field['primary']) ? (bool) (isset($field['primary']) && $field['primary']):null;
                     $colDesc['default'] = isset($field['default']) ? $field['default']:null;
                     $colDesc['autoincrement'] = isset($field['autoincrement']) ? (bool) (isset($field['autoincrement']) && $field['autoincrement']):null;
-                    $colDesc['sequence'] = isset($field['sequence']) ? (string) $field['sequence']:null;
                     $colDesc['values'] = isset($field['values']) ? (array) $field['values']:null;
 
                     // Include all the specified and valid validators in the colDesc
index 74d68fe3cb0cc2644cf1e59824b4b0f0c8e04ef4..e790f11220807d12fb4e374010e0e3220b3d79dc 100644 (file)
@@ -14,10 +14,8 @@ 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_SEQNAME_FORMAT          => "%s_seq",
             IPF_ORM::ATTR_TBLNAME_FORMAT          => "%s",
             IPF_ORM::ATTR_QUOTE_IDENTIFIER        => false,
-            IPF_ORM::ATTR_SEQCOL_NAME             => 'id',
             IPF_ORM::ATTR_PORTABILITY             => IPF_ORM::PORTABILITY_ALL,
             IPF_ORM::ATTR_EXPORT                  => IPF_ORM::EXPORT_ALL,
             IPF_ORM::ATTR_DECIMAL_PLACES          => 2,
index 57b9f279e21886064fe115bf55275a8da5be2935..a89718d97451de8a53f8ea439a0002df1320a531 100644 (file)
@@ -203,7 +203,6 @@ abstract class IPF_ORM_Record extends IPF_ORM_Record_Abstract implements Countab
     {
         switch ($this->_table->getIdentifierType()) {
             case IPF_ORM::IDENTIFIER_AUTOINC:
-            case IPF_ORM::IDENTIFIER_SEQUENCE:
             case IPF_ORM::IDENTIFIER_NATURAL:
                 $name = $this->_table->getIdentifier();
                 if (is_array($name)) {
index 6f3b46095059f947c95555fdf1127698ce3b2cb3..a5e36d6deb1e481345093baf4101273922acf7ef 100644 (file)
@@ -369,7 +369,6 @@ class IPF_ORM_Relation_Parser
                     unset($col['type']);
                     unset($col['length']);
                     unset($col['autoincrement']);
-                    unset($col['sequence']);
                     unset($col['primary']);
 
                     $def['table']->setColumn($column, $type, $length, $col);
diff --git a/ipf/orm/sequence.php b/ipf/orm/sequence.php
deleted file mode 100644 (file)
index 77ce93b..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-class IPF_ORM_Sequence extends IPF_ORM_Connection_Module
-{
-    public function nextId($seqName, $ondemand = true)
-    {
-        throw new IPF_ORM_Sequence_Exception('method not implemented');
-    }
-
-    public function lastInsertId($table = null, $field = null)
-    {
-        throw new IPF_ORM_Exception('method not implemented');
-    }
-
-    public function currId($seqName)
-    {
-        $this->warnings[] = 'database does not support getting current
-            sequence value, the sequence value was incremented';
-        return $this->nextId($seqName);
-    }
-}
\ No newline at end of file
diff --git a/ipf/orm/sequence/mysql.php b/ipf/orm/sequence/mysql.php
deleted file mode 100644 (file)
index 4293095..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-class IPF_ORM_Sequence_Mysql extends IPF_ORM_Sequence
-{
-    public function nextId($seqName, $onDemand = true)
-    {
-        $sequenceName  = $this->conn->quoteIdentifier($seqName, true);
-        $seqcolName    = $this->conn->quoteIdentifier($this->conn->getAttribute(IPF_ORM::ATTR_SEQCOL_NAME), true);
-        $query         = 'INSERT INTO ' . $sequenceName . ' (' . $seqcolName . ') VALUES (NULL)';
-        
-        try {
-
-            $this->conn->exec($query);
-
-        } catch(IPF_ORM_Exception $e) {
-            if ($onDemand && $e->getPortableCode() == IPF_ORM::ERR_NOSUCHTABLE) {
-                // Since we are creating the sequence on demand
-                // we know the first id = 1 so initialize the
-                // sequence at 2
-                try {
-                    $result = $this->conn->export->createSequence($seqName, 2);
-                } catch(IPF_ORM_Exception $e) {
-                    throw new IPF_ORM_Exception('on demand sequence ' . $seqName . ' could not be created');
-                }
-                // First ID of a newly created sequence is 1
-                return 1;
-            }
-            throw $e;
-        }
-
-        $value = $this->lastInsertId();
-
-        if (is_numeric($value)) {
-            $query = 'DELETE FROM ' . $sequenceName . ' WHERE ' . $seqcolName . ' < ' . $value;
-            $this->conn->exec($query);
-        }
-        return $value;
-    }
-
-    public function lastInsertId($table = null, $field = null)
-    {
-        return $this->conn->getDbh()->lastInsertId();
-    }
-
-    public function currId($seqName)
-    {
-        $sequenceName   = $this->conn->quoteIdentifier($seqName, true);
-        $seqcolName     = $this->conn->quoteIdentifier($this->conn->getAttribute(IPF_ORM::ATTR_SEQCOL_NAME), true);
-        $query          = 'SELECT MAX(' . $seqcolName . ') FROM ' . $sequenceName;
-        return (int) $this->conn->fetchOne($query);
-    }
-}
\ No newline at end of file
index 325c90d48f5917cc176d6900a4e9201345cd4d25..90834c5228f07b846b25598217d96e69999eaa37 100644 (file)
@@ -20,7 +20,6 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
 
     protected $_options      = array('name'           => null,
                                      'tableName'      => null,
-                                     'sequenceName'   => null,
                                      'inheritanceMap' => array(),
                                      'enumMap'        => array(),
                                      'type'           => null,
@@ -130,21 +129,6 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
                                     $found = true;
                                 }
                                 break;
-                            case 'seq':
-                            case 'sequence':
-                                $this->_identifierType = IPF_ORM::IDENTIFIER_SEQUENCE;
-                                $found = true;
-
-                                if (is_string($value)) {
-                                    $this->_options['sequenceName'] = $value;
-                                } else {
-                                    if (($sequence = $this->getAttribute(IPF_ORM::ATTR_DEFAULT_SEQUENCE)) !== null) {
-                                        $this->_options['sequenceName'] = $sequence;
-                                    } else {
-                                        $this->_options['sequenceName'] = $this->_conn->formatter->getSequenceName($this->_options['tableName']);
-                                    }
-                                }
-                                break;
                         }
                     }
                     if ( ! isset($this->_identifierType)) {
@@ -1080,7 +1064,6 @@ class IPF_ORM_Table extends IPF_ORM_Configurable implements Countable
                     || $name == 'autoincrement'
                     || $name == 'default'
                     || $name == 'values'
-                    || $name == 'sequence'
                     || $name == 'zerofill'
                     || $name == 'owner'
                     || $name == 'scale'