Commit 30a07506 authored by Alexander Butenko's avatar Alexander Butenko

added test for join

parent a5f25d09
......@@ -15,37 +15,66 @@ $tables = Array (
'createdAt' => 'datetime',
'expires' => 'datetime',
'loginCount' => 'int(10) default 0'
),
'products' => Array (
'customerId' => 'int(10) not null',
'userId' => 'int(10) not null',
'productName' => 'char(50)'
)
);
$data = Array (
Array ('login' => 'user1',
'customerId' => 10,
'firstName' => 'John',
'lastName' => 'Doe',
'password' => $db->func('SHA1(?)',Array ("secretpassword+salt")),
'createdAt' => $db->now(),
'expires' => $db->now('+1Y'),
'loginCount' => $db->inc()
),
Array ('login' => 'user2',
'customerId' => 10,
'firstName' => 'Mike',
'lastName' => NULL,
'password' => $db->func('SHA1(?)',Array ("secretpassword2+salt")),
'createdAt' => $db->now(),
'expires' => $db->now('+1Y'),
'loginCount' => $db->inc(2)
'users' => Array (
Array ('login' => 'user1',
'customerId' => 10,
'firstName' => 'John',
'lastName' => 'Doe',
'password' => $db->func('SHA1(?)',Array ("secretpassword+salt")),
'createdAt' => $db->now(),
'expires' => $db->now('+1Y'),
'loginCount' => $db->inc()
),
Array ('login' => 'user2',
'customerId' => 10,
'firstName' => 'Mike',
'lastName' => NULL,
'password' => $db->func('SHA1(?)',Array ("secretpassword2+salt")),
'createdAt' => $db->now(),
'expires' => $db->now('+1Y'),
'loginCount' => $db->inc(2)
),
Array ('login' => 'user3',
'customerId' => 11,
'firstName' => 'Pete',
'lastName' => 'D',
'password' => $db->func('SHA1(?)',Array ("secretpassword2+salt")),
'createdAt' => $db->now(),
'expires' => $db->now('+1Y'),
'loginCount' => $db->inc(3)
)
),
Array ('login' => 'user3',
'customerId' => 11,
'firstName' => 'Pete',
'lastName' => 'D',
'password' => $db->func('SHA1(?)',Array ("secretpassword2+salt")),
'createdAt' => $db->now(),
'expires' => $db->now('+1Y'),
'loginCount' => $db->inc(3)
)
'products' => Array (
Array ('customerId' => 1,
'userId' => 1,
'productName' => 'product1',
),
Array ('customerId' => 1,
'userId' => 1,
'productName' => 'product2',
),
Array ('customerId' => 1,
'userId' => 1,
'productName' => 'product3',
),
Array ('customerId' => 1,
'userId' => 2,
'productName' => 'product4',
),
Array ('customerId' => 1,
'userId' => 2,
'productName' => 'product5',
),
)
);
function createTable ($name, $data) {
......@@ -64,12 +93,15 @@ foreach ($tables as $name => $fields) {
createTable ($name, $fields);
}
foreach ($data as $d) {
$id = $db->insert("users", $d);
if ($id)
$d['id'] = $id;
else {
echo "failed to insert: ".$db->getLastQuery() ."\n". $db->getLastError();
foreach ($data as $name => $datas) {
foreach ($datas as $d) {
$id = $db->insert($name, $d);
if ($id)
$d['id'] = $id;
else {
echo "failed to insert: ".$db->getLastQuery() ."\n". $db->getLastError();
}
}
}
......@@ -147,12 +179,21 @@ if ($db->count != 1) {
exit;
}
$db->join("users u", "p.userId=u.id", "LEFT");
$db->where("u.login",'user2');
$products = $db->get ("products p", null, "u.login, p.productName");
if ($db->count != 2) {
echo "Invalid products count on join ()";
exit;
}
$db->delete("users");
$db->get("users");
if ($db->count != 0) {
echo "Invalid users count after delete";
exit;
}
$db->delete("products");
echo "All done";
//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