SQL definition function included

This commit is contained in:
Geoff Munn 2009-01-09 04:01:37 +00:00
parent 5d9364721d
commit 59bc2da75f

View File

@ -308,23 +308,7 @@ class PostgreSQLDatabase extends Database {
* @param string $fieldSpec The new field specification
*/
public function alterField($tableName, $fieldName, $fieldSpec) {
// This wee function was built for MoT. It will preserve the binary format of the content,
// but change the character set
/*
$changes = $this->query("SELECT ID, \"$fieldName\" FROM \"$tableName\"")->map();
*/
$this->query("ALTER TABLE \"$tableName\" CHANGE \"$fieldName\" \"$fieldName\" $fieldSpec");
// This wee function was built for MoT. It will preserve the binary format of the content,
// but change the character set
/*
echo "<li>Fixing " . sizeof($changes) . " page's contnet";
foreach($changes as $id => $text) {
$SQL_text = Convert::raw2sql($text);
$this->query("UPDATE \"$tableName\" SET \"$fieldName\" = '$SQL_text' WHERE \"ID\" = '$id'");
}
*/
}
/**
@ -366,6 +350,29 @@ class PostgreSQLDatabase extends Database {
$this->query($this->getIndexSqlDefinition($tableName, $indexName, $indexSpec));
}
/*
* This takes the index spec which has been provided by a class (ie static $indexes = blah blah)
* and turns it into a proper string.
* Some indexes may be arrays, such as fulltext and unique indexes, and this allows database-specific
* arrays to be created.
*/
public function convertIndexSpec($indexSpec){
if(is_array($indexSpec)){
//Here we create a db-specific version of whatever index we need to create.
switch($indexSpec['type']){
case 'fulltext':
$indexSpec='fulltext (' . str_replace(' ', '', $indexSpec['value']) . ')';
break;
case 'unique':
$indexSpec='unique (' . $indexSpec['value'] . ')';
break;
}
}
//return $indexSpec;
return '';
}
protected function getIndexSqlDefinition($tableName, $indexName, $indexSpec) {
//$indexSpec = trim($indexSpec);
//if($indexSpec[0] != '(') list($indexType, $indexFields) = explode(' ',$indexSpec,2);