From 4566ec10a681ece495394b42026dd083a64d7e47 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 16 Aug 2007 06:33:41 +0000 Subject: [PATCH] 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 --- core/model/Database.php | 46 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/core/model/Database.php b/core/model/Database.php index a5799d779..8f62b9ac5 100755 --- a/core/model/Database.php +++ b/core/model/Database.php @@ -154,9 +154,10 @@ abstract class Database extends Object { // Transactional schema altering functions - they don't do anyhting except for update schemaUpdateTransaction function transCreateTable($table) { - $this->schemaUpdateTransaction[$table] = array('command' => 'create'); + $this->schemaUpdateTransaction[$table] = array('command' => 'create', 'newFields' => array(), 'newIndexes' => array()); } function transCreateField($table, $field, $schema) { + $this->transInitTable($table); $this->schemaUpdateTransaction[$table]['newFields'][$field] = $schema; } function transCreateIndex($table, $index, $schema) { @@ -169,6 +170,20 @@ abstract class Database extends Object { $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 @@ -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 = "\n"; + + foreach($this as $record) { + if($first) { + $result .= ""; + foreach($record as $k => $v) { + $result .= " "; + } + $result .= " \n"; + } + + $result .= ""; + foreach($record as $k => $v) { + $result .= " "; + } + $result .= " \n"; + + $first = false; + } + + if($first) return "No records found"; + return $result; + } + /** * 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.
" . Convert::raw2xml($k) . "
" . Convert::raw2xml($v) . "