mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Remove some notice level errors
Added Query::table(), which will return a query as a simple HTML table (for debugging purposes) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@40227 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
015a7dec45
commit
4566ec10a6
@ -154,9 +154,10 @@ abstract class Database extends Object {
|
|||||||
// Transactional schema altering functions - they don't do anyhting except for update schemaUpdateTransaction
|
// Transactional schema altering functions - they don't do anyhting except for update schemaUpdateTransaction
|
||||||
|
|
||||||
function transCreateTable($table) {
|
function transCreateTable($table) {
|
||||||
$this->schemaUpdateTransaction[$table] = array('command' => 'create');
|
$this->schemaUpdateTransaction[$table] = array('command' => 'create', 'newFields' => array(), 'newIndexes' => array());
|
||||||
}
|
}
|
||||||
function transCreateField($table, $field, $schema) {
|
function transCreateField($table, $field, $schema) {
|
||||||
|
$this->transInitTable($table);
|
||||||
$this->schemaUpdateTransaction[$table]['newFields'][$field] = $schema;
|
$this->schemaUpdateTransaction[$table]['newFields'][$field] = $schema;
|
||||||
}
|
}
|
||||||
function transCreateIndex($table, $index, $schema) {
|
function transCreateIndex($table, $index, $schema) {
|
||||||
@ -169,6 +170,20 @@ abstract class Database extends Object {
|
|||||||
$this->schemaUpdateTransaction[$table]['alteredIndexes'][$index] = $schema;
|
$this->schemaUpdateTransaction[$table]['alteredIndexes'][$index] = $schema;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handler for the other transXXX methods - mark the given table as being altered
|
||||||
|
* if it doesn't already exist
|
||||||
|
*/
|
||||||
|
protected function transInitTable($table) {
|
||||||
|
if(!$this->schemaUpdateTransaction[$table]) $this->schemaUpdateTransaction[$table] = array(
|
||||||
|
'command' => 'alter',
|
||||||
|
'newFields' => array(),
|
||||||
|
'newIndexes' => array(),
|
||||||
|
'alteredFields' => array(),
|
||||||
|
'alteredIndexes' => array(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the following table in the database, modifying whatever already exists
|
* Generate the following table in the database, modifying whatever already exists
|
||||||
@ -442,6 +457,35 @@ abstract class Query extends Object implements Iterator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return an HTML table containing the full result-set
|
||||||
|
*/
|
||||||
|
public function table() {
|
||||||
|
$first = true;
|
||||||
|
$result = "<table>\n";
|
||||||
|
|
||||||
|
foreach($this as $record) {
|
||||||
|
if($first) {
|
||||||
|
$result .= "<tr>";
|
||||||
|
foreach($record as $k => $v) {
|
||||||
|
$result .= "<th>" . Convert::raw2xml($k) . "</th> ";
|
||||||
|
}
|
||||||
|
$result .= "</tr> \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
$result .= "<tr>";
|
||||||
|
foreach($record as $k => $v) {
|
||||||
|
$result .= "<td>" . Convert::raw2xml($v) . "</td> ";
|
||||||
|
}
|
||||||
|
$result .= "</tr> \n";
|
||||||
|
|
||||||
|
$first = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($first) return "No records found";
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterator function implementation. Rewind the iterator to the first item and return it.
|
* Iterator function implementation. Rewind the iterator to the first item and return it.
|
||||||
* Makes use of {@link seek()} and {@link numRecords()}, takes care of the plumbing.
|
* Makes use of {@link seek()} and {@link numRecords()}, takes care of the plumbing.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user