/**
  * Builds the DDL SQL to drop an Index.
  *
  * @param      Index $index
  * @return     string
  */
 public function getDropIndexDDL(Index $index)
 {
     $pattern = "\nDROP INDEX %s ON %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($index->getName()), $this->quoteIdentifier($index->getTable()->getName()));
 }
Example #2
0
 /**
  * @param string $stmt
  * @return $this
  */
 public function parse($stmt)
 {
     $lines = array_map('trim', explode(PHP_EOL, $stmt));
     $this->first = array_shift($lines);
     $last = array_pop($lines);
     //remove AUTO_INCREMENT bit from raw statement
     $this->last = preg_replace('/AUTO_INCREMENT=\\d+ ?/', '', $last);
     $this->statement = str_replace($last, $this->last, $stmt);
     if ($this->name === null) {
         if (!preg_match('/`([^`]+)/', $this->first, $match)) {
             throw new \RuntimeException(sprintf('Unable to extract name from %s (looked at line %s)', $stmt, $lines[0]));
         }
         $this->name = $match[1];
     }
     foreach ($lines as $ln) {
         if (mb_substr($ln, -1) == ',') {
             $ln = mb_substr($ln, 0, -1);
         }
         //field lines start with back-tick
         switch ($ln[0]) {
             case '`':
                 $field = new Field($ln);
                 $this->fields[$field->getName()] = $field;
                 break;
             case 'P':
                 $this->primary = new Primary($ln);
                 break;
             case 'S':
                 //spatial
             //spatial
             case 'U':
                 //unique
             //unique
             case 'F':
                 //fulltext
             //fulltext
             case 'I':
                 //index
             //index
             case 'K':
                 //Key
                 $idx = new Index($ln);
                 $this->indexes[$idx->getName()] = $idx;
                 break;
             case 'C':
                 $constraint = new ForeignKey($ln);
                 $this->constraints[$constraint->getName()] = $constraint;
                 break;
             default:
                 throw new \LogicException(sprintf('Unable to parse line %s in %s', $ln, $stmt));
         }
     }
     return $this;
 }
 /**
  * Overrides the implementation from DefaultPlatform
  *
  * @author     Niklas Närhinen <*****@*****.**>
  * @return string
  * @see        DefaultPlatform::getDropIndexDDL
  */
 public function getDropIndexDDL(Index $index)
 {
     if ($index instanceof Unique) {
         $pattern = "\n    ALTER TABLE %s DROP CONSTRAINT %s;\n    ";
         return sprintf($pattern, $this->quoteIdentifier($index->getTable()->getName()), $this->quoteIdentifier($index->getName()));
     } else {
         return parent::getDropIndexDDL($index);
     }
 }
Example #4
0
 /**
  * Creates(if not already created) and returns the corresponding Index object
  *
  * @param string $schema     database name
  * @param string $table      table name
  * @param string $index_name index name
  *
  * @return Index corresponding Index object
  */
 public static function singleton($schema, $table, $index_name = '')
 {
     Index::_loadIndexes($table, $schema);
     if (!isset(Index::$_registry[$schema][$table][$index_name])) {
         $index = new Index();
         if (mb_strlen($index_name)) {
             $index->setName($index_name);
             Index::$_registry[$schema][$table][$index->getName()] = $index;
         }
         return $index;
     } else {
         return Index::$_registry[$schema][$table][$index_name];
     }
 }
Example #5
0
 /**
  * Builds the DDL SQL to add an Index.
  *
  * @param  Index  $index
  * @return string
  */
 public function getAddIndexDDL(Index $index)
 {
     // don't create index form primary key
     if ($this->getPrimaryKeyName($index->getTable()) == $this->quoteIdentifier($index->getName())) {
         return "";
     }
     $pattern = "\r\nCREATE %sINDEX %s ON %s (%s)%s;\r\n";
     return sprintf($pattern, $index->getIsUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->quoteIdentifier($index->getTable()->getName()), $this->getColumnListDDL($index->getColumns()), $this->generateBlockStorage($index));
 }
Example #6
0
 /**
  * Builds the DDL SQL for an Index object.
  *
  * @param      Index $index
  * @return     string
  */
 public function getIndexDDL(Index $index)
 {
     return sprintf('%sINDEX %s (%s)', $index->getIsUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->getColumnListDDL($index->getColumns()));
 }
Example #7
0
 /**
  * @param Index $index
  */
 public function addIndex(Index $index)
 {
     $index->setParentTable($this);
     $this->indexes[$index->getName()] = $index;
 }
Example #8
0
 /**
  * Add index
  * 
  * @param \deco\essentials\database\util\Index $index
  */
 public function addIndex(Index $index)
 {
     $this->indexes[$index->getName()] = $index;
 }
Example #9
0
 /**
  * Adds index to table
  * @param Index $index
  */
 public function addIndexToModel($index)
 {
     $this->query('insert into [indexes] values( null, %s, %s, %s, %s)', $index->getName(), $index->getModel()->getTableName(), $index->getHash(), $index->isUnique());
     PerfORMController::getBuilder()->createIndex($index);
 }
Example #10
0
 /**
  * @param Index $changedIndex
  */
 public function addChangedIndex(Index $changedIndex)
 {
     $this->changedIndexes[$changedIndex->getName()] = $changedIndex;
 }