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

added test for join

parent a5f25d09
...@@ -15,9 +15,15 @@ $tables = Array ( ...@@ -15,9 +15,15 @@ $tables = Array (
'createdAt' => 'datetime', 'createdAt' => 'datetime',
'expires' => 'datetime', 'expires' => 'datetime',
'loginCount' => 'int(10) default 0' 'loginCount' => 'int(10) default 0'
),
'products' => Array (
'customerId' => 'int(10) not null',
'userId' => 'int(10) not null',
'productName' => 'char(50)'
) )
); );
$data = Array ( $data = Array (
'users' => Array (
Array ('login' => 'user1', Array ('login' => 'user1',
'customerId' => 10, 'customerId' => 10,
'firstName' => 'John', 'firstName' => 'John',
...@@ -45,7 +51,30 @@ $data = Array ( ...@@ -45,7 +51,30 @@ $data = Array (
'expires' => $db->now('+1Y'), 'expires' => $db->now('+1Y'),
'loginCount' => $db->inc(3) '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) { function createTable ($name, $data) {
...@@ -64,13 +93,16 @@ foreach ($tables as $name => $fields) { ...@@ -64,13 +93,16 @@ foreach ($tables as $name => $fields) {
createTable ($name, $fields); createTable ($name, $fields);
} }
foreach ($data as $d) {
$id = $db->insert("users", $d); foreach ($data as $name => $datas) {
foreach ($datas as $d) {
$id = $db->insert($name, $d);
if ($id) if ($id)
$d['id'] = $id; $d['id'] = $id;
else { else {
echo "failed to insert: ".$db->getLastQuery() ."\n". $db->getLastError(); echo "failed to insert: ".$db->getLastQuery() ."\n". $db->getLastError();
} }
}
} }
$db->orderBy("id","asc"); $db->orderBy("id","asc");
...@@ -147,12 +179,21 @@ if ($db->count != 1) { ...@@ -147,12 +179,21 @@ if ($db->count != 1) {
exit; 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->delete("users");
$db->get("users"); $db->get("users");
if ($db->count != 0) { if ($db->count != 0) {
echo "Invalid users count after delete"; echo "Invalid users count after delete";
exit; exit;
} }
$db->delete("products");
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