Пример #1
0
 /**
  * Extracts information about an index from the XML element $index
  * 
  * @param SimpleXMLElement $index
  *
  * @return ezcDbSchemaIndex or an inherited class
  */
 private function parseIndex(SimpleXMLElement $index)
 {
     $indexFields = array();
     foreach ($index->field as $indexField) {
         $indexFieldName = (string) $indexField->name;
         $indexFields[$indexFieldName] = ezcDbSchema::createNewIndexField(isset($indexField->sorting) ? (string) $indexField->sorting : null);
     }
     return ezcDbSchema::createNewIndex($indexFields, isset($index->primary) ? (string) $index->primary : false, isset($index->unique) ? (string) $index->unique : false);
 }
Пример #2
0
 /**
  * Loops over all the indexes in the table $table and extracts information.
  *
  * This method extracts information about the table $tableName's indexes
  * from the database and returns this schema as an array of
  * ezcDbSchemaIndex objects. The key in the array is the index' name.
  *
  * @param  string $tableName
  * @return array(string=>ezcDbSchemaIndex)
  */
 protected function fetchTableIndexes($tableName)
 {
     $indexBuffer = array();
     $resultArray = $this->db->query("SHOW INDEX FROM `{$tableName}`");
     foreach ($resultArray as $row) {
         $keyName = $row['key_name'];
         if ($keyName == 'PRIMARY') {
             $keyName = 'primary';
         }
         $indexBuffer[$keyName]['primary'] = false;
         $indexBuffer[$keyName]['unique'] = true;
         if ($keyName == 'primary') {
             $indexBuffer[$keyName]['primary'] = true;
             $indexBuffer[$keyName]['unique'] = true;
         } else {
             $indexBuffer[$keyName]['unique'] = $row['non_unique'] ? false : true;
         }
         $indexBuffer[$keyName]['fields'][$row['column_name']] = ezcDbSchema::createNewIndexField();
         //            if ( $row['sub_part'] )
         //            {
         //                $indexBuffer[$keyName]['options']['limitations'][$row['column_name']] = $row['sub_part'];
         //            }
     }
     $indexes = array();
     foreach ($indexBuffer as $indexName => $indexInfo) {
         $indexes[$indexName] = ezcDbSchema::createNewIndex($indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique']);
     }
     return $indexes;
 }
Пример #3
0
 /**
  * Loops over all the indexes in the table $table and extracts information.
  *
  * This method extracts information about the table $tableName's indexes
  * from the database and returns this schema as an array of
  * ezcDbSchemaIndex objects. The key in the array is the index' name.
  *
  * @param  string $tableName
  * @return array(string=>ezcDbSchemaIndex)
  */
 protected function fetchTableIndexes($tableName)
 {
     $indexBuffer = array();
     $indexesArray = array();
     // fetching index info from Oracle
     $getIndexSQL = "SELECT uind.index_name AS name, " . "       uind.index_type AS type, " . "       decode( uind.uniqueness, 'NONUNIQUE', 0, 'UNIQUE', 1 ) AS is_unique, " . "       uind_col.column_name AS column_name, " . "       uind_col.column_position AS column_pos " . "FROM user_indexes uind, user_ind_columns uind_col " . "WHERE uind.index_name = uind_col.index_name AND uind_col.table_name = '{$tableName}'";
     $indexesArray = $this->db->query($getIndexSQL)->fetchAll();
     $primaryFound = false;
     // getting columns to which each index related.
     foreach ($indexesArray as $row) {
         $keyName = $row['name'];
         if ($keyName == $tableName . '_pkey') {
             $keyName = 'primary';
             $indexBuffer[$keyName]['primary'] = true;
             $indexBuffer[$keyName]['unique'] = true;
             $primaryFound = true;
         } else {
             $indexBuffer[$keyName]['primary'] = false;
             $indexBuffer[$keyName]['unique'] = $row['is_unique'] == 1 ? true : false;
         }
         $indexBuffer[$keyName]['fields'][$row['column_name']] = ezcDbSchema::createNewIndexField();
     }
     $indexes = array();
     foreach ($indexBuffer as $indexName => $indexInfo) {
         $indexes[$indexName] = ezcDbSchema::createNewIndex($indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique']);
     }
     return $indexes;
 }
Пример #4
0
 /**
  * Loops over all the indexes in the table $table and extracts information.
  *
  * This method extracts information about the table $tableName's indexes
  * from the database and returns this schema as an array of
  * ezcDbSchemaIndex objects. The key in the array is the index' name.
  *
  * @param  string $tableName
  * @return array(string=>ezcDbSchemaIndex)
  */
 protected function fetchTableIndexes($tableName)
 {
     $indexBuffer = array();
     $resultArray = array();
     // fetching index info from PostgreSQL
     $getIndexSQL = "SELECT relname, pg_index.indisunique, pg_index.indisprimary, \n                               pg_index.indkey, pg_index.indrelid \n                         FROM pg_class, pg_index\n                         WHERE oid IN ( \n                                SELECT indexrelid \n                                FROM pg_index, pg_class \n                                WHERE pg_class.relname='{$tableName}' AND pg_class.oid=pg_index.indrelid \n                             ) \n                      AND pg_index.indexrelid = oid";
     $indexesArray = $this->db->query($getIndexSQL)->fetchAll();
     // getting columns to which each index related.
     foreach ($indexesArray as $row) {
         $myIndex[] = $row['relname'];
         $colNumbers = explode(' ', $row['indkey']);
         $colNumbersSQL = 'IN (' . join(' ,', $colNumbers) . ' )';
         $indexColumns = $this->db->query("SELECT attname \n                                               FROM pg_attribute \n                                               WHERE attrelid={$row['indrelid']} \n                                                     AND attnum {$colNumbersSQL};");
         foreach ($indexColumns as $colRow) {
             $resultArray[] = array('key_name' => $row['relname'], 'column_name' => $colRow['attname'], 'non_unique' => !$row['indisunique'], 'primary' => !$row['indisprimary']);
             $indexColumnNames[] = $colRow['attname'];
         }
     }
     foreach ($resultArray as $row) {
         $keyName = $row['key_name'];
         if (substr($keyName, -5) == '_pkey') {
             $keyName = 'primary';
         }
         $indexBuffer[$keyName]['primary'] = false;
         $indexBuffer[$keyName]['unique'] = true;
         if ($keyName == 'primary') {
             $indexBuffer[$keyName]['primary'] = true;
             $indexBuffer[$keyName]['unique'] = true;
         } else {
             $indexBuffer[$keyName]['unique'] = $row['non_unique'] ? false : true;
         }
         $indexBuffer[$keyName]['fields'][$row['column_name']] = ezcDbSchema::createNewIndexField();
     }
     $indexes = array();
     foreach ($indexBuffer as $indexName => $indexInfo) {
         $indexes[$indexName] = ezcDbSchema::createNewIndex($indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique']);
     }
     return $indexes;
 }
Пример #5
0
 /**
  * Loops over all the indexes in the table $table and extracts information.
  *
  * This method extracts information about the table $tableName's indexes
  * from the database and returns this schema as an array of
  * ezcDbSchemaIndex objects. The key in the array is the index' name.
  *
  * @param  string $tableName
  * @return array(string=>ezcDbSchemaIndex)
  */
 protected function fetchTableIndexes($tableName)
 {
     $indexBuffer = array();
     $indexNamesArray = $this->db->query("PRAGMA INDEX_LIST ('{$tableName}')");
     $primaryFound = false;
     foreach ($indexNamesArray as $row) {
         $keyName = $row['1'];
         if ($keyName == $tableName . '_pri') {
             $keyName = 'primary';
             $indexBuffer[$keyName]['primary'] = true;
             $indexBuffer[$keyName]['unique'] = true;
             $primaryFound = true;
         } else {
             $indexBuffer[$keyName]['primary'] = false;
             $indexBuffer[$keyName]['unique'] = $row[2] ? true : false;
         }
         $indexArray = $this->db->query("PRAGMA INDEX_INFO ( '{$row[1]}' )");
         foreach ($indexArray as $indexColumnRow) {
             $indexBuffer[$keyName]['fields'][$indexColumnRow[2]] = ezcDbSchema::createNewIndexField();
         }
     }
     // search primary index
     $fieldArray = $this->db->query("PRAGMA TABLE_INFO ('{$tableName}')");
     foreach ($fieldArray as $row) {
         if ($row[5] == '1') {
             $keyName = 'primary';
             $indexBuffer[$keyName]['primary'] = true;
             $indexBuffer[$keyName]['unique'] = true;
             $indexBuffer[$keyName]['fields'][$row[1]] = ezcDbSchema::createNewIndexField();
         }
     }
     $indexes = array();
     foreach ($indexBuffer as $indexName => $indexInfo) {
         $indexes[$indexName] = ezcDbSchema::createNewIndex($indexInfo['fields'], $indexInfo['primary'], $indexInfo['unique']);
     }
     return $indexes;
 }