From d33132b9cf27f0213562896033dc52565c8318f9 Mon Sep 17 00:00:00 2001 From: xue <> Date: Mon, 20 Aug 2007 12:09:02 +0000 Subject: fixed typos. --- .../protected/pages/Database/SqlMap.page | 86 +++++++++++----------- 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'demos/quickstart/protected/pages/Database/SqlMap.page') diff --git a/demos/quickstart/protected/pages/Database/SqlMap.page b/demos/quickstart/protected/pages/Database/SqlMap.page index 2e3aed16..40e8ba20 100644 --- a/demos/quickstart/protected/pages/Database/SqlMap.page +++ b/demos/quickstart/protected/pages/Database/SqlMap.page @@ -3,7 +3,7 @@

Data Mapper

-

Data Mappers moves data between objects and a database while keeping them +

Data Mappers moves data between objects and a database while keeping them independent of each other and the mapper itself. If you started with Active Records, you may eventually faced with more complex business @@ -13,11 +13,11 @@ that is, the object schema and the relational schema don't match up.

-

The Data Mapper separates the in-memory objects from the database. Its responsibility - is to transfer data between the two and also to isolate them from each other. - With Data Mapper the in-memory objects needn't know even that there's a database +

The Data Mapper separates the in-memory objects from the database. Its responsibility + is to transfer data between the two and also to isolate them from each other. + With Data Mapper the in-memory objects needn't know even that there's a database present; they need no SQL interface code, and certainly no knowledge of the - database schema. (The database schema is always ignorant of the objects that use it.) + database schema. (The database schema is always ignorant of the objects that use it.)

When to Use It

@@ -28,46 +28,46 @@ what the database structure is, because all the correspondence is done by the mappers.

-

This helps you in the code because you can understand and work with the domain objects - without having to understand how they're stored in the database. You can modify the +

This helps you in the code because you can understand and work with the domain objects + without having to understand how they're stored in the database. You can modify the business models or the database without having to alter either. With complicated mappings, particularly those involving existing databases, this is very valuable.

-

The price, of course, is the extra layer that you don't get with - Active Record, - so the test for using these patterns is the complexity of the business logic. - If you have fairly simple business logic, an Active Record - will probably work. +

The price, of course, is the extra layer that you don't get with + Active Record, + so the test for using these patterns is the complexity of the business logic. + If you have fairly simple business logic, an Active Record + will probably work. For more complicated logic a Data Mapper may be more suitable.

SqlMap Data Mapper

-

The SqlMap DataMapper framework makes it easier to use a database with a PHP application. - SqlMap DataMapper couples objects with stored procedures or SQL statements using - a XML descriptor. Simplicity is the biggest advantage of the SqlMap DataMapper over - object relational mapping tools. To use SqlMap DataMapper you rely on your own objects, - XML, and SQL. There is little to learn that you don't already know. +

The SqlMap DataMapper framework makes it easier to use a database with a PHP application. + SqlMap DataMapper couples objects with stored procedures or SQL statements using + a XML descriptor. Simplicity is the biggest advantage of the SqlMap DataMapper over + object relational mapping tools. To use SqlMap DataMapper you rely on your own objects, + XML, and SQL. There is little to learn that you don't already know. With SqlMap DataMapper you have the full power of both SQL and stored procedures at your fingertip

alt="SqlMap Data Mapper Overview" id="fig:sqlmap.png" class="figure"/> - - Here's a high level description of the work flow illustrated in the figure abov. + + Here's a high level description of the work flow illustrated in the figure above. Provide a parameter, either as an object or a primitive type. The parameter can be - used to set runtime values in your SQL statement or stored procedure. If a runtime value + used to set runtime values in your SQL statement or stored procedure. If a runtime value is not needed, the parameter can be omitted.

-

Execute the mapping by passing the parameter and the name you gave the statement or +

Execute the mapping by passing the parameter and the name you gave the statement or procedure in your XML descriptor. This step is where the magic happens. The framework - will prepare the SQL statement or stored procedure, set any runtime values using your + will prepare the SQL statement or stored procedure, set any runtime values using your parameter, execute the procedure or statement, and return the result.

In the case of an update, the number of rows affected is returned. In the case of a - query, a single object, or a collection of objects is returned. Like the parameter, + query, a single object, or a collection of objects is returned. Like the parameter, the result object, or collection of objects, can be a plain-old object or a primitive PHP type.

@@ -82,8 +82,8 @@ $dsn = 'pgsql:host=localhost;dbname=test'; //Postgres SQL $conn = new TDbConnection($dsn, 'dbuser','dbpass'); $manager = new TSqlMapManager($conn); $manager->configureXml('my-sqlmap.xml'); -$sqlmap = $manager->getSqlMapGateway(); - +$sqlmap = $manager->getSqlMapGateway(); +

@@ -96,31 +96,31 @@ $sqlmap = $manager->getSqlMapGateway();

SqlMap database connection can also be configured using a <module> - tag in the application.xml + tag in the application.xml or config.xml as follows. - - - + +

The ConfigFile attribute should point to a SqlMap configuration file - (to be detailed later) either using absolute path, relative path or the + (to be detailed later) either using absolute path, relative path or the Prado's namespace dot notation path (must omit the ".xml" extension). - +

Tip: The EnableCache attribute when set to "true" will cache the parsed configuration. You must clear or disable the cache if you - make chanages your configuration file. + make changes to your configuration file. A cache module must also be defined for the cache to function. -
+

To obtain the SqlMap gateway interface from the <module> configuration, simply @@ -140,8 +140,8 @@ class MyPage extends TPage

A quick example

Let us - consider the following "users" table that contains two columns named "username" and "email", - where "username" is also the primary key. + consider the following "users" table that contains two columns named "username" and "email", + where "username" is also the primary key. CREATE TABLE users ( @@ -178,7 +178,7 @@ class User attribute will be used as the identifier for the query. The resultClass attribute value is the name of the class the the objects to be returned. We can now query the objects as follows: - + //assume that $sqlmap is an TSqlMapGateway instance $userList = $sqlmap->queryForList("SelectUsers"); @@ -189,7 +189,7 @@ $user = $sqlmap->queryForObject("SelectUsers");

The above example shows demonstrates only a fraction of the capabilities - of the SqlMap Data Mapper. Further details can be found in the + of the SqlMap Data Mapper. Further details can be found in the SqlMap Manual.

@@ -197,12 +197,12 @@ $user = $sqlmap->queryForObject("SelectUsers");

The above example may seem trival and it also seems that there is alot work just to retrieve some data. However, notice that the User class is totally unware of been stored in the database, and the database is - unware of the User class. + unware of the User class.

One of advantages of SqlMap is the ability to map complex object relationship, collections from an existing - database. On the other hand, Active Record + database. On the other hand, Active Record provide a very simple way to interact with the underlying database but unable to do more complicated relationship or collections. A good compromise is to use SqlMap to retrieve @@ -214,11 +214,11 @@ $user = $sqlmap->queryForObject("SelectUsers"); class UserRecord extends TActiveRecord { - const TABLE='users'; //table name + const TABLE='users'; //table name public $username; //the column named "username" in the "users" table public $email; - + /** * @return TActiveRecord active record finder instance */ @@ -245,7 +245,7 @@ class UserRecord extends TActiveRecord

The PHP code for retrieving the users remains the same, but SqlMap returns Active Records instead, and we can take advantage of the Active Record methods. - + //assume that $sqlmap is an TSqlMapGateway instance $user = $sqlmap->queryForObject("SelectUsers"); @@ -259,7 +259,7 @@ $user->save(); //save it using Active Record

-- cgit v1.2.3