function _db_homogenize($qstruct, $db_reduce = null) { global $SCHEMA; global $debug; if ($debug) { echo "homogenize: "; print_r($qstruct); echo "<br>\n"; } $h**o = $qstruct; if (($test = @$qstruct["TABLE"]) && is_string($test)) { $h**o["TABLE"] = split(",", $test); } $h**o["BASE_TABLE"] = array(); foreach ($h**o["TABLE"] as $alias => $tp_table) { if (is_string($tp_table)) { _db_temporal($tp_table, $table); if ($db_reduce && !_db_check($db_reduce, $table)) { unset($h**o["TABLE"][$alias]); continue; } if (is_int($alias)) { $alias = $tp_table; } $h**o["BASE_TABLE"][$alias] = $table; } elseif (is_array($tp_table)) { $h**o["TABLE"][$alias] = _db_homogenize($tp_table, $db_reduce); } else { die("bad qstruct (TABLE) - this should not happen\n"); } } _db_homogenize_field($h**o, $qstruct, $h**o["BASE_TABLE"], $db_reduce); $h**o["FIELD"] = _db_strip_permissions($h**o, $h**o["FIELD"]); _db_stripfields($h**o["FIELD"], $db_reduce); if ($test = @$qstruct["AGG"]["FIELD"]) { _db_homogenize_field($h**o["AGG"], $qstruct["AGG"], $h**o["BASE_TABLE"], $db_reduce); _db_stripfields($h**o["AGG"]["FIELD"], $db_reduce); } if ($test = @$qstruct["AGG"]["GROUP"]) { $h**o["AGG"]["GROUP"] = split(",", $test); _db_stripfields($h**o["AGG"]["GROUP"], $db_reduce); } if ($test = @$qstruct["ORDER"]) { $h**o["ORDER"] = split(",", $test); _db_stripfields($h**o["ORDER"], $db_reduce); } _db_stripcond($h**o["COND"], $db_reduce); if ($debug) { echo "homogenized: "; print_r($h**o); echo "<br>\n"; } return $h**o; }
function _db_check(&$database, &$table, $field = null) { if (!$database) { // find one global $CONFIG; $database = array_keys($CONFIG); } if (is_array($database)) { foreach ($database as $item) { if (_db_check($item, $table, $field)) { $database = $item; return true; } } return false; } if (!$table) { // find one global $SCHEMA; $table = array_keys($SCHEMA); } if (is_array($table)) { foreach ($table as $item) { if (_db_check($database, $item, $field)) { $table = $item; return true; } } return false; } // now we know everything is flat.... global $SCHEMA; if ($field) { return $SCHEMA[$table]["FIELDS"][$field] && $SCHEMA[$table]["DB"] == $database; } return $SCHEMA[$table]["DB"] == $database; }