PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB2 » Bug #3721

change buildManipSQL() to use PHP-functions

Details

Request #3721change buildManipSQL() to use PHP-functions
Submitted2005-03-06 08:38 UTC
Fromakorthaus at web dot de
StatusClosed
PackageMDB2
PHP Version5.0.3
OSLinux 2.4.28 (Gentoo)
Roadmaps(Not assigned)

Comments

[2005-03-06 08:38 UTC] akorthaus at web dot de

Description:
------------
I tried to write an autoExecute() methode for ADOdb (http://phplens.com/lens/lensforum/msgs.php?id=11643). Now it is implemented there, but not 1:1 my version (but based on this code), which I wrote on base of PEAR::DB/MDB/2, perhaps it is useful for you, I reduced the changes to buildManipSQL() from Extended.php.

Difference is that I do not use php-loops (foreach), but I use php-functions as implode() and str_repeat() instead (should be faster).

Reproduce code:
---------------
function buildManipSQL($table, $table_fields, $mode, $where = false)
{
$db =& $GLOBALS['_MDB2_databases'][$this->db_index];
if (count($table_fields) == 0) {
$db->raiseError(MDB2_ERROR_NEED_MORE_DATA);
}
switch ($mode) {
case MDB2_AUTOQUERY_INSERT:
$cols = implode(',', array_keys($table_fields));
$values = '?'.str_repeat(',?', count($table_fields)-1);
return 'INSERT INTO '.$table.' ('.$cols.') VALUES ('.$values.')';
break;
case MDB2_AUTOQUERY_UPDATE:
$set = implode('= ?,', array_keys($table_fields)).'= ?';
$sql = 'UPDATE '.$table.' SET '.$set;
if ($where !== false) $sql .= ' WHERE '.$where;
return $sql;
break;
default:
$db->raiseError(MDB2_ERROR_SYNTAX);
}
}

[2005-03-06 16:15 UTC] smith at backendmedia dot com

This bug has been fixed in CVS.

In case this was a documentation problem, the fix will show up at the
end of next Sunday (CET) on pear.php.net.

In case this was a pear.php.net website problem, the change will show
up on the website in short time.

Thank you for the report, and for helping us make PEAR better.