Esempio n. 1
0
 /**
  * Compiles an ALTER TABLE statement from components array
  *
  * @param array Array of SQL query components
  * @return string SQL ALTER TABLE query
  * @see parseALTERTABLE()
  */
 public function compileALTERTABLE($components)
 {
     $query = '';
     // Execute query (based on handler derived from the TABLE name which we actually know for once!)
     switch ((string) $this->databaseConnection->handlerCfg[$this->databaseConnection->lastHandlerKey]['type']) {
         case 'native':
             $query = parent::compileALTERTABLE($components);
             break;
         case 'adodb':
             $tableName = $this->databaseConnection->quoteName($components['TABLE'], NULL, TRUE);
             $fieldName = $this->databaseConnection->quoteName($components['FIELD'], NULL, TRUE);
             switch (strtoupper(str_replace(array(' ', "\n", "\r", "\t"), '', $components['action']))) {
                 case 'ADD':
                     $query = $this->databaseConnection->handlerInstance[$this->databaseConnection->lastHandlerKey]->DataDictionary->AddColumnSQL($tableName, $fieldName . ' ' . $this->compileFieldCfg($components['definition']));
                     break;
                 case 'CHANGE':
                     $query = $this->databaseConnection->handlerInstance[$this->databaseConnection->lastHandlerKey]->DataDictionary->AlterColumnSQL($tableName, $fieldName . ' ' . $this->compileFieldCfg($components['definition']));
                     break;
                 case 'DROP':
                 case 'DROPKEY':
                     break;
                 case 'ADDKEY':
                 case 'ADDPRIMARYKEY':
                 case 'ADDUNIQUE':
                     $query .= ' (' . implode(',', $components['fields']) . ')';
                     break;
                 case 'DEFAULTCHARACTERSET':
                 case 'ENGINE':
                     // ??? todo!
                     break;
             }
             break;
     }
     return $query;
 }
Esempio n. 2
0
 /**
  * Compiles DROP INDEX statements from component information
  *
  * MySQL only needs uniqueness of index names per table, but many DBMS require uniqueness of index names per schema.
  * The table name is hashed and prepended to the index name to make sure index names are unique.
  *
  * @param $indexName
  * @param $tableName
  * @return array
  * @see compileALTERTABLE()
  */
 public function compileDROPINDEX($indexName, $tableName)
 {
     $indexIdentifier = $this->databaseConnection->quoteName(hash('crc32b', $tableName) . '_' . $indexName, NULL, TRUE);
     return $this->databaseConnection->handlerInstance[$this->databaseConnection->handler_getFromTableList($tableName)]->DataDictionary->DropIndexSQL($indexIdentifier, $this->databaseConnection->quoteName($tableName));
 }