本文整理汇总了PHP中ezcDbSchema::createNewIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP ezcDbSchema::createNewIndex方法的具体用法?PHP ezcDbSchema::createNewIndex怎么用?PHP ezcDbSchema::createNewIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ezcDbSchema
的用法示例。
在下文中一共展示了ezcDbSchema::createNewIndex方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseIndex
/**
* 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: fetchTableIndexes
/**
* 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: fetchTableIndexes
/**
* 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: fetchTableIndexes
/**
* 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;
}