mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
MINOR Fixed undefined variables
This commit is contained in:
parent
b85db20c88
commit
17c8ea054d
@ -424,13 +424,10 @@ class SQLite3Database 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) {
|
||||||
|
|
||||||
$oldFieldList = $this->fieldList($tableName);
|
$oldFieldList = $this->fieldList($tableName);
|
||||||
|
$oldCols = array();
|
||||||
|
|
||||||
if(array_key_exists($oldName, $oldFieldList)) {
|
if(array_key_exists($oldName, $oldFieldList)) {
|
||||||
|
|
||||||
$oldCols = array();
|
|
||||||
|
|
||||||
foreach($oldFieldList as $name => $spec) {
|
foreach($oldFieldList as $name => $spec) {
|
||||||
$oldCols[] = "\"$name\"" . (($name == $oldName) ? " AS $newName" : '');
|
$oldCols[] = "\"$name\"" . (($name == $oldName) ? " AS $newName" : '');
|
||||||
$newCols[] = "\"". (($name == $oldName) ? $newName : $name). "\"";
|
$newCols[] = "\"". (($name == $oldName) ? $newName : $name). "\"";
|
||||||
@ -459,8 +456,8 @@ class SQLite3Database extends SS_Database {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function fieldList($table) {
|
public function fieldList($table) {
|
||||||
|
|
||||||
$sqlCreate = DB::query('SELECT sql FROM sqlite_master WHERE type = "table" AND name = "' . $table . '"')->record();
|
$sqlCreate = DB::query('SELECT sql FROM sqlite_master WHERE type = "table" AND name = "' . $table . '"')->record();
|
||||||
|
$fieldList = array();
|
||||||
|
|
||||||
if($sqlCreate && $sqlCreate['sql']) {
|
if($sqlCreate && $sqlCreate['sql']) {
|
||||||
preg_match('/^[\s]*CREATE[\s]+TABLE[\s]+"[a-zA-Z0-9_]+"[\s]*\((.+)\)[\s]*$/ims', $sqlCreate['sql'], $matches);
|
preg_match('/^[\s]*CREATE[\s]+TABLE[\s]+"[a-zA-Z0-9_]+"[\s]*\((.+)\)[\s]*$/ims', $sqlCreate['sql'], $matches);
|
||||||
@ -471,10 +468,9 @@ class SQLite3Database extends SS_Database {
|
|||||||
$name = str_replace('"', '', trim($name));
|
$name = str_replace('"', '', trim($name));
|
||||||
$fieldList[$name] = implode(' ', $details);
|
$fieldList[$name] = implode(' ', $details);
|
||||||
}
|
}
|
||||||
return $fieldList;
|
|
||||||
} else {
|
|
||||||
return array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $fieldList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -484,7 +480,6 @@ class SQLite3Database extends SS_Database {
|
|||||||
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
* @param string $indexSpec The specification of the index, see Database::requireIndex() for more details.
|
||||||
*/
|
*/
|
||||||
public function createIndex($tableName, $indexName, $indexSpec) {
|
public function createIndex($tableName, $indexName, $indexSpec) {
|
||||||
|
|
||||||
$spec = $this->convertIndexSpec($indexSpec, $indexName);
|
$spec = $this->convertIndexSpec($indexSpec, $indexName);
|
||||||
if(!preg_match('/".+"/', $indexName)) $indexName = "\"$indexName\"";
|
if(!preg_match('/".+"/', $indexName)) $indexName = "\"$indexName\"";
|
||||||
|
|
||||||
@ -498,8 +493,7 @@ class SQLite3Database extends SS_Database {
|
|||||||
* Some indexes may be arrays, such as fulltext and unique indexes, and this allows database-specific
|
* Some indexes may be arrays, such as fulltext and unique indexes, and this allows database-specific
|
||||||
* arrays to be created.
|
* arrays to be created.
|
||||||
*/
|
*/
|
||||||
public function convertIndexSpec($indexSpec, $indexName = null){
|
public function convertIndexSpec($indexSpec, $indexName = null) {
|
||||||
|
|
||||||
if(is_array($indexSpec)) {
|
if(is_array($indexSpec)) {
|
||||||
$indexSpec = $indexSpec['value'];
|
$indexSpec = $indexSpec['value'];
|
||||||
} else if(is_numeric($indexSpec)) {
|
} else if(is_numeric($indexSpec)) {
|
||||||
@ -536,7 +530,6 @@ class SQLite3Database extends SS_Database {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function indexList($table) {
|
public function indexList($table) {
|
||||||
|
|
||||||
$indexList = array();
|
$indexList = array();
|
||||||
foreach(DB::query('PRAGMA index_list("' . $table . '")') as $index) {
|
foreach(DB::query('PRAGMA index_list("' . $table . '")') as $index) {
|
||||||
$list = array();
|
$list = array();
|
||||||
@ -553,7 +546,7 @@ class SQLite3Database extends SS_Database {
|
|||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function tableList() {
|
public function tableList() {
|
||||||
|
$tables = array();
|
||||||
foreach($this->query('SELECT name FROM sqlite_master WHERE type = "table"') as $record) {
|
foreach($this->query('SELECT name FROM sqlite_master WHERE type = "table"') as $record) {
|
||||||
//$table = strtolower(reset($record));
|
//$table = strtolower(reset($record));
|
||||||
$table = reset($record);
|
$table = reset($record);
|
||||||
|
Loading…
Reference in New Issue
Block a user