Permalink
Browse files

MINOR Clearer documentation on MSSQLDatabase::getPrimaryKey()

  • Loading branch information...
1 parent 9a86a6d commit 7b6899b3f00317b5bd66c71990825169b6385b78 @halkyon halkyon committed Oct 20, 2010
Showing with 17 additions and 15 deletions.
  1. +17 −15 code/MSSQLDatabase.php
View
@@ -314,25 +314,27 @@ public function query($sql, $errorLevel = E_USER_ERROR) {
public function getGeneratedID($table) {
return $this->query("SELECT IDENT_CURRENT('$table')")->value();
}
-
- /*
- * This is a handy helper function which will return the primary key for any paricular table
- * In MSSQL, the primary key is often an internal identifier, NOT the standard name (ie, 'ID'),
- * so we need to do a lookup for it.
- */
- function getPrimaryKey($tableName){
- $indexes=DB::query("EXEC sp_helpindex '$tableName';");
- $primary_key='';
- foreach($indexes as $this_index){
- if($this_index['index_keys']=='ID'){
- $primary_key=$this_index['index_name'];
+
+ /**
+ * MSSQL stores the primary key column with an internal identifier,
+ * so a lookup needs to be done to determine it.
+ *
+ * @param string $tableName Name of table with primary key column "ID"
+ * @return string Internal identifier for primary key
+ */
+ function getPrimaryKey($tableName) {
+ $indexes = DB::query("EXEC sp_helpindex '$tableName';");
+ $indexName = '';
+ foreach($indexes as $index) {
+ if($index['index_keys'] == 'ID') {
+ $indexName = $index['index_name'];
break;
}
}
-
- return $primary_key;
+
+ return $indexName;
}
-
+
function getIdentityColumn($tableName) {
return $this->query("
SELECT

0 comments on commit 7b6899b

Please sign in to comment.