Commit 0cd7ef84 authored by Alexander Butenko's avatar Alexander Butenko

Update tests

parent 00529ef3
...@@ -153,6 +153,10 @@ if ($db->count != 1) { ...@@ -153,6 +153,10 @@ if ($db->count != 1) {
exit; exit;
} }
$q = "drop table {$prefix}test;";
$db->rawQuery($q);
$db->orderBy("id","asc"); $db->orderBy("id","asc");
$users = $db->get("users"); $users = $db->get("users");
if ($db->count != 3) { if ($db->count != 3) {
...@@ -253,7 +257,7 @@ if ($db->count != 2) { ...@@ -253,7 +257,7 @@ if ($db->count != 2) {
echo "Invalid users count on where() with between"; echo "Invalid users count on where() with between";
exit; exit;
} }
///
$db->where ("id", 2); $db->where ("id", 2);
$db->orWhere ("customerId", 11); $db->orWhere ("customerId", 11);
$r = $db->get("users"); $r = $db->get("users");
...@@ -261,14 +265,14 @@ if ($db->count != 2) { ...@@ -261,14 +265,14 @@ if ($db->count != 2) {
echo "Invalid users count on orWhere()"; echo "Invalid users count on orWhere()";
exit; exit;
} }
///
$db->where ("lastName", NULL, '<=>'); $db->where ("lastName", NULL, '<=>');
$r = $db->get("users"); $r = $db->get("users");
if ($db->count != 1) { if ($db->count != 1) {
echo "Invalid users count on null where()"; echo "Invalid users count on null where()";
exit; exit;
} }
///
$db->join("users u", "p.userId=u.id", "LEFT"); $db->join("users u", "p.userId=u.id", "LEFT");
$db->where("u.login",'user2'); $db->where("u.login",'user2');
$db->orderBy("CONCAT(u.login, u.firstName)"); $db->orderBy("CONCAT(u.login, u.firstName)");
...@@ -277,7 +281,7 @@ if ($db->count != 2) { ...@@ -277,7 +281,7 @@ if ($db->count != 2) {
echo "Invalid products count on join ()"; echo "Invalid products count on join ()";
exit; exit;
} }
///
$db->where("id = ? or id = ?", Array(1,2)); $db->where("id = ? or id = ?", Array(1,2));
$res = $db->get ("users"); $res = $db->get ("users");
if ($db->count != 2) { if ($db->count != 2) {
...@@ -285,26 +289,40 @@ if ($db->count != 2) { ...@@ -285,26 +289,40 @@ if ($db->count != 2) {
exit; exit;
} }
///
$db->where("id = 1 or id = 2"); $db->where("id = 1 or id = 2");
$res = $db->get ("users"); $res = $db->get ("users");
if ($db->count != 2) { if ($db->count != 2) {
echo "Invalid users count on select with multiple params"; echo "Invalid users count on select with multiple params";
exit; exit;
} }
///
$usersQ = $db->subQuery(); $usersQ = $db->subQuery();
$usersQ->where ("login", "user2"); $usersQ->where ("login", "user2");
$usersQ->getOne ("users", "id"); $usersQ->getOne ("users", "id");
$db2 = $db->copy(); $db->where ("userId", $usersQ);
$db2->where ("userId", $usersQ); $cnt = $db->getValue ("products", "count(id)");
$cnt = $db2->getValue ("products", "count(id)");
if ($cnt != 2) { if ($cnt != 2) {
echo "Invalid select result with subquery"; echo "Invalid select result with subquery";
exit; 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();
$count_members = $cnt->getValue ('users', "COUNT(id)");
echo "count {$count_members}\n";
echo $cnt->getLastQuery() . "\n";
$data = $db->get('users');
print_r ($data);
echo $cnt->getLastQuery() . "\n";
///
$usersQ = $db->subQuery ("u"); $usersQ = $db->subQuery ("u");
$usersQ->where ("active", 1); $usersQ->where ("active", 1);
$usersQ->get("users"); $usersQ->get("users");
...@@ -319,7 +337,7 @@ if ($db->count != 5) { ...@@ -319,7 +337,7 @@ if ($db->count != 5) {
echo "invalid join with subquery count"; echo "invalid join with subquery count";
exit; exit;
} }
///
//TODO: insert test //TODO: insert test
$db->delete("users"); $db->delete("users");
$db->get("users"); $db->get("users");
...@@ -329,9 +347,6 @@ if ($db->count != 0) { ...@@ -329,9 +347,6 @@ if ($db->count != 0) {
} }
$db->delete("products"); $db->delete("products");
$q = "drop table {$prefix}test;";
$db->rawQuery($q);
echo "All done"; echo "All done";
//print_r($db->rawQuery("CALL simpleproc(?)",Array("test"))); //print_r($db->rawQuery("CALL simpleproc(?)",Array("test")));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment