MINOR Clearer documentation on MSSQLDatabase::getPrimaryKey()

This commit is contained in:
Sean Harvey 2010-10-20 03:21:54 +00:00
parent 9a86a6d9a5
commit 7b6899b3f0

View File

@ -314,25 +314,27 @@ class MSSQLDatabase extends SS_Database {
public function getGeneratedID($table) { public function getGeneratedID($table) {
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) {
return $this->query(" return $this->query("
SELECT SELECT