mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 06:05:53 +00:00
MINOR Clearer documentation on MSSQLDatabase::getPrimaryKey()
This commit is contained in:
parent
9a86a6d9a5
commit
7b6899b3f0
@ -315,22 +315,24 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
return $this->query("SELECT IDENT_CURRENT('$table')")->value();
|
return $this->query("SELECT IDENT_CURRENT('$table')")->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* This is a handy helper function which will return the primary key for any paricular table
|
* MSSQL stores the primary key column with an internal identifier,
|
||||||
* In MSSQL, the primary key is often an internal identifier, NOT the standard name (ie, 'ID'),
|
* so a lookup needs to be done to determine it.
|
||||||
* so we need to do a lookup for it.
|
*
|
||||||
|
* @param string $tableName Name of table with primary key column "ID"
|
||||||
|
* @return string Internal identifier for primary key
|
||||||
*/
|
*/
|
||||||
function getPrimaryKey($tableName){
|
function getPrimaryKey($tableName) {
|
||||||
$indexes=DB::query("EXEC sp_helpindex '$tableName';");
|
$indexes = DB::query("EXEC sp_helpindex '$tableName';");
|
||||||
$primary_key='';
|
$indexName = '';
|
||||||
foreach($indexes as $this_index){
|
foreach($indexes as $index) {
|
||||||
if($this_index['index_keys']=='ID'){
|
if($index['index_keys'] == 'ID') {
|
||||||
$primary_key=$this_index['index_name'];
|
$indexName = $index['index_name'];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $primary_key;
|
return $indexName;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getIdentityColumn($tableName) {
|
function getIdentityColumn($tableName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user