diff --git a/core/model/DB.php b/core/model/DB.php index 87ae40323..6a0e611c9 100755 --- a/core/model/DB.php +++ b/core/model/DB.php @@ -15,13 +15,13 @@ class DB { * @var Database */ protected static $globalConn; - + /** * The last SQL query run. * @var string */ public static $lastQuery; - + /** * Set the global database connection. * Pass an object that's a subclass of Database. This object will be used when {@link DB::query()} @@ -31,7 +31,7 @@ class DB { static function setConn($globalConn) { DB::$globalConn = $globalConn; } - + /** * Get the global database connection. * @return Database @@ -39,7 +39,7 @@ class DB { static function getConn() { return DB::$globalConn; } - + /** * Connect to a database. * Given the database configuration, this method will create the correct subclass of Database, @@ -58,7 +58,7 @@ class DB { } // TODO:pkrenn_remove end DB::setConn($conn); } - + /** * Build the connection string from input. * @param array $parameters The connection details. @@ -67,18 +67,18 @@ class DB { public function getConnect($parameters) { return DB::$globalConn->getConnect($parameters); } - + /** * Execute the given SQL query. * @param string $sql The SQL query to execute * @param int $errorLevel The level of error reporting to enable for the query * @return Query */ - static function query($sql, $errorLevel = E_USER_ERROR) { + static function query($sql, $errorLevel = E_USER_ERROR) { DB::$lastQuery = $sql; - return DB::$globalConn->query($sql, $errorLevel); + return DB::$globalConn->query($sql, $errorLevel); } - + /** * Execute a complex manipulation on the database. * A manipulation is an array of insert / or update sequences. The keys of the array are table names, @@ -87,11 +87,11 @@ class DB { * also be a SQL function or similar. * @param array $manipulation */ - static function manipulate($manipulation) { + static function manipulate($manipulation) { DB::$lastQuery = $manipulation; - return DB::$globalConn->manipulate($manipulation); + return DB::$globalConn->manipulate($manipulation); } - + /** * Get the autogenerated ID from the previous INSERT query. * @return int @@ -99,16 +99,16 @@ class DB { static function getGeneratedID($table) { return DB::$globalConn->getGeneratedID($table); } - + /** * Get the ID for the next new record for the table. * @var string $table The name od the table. * @return int */ - static function getNextID($table) { + static function getNextID($table) { return DB::$globalConn->getNextID($table); } - + /** * Check if the connection to the database is active. * @return boolean @@ -116,7 +116,7 @@ class DB { static function isActive() { return DB::$globalConn->isActive(); } - + /** * Create the database and connect to it. This can be called if the * initial database connection is not successful because the database @@ -130,7 +130,7 @@ class DB { static function createDatabase($connect, $username, $password, $database) { return DB::$globalConn->createDatabase($connect, $username, $password, $database); } - + /** * Create a new table. * The table will have a single field - the integer key ID. @@ -139,7 +139,7 @@ class DB { static function createTable($table) { return DB::$globalConn->createTable($table); } - + /** * Create a new field on a table. * @param string $table Name of the table. @@ -149,7 +149,7 @@ class DB { static function createField($table, $field, $spec) { return DB::$globalConn->createField($table, $field, $spec); } - + /** * Generate the following table in the database, modifying whatever already exists * as necessary. @@ -164,7 +164,7 @@ class DB { static function requireTable($table, $fieldSchema = null, $indexSchema = null) { return DB::$globalConn->requireTable($table, $fieldSchema, $indexSchema); } - + /** * Generate the given field on the table, modifying whatever already exists as necessary. * @param string $table The table name. @@ -174,7 +174,7 @@ class DB { static function requireField($table, $field, $spec) { return DB::$globalConn->requireField($table, $field, $spec); } - + /** * Generate the given index in the database, modifying whatever already exists as necessary. * @param string $table The table name. @@ -184,7 +184,7 @@ class DB { static function requireIndex($table, $index, $spec) { return DB::$globalConn->requireIndex($table, $index, $spec); } - + /** * If the given table exists, move it out of the way by renaming it to _obsolete_(tablename). * @param string $table The table name. @@ -192,7 +192,7 @@ class DB { static function dontRequireTable($table) { return DB::$globalConn->dontRequireTable($table); } - + /** * Checks a table's integrity and repairs it if necessary. * @var string $tableName The name of the table. @@ -201,7 +201,7 @@ class DB { static function checkAndRepairTable($table) { return DB::$globalConn->checkAndRepairTable($table); } - + /** * Return the number of rows affected by the previous operation. * @return int @@ -209,7 +209,7 @@ class DB { static function affectedRows() { return DB::$globalConn->affectedRows(); } - + /** * Returns a list of all tables in the database. * The table names will be in lower case. @@ -218,7 +218,7 @@ class DB { static function tableList() { return DB::$globalConn->tableList(); } - + /** * Enable supression of database messages. */ diff --git a/core/model/PDODatabase.php b/core/model/PDODatabase.php index c346f0132..9d0cc4199 100644 --- a/core/model/PDODatabase.php +++ b/core/model/PDODatabase.php @@ -14,20 +14,19 @@ class PDODatabase extends Database { * @var resource */ private $dbConn; - + /** * True if we are connected to a database. * @var boolean */ private $active; - + /** * The name of the database. * @var string */ private $database; - - + /** * Last PDO statement, needed for affectedRows() @@ -67,7 +66,7 @@ class PDODatabase extends Database { } parent::__construct(); } - + /** * Build the connection string from input. * @param array $parameters The connection details. @@ -103,7 +102,7 @@ class PDODatabase extends Database { $connect = $type . ':host=' . $parameters['server'] . $instance . ';port=' . $port; return $connect; } - + /** * Returns true if this database supports collations */ @@ -122,7 +121,7 @@ class PDODatabase extends Database { } return $collations; } - + /** * Get the database version. * @return float @@ -143,7 +142,7 @@ class PDODatabase extends Database { $version = ereg_replace("([A-Za-z-])", "", $dbVersion); return substr(trim($version), 0, 3); // Just get the major and minor version } - + /** * Get the database server, namely mysql, pgsql, or mssql. * @return string @@ -163,7 +162,7 @@ class PDODatabase extends Database { return; } //Debug::backtrace(); - if(isset($_REQUEST['showqueries'])) { + if(isset($_REQUEST['showqueries'])) { Debug::message("\n" . $sql . "\n"); $starttime = microtime(true); } @@ -177,14 +176,14 @@ class PDODatabase extends Database { $duration = microtime(true) - $starttime; Debug::message("\n" . $duration . "\n"); } - + if(!$handle && $errorLevel) { $error = $stmt->errorInfo(); $this->databaseError("Couldn't run query: $sql | " . $error[2], $errorLevel); } return new PDOQuery($this, $stmt); } - + /** * Get the ID for the next new record for the table. * Get the autogenerated ID from the previous INSERT query. @@ -211,7 +210,7 @@ class PDODatabase extends Database { $result = $stmt->fetchColumn(); return $handle ? $result : 1; } - + /** * Determine if the the table is active. * @return bool @@ -219,7 +218,7 @@ class PDODatabase extends Database { public function isActive() { return $this->active ? true : false; } - + /** * Create the database and connect to it. This can be called if the * initial database connection is not successful because the database @@ -307,7 +306,7 @@ class PDODatabase extends Database { self::alterTable($tableName, null, $indexes, null, null); } } - + /** * Alter fields and indexes in existing table. * @var string $tableName The name of the table. @@ -325,20 +324,20 @@ class PDODatabase extends Database { $stmt->execute(); } } - + if ($newIndexes) { foreach ($newIndexes as $name => $column) { $stmt = $this->dbConn->prepare("CREATE INDEX $name ON $table $column"); $stmt->execute(); } } - + if ($alteredFields) { foreach ($alteredFields as $field => $type) { self::alterField($table, $field, $type); } } - + if ($alteredIndexes) { foreach ($newIndexes as $name => $column) { $this->dbConn->query("DROP INDEX $name"); @@ -347,7 +346,7 @@ class PDODatabase extends Database { } } } - + /** * Rename an existing table, the TO is necessary for PostgreSQL and MS SQL. * @var string $oldTableName The name of the existing table. @@ -358,7 +357,7 @@ class PDODatabase extends Database { $stmt = $this->dbConn->prepare("ALTER TABLE $oldTableName RENAME TO $newTableName"); $stmt->execute(); } - + /** * Checks a table's integrity and repairs it if necessary - only available in MySQL, not supported in PostgreSQL and MS SQL. * @var string $tableName The name of the table. @@ -379,7 +378,7 @@ class PDODatabase extends Database { return false; } } - + /** * Helper function used by checkAndRepairTable. * @param string $sql Query to run. @@ -405,7 +404,7 @@ class PDODatabase extends Database { $stmt = $this->dbConn->prepare("ALTER TABLE $tableName ADD $fieldName $fieldSpec"); $stmt->execute(); } - + /** * Change the database type of the given field. * @param string $table The table where to change the field. @@ -436,32 +435,32 @@ class PDODatabase extends Database { } $stmt->execute(); } - + /** * Create an index on a table. * @param string $tableName The name of the table. * @param string $indexName The name of the index. * @param string $indexSpec The specification of the index, see Database::requireIndex() for more details. - * @return void + * @return void */ public function createIndex($tableName, $indexName, $indexSpec) { $stmt = $this->dbConn->prepare("CREATE INDEX $indexName ON $tableName $indexSpec"); $stmt->execute(); } - + /** * Alter an index on a table. * @param string $tableName The name of the table. * @param string $indexName The name of the index. * @param string $indexSpec The specification of the index, see Database::requireIndex() for more details. - * @return void + * @return void */ public function alterIndex($tableName, $indexName, $indexSpec) { $this->dbConn->query("DROP INDEX $indexName"); $stmt = $this->dbConn->prepare("CREATE INDEX $indexName ON $tableName $indexSpec"); $stmt->execute(); } - + /** * Get a list of all the fields for the given table. * The results are not totally equal for all databases (for example collations are handled very differently, PostgreSQL disregards zerofill,...) @@ -558,7 +557,7 @@ class PDODatabase extends Database { return $fieldList; } - + /** * Get a list of all the indexes for the given table. * @param string $able Table of which to show the indexes. @@ -614,7 +613,7 @@ class PDODatabase extends Database { return $indexList; } - + /** * Returns a list of all the tables in the database. * Table names will all be in lowercase. @@ -642,7 +641,7 @@ class PDODatabase extends Database { } return isset($tables) ? $tables : null; } - + /** * Return the number of rows affected (DELETE, INSERT, or UPDATE) by the previous operation. */ @@ -713,4 +712,5 @@ class PDOQuery extends Query { } } -?> + +?> \ No newline at end of file