[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. |