--- branches/pear-db/my2pg/xx_pear_db.php 2004/03/05 23:38:19 52 +++ branches/pear-db/my2pg/xx_pear_db.php 2004/03/06 00:33:16 53 @@ -26,13 +26,11 @@ if (DB::isError($db)) { XXX_debug($db->getMessage() ." / ". $db->getUserInfo() . " / ". - $db->getDebugInfo()); + $db->getDebugInfo()); # XXX remove this! print $db->getDebugInfo(); - die($db->getMessage()); } - } function xx_errno() { @@ -50,9 +48,10 @@ return; } + $arr = $rs->fetchRow(DB_FETCHMODE_ASSOC, $GLOBALS["xx_element_nr $rs"]); + XXX_debug("xx_fetch_array ($rs) row: ".$GLOBALS["xx_element_nr $rs"]); - $arr = $rs->fetchRow(DB_FETCHMODE_ASSOC, $GLOBALS["xx_element_nr $rs"]); $GLOBALS["xx_element_nr $rs"]++; return $arr; } @@ -88,19 +87,11 @@ return $num; } -function xx_query($sql, $con = 0) { - global $db; - - if ($con == 0) { - $con = $db; - XXX_debug("xx_query (fixed conn): $sql"); - } else { - XXX_debug("xx_query (conn: $con): $sql"); - } +function filter_sql($sql) { # PostgreSQL MVC obsoletes usage of lock/unlock in mysql terms if (preg_match('/^\s*lock/is', $sql) || preg_match('/^\s*unlock/is', $sql)) { - return 1; + return; } # fix Mysql contact function into something SQL92 compliant @@ -118,18 +109,32 @@ $sql = preg_replace('/password\(([^\)]+)\)/is', 'md5(\\1)', $sql); + return $sql; +} + +function xx_query($sql, $con = 0) { + global $db; + + if ($con == 0) { + $con = $db; + XXX_debug("xx_query (fixed conn): $sql"); + } else { + XXX_debug("xx_query (conn: $con): $sql"); + } + + $sql =filter_sql($sql); + if (! isset($sql)) { + return; + } + $GLOBALS["xx_last_sql"] = $sql; XXX_debug("xx_query [transformed]: $sql"); - $GLOBALS["xx_element_nr $ret"] = 0; - $ret = $con->query($sql); + xx_iserror($ret); - if ($db->isError($ret)) { - #die($db->getUserInfo()); - die($db->DebugInfo()); - } + $GLOBALS["xx_element_nr $ret"] = 0; # $GLOBALS["pg_last_oid"] = pg_last_oid($ret); if ($ret) { @@ -139,6 +144,30 @@ } } +# check for error, if so, die! +function xx_iserror($ret, $message = "") { + global $db; + if ($db->isError($ret)) { + die($message . $ret->getDebugInfo()); + } +} + +# prepare and execute statement in one function +function xx_prepare_execute() { + global $db; + + $args = func_get_args(); + $sql = array_shift($args); + + XXX_debug("xx_prepare_execute: $sql [".join("|",$args)."]"); + + $sth = $db->prepare($sql); + xx_iserror($sth); + $ret = $db->execute($sth, $args); + xx_iserror($ret); + return $ret; +} + function xx_data_seek($rs, $element_nr) { $GLOBALS["xx_element_nr"] = $element_nr; }