Commit f02cae82 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 7aaf8c49
<?php
interface iDoctrine_EventListener {
interface Doctrine_EventListener_Interface {
public function onLoad(Doctrine_Record $record);
public function onPreLoad(Doctrine_Record $record);
......@@ -25,21 +26,20 @@ interface iDoctrine_EventListener {
public function onWakeUp(Doctrine_Record $record);
public function onClose(Doctrine_Connection $conn);
public function onPreClose(Doctrine_Connection $conn);
public function onClose(Doctrine_Connection $connection);
public function onPreClose(Doctrine_Connection $connection);
public function onOpen(Doctrine_Connection $conn);
public function onOpen(Doctrine_Connection $connection);
public function onTransactionCommit(Doctrine_Connection $conn);
public function onPreTransactionCommit(Doctrine_Connection $conn);
public function onTransactionCommit(Doctrine_Connection $connection);
public function onPreTransactionCommit(Doctrine_Connection $connection);
public function onTransactionRollback(Doctrine_Connection $conn);
public function onPreTransactionRollback(Doctrine_Connection $conn);
public function onTransactionRollback(Doctrine_Connection $connection);
public function onPreTransactionRollback(Doctrine_Connection $connection);
public function onTransactionBegin(Doctrine_Connection $conn);
public function onPreTransactionBegin(Doctrine_Connection $conn);
public function onTransactionBegin(Doctrine_Connection $connection);
public function onPreTransactionBegin(Doctrine_Connection $connection);
public function onCollectionDelete(Doctrine_Collection $collection);
public function onPreCollectionDelete(Doctrine_Collection $collection);
}
?>
<?php
// using PDO dsn for connecting sqlite memory table
$dbh = Doctrine_Db::getConnection('sqlite::memory:');
class MyLogger extends Doctrine_Db_EventListener {
public function onPreQuery(Doctrine_Db_Event $event) {
print "database is going to be queried!";
}
public function onQuery(Doctrine_Db_Event $event) {
print "executed: " . $event->getQuery();
}
}
$dbh->setListener(new MyLogger());
$dbh->query("SELECT * FROM foo");
// prints:
// database is going to be queried
// executed: SELECT * FROM foo
class MyLogger2 extends Doctrine_Overloadable {
public function __call($m, $a) {
print $m." called!";
}
}
$dbh->setListener(new MyLogger2());
$dbh->exec("DELETE FROM foo");
// prints:
// onPreExec called!
// onExec called!
?>
......@@ -53,34 +53,3 @@ foreach($e as $line) {
}
renderQueries($str);
?>
Propably the most complex feature DQL parser has to offer is its LIMIT clause parser. In pure
sql the limit clause limits the number of rows returned. So for example when fetching users and their
phonenumbers using limit 20 you might get anything between 1-20 users, since the first user might have 20 phonenumbers and
hence the record set would consist of 20 rows.
<br \><br \>
DQL overcomes this problem with subqueries and with complex but efficient subquery analysis. In the next example
we are going to fetch first 20 users and all their phonenumbers with single efficient query. Notice how the DQL parser is smart enough
to use column aggregation inheritance even in the subquery.
<br \><br \>
<?php
$str = "
DQL QUERY: FROM User(id).Phonenumber LIMIT 20
SQL QUERY: SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity WHERE (entity.type = 0) LIMIT 20) AND (entity.type = 0)
";
renderQueries($str);
?>
In the next example
we are going to fetch first 20 users and all their phonenumbers and only those users that actually have phonenumbers (hence the usage of colon operator = INNER JOIN) with single efficient query.
Notice how the DQL parser is smart enough to use the INNER JOIN in the subquery.
<br \>
<?php
$str = "
DQL QUERY: FROM User(id):Phonenumber LIMIT 20
SQL QUERY: SELECT entity.id AS entity__id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity INNER JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE entity.id IN (SELECT DISTINCT entity.id FROM entity INNER JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (entity.type = 0) LIMIT 20) AND (entity.type = 0)
";
renderQueries($str);
?>
......@@ -394,6 +394,7 @@ $menu = array("Getting started" =>
),
),
*/
/**
"Improving performance" => array(
"Introduction",
"Data types" =>
......@@ -434,7 +435,7 @@ $menu = array("Getting started" =>
"Performance monitoring" => array( "Using the database profiler")
),
*/
"Technology" => array(
"Architecture",
"Design patterns used",
......@@ -535,7 +536,7 @@ $menu = array("Getting started" =>
}
$e = implode(".",array($i,$i2,$i3));
print "<dt>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i.$i2#$e\">".$v2."</a>$str</dt>\n";
print "<dt>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i.$i2#$e\">".$v2."</a></dt>\n";
$i3++;
}
print "</dl></dd>";
......@@ -552,7 +553,7 @@ $menu = array("Getting started" =>
$str .= " [ <font color='red'>code</font> ] ";
//touch("codes/$title - $t.php");
}
print "<dt>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i#$e\">".$t."</a>$str</dt>\n";
print "<dt>".$e." <a href=\"".$_SERVER['PHP_SELF']."?index=$i#$e\">".$t."</a></dt>\n";
}
$i2++;
......
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