예제 #1
0
function sync_table($src, $dst, $cond = array(), $transl = "", $modes = array("INSERT", "UPDATE", "DELETE"))
{
    global $SYNC_STATUS;
    global $SCHEMA;
    global $ERROR;
    global $debug;
    $tdef = $SCHEMA[$src];
    $version = _db_extfield($src, "version");
    $limit = @$SYNC_STATUS[$src][$dst];
    if ($limit) {
        $cond["{$version} >"] = $limit;
    }
    $qstruct = array("TABLE" => $src, "FIELD" => array(), "COND" => $cond, "ORDER" => "", "START" => 0, "COUNT" => 0);
    $databases = array();
    $q2 = _db_mangle_query($databases, $qstruct);
    // currently only 1 database supported
    $database = key($databases);
    $query = _db_make_query($database, $subqs, $q2);
    $env = array("DB" => $database, "ARG" => $subqs, "CB_PROCESS" => "_sync_cb_table", "SRC" => $src, "DST" => $dst, "TRANSL" => $transl, "MODES" => $modes, "version" => $version, "MAXTIME" => $limit);
    $ok = _db_multiquery($env, false, $query, array("_db_cb_process_data"));
    if (!$ok) {
        if (!$ERROR) {
            $ERROR = "unknown sync error";
        }
        if ($debug) {
            echo "sync oops............................ {$ERROR} <br>\n";
        }
        return false;
    }
    $SYNC_STATUS[$src][$dst] = $env["MAXTIME"];
    return true;
}
function _db_create_view($NEW, $alias, $qstruct)
{
    global $SCHEMA;
    $oldschema = $SCHEMA;
    $SCHEMA = $NEW;
    $databases = array();
    $q2 = _db_mangle_query($databases, $qstruct);
    if (count($databases) == 1) {
        $database = key($databases);
        $query = _db_make_query($database, $subqs, $q2);
    } else {
        $SCHEMA = $oldschema;
        return "/* cannot create distributed view '{$alias}' */\n";
    }
    $SCHEMA = $oldschema;
    return "drop view if exists {$alias};\ncreate view {$alias} as {$query};\n\n";
}
예제 #3
0
function _db_read($qstruct)
{
    global $ERROR;
    global $debug;
    if ($debug) {
        echo "_db_read raw data: ";
        print_r($qstruct);
        echo "<br>\n";
    }
    $databases = array();
    $q2 = _db_mangle_query($databases, $qstruct);
    // currently only 1 database supported
    $database = key($databases);
    $mainquery = _db_make_query($database, $subqs, $q2);
    $query = $mainquery;
    if ($subqs) {
        foreach ($subqs as $name => $tuple) {
            $joinfields = $tuple[0];
            $subquery = $tuple[1];
            if ($joinfields) {
                if (is_array($joinfields)) {
                    $joinfields = implode(",", $joinfields);
                }
                $subquery = "select * from ({$mainquery}) mainquery join ({$subquery}) subquery using({$joinfields})";
            }
            if ($debug) {
                $subquery = "/* alias='{$name}' joinfields='{$joinfields}' */ {$subquery}";
            }
            $query .= "; {$subquery}";
        }
    }
    $env = array("DB" => $database, "ARG" => $subqs, "CB_PROCESS" => "_db_cb_make_keys");
    $ok = _db_multiquery($env, false, $query, array("_db_cb_process_data", "_db_cb_process_subdata"));
    if (!$ok) {
        if (!$ERROR) {
            $ERROR = "unknown retrieval error";
        }
        if ($debug) {
            echo "oops............................ {$ERROR} <br>\n";
        }
        return array();
    }
    $res = array_shift($env["RES"]);
    if ($res) {
        $res = _db_do_datasplit($res, $env);
        if ($debug) {
            echo "got data.<br>\n";
        }
    }
    return $res;
}