mirror of
https://github.com/processwire/processwire.git
synced 2025-08-14 10:45:54 +02:00
Modifications to $database->getPrimaryKey() method (I thought these were in the previous commit that added this method but looks like they weren't)
This commit is contained in:
@@ -261,6 +261,8 @@ class Sanitizer extends Wire {
|
|||||||
'intSigned' => 'i',
|
'intSigned' => 'i',
|
||||||
'intUnsigned' => 'i',
|
'intUnsigned' => 'i',
|
||||||
'kebabCase' => 's',
|
'kebabCase' => 's',
|
||||||
|
'line' => 's',
|
||||||
|
'lines' => 's',
|
||||||
'markupToLine' => 's',
|
'markupToLine' => 's',
|
||||||
'markupToText' => 's',
|
'markupToText' => 's',
|
||||||
'max' => 'fi',
|
'max' => 'fi',
|
||||||
|
@@ -994,7 +994,7 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
* also makes the return value indexed by column name (associative array).
|
* also makes the return value indexed by column name (associative array).
|
||||||
*
|
*
|
||||||
* @param string $table Table name or or `table.column` to get for specific column (when combined with verbose=true)
|
* @param string $table Table name or or `table.column` to get for specific column (when combined with verbose=true)
|
||||||
* @param bool|string $verbose Include array of verbose information for each? (default=false)
|
* @param bool|int|string $verbose Include array of verbose information for each? (default=false)
|
||||||
* - Omit or false (bool) to just get column names.
|
* - Omit or false (bool) to just get column names.
|
||||||
* - True (bool) or 1 (int) to get a verbose array of information for each column, indexed by column name.
|
* - True (bool) or 1 (int) to get a verbose array of information for each column, indexed by column name.
|
||||||
* - 2 (int) to get raw MySQL column information, indexed by column name (added 3.0.182).
|
* - 2 (int) to get raw MySQL column information, indexed by column name (added 3.0.182).
|
||||||
@@ -1040,7 +1040,7 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
* index `name`, `type` and `columns` (array) for each index.
|
* index `name`, `type` and `columns` (array) for each index.
|
||||||
*
|
*
|
||||||
* @param string $table Name of table to get indexes for or `table.index` (usually combined with verbose option).
|
* @param string $table Name of table to get indexes for or `table.index` (usually combined with verbose option).
|
||||||
* @param bool $verbose Include array of verbose information for each? (default=false)
|
* @param bool|int|string $verbose Include array of verbose information for each? (default=false)
|
||||||
* - Omit or false (bool) to just get index names.
|
* - Omit or false (bool) to just get index names.
|
||||||
* - True (bool) or 1 (int) to get a verbose array of information for each index, indexed by index name.
|
* - True (bool) or 1 (int) to get a verbose array of information for each index, indexed by index name.
|
||||||
* - 2 (int) to get regular PHP array of raw MySQL index information.
|
* - 2 (int) to get regular PHP array of raw MySQL index information.
|
||||||
@@ -1079,23 +1079,33 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
|||||||
$query->closeCursor();
|
$query->closeCursor();
|
||||||
if($getIndex) return isset($indexes[$getIndex]) ? $indexes[$getIndex] : array();
|
if($getIndex) return isset($indexes[$getIndex]) ? $indexes[$getIndex] : array();
|
||||||
return $indexes;
|
return $indexes;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get array of info for given table’s primary key/index
|
* Get column(s) or info for given table’s primary key/index
|
||||||
|
*
|
||||||
|
* By default it returns a string with the column name compromising the primary key, i.e. `col1`.
|
||||||
|
* If the primary key is multiple columns then it returns a CSV string, like `col1,col2,col3`.
|
||||||
|
*
|
||||||
|
* If you specify boolean `true` for the verbose option then it returns an simplified array of
|
||||||
|
* information about the primary key. If you specify integer `2` then it returns an array of
|
||||||
|
* raw MySQL SHOW INDEX information.
|
||||||
*
|
*
|
||||||
* @param string $table
|
* @param string $table
|
||||||
* @param bool $getRaw Get raw MySQL array of info rather than simplied array? (default=false)
|
* @param bool|int $verbose Get array of info rather than column(s) string? (default=false)
|
||||||
* @return array
|
* @return string|array
|
||||||
* @since 3.0.182
|
* @since 3.0.182
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function getPrimaryKey($table, $getRaw = false) {
|
public function getPrimaryKey($table, $verbose = false) {
|
||||||
if($getRaw) {
|
if($verbose === 2) {
|
||||||
return $this->getIndexes("$table.PRIMARY", 2);
|
return $this->getIndexes("$table.PRIMARY", 2);
|
||||||
} else {
|
} else if($verbose) {
|
||||||
return $this->getIndexes($table, 'PRIMARY');
|
return $this->getIndexes($table, 'PRIMARY');
|
||||||
|
} else {
|
||||||
|
$a = $this->getIndexes($table, 'PRIMARY');
|
||||||
|
if(empty($a) || empty($a['columns'])) return '';
|
||||||
|
return implode(',', $a['columns']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user