From fd4b8d9f45d1707035021bc19b8d5bc17ede66ce Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 12 Feb 2007 12:46:11 +0000 Subject: Add IBM DB2 driver for active record. --- .../protected/pages/Database/ActiveRecord.page | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'demos/quickstart/protected/pages/Database') diff --git a/demos/quickstart/protected/pages/Database/ActiveRecord.page b/demos/quickstart/protected/pages/Database/ActiveRecord.page index 406a39fe..2562f674 100644 --- a/demos/quickstart/protected/pages/Database/ActiveRecord.page +++ b/demos/quickstart/protected/pages/Database/ActiveRecord.page @@ -100,10 +100,11 @@ You may need to quote (specific to your database) the value of the $_tablena E.g. MySQL uses back-ticks, $_tablename = "`database1`.`table1`" -
Tip: +

Since TActiveRecord extends TComponent, setter and getter methods can be defined to allow control over how variables are set and returned. For example, adding a $level property to the UserRecord class: +

class UserRecord extends TActiveRecord { ... //existing definitions as above @@ -117,9 +118,8 @@ class UserRecord extends TActiveRecord { } } -
-
Note: +
Info: TActiveRecord can also work with database views by specifying the value $_tablename corresponding to the view name. However, objects returned from views are read-only, calling the save() or delete() method @@ -275,7 +275,7 @@ Method names starting with findAllBy return an array of records. The condition is taken as part of the method name after findBy or findAllBy. The following blocks of code are equivalent: - +

$finder->findByName($name) $finder->find('Name = ?', $name); @@ -291,7 +291,10 @@ $finder->find('Username = ? AND Password = ?', $name, $pass); $finder->findAllByAge($age); $finder->findAll('Age = ?', $age); -

+ +
Tip: +You may also use OR as a condition in the dynamic methods. +

findBySql()

Finds records using full SQL, returns corresponding array of record objects.

@@ -303,6 +306,7 @@ $finder->findAll('Age = ?', $age);

Add a new record using TActiveRecord is very simple, just create a new Active Record object and call the save() method. E.g. +

$user1 = new UserRecord(); $user1->username = "admin" @@ -319,7 +323,6 @@ definitions that automatically creates a primary key for the newly insert record For example, if you insert a new record into a MySQL table that has columns defined with "autoincrement", the Active Record objects will be updated with the new incremented values.
-

To update a record in the database, just change one or more properties of @@ -353,15 +356,16 @@ ends the object life-cycle, no futher actions can be performed on the object. You can also delete records in the database by primary keys without loading any records using the deleteByPk() method. For example, to delete one or records with tables having a scalar primary key. +

$finder->deleteByPk($primaryKey); //delete 1 record $finder->deleteByPk($key1,$key2,...); //delete multiple records $finder->deleteByPk(array($key1,$key2,...)); //delete multiple records -

For composite primary keys (determined automatically from the table definitions): +

$finder->deleteByPk(array($key1,$key2)); //delete 1 record @@ -371,7 +375,6 @@ $finder->deleteByPk(array($key1,$key2), array($key3,$key4),...); //delete multiple records $finder->deleteByPk(array( array($key1,$key2), array($key3,$key4), .. )); -

deleteAll() and deleteBy*()

@@ -387,16 +390,13 @@ $finder->deleteByName($name); //delete by username and password $finder->deleteBy_Username_And_Password($name,$pass); -

- -

Transactions

All Active Record objects contains the property DbConnection that can be used to obtain a transaction object. $finder = UserRecord::finder(); - +$finder->DbConnection->Active=true; //open if necessary $transaction = $finder->DbConnection->beginTransaction(); try { -- cgit v1.2.3