From c004bbdf4f0e824e5ccbaef8f98ca4a3d44d3b49 Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 14 Jul 2006 06:46:31 +0000 Subject: Changed SQLMap manual into a prado app. --- .../pages/Manual/StatementElementAttributes.page | 216 +++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 demos/sqlmap-docs/protected/pages/Manual/StatementElementAttributes.page (limited to 'demos/sqlmap-docs/protected/pages/Manual/StatementElementAttributes.page') diff --git a/demos/sqlmap-docs/protected/pages/Manual/StatementElementAttributes.page b/demos/sqlmap-docs/protected/pages/Manual/StatementElementAttributes.page new file mode 100644 index 00000000..e5cef09d --- /dev/null +++ b/demos/sqlmap-docs/protected/pages/Manual/StatementElementAttributes.page @@ -0,0 +1,216 @@ + + +

Statement-type Element Attributes

+

The six statement-type elements take various attributes. See +Mapped Statements for a +table itemizing which attributes each +element-type accepts. The individual attributes are described in the sections +that follow.

+ +

id attribute

+

+The required id attribute provides a name for this statement, which must +be unique within this <SqlMap>.

+ +

parameterMap attribute

+

A Parameter Map defines an ordered list of values that match up with the "?" +placeholders of a standard, parameterized query statement. +The following example shows a <parameterMap> and a corresponding +<statement>. + + + + + + + + + insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (?,?); + + + +In the above example, the Parameter Map describes two parameters that +will match, in order, two placeholders in the SQL statement. The first "?" +is replaced by the value of the id property. The second is replaced with +the description property.

+ +

SQLMap also supports named, inline parameters, which most developers seem to +prefer. However, Parameter Maps are useful when the SQL must be kept in a +standard form or when extra information needs to be provided. See +Parameter Maps for futher details.

+ +

parameterClass attribute

+

If a parameterMap attribute is not specified, you may specify a +parameterClass instead and use inline parameters. +The value of the parameterClass attribute +can be any existing PHP class name. The following example shows a +statement using a PHP class named Product in parameterClass +attribute.

+ + + + insert into PRODUCT values (#id#, #description#, #price#) + + + +

resultMap attribute

+

A Result Map lets you control how data is extracted from the result of a +query, and how the columns are mapped to object properties. +The following example shows a <resultMap> element and a +corresponding <statement> element.

+ + + + + + + + + select * from PRODUCT + + + +

In the above example, the result of the SQL query will be mapped to +an instance of the Product class using the "select-product-result" +<resultMap>. The <resultMap> says to +populate the id property +from the PRD_ID column, and to populate the description property +from the PRD_DESCRIPTION column.

+ +
Tip: +In the above example, note that using " select * " is supported. If +you want all the columns, you don't need to map them all individually. (Though +many developers consider it a good practice to always specify the columns +expected.) +
+ +

See Result Maps for futher details.

+ +

resultClass attribute

+

If a resultMap is not specified, you may specify a resultClass +instead. The value of the resultClass attribute can be the name of a PHP +class or primitives like integer, string, or array. The class +specified will be automatically mapped to the columns in the result, based on +the result metadata. The following example shows a <statement> element +with a resultClass attribute.

+ + + + SELECT + PER_ID as Id, + PER_FIRST_NAME as FirstName, + PER_LAST_NAME as LastName, + PER_BIRTH_DATE as BirthDate, + PER_WEIGHT_KG as WeightInKilograms, + PER_HEIGHT_M as HeightInMeters + FROM PERSON + WHERE PER_ID = #value# + + + +

In the above example, the Person class has properties including: +Id, FirstName, LastName, BirthDate, +WeightInKilograms, and HeightInMeters. Each of these corresponds +with the column aliases described by the SQL select statement using the "as" +keyword, a standard SQL feature. When executed, a Person object is +instantiated and populated by matching the object property names to the column +names from the query.

+ +

Using SQL aliases to map columns to properties saves defining a +<resultMap> element, but there are limitations. There is no way to +specify the types of the output columns (if needed), there is no way to +automatically load related data such as complex properties.You can overcome +these limitations with an explicit Result Map.

+ +

listClass attribute

+

In addition to providing the ability to return an TList of objects, the +DataMapper supports the use of custom collection: a class that implements +ArrayAccess. The following is an example of a TList (it implements +ArrayAccess) class that can be used with the DataMapper.

+ + +class AccountCollection extends TList +{ + public function addRange($accounts) + { + foreach($accounts as $account) + $this->add($account); + } + + public function copyTo(TList $array) + { + $array->copyFrom($this); + } +} + + +

An ArrayAccess class can be specified for a select statement through the +listClass attribute. The value of the listClass attribute is the +full name of a PHP class that implements ArrayAccess. The statement +should also indicate the resultClass so that the DataMapper knows how to +handle the type of objects in the collection. The resultClass specified +will be automatically mapped to the columns in the result, based on the result +metadata. The following example shows a <statement> element with a +listClass attribute.

+ + + + select + Account_ID as Id, + Account_FirstName as FirstName, + Account_LastName as LastName, + Account_Email as EmailAddress + from Accounts + order by Account_LastName, Account_FirstName + + + +

cacheModel attribute

+

If you want to cache the result of a query, you can specify a Cache Model as +part of the <statement> element. The following example shows a +<cacheModel> element and a corresponding <statement>.

+ + + + + + + + + + + + select * from PRODUCT where PRD_CAT_ID = #value# + + + +

In the above example, a cache is defined for products that uses a +Least Recently Used [LRU] type and flushes every 24 hours or whenever +associated update statements are executed. See +Cache Models for futher details

+ +

extends attribute

+

When writing Sql, you often encounter duplicate fragments of SQL. SQLMap +offers a simple yet powerful attribute to reuse them.

+ + + + + + + +
\ No newline at end of file -- cgit v1.2.3