Commit 6fffa9e6 authored by zYne's avatar zYne

Manual codes updated Session -> Connection

parent acced2b9
...@@ -67,8 +67,15 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator ...@@ -67,8 +67,15 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
/** /**
* constructor * constructor
*/ *
public function __construct(Doctrine_Table $table) { * @param Doctrine_Table|string $table
*/
public function __construct($table) {
if( ! ($table instanceof Doctrine_Table))
$table = Doctrine_Manager::getInstance()
->getCurrentConnection()
->getTable($table);
$this->table = $table; $this->table = $table;
$name = $table->getAttribute(Doctrine::ATTR_COLL_KEY); $name = $table->getAttribute(Doctrine::ATTR_COLL_KEY);
......
...@@ -22,13 +22,13 @@ $manager = Doctrine_Manager::getInstance(); ...@@ -22,13 +22,13 @@ $manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_LISTENER,new MyListener()); $manager->setAttribute(Doctrine::ATTR_LISTENER,new MyListener());
// setting session level listener // setting connection level listener
$session = $manager->openSession($dbh); $conn = $manager->openConnection($dbh);
$session->setAttribute(Doctrine::ATTR_LISTENER,new MyListener2()); $conn->setAttribute(Doctrine::ATTR_LISTENER,new MyListener2());
// setting factory level listener // setting factory level listener
$table = $session->getTable("User"); $table = $conn->getTable("User");
$table->setAttribute(Doctrine::ATTR_LISTENER,new MyListener()); $table->setAttribute(Doctrine::ATTR_LISTENER,new MyListener());
?> ?>
...@@ -25,19 +25,19 @@ interface iDoctrine_EventListener { ...@@ -25,19 +25,19 @@ interface iDoctrine_EventListener {
public function onWakeUp(Doctrine_Record $record); public function onWakeUp(Doctrine_Record $record);
public function onClose(Doctrine_Session $session); public function onClose(Doctrine_Connection $conn);
public function onPreClose(Doctrine_Session $session); public function onPreClose(Doctrine_Connection $conn);
public function onOpen(Doctrine_Session $session); public function onOpen(Doctrine_Connection $conn);
public function onTransactionCommit(Doctrine_Session $session); public function onTransactionCommit(Doctrine_Connection $conn);
public function onPreTransactionCommit(Doctrine_Session $session); public function onPreTransactionCommit(Doctrine_Connection $conn);
public function onTransactionRollback(Doctrine_Session $session); public function onTransactionRollback(Doctrine_Connection $conn);
public function onPreTransactionRollback(Doctrine_Session $session); public function onPreTransactionRollback(Doctrine_Connection $conn);
public function onTransactionBegin(Doctrine_Session $session); public function onTransactionBegin(Doctrine_Connection $conn);
public function onPreTransactionBegin(Doctrine_Session $session); public function onPreTransactionBegin(Doctrine_Connection $conn);
public function onCollectionDelete(Doctrine_Collection $collection); public function onCollectionDelete(Doctrine_Collection $collection);
public function onPreCollectionDelete(Doctrine_Collection $collection); public function onPreCollectionDelete(Doctrine_Collection $collection);
......
<?php <?php
$table = $session->getTable("User"); $table = $conn->getTable("User");
$table->setEventListener(new MyListener2()); $table->setEventListener(new MyListener2());
......
...@@ -17,7 +17,7 @@ class Email extends Doctrine_Record { ...@@ -17,7 +17,7 @@ class Email extends Doctrine_Record {
$this->hasColumn("address","string",150,"email|unique"); $this->hasColumn("address","string",150,"email|unique");
} }
} }
$session = Doctrine_Manager::getInstance()->openSession(new PDO("dsn","username","password")); $conn = Doctrine_Manager::getInstance()->openConnection(new PDO("dsn","username","password"));
$user = new User(); $user = new User();
$user->name = "this is an example of too long name"; $user->name = "this is an example of too long name";
...@@ -36,7 +36,7 @@ $user->Email->address = "drink@drinkmore.info"; ...@@ -36,7 +36,7 @@ $user->Email->address = "drink@drinkmore.info";
$user->save(); // saved $user->save(); // saved
$user = $session->create("User"); $user = $conn->create("User");
$user->Email->address = "drink@drinkmore.info"; // not unique! $user->Email->address = "drink@drinkmore.info"; // not unique!
$user->save(); // throws a Doctrine_Validator_Exception $user->save(); // throws a Doctrine_Validator_Exception
?> ?>
<?php <?php
$table = $session->getTable("User"); $table = $conn->getTable("User");
$users = $table->findAll(); $users = $table->findAll();
......
<?php <?php
$table = $session->getTable("User"); $table = $conn->getTable("User");
$table->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_IMMEDIATE); $table->setAttribute(Doctrine::ATTR_FETCHMODE, Doctrine::FETCH_IMMEDIATE);
...@@ -7,7 +7,7 @@ $users = $table->findAll(); ...@@ -7,7 +7,7 @@ $users = $table->findAll();
// or // or
$users = $session->query("FROM User-I"); // immediate collection $users = $conn->query("FROM User-I"); // immediate collection
foreach($users as $user) { foreach($users as $user) {
print $user->name; print $user->name;
...@@ -20,7 +20,7 @@ $users = $table->findAll(); ...@@ -20,7 +20,7 @@ $users = $table->findAll();
// or // or
$users = $session->query("FROM User-L"); // lazy collection $users = $conn->query("FROM User-L"); // lazy collection
foreach($users as $user) { foreach($users as $user) {
print $user->name; print $user->name;
...@@ -32,7 +32,7 @@ $users = $table->findAll(); ...@@ -32,7 +32,7 @@ $users = $table->findAll();
// or // or
$users = $session->query("FROM User-B"); // batch collection $users = $conn->query("FROM User-B"); // batch collection
foreach($users as $user) { foreach($users as $user) {
print $user->name; print $user->name;
...@@ -44,7 +44,7 @@ $users = $table->findAll(); ...@@ -44,7 +44,7 @@ $users = $table->findAll();
// or // or
$users = $session->query("FROM User-O"); // offset collection $users = $conn->query("FROM User-O"); // offset collection
foreach($users as $user) { foreach($users as $user) {
print $user->name; print $user->name;
......
<?php <?php
$users = $session->query("FROM User"); $users = $conn->query("FROM User");
// now lets load phonenumbers for all users // now lets load phonenumbers for all users
......
<?php <?php
// Doctrine_Manager controls all the sessions // Doctrine_Manager controls all the connections
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
// open first session // open first connection
$session = $manager->openSession(new PDO("dsn","username","password"), "session 1"); $conn = $manager->openConnection(new PDO("dsn","username","password"), "connection 1");
// open second session // open second connection
$session2 = $manager->openSession(new PDO("dsn2","username2","password2"), "session 2"); $conn2 = $manager->openConnection(new PDO("dsn2","username2","password2"), "connection 2");
$manager->getCurrentSession(); // $session2 $manager->getCurrentConnection(); // $conn2
$manager->setCurrentSession("session 1"); $manager->setCurrentConnection("connection 1");
$manager->getCurrentSession(); // $session $manager->getCurrentConnection(); // $conn
// iterating through sessions // iterating through connections
foreach($manager as $session) { foreach($manager as $conn) {
} }
?> ?>
<?php <?php
// Doctrine_Manager controls all the sessions // Doctrine_Manager controls all the connections
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
// Doctrine_Session // Doctrine_Connection
// a script may have multiple open sessions // a script may have multiple open connections
// (= multiple database connections) // (= multiple database connections)
$dbh = new PDO("dsn","username","password"); $dbh = new PDO("dsn","username","password");
$session = $manager->openSession(); $conn = $manager->openConnection();
// or if you want to use Doctrine Doctrine_DB and its // or if you want to use Doctrine Doctrine_DB and its
// performance monitoring capabilities // performance monitoring capabilities
$dsn = "schema://username:password@dsn/dbname"; $dsn = "schema://username:password@dsn/dbname";
$dbh = Doctrine_DB::getConnection($dsn); $dbh = Doctrine_DB::getConnection($dsn);
$session = $manager->openSession(); $conn = $manager->openConnection();
?> ?>
...@@ -2,26 +2,26 @@ ...@@ -2,26 +2,26 @@
// find all users // find all users
$coll = $session->query("FROM User"); $coll = $conn->query("FROM User");
// find all users with only their names (and primary keys) fetched // find all users with only their names (and primary keys) fetched
$coll = $session->query("FROM User(name)"); $coll = $conn->query("FROM User(name)");
// find all groups // find all groups
$coll = $session->query("FROM Group"); $coll = $conn->query("FROM Group");
// find all users and user emails // find all users and user emails
$coll = $session->query("FROM User.Email"); $coll = $conn->query("FROM User.Email");
// find all users and user emails with only user name and // find all users and user emails with only user name and
// age + email address loaded // age + email address loaded
$coll = $session->query("FROM User(name, age).Email(address)"); $coll = $conn->query("FROM User(name, age).Email(address)");
// find all users, user email and user phonenumbers // find all users, user email and user phonenumbers
$coll = $session->query("FROM User.Email, User.Phonenumber"); $coll = $conn->query("FROM User.Email, User.Phonenumber");
?> ?>
<?php <?php
// select all users and load the data directly (Immediate fetching strategy) // select all users and load the data directly (Immediate fetching strategy)
$coll = $session->query("FROM User-I"); $coll = $conn->query("FROM User-I");
// or // or
$coll = $session->query("FROM User-IMMEDIATE"); $coll = $conn->query("FROM User-IMMEDIATE");
// select all users and load the data in batches // select all users and load the data in batches
$coll = $session->query("FROM User-B"); $coll = $conn->query("FROM User-B");
// or // or
$coll = $session->query("FROM User-BATCH"); $coll = $conn->query("FROM User-BATCH");
// select all user and use lazy fetching // select all user and use lazy fetching
$coll = $session->query("FROM User-L"); $coll = $conn->query("FROM User-L");
// or // or
$coll = $session->query("FROM User-LAZY"); $coll = $conn->query("FROM User-LAZY");
?> ?>
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// find the first ten users and their emails // find the first ten users and their emails
$coll = $session->query("FROM User, User.Email LIMIT 10"); $coll = $conn->query("FROM User, User.Email LIMIT 10");
// find the first ten users starting from the user number 5 // find the first ten users starting from the user number 5
$coll = $session->query("FROM User LIMIT 10 OFFSET 5"); $coll = $conn->query("FROM User LIMIT 10 OFFSET 5");
?> ?>
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// retrieve all users with only their properties id and name loaded // retrieve all users with only their properties id and name loaded
$users = $session->query("FROM User(id, name)"); $users = $conn->query("FROM User(id, name)");
?> ?>
<?php <?php
$session = Doctrine_Manager::getInstance()->openSession(new PDO("dsn","username","password")); $conn = Doctrine_Manager::getInstance()->openConnection(new PDO("dsn","username","password"));
$query = new Doctrine_Query($session); $query = new Doctrine_Query($conn);
$query->from("User-b") $query->from("User-b")
->where("User.name LIKE 'Jack%'") ->where("User.name LIKE 'Jack%'")
......
<?php <?php
// find all users, sort by name descending // find all users, sort by name descending
$coll = $session->query("FROM User ORDER BY User.name DESC"); $coll = $conn->query("FROM User ORDER BY User.name DESC");
// find all users sort by name ascending // find all users sort by name ascending
$coll = $session->query("FROM User ORDER BY User.name ASC"); $coll = $conn->query("FROM User ORDER BY User.name ASC");
// or // or
$coll = $session->query("FROM User ORDER BY User.name"); $coll = $conn->query("FROM User ORDER BY User.name");
// find all users and their emails, sort by email address // find all users and their emails, sort by email address
$coll = $session->query("FROM User, User.Email ORDER BY User.Email.address"); $coll = $conn->query("FROM User, User.Email ORDER BY User.Email.address");
// find all users and their emails, sort by user name and email address // find all users and their emails, sort by user name and email address
$coll = $session->query("FROM User, User.Email ORDER BY User.name, User.Email.address"); $coll = $conn->query("FROM User, User.Email ORDER BY User.name, User.Email.address");
?> ?>
...@@ -4,24 +4,24 @@ ...@@ -4,24 +4,24 @@
// find all groups where the group primary key is bigger than 10 // find all groups where the group primary key is bigger than 10
$coll = $session->query("FROM Group WHERE Group.id > 10"); $coll = $conn->query("FROM Group WHERE Group.id > 10");
// find all users where users where user name matches a regular expression, // find all users where users where user name matches a regular expression,
// REGEXP keyword must be supported by the underlying database // REGEXP keyword must be supported by the underlying database
$coll = $session->query("FROM User WHERE User.name REGEXP '[ad]'"); $coll = $conn->query("FROM User WHERE User.name REGEXP '[ad]'");
// find all users and their associated emails where SOME of the users phonenumbers // find all users and their associated emails where SOME of the users phonenumbers
// (the association between user and phonenumber tables is Many-To-Many) starts with 123 // (the association between user and phonenumber tables is Many-To-Many) starts with 123
$coll = $session->query("FROM User, User.Email WHERE User.Phonenumber.phonenumber LIKE '123%'"); $coll = $conn->query("FROM User, User.Email WHERE User.Phonenumber.phonenumber LIKE '123%'");
// multiple conditions // multiple conditions
$coll = $session->query("FROM User WHERE User.name LIKE '%Jack%' && User.Email.address LIKE '%@drinkmore.info'"); $coll = $conn->query("FROM User WHERE User.name LIKE '%Jack%' && User.Email.address LIKE '%@drinkmore.info'");
// nesting conditions // nesting conditions
$coll = $session->query("FROM User WHERE (User.name LIKE '%Jack%' || User.name LIKE '%John%') && User.Email.address LIKE '%@drinkmore.info'"); $coll = $conn->query("FROM User WHERE (User.name LIKE '%Jack%' || User.name LIKE '%John%') && User.Email.address LIKE '%@drinkmore.info'");
?> ?>
<?php <?php
$query = new Doctrine_RawSql($session); $query = new Doctrine_RawSql($conn);
$query->parseQuery("SELECT {entity.*}, {phonenumber.*} $query->parseQuery("SELECT {entity.*}, {phonenumber.*}
FROM entity FROM entity
......
<?php <?php
$query = new Doctrine_RawSql($session); $query = new Doctrine_RawSql($conn);
$query->select('{entity.name}') $query->select('{entity.name}')
->from('entity'); ->from('entity');
......
<?php <?php
$query = new Doctrine_RawSql($session); $query = new Doctrine_RawSql($conn);
$query->parseQuery("SELECT {entity.name} FROM entity"); $query->parseQuery("SELECT {entity.name} FROM entity");
......
<?php <?php
$user = $session->create("User"); $user = $conn->create("User");
// alternative way: // alternative way:
$table = $session->getTable("User"); $table = $conn->getTable("User");
$user = $table->create(); $user = $table->create();
......
<?php <?php
$table = $session->getTable("User"); $table = $conn->getTable("User");
$user = $table->find(2); $user = $table->find(2);
......
<?php <?php
$table = $session->getTable("User"); $table = $conn->getTable("User");
// find by primary key // find by primary key
...@@ -19,5 +19,5 @@ foreach($table->findByDql("name LIKE '%John%'") as $user) { ...@@ -19,5 +19,5 @@ foreach($table->findByDql("name LIKE '%John%'") as $user) {
// finding objects with DQL // finding objects with DQL
$users = $session->query("FROM User WHERE User.name LIKE '%John%'"); $users = $conn->query("FROM User WHERE User.name LIKE '%John%'");
?> ?>
<?php <?php
$table = $session->getTable("User"); $table = $conn->getTable("User");
$user = $table->find(2); $user = $table->find(2);
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
$user = new User(); $user = new User();
$user->name = "Jack"; $user->name = "Jack";
$group = $session->create("Group"); $group = $conn->create("Group");
$group->name = "Drinking Club"; $group->name = "Drinking Club";
// saves all the changed objects into database // saves all the changed objects into database
$session->flush(); $conn->flush();
?> ?>
<?php <?php
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
// open new session // open new connection
$session = $manager->openSession(new PDO("dsn","username","password")); $conn = $manager->openConnection(new PDO("dsn","username","password"));
// getting a table object // getting a table object
$table = $session->getTable("User"); $table = $conn->getTable("User");
?> ?>
<?php <?php
switch($session->getState()) switch($conn->getState())
case Doctrine_Session::STATE_ACTIVE: case Doctrine_Connection::STATE_ACTIVE:
// session open and zero open transactions // connection open and zero open transactions
break; break;
case Doctrine_Session::STATE_ACTIVE: case Doctrine_Connection::STATE_ACTIVE:
// one open transaction // one open transaction
break; break;
case Doctrine_Session::STATE_BUSY: case Doctrine_Connection::STATE_BUSY:
// multiple open transactions // multiple open transactions
break; break;
case Doctrine_Session::STATE_CLOSED: case Doctrine_Connection::STATE_CLOSED:
// session closed // connection closed
break; break;
endswitch; endswitch;
?> ?>
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// select all users // select all users
$session->query("FROM User"); $conn->query("FROM User");
// select all users where user email is jackdaniels@drinkmore.info // select all users where user email is jackdaniels@drinkmore.info
$session->query("FROM User WHERE User.Email.address = 'jackdaniels@drinkmore.info'"); $conn->query("FROM User WHERE User.Email.address = 'jackdaniels@drinkmore.info'");
?> ?>
...@@ -4,18 +4,18 @@ class UserTable extends Doctrine_Table { ...@@ -4,18 +4,18 @@ class UserTable extends Doctrine_Table {
* you can add your own finder methods here * you can add your own finder methods here
*/ */
public function findByName($name) { public function findByName($name) {
return $this->getSession()->query("FROM User WHERE name LIKE '%$name%'"); return $this->getConnection()->query("FROM User WHERE name LIKE '%$name%'");
} }
} }
class User extends Doctrine_Record { } class User extends Doctrine_Record { }
$session = Doctrine_Manager::getInstance() $conn = Doctrine_Manager::getInstance()
->openSession(new PDO("dsn","username","password")); ->openConnection(new PDO("dsn","username","password"));
// doctrine will now check if a class called UserTable exists // doctrine will now check if a class called UserTable exists
// and if it inherits Doctrine_Table // and if it inherits Doctrine_Table
$table = $session->getTable("User"); $table = $conn->getTable("User");
print get_class($table); // UserTable print get_class($table); // UserTable
......
<?php <?php
$table = $session->getTable("User"); $table = $conn->getTable("User");
// find by primary key // find by primary key
......
<?php <?php
$table = $session->getTable('User'); $table = $conn->getTable('User');
// getting column names // getting column names
......
<?php <?php
$sess = Doctrine_Manager::getInstance()->openSession(new PDO("dsn","username","password")); $sess = Doctrine_Manager::getInstance()->openConnection(new PDO("dsn","username","password"));
// select first ten rows starting from the row 20 // select first ten rows starting from the row 20
......
<?php <?php
try { try {
$session->beginTransaction(); $conn->beginTransaction();
$user->save(); $user->save();
$session->beginTransaction(); $conn->beginTransaction();
$group->save(); $group->save();
$email->save(); $email->save();
$session->commit(); $conn->commit();
$session->commit(); $conn->commit();
} catch(Exception $e) { } catch(Exception $e) {
$session->rollback(); $conn->rollback();
} }
?> ?>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// works only if you use doctrine database handler // works only if you use doctrine database handler
$dbh = $session->getDBH(); $dbh = $conn->getDBH();
$times = $dbh->getExecTimes(); $times = $dbh->getExecTimes();
......
<?php <?php
$sess = Doctrine_Manager::getInstance()->openSession(new PDO("dsn","username","password")); $sess = Doctrine_Manager::getInstance()->openConnection(new PDO("dsn","username","password"));
// gets the next ID from a sequence // gets the next ID from a sequence
......
<?php <?php
$sess = Doctrine_Manager::getInstance()->openSession(new PDO("dsn","username","password")); $sess = Doctrine_Manager::getInstance()->openConnection(new PDO("dsn","username","password"));
try { try {
$sess->beginTransaction(); $sess->beginTransaction();
......
...@@ -39,7 +39,7 @@ $user->save(); ...@@ -39,7 +39,7 @@ $user->save();
$user->Groupuser->delete(); $user->Groupuser->delete();
$groups = new Doctrine_Collection($session->getTable("Group")); $groups = new Doctrine_Collection($conn->getTable("Group"));
$groups[0]->name = "Third Group"; $groups[0]->name = "Third Group";
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
*/ */
$users->delete(); $users->delete();
/** /**
* On session drivers other than mysql doctrine would now perform three queries * On connection drivers other than mysql doctrine would now perform three queries
* regardless of how many users, emails and phonenumbers there are * regardless of how many users, emails and phonenumbers there are
* *
* the queries would look something like: * the queries would look something like:
......
...@@ -62,7 +62,7 @@ class EntityListener extends Doctrine_EventListener { ...@@ -62,7 +62,7 @@ class EntityListener extends Doctrine_EventListener {
$manager = Doctrine_Manager::getInstance(); $manager = Doctrine_Manager::getInstance();
$session = $manager->openSession(new PDO("DSN","username","password")); $conn = $manager->openConnection(new PDO("DSN","username","password"));
$user = new User(); $user = new User();
......
<?php <?php
$sess = $manager->openSession(Doctrine_DB::getConnection("schema://username:password@hostname/database")); $sess = $manager->openConnection(Doctrine_DB::getConnection("schema://username:password@hostname/database"));
// get session state: // get connection state:
switch($sess): switch($sess):
case Doctrine_Session::STATE_BUSY: case Doctrine_Connection::STATE_BUSY:
// multiple open transactions // multiple open transactions
break; break;
case Doctrine_Session::STATE_ACTIVE: case Doctrine_Connection::STATE_ACTIVE:
// one open transaction // one open transaction
break; break;
case Doctrine_Session::STATE_CLOSED: case Doctrine_Connection::STATE_CLOSED:
// closed state // closed state
break; break;
case Doctrine_Session::STATE_OPEN: case Doctrine_Connection::STATE_OPEN:
// open state and zero open transactions // open state and zero open transactions
break; break;
endswitch; endswitch;
...@@ -21,10 +21,10 @@ endswitch; ...@@ -21,10 +21,10 @@ endswitch;
$dbh = $sess->getDBH(); $dbh = $sess->getDBH();
// flushing the session // flushing the connection
$sess->flush(); $sess->flush();
// print lots of useful info about session: // print lots of useful info about connection:
print $sess; print $sess;
?> ?>
<?php <?php
$session->beginTransaction(); $conn->beginTransaction();
$user = new User(); $user = new User();
$user->name = 'New user'; $user->name = 'New user';
$user->save(); $user->save();
$user = $session->getTable('User')->find(5); $user = $conn->getTable('User')->find(5);
$user->name = 'Modified user'; $user->name = 'Modified user';
$user->save(); $user->save();
$session->commit(); // all the queries are executed here $conn->commit(); // all the queries are executed here
?> ?>
<?php <?php
function saveUserAndGroup(Doctrine_Session $session, User $user, Group $group) { function saveUserAndGroup(Doctrine_Connection $conn, User $user, Group $group) {
$session->beginTransaction(); $conn->beginTransaction();
$user->save(); $user->save();
$group->save(); $group->save();
$session->commit(); $conn->commit();
} }
try { try {
$session->beginTransaction(); $conn->beginTransaction();
saveUserAndGroup($session,$user,$group); saveUserAndGroup($conn,$user,$group);
saveUserAndGroup($session,$user2,$group2); saveUserAndGroup($conn,$user2,$group2);
saveUserAndGroup($session,$user3,$group3); saveUserAndGroup($conn,$user3,$group3);
$session->commit(); $conn->commit();
} catch(Doctrine_Exception $e) { } catch(Doctrine_Exception $e) {
$session->rollback(); $conn->rollback();
} }
?> ?>
<?php <?php
$session->beginTransaction(); $conn->beginTransaction();
$user = new User(); $user = new User();
$user->name = 'New user'; $user->name = 'New user';
$user->save(); $user->save();
$user = $session->getTable('User')->find(5); $user = $conn->getTable('User')->find(5);
$user->name = 'Modified user'; $user->name = 'Modified user';
$user->save(); $user->save();
$pending = $session->getInserts(); // an array containing one element $pending = $conn->getInserts(); // an array containing one element
$pending = $session->getUpdates(); // an array containing one element $pending = $conn->getUpdates(); // an array containing one element
$session->commit(); // all the queries are executed here $conn->commit(); // all the queries are executed here
?> ?>
...@@ -210,6 +210,5 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase { ...@@ -210,6 +210,5 @@ class Doctrine_Query_Limit_TestCase extends Doctrine_UnitTestCase {
$this->assertEqual($q->getQuery(), $this->assertEqual($q->getQuery(),
"SELECT photo.id AS photo__id, photo.name AS photo__name FROM photo LEFT JOIN phototag ON photo.id = phototag.photo_id LEFT JOIN tag ON tag.id = phototag.tag_id WHERE photo.id IN (SELECT DISTINCT photo.id FROM photo LEFT JOIN phototag ON photo.id = phototag.photo_id LEFT JOIN tag ON tag.id = phototag.tag_id WHERE tag.id = ? LIMIT 100) AND tag.id = ? ORDER BY photo.id DESC"); "SELECT photo.id AS photo__id, photo.name AS photo__name FROM photo LEFT JOIN phototag ON photo.id = phototag.photo_id LEFT JOIN tag ON tag.id = phototag.tag_id WHERE photo.id IN (SELECT DISTINCT photo.id FROM photo LEFT JOIN phototag ON photo.id = phototag.photo_id LEFT JOIN tag ON tag.id = phototag.tag_id WHERE tag.id = ? LIMIT 100) AND tag.id = ? ORDER BY photo.id DESC");
} }
} }
?> ?>
...@@ -28,7 +28,7 @@ require_once("QueryLimitTestCase.php"); ...@@ -28,7 +28,7 @@ require_once("QueryLimitTestCase.php");
error_reporting(E_ALL); error_reporting(E_ALL);
$test = new GroupTest("Doctrine Framework Unit Tests"); $test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_SessionTestCase()); $test->addTestCase(new Doctrine_SessionTestCase());
...@@ -66,7 +66,7 @@ $test->addTestCase(new Doctrine_CollectionTestCase()); ...@@ -66,7 +66,7 @@ $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_QueryTestCase());
$test->addTestCase(new Doctrine_RawSql_TestCase()); $test->addTestCase(new Doctrine_RawSql_TestCase());
*/
$test->addTestCase(new Doctrine_Query_Limit_TestCase()); $test->addTestCase(new Doctrine_Query_Limit_TestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());
......
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