Thread: [Openfirst-cvscommit] SF.net SVN: openfirst: [171] trunk/src/includes
Brought to you by:
xtimg
From: <ast...@us...> - 2006-06-21 19:16:57
|
Revision: 171 Author: astronouth7303 Date: 2006-06-21 12:16:53 -0700 (Wed, 21 Jun 2006) ViewCVS: http://svn.sourceforge.net/openfirst/?rev=171&view=rev Log Message: ----------- Work on bug #266. DataBase::replace() now defaults to a set of DELETE/INSERT statements instead of the REPLACE. Needs testing. Modified Paths: -------------- trunk/src/includes/MSSQLDataBase.php trunk/src/includes/ODBCDataBase.php trunk/src/includes/dbase.php Modified: trunk/src/includes/MSSQLDataBase.php =================================================================== --- trunk/src/includes/MSSQLDataBase.php 2006-06-21 18:26:09 UTC (rev 170) +++ trunk/src/includes/MSSQLDataBase.php 2006-06-21 19:16:53 UTC (rev 171) @@ -165,7 +165,6 @@ */ #Used for quoting field and DB names - # FIXME: I don't think MSSQL takes ` as a quote. function quoteName($name, $delimiter = ',') { if (is_array($name)) { $value = ''; @@ -175,7 +174,7 @@ $value = substr($value, 0, -strlen($delimiter)); return $value; } else { - return '`'.$this->escape($name).'`'; + return '['.$this->escape($name).']'; } } @@ -283,19 +282,5 @@ } return $this->query( $sql ); } - - /** REPLACE query wrapper. - * Copied from MediaWiki (but removed the fancy stuff). - * - * @param string $table The table to perform it on. - * @param array $unique An array of unique values that distinquish a row. - * @param array $values An array of values to use in a SET clause. - * - * @todo Insert REPLACE substitute. - */ - function replace( $table, $unique, $values ) { - $sql = "REPLACE INTO ".$this->quoteTable($table)." SET ".$this->quoteFDPairs($values); - return $this->query( $sql ); - } } ?> Modified: trunk/src/includes/ODBCDataBase.php =================================================================== --- trunk/src/includes/ODBCDataBase.php 2006-06-21 18:26:09 UTC (rev 170) +++ trunk/src/includes/ODBCDataBase.php 2006-06-21 19:16:53 UTC (rev 171) @@ -112,8 +112,7 @@ #TODO: Write me! } - #Does ODBC support backticks???? -/* function quoteName($name, $delimiter = ',') { + function quoteName($name, $delimiter = ',') { if (is_array($name)) { $value = ''; foreach ($name as $text) { @@ -122,14 +121,8 @@ $value = substr($value, 0, -strlen($delimiter)); return $value; } else { - return '`'.$this->escape($name).'`'; + return '"'.$this->escape($name).'"'; } - }*/ - - # Does ODBC support REPLACE???? -/* function replace( $table, $unique, $values ) { - $sql = "REPLACE INTO ".$this->quoteTable($table)." SET ".$this->quoteFDPairs($values); - return $this->query( $sql ); - }*/ + } } ?> Modified: trunk/src/includes/dbase.php =================================================================== --- trunk/src/includes/dbase.php 2006-06-21 18:26:09 UTC (rev 170) +++ trunk/src/includes/dbase.php 2006-06-21 19:16:53 UTC (rev 171) @@ -344,15 +344,20 @@ /** REPLACE query wrapper. * Copied from MediaWiki (but removed the fancy stuff). * - * Should this be changed to an alternate form by default? + * @note When implementing a subclass, this should be replaced if a single + * statement exists for the engine in question. (eg, MySQL uses a single + * "REPLACE INTO" statement.) * * @param string $table The table to perform it on. * @param array $unique An array of unique values that distinquish a row. - * @param array $values An array of values to use in a SET clause. + * @param array $values An array of values to use, as if they had been passed to insert(). */ function replace( $table, $unique, $values ) { - $sql = "REPLACE INTO ".$this->quoteTable($table)." SET ".$this->quoteFDPairs($values+$unique); - return $this->query( $sql ); + $etable = $this->quoteTable($table); + $eunique = $this->quoteFDPairs($unique, ' AND '); + $sql = "DELTE FROM {$etable} WHERE {$eunique}; + INSERT INTO {$etable} (".$this->quoteField(array_keys($values)).") VALUES (".$this->quoteData(array_values($values)).")"; + return $this->query( $sql ); } /** INSERT query wrapper. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ast...@us...> - 2006-06-21 22:16:59
|
Revision: 174 Author: astronouth7303 Date: 2006-06-21 15:16:55 -0700 (Wed, 21 Jun 2006) ViewCVS: http://svn.sourceforge.net/openfirst/?rev=174&view=rev Log Message: ----------- Implemented check() Modified Paths: -------------- trunk/src/includes/MSSQLDataBase.php trunk/src/includes/MySQLDataBase.php trunk/src/includes/ODBCDataBase.php Modified: trunk/src/includes/MSSQLDataBase.php =================================================================== --- trunk/src/includes/MSSQLDataBase.php 2006-06-21 21:45:45 UTC (rev 173) +++ trunk/src/includes/MSSQLDataBase.php 2006-06-21 22:16:55 UTC (rev 174) @@ -27,8 +27,14 @@ class MSSQLDataBase extends DataBase { /*private*/ var $type, $connection, $lastquery, $db; + + function MSSQLDataBase() { + $args = func_get_args(); + call_user_func_array(array(&$this, '__construct'), $args); + } + // Wrapper for database selection. - function MSSQLDataBase($type = dbMSSQL, $server = false, $username = false, $password = false, $newlink = false, $flags = false) { + function __construct($type = dbMSSQL, $server = false, $username = false, $password = false, $newlink = false, $flags = false) { $this->type = dbMSSQL; global $sqlTablePrefix; $this->prefix = $sqlTablePrefix; @@ -106,6 +112,10 @@ } } + function check() { + return $this->connection !== false; + } + function fetchObject($resource, $rownumber = false) { $this->checkForFunction('mssql_fetch_object'); return mssql_fetch_object($resource); @@ -150,7 +160,7 @@ # Check if there the connection is valid function check() { - #TODO: Write me! + return $this->connection !== false && is_resource($this->connection); } function escape($text) { Modified: trunk/src/includes/MySQLDataBase.php =================================================================== --- trunk/src/includes/MySQLDataBase.php 2006-06-21 21:45:45 UTC (rev 173) +++ trunk/src/includes/MySQLDataBase.php 2006-06-21 22:16:55 UTC (rev 174) @@ -123,11 +123,11 @@ # Check if there the connection is valid function check() { - #TODO: Write me! + return $this->connection !== false && is_resource($this->connection) && @mysql_ping($this->connection); } function escape($text) { - return mysql_real_escape_string($text); + return mysql_real_escape_string($text, $this->connection); } /** SQL escaping and quoting. Modified: trunk/src/includes/ODBCDataBase.php =================================================================== --- trunk/src/includes/ODBCDataBase.php 2006-06-21 21:45:45 UTC (rev 173) +++ trunk/src/includes/ODBCDataBase.php 2006-06-21 22:16:55 UTC (rev 174) @@ -109,7 +109,7 @@ # Check if there the connection is valid function check() { - #TODO: Write me! + return $this->connection != false && is_resource($this->connection); } function quoteName($name, $delimiter = ',') { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ast...@us...> - 2006-06-21 22:43:16
|
Revision: 175 Author: astronouth7303 Date: 2006-06-21 15:43:09 -0700 (Wed, 21 Jun 2006) ViewCVS: http://svn.sourceforge.net/openfirst/?rev=175&view=rev Log Message: ----------- Changed devel version string from "CVS" to "Devel" Modified Paths: -------------- trunk/src/includes/BaseModule.php trunk/src/includes/functions.php Modified: trunk/src/includes/BaseModule.php =================================================================== --- trunk/src/includes/BaseModule.php 2006-06-21 22:16:55 UTC (rev 174) +++ trunk/src/includes/BaseModule.php 2006-06-21 22:43:09 UTC (rev 175) @@ -32,7 +32,7 @@ $this->mName = 'openFIRST'; $this->mID = 'openfirst.base'; $this->mDir = 'config'; - $this->mVersion = 'CVS'; + $this->mVersion = 'DEVEL'; $this->mDate = time(); // Definitive date please? $this->mAuthor = 'The openFIRST Team'; $this->mMaintainer = 'The openFIRST Team'; @@ -52,4 +52,4 @@ return new BaseModule($Dir); } } -?> \ No newline at end of file +?> Modified: trunk/src/includes/functions.php =================================================================== --- trunk/src/includes/functions.php 2006-06-21 22:16:55 UTC (rev 174) +++ trunk/src/includes/functions.php 2006-06-21 22:43:09 UTC (rev 175) @@ -192,9 +192,9 @@ /** Compares 2 module versions * - * The versions strings are either PHP-formatted versions, or "CVS" (case + * The versions strings are either PHP-formatted versions, or "Devel" (case * sensitive) to mean development (use dates instead). (See version_compare() - * <http://us3.php.net/manual/en/function.version-compare.php> for the details + * <http://www.php.net/manual/en/function.version-compare.php> for the details * as to how to format versions.) * * It is always assumed that dev is newer if compared to a version. @@ -202,10 +202,11 @@ * @param string $left The left-hand version * @param string $right The right-hand version * @return mixed -1 if the left is older, 1 if the right is older, 0 if they - * are equal, and false if dates should be used (ie, they're both CVS). + * are equal, and false if dates should be used (ie, they're both + * development versions). */ function ofCompareVersions($left, $right) { - if ($left == 'CVS' && $right == 'CVS') { + if ($left == 'Devel' && $right == 'Devel') { return false; } version_compare($left, $right); @@ -248,4 +249,4 @@ } } } -?> \ No newline at end of file +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ast...@us...> - 2006-06-22 22:52:34
|
Revision: 185 Author: astronouth7303 Date: 2006-06-22 15:52:27 -0700 (Thu, 22 Jun 2006) ViewCVS: http://svn.sourceforge.net/openfirst/?rev=185&view=rev Log Message: ----------- Fixing inheritance. Modified Paths: -------------- trunk/src/includes/MSSQLDataBase.php trunk/src/includes/MySQLDataBase.php trunk/src/includes/ODBCDataBase.php trunk/src/includes/dbase.php Modified: trunk/src/includes/MSSQLDataBase.php =================================================================== --- trunk/src/includes/MSSQLDataBase.php 2006-06-22 22:18:39 UTC (rev 184) +++ trunk/src/includes/MSSQLDataBase.php 2006-06-22 22:52:27 UTC (rev 185) @@ -26,7 +26,7 @@ require_once('dbase.php'); class MSSQLDataBase extends DataBase { - /*private*/ var $type, $connection, $lastquery, $db; + /*private*/ /*var $type, $connection, $lastquery, $db;*/ function MSSQLDataBase() { $args = func_get_args(); @@ -35,9 +35,8 @@ // Wrapper for database selection. function __construct($type = dbMSSQL, $server = false, $username = false, $password = false, $newlink = false, $flags = false) { + parent::__construct(); $this->type = dbMSSQL; - global $sqlTablePrefix; - $this->prefix = $sqlTablePrefix; $this->checkForFunction('mssql_connect'); $this->connection = mssql_connect($server, $username, $password); } Modified: trunk/src/includes/MySQLDataBase.php =================================================================== --- trunk/src/includes/MySQLDataBase.php 2006-06-22 22:18:39 UTC (rev 184) +++ trunk/src/includes/MySQLDataBase.php 2006-06-22 22:52:27 UTC (rev 185) @@ -26,12 +26,16 @@ require_once('dbase.php'); class MySQLDataBase extends DataBase { - /*private*/ var $type, $connection, $lastquery, $db, $prefix; + /*private*/ /*var $type, $connection, $lastquery, $db, $prefix;*/ + function MySQLDataBase() { + $args = func_get_args(); + call_user_func_array(array(&$this, '__construct'), $args); + } + // Wrapper for database selection. - function MySQLDataBase($type = dbMYSQL, $server = false, $username = false, $password = false, $newlink = false, $flags = false) { + function __construct($type = dbMYSQL, $server = false, $username = false, $password = false, $newlink = false, $flags = false) { + parent::__construct($type, $server, $username, $password, $newlink, $flags); $this->type = dbMYSQL; - global $sqlTablePrefix; - $this->prefix = $sqlTablePrefix; $this->checkForFunction('mysql_connect'); if($flags !== false) { $this->connection = mysql_connect($server, $username, $password, $newlink, $flags); Modified: trunk/src/includes/ODBCDataBase.php =================================================================== --- trunk/src/includes/ODBCDataBase.php 2006-06-22 22:18:39 UTC (rev 184) +++ trunk/src/includes/ODBCDataBase.php 2006-06-22 22:52:27 UTC (rev 185) @@ -26,13 +26,16 @@ require_once('dbase.php'); class ODBCDataBase extends DataBase { - /*private*/ var $type, $connection, $lastquery, $db, $prefix; + /*private*/ /*var $type, $connection, $lastquery, $db, $prefix;*/ + function ODBCDataBase() { + $args = func_get_args(); + call_user_func_array(array(&$this, '__construct'), $args); + } + // Wrapper for database selection. - function ODBCDataBase($type = dbMYSQL, $server = '', $username = '', $password = '', $newlink = false, $flags = null) { - $this->type = $type; - global $sqlTablePrefix; - $this->prefix = $sqlTablePrefix; - + function __construct($type = dbODBC, $server = '', $username = '', $password = '', $newlink = false, $flags = null) { + parent::__construct($type, $server, $username, $password, $newlink, $flags); + $this->type = dbODBC; $this->checkForFunction('odbc_connect'); if($newlink !== false) { $this->connection = odbc_connect($server, $username, $password, $newlink); Modified: trunk/src/includes/dbase.php =================================================================== --- trunk/src/includes/dbase.php 2006-06-22 22:18:39 UTC (rev 184) +++ trunk/src/includes/dbase.php 2006-06-22 22:52:27 UTC (rev 185) @@ -51,8 +51,12 @@ */ class DataBase { /*private*/ var $type, $connection, $lastquery, $db, $prefix, $overrides; + function DataBase($type = dbUNKNOWN, $server = '', $username = '', $password = '', $newlink = '', $flags = '') { + $args = func_get_args(); + call_user_func_array(array(&$this, '__construct'), $args); + } // Wrapper for database selection. - function DataBase($type = dbUNKNOWN, $server = '', $username = '', $password = '', $newlink = '', $flags = '') { + function __construct($type = dbUNKNOWN, $server = '', $username = '', $password = '', $newlink = '', $flags = '') { $this->type = $type; global $sqlTablePrefix; $this->prefix = $sqlTablePrefix; @@ -548,7 +552,7 @@ $scol .= $this->quoteField($col->getName()).' '; } $type = $col->getType(); - if (in_array(strtolower($type), $this->overrides)) { + if (array_key_exists(strtolower($type), $this->overrides)) { $type = $this->overrides[strtolower($type)]; } if ($type == 'SET' || $type == 'ENUM') { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ast...@us...> - 2006-06-23 22:31:32
|
Revision: 200 Author: astronouth7303 Date: 2006-06-23 15:31:26 -0700 (Fri, 23 Jun 2006) ViewCVS: http://svn.sourceforge.net/openfirst/?rev=200&view=rev Log Message: ----------- Found bug in key altering, was case sensitive. Now it isn't. Modified Paths: -------------- trunk/src/includes/dbase.php trunk/src/includes/xmlModule.php Modified: trunk/src/includes/dbase.php =================================================================== --- trunk/src/includes/dbase.php 2006-06-23 05:11:49 UTC (rev 199) +++ trunk/src/includes/dbase.php 2006-06-23 22:31:26 UTC (rev 200) @@ -585,9 +585,9 @@ foreach($table->getKeys() as $keyname) { $key = $table->getKey($keyname); $skey = ''; - if ($key->getType() == 'PRIMARY') { + if (strcasecmp($key->getType(), 'PRIMARY') == 0) { $skey = 'PRIMARY KEY'; - } else if ($key->getType() == 'UNIQUE') { + } else if (strcasecmp($key->getType(), 'UNIQUE') == 0) { $skey = 'UNIQUE '.$this->quoteField($key->getName()); } else { $skey = 'INDEX '.$this->quoteField($key->getName()); Modified: trunk/src/includes/xmlModule.php =================================================================== --- trunk/src/includes/xmlModule.php 2006-06-23 05:11:49 UTC (rev 199) +++ trunk/src/includes/xmlModule.php 2006-06-23 22:31:26 UTC (rev 200) @@ -653,7 +653,7 @@ $this->mName = $this->mType = false; if (isset($args[0])) $this->mName = $args[0]; - if (isset($args[1])) $this->mType = $args[1]; + if (isset($args[1])) $this->mType = strtoupper($args[1]); if ( (strcasecmp($this->mType, 'primary') == 0) || (strcasecmp($this->mName, 'primary') == 0) ) { $this->mType = 'PRIMARY'; @@ -823,4 +823,4 @@ } } -?> \ No newline at end of file +?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ast...@us...> - 2006-07-04 14:07:09
|
Revision: 209 Author: astronouth7303 Date: 2006-07-04 07:07:01 -0700 (Tue, 04 Jul 2006) ViewCVS: http://svn.sourceforge.net/openfirst/?rev=209&view=rev Log Message: ----------- Added __clone() methods, so that PHP5 code doesn't screw it up. Modified Paths: -------------- trunk/src/includes/MSSQLDataBase.php trunk/src/includes/MySQLDataBase.php trunk/src/includes/ODBCDataBase.php trunk/src/includes/dbase.php Modified: trunk/src/includes/MSSQLDataBase.php =================================================================== --- trunk/src/includes/MSSQLDataBase.php 2006-07-04 14:06:05 UTC (rev 208) +++ trunk/src/includes/MSSQLDataBase.php 2006-07-04 14:07:01 UTC (rev 209) @@ -45,6 +45,14 @@ return new MSSQLDataBase(dbMSSQL, $server, $username, $password); } + /** + * Called in PHP5 when you clone an object to re-initialize properties. + * Needed primarily because otherwise error numbers and such would get mixed up. + */ + function __clone() { + $this->connection = mssql_connect($this->server, $this->username, $this->password); + } + /*public*/ function getTypeName() { return 'Microsoft SQL'; } Modified: trunk/src/includes/MySQLDataBase.php =================================================================== --- trunk/src/includes/MySQLDataBase.php 2006-07-04 14:06:05 UTC (rev 208) +++ trunk/src/includes/MySQLDataBase.php 2006-07-04 14:07:01 UTC (rev 209) @@ -50,6 +50,18 @@ return new MySQLDataBase(dbMYSQL, $server, $username, $password, $newlink, $flags); } + /** + * Called in PHP5 when you clone an object to re-initialize properties. + * Needed primarily because otherwise error numbers and such would get mixed up. + */ + function __clone() { + if($this->flags !== false) { + $this->connection = mysql_connect($this->server, $this->username, $this->password, true, $this->flags); + } else { + $this->connection = mysql_connect($this->server, $this->username, $this->password); + } + } + /*public*/ function getTypeName() { return 'MySQL'; } Modified: trunk/src/includes/ODBCDataBase.php =================================================================== --- trunk/src/includes/ODBCDataBase.php 2006-07-04 14:06:05 UTC (rev 208) +++ trunk/src/includes/ODBCDataBase.php 2006-07-04 14:07:01 UTC (rev 209) @@ -48,6 +48,14 @@ return new MySQLDataBase(dbODBC, $server, $username, $password, $newlink); } + /** + * Called in PHP5 when you clone an object to re-initialize properties. + * Needed primarily because otherwise error numbers and such would get mixed up. + */ + function __clone() { + $this->connection = odbc_connect($this->server, $this->username, $this->password, true); + } + /*public*/ function getTypeName() { return 'ODBC'; } Modified: trunk/src/includes/dbase.php =================================================================== --- trunk/src/includes/dbase.php 2006-07-04 14:06:05 UTC (rev 208) +++ trunk/src/includes/dbase.php 2006-07-04 14:07:01 UTC (rev 209) @@ -32,14 +32,14 @@ $ogLastQuery = ''; -function &ofCreateDataBase($type, $server, $password, $newlink = false, $flags = false) { +function &ofCreateDataBase($type, $server, $username, $password, $newlink = false, $flags = false) { $class = "{$type}DataBase"; if (!class_exists($class)) { // This assumption is only for DataBase implementations require_once("{$class}.php"); } //$obj =& $class::factory($server, $password, $newlink, $flags); - $obj =& call_user_func(array($class, 'factory'), $server, $password, $newlink, $flags); + $obj =& call_user_func(array($class, 'factory'), $server, $username, $password, $newlink, $flags); return $obj; } @@ -51,12 +51,17 @@ */ class DataBase { /*private*/ var $type, $connection, $lastquery, $db, $prefix, $overrides; + /*private*/ var $server, $username, $password, $flags; // $newlink isn't needed function DataBase($type = dbUNKNOWN, $server = '', $username = '', $password = '', $newlink = '', $flags = '') { $args = func_get_args(); call_user_func_array(array(&$this, '__construct'), $args); } // Wrapper for database selection. - function __construct($type = dbUNKNOWN, $server = '', $username = '', $password = '', $newlink = '', $flags = '') { + function __construct($type = dbUNKNOWN, $server = false, $username = false, $password = false, $newlink = false, $flags = false) { + $this->server = $server; + $this->username = $username; + $this->password = $password; + $this->flags = $flags; $this->type = $type; global $sqlTablePrefix; $this->prefix = $sqlTablePrefix; @@ -68,7 +73,15 @@ /*static*/ function &factory($server = false, $username = false, $password = false, $newlink = false, $flags = false) { # Override } - + + /** + * Called in PHP5 when you clone an object to re-initialize properties. + */ + function __clone() { + # Override + //$this->connection = __connect__($this->server, $this->username, $this->password, $this->flags); + } + /** Returns the display name for this type of database. */ /*public*/ function getTypeName() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |