Exemplo n.º 1
0
///
$usersQ = $db->subQuery();
$usersQ->where("login", "user2");
$usersQ->getOne("users", "id");
$db->where("userId", $usersQ);
$cnt = $db->getValue("products", "count(id)");
if ($cnt != 2) {
    echo "Invalid select result with subquery";
    exit;
}
///
$dbi_sub = $db->subQuery();
$dbi_sub->where('active', 1);
$dbi_sub->get('users', null, 'id');
$db->where('id', $dbi_sub, 'IN');
$cnt = $db->copy();
$c = $cnt->getValue('users', "COUNT(id)");
if ($c != 3) {
    echo "copy with subquery count failed";
    exit;
}
$data = $db->get('users');
if (count($data) != 3) {
    echo "copy with subquery data count failed";
    exit;
}
///
$usersQ = $db->subQuery("u");
$usersQ->where("active", 1);
$usersQ->get("users");
$db->join($usersQ, "p.userId=u.id", "LEFT");
$db->where("id = ? or id = ?", array(1, 2));
$res = $db->get("users");
if ($db->count != 2) {
    echo "Invalid users count on select with multiple params";
    exit;
}
$db->where("id = 1 or id = 2");
$res = $db->get("users");
if ($db->count != 2) {
    echo "Invalid users count on select with multiple params";
    exit;
}
$usersQ = $db->subQuery();
$usersQ->where("login", "user2");
$usersQ->getOne("users", "id");
$db2 = $db->copy();
$db2->where("userId", $usersQ);
$res = $db2->getOne("products", "count(id) as cnt");
if ($res['cnt'] != 2) {
    echo "Invalid select result with subquery";
    exit;
}
//TODO: insert test
$db->delete("users");
$db->get("users");
if ($db->count != 0) {
    echo "Invalid users count after delete";
    exit;
}
$db->delete("products");
echo "All done";