MINOR: MSSQL stub function created for Postgres-specific functionality

This commit is contained in:
Geoff Munn 2011-01-12 02:05:32 +00:00
parent c104222019
commit 7ea6652e56

View File

@ -213,9 +213,9 @@ class MSSQLDatabase extends SS_Database {
* This will set up the full text search capabilities. * This will set up the full text search capabilities.
*/ */
function createFullTextCatalog() { function createFullTextCatalog() {
$result = $this->query("SELECT name FROM sys.fulltext_catalogs WHERE name = 'ftCatalog';")->value(); $result = $this->query("SELECT name FROM sys.fulltext_catalogs WHERE name = 'ftCatalog';")->value();
if(!$result) $this->query("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;"); if(!$result) $this->query("CREATE FULLTEXT CATALOG ftCatalog AS DEFAULT;");
} }
/** /**
* Sleep until the catalog has been fully rebuilt. This is a busy wait designed for situations * Sleep until the catalog has been fully rebuilt. This is a busy wait designed for situations
@ -322,8 +322,8 @@ class MSSQLDatabase extends SS_Database {
* @param string $tableName Name of table with primary key column "ID" * @param string $tableName Name of table with primary key column "ID"
* @return string Internal identifier for primary key * @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';");
$indexName = ''; $indexName = '';
foreach($indexes as $index) { foreach($indexes as $index) {
if($index['index_keys'] == 'ID') { if($index['index_keys'] == 'ID') {
@ -422,9 +422,9 @@ class MSSQLDatabase extends SS_Database {
$databases = $this->allDatabaseNames(); $databases = $this->allDatabaseNames();
foreach($databases as $dbname) { foreach($databases as $dbname) {
if($dbname == $name) return true; if($dbname == $name) return true;
} }
return false; return false;
} }
/** /**
* Return all databases names from the server. * Return all databases names from the server.
@ -569,6 +569,7 @@ class MSSQLDatabase extends SS_Database {
and c.name = '$colName'")->value(); and c.name = '$colName'")->value();
} }
/** /**
* Get enum values from a constraint check clause. * Get enum values from a constraint check clause.
* @param string $clause Check clause to parse values from * @param string $clause Check clause to parse values from
@ -581,7 +582,8 @@ class MSSQLDatabase extends SS_Database {
$bits = preg_split('/ *= */', $segment); $bits = preg_split('/ *= */', $segment);
for($i = 1; $i < sizeof($bits); $i += 2) { for($i = 1; $i < sizeof($bits); $i += 2) {
array_unshift($constraints, substr(rtrim($bits[$i], ')'), 1, -1)); array_unshift($constraints, substr(rtrim($bits[$i], ')'), 1, -1));
}
}
} }
return $constraints; return $constraints;
} }
@ -637,6 +639,8 @@ class MSSQLDatabase extends SS_Database {
//NOTE: 'with nocheck' seems to solve a few problems I've been having for modifying existing tables. //NOTE: 'with nocheck' seems to solve a few problems I've been having for modifying existing tables.
$alterCol .= ";\n$prefix WITH NOCHECK ADD CONSTRAINT \"{$tableName}_{$colName}_check\" $matches[4]"; $alterCol .= ";\n$prefix WITH NOCHECK ADD CONSTRAINT \"{$tableName}_{$colName}_check\" $matches[4]";
} }
} }
} }
@ -680,8 +684,8 @@ class MSSQLDatabase extends SS_Database {
* @param string $newName The new name of the field * @param string $newName The new name of the field
*/ */
public function renameField($tableName, $oldName, $newName) { public function renameField($tableName, $oldName, $newName) {
$this->query("EXEC sp_rename @objname = '$tableName.$oldName', @newname = '$newName', @objtype = 'COLUMN'"); $this->query("EXEC sp_rename @objname = '$tableName.$oldName', @newname = '$newName', @objtype = 'COLUMN'");
} }
public function fieldList($table) { public function fieldList($table) {
//This gets us more information than we need, but I've included it all for the moment.... //This gets us more information than we need, but I've included it all for the moment....
@ -744,7 +748,7 @@ class MSSQLDatabase extends SS_Database {
$clause = $this->getConstraintCheckClause($table, $field['column_name']); $clause = $this->getConstraintCheckClause($table, $field['column_name']);
if($clause) { if($clause) {
$constraints = $this->enumValuesFromCheckClause($clause); $constraints = $this->enumValuesFromCheckClause($clause);
$default = substr($field['column_default'], 2, -2); $default=substr($field['column_default'], 2, -2);
$field['data_type'] = $this->enum(array( $field['data_type'] = $this->enum(array(
'default' => $default, 'default' => $default,
'name' => $field['column_name'], 'name' => $field['column_name'],
@ -778,6 +782,18 @@ class MSSQLDatabase extends SS_Database {
return $output; return $output;
} }
/**
*
* This is a stub function. Postgres caches the fieldlist results.
*
* @param string $tableName
*
* @return boolean
*/
function clear_cached_fieldlist($tableName=false){
return true;
}
/** /**
* Create an index on a table. * Create an index on a table.
* @param string $tableName The name of the table. * @param string $tableName The name of the table.
@ -861,18 +877,18 @@ class MSSQLDatabase extends SS_Database {
* @param string $indexSpec The specification of the index, see SS_Database::requireIndex() for more details. * @param string $indexSpec The specification of the index, see SS_Database::requireIndex() for more details.
*/ */
public function alterIndex($tableName, $indexName, $indexSpec) { public function alterIndex($tableName, $indexName, $indexSpec) {
$indexSpec = trim($indexSpec); $indexSpec = trim($indexSpec);
if($indexSpec[0] != '(') { if($indexSpec[0] != '(') {
list($indexType, $indexFields) = explode(' ', $indexSpec, 2); list($indexType, $indexFields) = explode(' ',$indexSpec,2);
} else { } else {
$indexFields = $indexSpec; $indexFields = $indexSpec;
} }
if(!$indexType) { if(!$indexType) {
$indexType = "index"; $indexType = "index";
} }
$this->query("DROP INDEX $indexName ON $tableName;"); $this->query("DROP INDEX $indexName ON $tableName;");
$this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields"); $this->query("ALTER TABLE \"$tableName\" ADD $indexType \"$indexName\" $indexFields");
} }
@ -1148,7 +1164,7 @@ class MSSQLDatabase extends SS_Database {
/** /**
* Returns the database-specific version of the random() function * Returns the database-specific version of the random() function
*/ */
function random() { function random(){
return 'RAND()'; return 'RAND()';
} }
@ -1251,10 +1267,11 @@ class MSSQLDatabase extends SS_Database {
* @param string $value String to escape * @param string $value String to escape
* @return string Escaped string * @return string Escaped string
*/ */
function addslashes($value) { function addslashes($value){
$value = str_replace("'", "''", $value); $value=str_replace("'","''",$value);
$value = str_replace("\0", "[NULL]", $value); $value=str_replace("\0","[NULL]",$value);
return $value;
return $value;
} }
/** /**
@ -1672,13 +1689,13 @@ class MSSQLQuery extends SS_Query {
public function __destruct() { public function __destruct() {
if(is_resource($this->handle)) { if(is_resource($this->handle)) {
if($this->mssql) { if($this->mssql) {
mssql_free_result($this->handle); mssql_free_result($this->handle);
} else { } else {
sqlsrv_free_stmt($this->handle); sqlsrv_free_stmt($this->handle);
}
} }
} }
}
public function seek($row) { public function seek($row) {
if(!is_resource($this->handle)) return false; if(!is_resource($this->handle)) return false;
@ -1692,7 +1709,6 @@ class MSSQLQuery extends SS_Query {
public function numRecords() { public function numRecords() {
if(!is_resource($this->handle)) return false; if(!is_resource($this->handle)) return false;
if($this->mssql) { if($this->mssql) {
return mssql_num_rows($this->handle); return mssql_num_rows($this->handle);
} else { } else {
@ -1706,6 +1722,7 @@ class MSSQLQuery extends SS_Query {
} }
public function nextRecord() { public function nextRecord() {
if(!is_resource($this->handle)) return false; if(!is_resource($this->handle)) return false;
// Coalesce rather than replace common fields. // Coalesce rather than replace common fields.