cvs: peardoc /en/package/database db-dataobject.xml /en/package/database/db-dataobject intro-casting.xml intro-filters.xml intro-relations.xml
| From: | Alan Knowles | Date: | Wed, 12 Nov 2003 01:49:15 +0000 |
| Subject: | cvs: peardoc /en/package/database db-dataobject.xml /en/package/database/db-dataobject intro-casting.xml intro-filters.xml intro-relations.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-1951@lists.php.net to get a copy of this message | ||
alan_k Tue Nov 11 20:49:15 2003 EDT
Added files:
/peardoc/en/package/database/db-dataobject intro-casting.xml
Modified files:
/peardoc/en/package/database db-dataobject.xml
/peardoc/en/package/database/db-dataobject intro-filters.xml
intro-relations.xml
Log:
adding casting documentation
Index: peardoc/en/package/database/db-dataobject.xml diff -u peardoc/en/package/database/db-dataobject.xml:1.9 peardoc/en/package/database/db-dataobject.xml:1.10 --- peardoc/en/package/database/db-dataobject.xml:1.9 Tue Nov 11 08:04:16 2003 +++ peardoc/en/package/database/db-dataobject.xml Tue Nov 11 20:49:14 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.9 $ --> +<!-- $Revision: 1.10 $ --> <sect1 id="package.database.db-dataobject"> <title>DB_DataObject</title> @@ -81,6 +81,9 @@ &package.database.db-dataobject.db-dataobject.debuglevel; &package.database.db-dataobject.db-dataobject.debug; &package.database.db-dataobject.db-dataobject.raiseerror; + +<!-- casting.. a little experimental at present --> + &package.database.db-dataobject.intro-casting; <!-- This shouldnt really be public.... &package.database.db-dataobject.db-dataobject.staticinitialize; Index: peardoc/en/package/database/db-dataobject/intro-filters.xml diff -u peardoc/en/package/database/db-dataobject/intro-filters.xml:1.3 peardoc/en/package/database/db-dataobject/intro-filters.xml:1.4 --- peardoc/en/package/database/db-dataobject/intro-filters.xml:1.3 Tue Nov 11 08:50:49 2003 +++ peardoc/en/package/database/db-dataobject/intro-filters.xml Tue Nov 11 20:49:15 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <refentry id="package.database.db-dataobject.intro-filters"> <refnamediv> Index: peardoc/en/package/database/db-dataobject/intro-relations.xml diff -u peardoc/en/package/database/db-dataobject/intro-relations.xml:1.5 peardoc/en/package/database/db-dataobject/intro-relations.xml:1.6 --- peardoc/en/package/database/db-dataobject/intro-relations.xml:1.5 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-relations.xml Tue Nov 11 20:49:15 2003 @@ -1,6 +1,6 @@ -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> - <refentry id="packages.database.db-dataobject.relations"> + <refentry id="package.database.db-dataobject.intro-relations"> <refnamediv> <refname>Automatic Table Linking and Joins</refname> <refpurpose> Index: peardoc/en/package/database/db-dataobject/intro-casting.xml +++ peardoc/en/package/database/db-dataobject/intro-casting.xml <!-- $Revision: 1.1 $ --> <refentry id="package.database.db-dataobject.intro-casting"> <refnamediv> <refname>Casting - Dates, Blobs and Null</refname> <refpurpose> DB_DataObject_Cast ::date(), ::blob(), ::sql() </refpurpose> </refnamediv> <refsect1> <title>Dealing with Casting, (everything except strings and numbers)</title> <warning><para> This is experimental!, although it is documented, it currently only supports a limited amount of databases (send me fixes if you want it to support your favorite database), and the internal operations/API may change in the future.. </para></warning> <para> DataObjects is a very easy way to work with databases that are focused on numbers and strings. You can also use it on date fields (although you must format your strings correctly), and you can use it with other types by using raw SQL query(), and the string value "null" is automatically converted to NULL in the database. </para> <para> In an effort to provide a cleaner way to code to the richer database types, the DB_DataObject_Cast object was created. It's purpose is to simply create an object to represent some of the more unusual types. Below is an example of using it to create a few simple types. </para> <para> Cast Objects can be used in both building queries, and assigning values <example> <title> Cast Objects for building and assigning values</title> <programlisting role="php"><![CDATA[ <?php // using Cast Objects for building a query. $person = DB_DataObject::factory('person'); // assign the value of birthday to a Cast object with a date. $person->birthday = DB_DataObject_Cast::date(2000,12,30); $person->find(); while ($person->fetch()) { echo "{$person->name} has a birthday on 30 december 2002<BR>"; } // use Cast Objects for assigning values. $person = DB_DataObject::factory('person'); $person->get(12); // set the persons's birthday to 30 december 2000 $person->birthday = DB_DataObject_Cast::date(2000,12,30); // now update the database. $person->update(); ?> ]]> </programlisting> </example> </para> <para> As you can see, This component is in it"s infancy, so if you have any feature requests, ideas, please do not hesitate to contact me at alan_k at php dot net. </para> </refsect1> <refsect1> <title>The blob and string type</title> <para> Blobs are fields which can store large amounts of binary data in the databases. </para> <para> At present only blobs is only supported in postgres using the bytea type. (please email me with code for other databases.) </para> <para> <example> <title> Inserting a photo and a big text file</title> <programlisting role="php"><![CDATA[ <?php $person = DB_DataObject::factory('person'); $person->name = 'fred' // use blob for binary data. $person->photo = DB_DataObject_Cast::blob(file_get_contents('xxx.jpg')); // use string for textural data into a blob type. $person->xmldocs = DB_DataObject_Cast::string(file_get_contents('xxx.xml')); // now insert into the database. $person->insert(); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1> <title>The date type</title> <para> Most dates are stored in a database in ISO standard format, this method, allows you to create date types, from either Year,month,day, Human readable day/month/year, or standard iso format year-month-day. It fills in the remaining values based on simple rules. </para> <para> <example> <title> Inserting a date in various formats</title> <programlisting role="php"><![CDATA[ <?php $person = DB_DataObject::factory('person'); $person->name = 'fred' // use a human readable date // full format $person->birthday = new DB_DataObject_Cast::date('21/12/2003'); // use only a month/year - actually sets to 1 december 2003 $person->expires = DB_DataObject_Cast::date('12/2003'); // use only a year only - actually sets to 1 jan 2003 $person->expires = DB_DataObject_Cast::date(2003); // use a iso formated // full formated $person->birthday = DB_DataObject_Cast::date('2003-12-21'); // use only a year-month - actually sets to 1 december 2003 $person->expires = DB_DataObject_Cast::date('2003-12'); // using array syntax // full formated $person->birthday = DB_DataObject_Cast::date(2003,12,21); // use only a year-month - actually sets to 1 december 2003 $person->expires = DB_DataObject_Cast::date(2003,12); // the real values are stored in object variables echo $person->birthday->year; // prints 2003 echo $person->birthday->month; // prints 12 echo $person->birthday->day; // prints 21 // you can do simple date addition (similar to mktime) $d = DB_DataObject_Cast::date('01/12/2003'); $nextMonth = DB_DataObject_Cast::date($d->year,$d->month+1,1); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1> <title>The sql type</title> <para> Some types are sql specific, or may even be database specific, you can use the sql type to put raw strings as part of the sql statement. </para> <para> <example> <title> using raw sql</title> <programlisting role="php"><![CDATA[ <?php $person = DB_DataObject::factory('person'); $person->get(12); // set the birthday to null. $person->birthday = DB_DataObject_Cast::sql('NULL'); // do a sql cast statement (postgres specific) $data = DB_DataObject_Cast::sql('cast("123123",datetime)'); // now insert into the database. $person->insert(); ?> ]]> </programlisting> </example> </para> </refsect1> </refentry>
Index: peardoc/en/package/database/db-dataobject.xml diff -u peardoc/en/package/database/db-dataobject.xml:1.9 peardoc/en/package/database/db-dataobject.xml:1.10 --- peardoc/en/package/database/db-dataobject.xml:1.9 Tue Nov 11 08:04:16 2003 +++ peardoc/en/package/database/db-dataobject.xml Tue Nov 11 20:49:14 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.9 $ --> +<!-- $Revision: 1.10 $ --> <sect1 id="package.database.db-dataobject"> <title>DB_DataObject</title> @@ -81,6 +81,9 @@ &package.database.db-dataobject.db-dataobject.debuglevel; &package.database.db-dataobject.db-dataobject.debug; &package.database.db-dataobject.db-dataobject.raiseerror; + +<!-- casting.. a little experimental at present --> + &package.database.db-dataobject.intro-casting; <!-- This shouldnt really be public.... &package.database.db-dataobject.db-dataobject.staticinitialize; Index: peardoc/en/package/database/db-dataobject/intro-filters.xml diff -u peardoc/en/package/database/db-dataobject/intro-filters.xml:1.3 peardoc/en/package/database/db-dataobject/intro-filters.xml:1.4 --- peardoc/en/package/database/db-dataobject/intro-filters.xml:1.3 Tue Nov 11 08:50:49 2003 +++ peardoc/en/package/database/db-dataobject/intro-filters.xml Tue Nov 11 20:49:15 2003 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <refentry id="package.database.db-dataobject.intro-filters"> <refnamediv> Index: peardoc/en/package/database/db-dataobject/intro-relations.xml diff -u peardoc/en/package/database/db-dataobject/intro-relations.xml:1.5 peardoc/en/package/database/db-dataobject/intro-relations.xml:1.6 --- peardoc/en/package/database/db-dataobject/intro-relations.xml:1.5 Tue Oct 14 18:54:08 2003 +++ peardoc/en/package/database/db-dataobject/intro-relations.xml Tue Nov 11 20:49:15 2003 @@ -1,6 +1,6 @@ -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> - <refentry id="packages.database.db-dataobject.relations"> + <refentry id="package.database.db-dataobject.intro-relations"> <refnamediv> <refname>Automatic Table Linking and Joins</refname> <refpurpose> Index: peardoc/en/package/database/db-dataobject/intro-casting.xml +++ peardoc/en/package/database/db-dataobject/intro-casting.xml <!-- $Revision: 1.1 $ --> <refentry id="package.database.db-dataobject.intro-casting"> <refnamediv> <refname>Casting - Dates, Blobs and Null</refname> <refpurpose> DB_DataObject_Cast ::date(), ::blob(), ::sql() </refpurpose> </refnamediv> <refsect1> <title>Dealing with Casting, (everything except strings and numbers)</title> <warning><para> This is experimental!, although it is documented, it currently only supports a limited amount of databases (send me fixes if you want it to support your favorite database), and the internal operations/API may change in the future.. </para></warning> <para> DataObjects is a very easy way to work with databases that are focused on numbers and strings. You can also use it on date fields (although you must format your strings correctly), and you can use it with other types by using raw SQL query(), and the string value "null" is automatically converted to NULL in the database. </para> <para> In an effort to provide a cleaner way to code to the richer database types, the DB_DataObject_Cast object was created. It's purpose is to simply create an object to represent some of the more unusual types. Below is an example of using it to create a few simple types. </para> <para> Cast Objects can be used in both building queries, and assigning values <example> <title> Cast Objects for building and assigning values</title> <programlisting role="php"><![CDATA[ <?php // using Cast Objects for building a query. $person = DB_DataObject::factory('person'); // assign the value of birthday to a Cast object with a date. $person->birthday = DB_DataObject_Cast::date(2000,12,30); $person->find(); while ($person->fetch()) { echo "{$person->name} has a birthday on 30 december 2002<BR>"; } // use Cast Objects for assigning values. $person = DB_DataObject::factory('person'); $person->get(12); // set the persons's birthday to 30 december 2000 $person->birthday = DB_DataObject_Cast::date(2000,12,30); // now update the database. $person->update(); ?> ]]> </programlisting> </example> </para> <para> As you can see, This component is in it"s infancy, so if you have any feature requests, ideas, please do not hesitate to contact me at alan_k at php dot net. </para> </refsect1> <refsect1> <title>The blob and string type</title> <para> Blobs are fields which can store large amounts of binary data in the databases. </para> <para> At present only blobs is only supported in postgres using the bytea type. (please email me with code for other databases.) </para> <para> <example> <title> Inserting a photo and a big text file</title> <programlisting role="php"><![CDATA[ <?php $person = DB_DataObject::factory('person'); $person->name = 'fred' // use blob for binary data. $person->photo = DB_DataObject_Cast::blob(file_get_contents('xxx.jpg')); // use string for textural data into a blob type. $person->xmldocs = DB_DataObject_Cast::string(file_get_contents('xxx.xml')); // now insert into the database. $person->insert(); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1> <title>The date type</title> <para> Most dates are stored in a database in ISO standard format, this method, allows you to create date types, from either Year,month,day, Human readable day/month/year, or standard iso format year-month-day. It fills in the remaining values based on simple rules. </para> <para> <example> <title> Inserting a date in various formats</title> <programlisting role="php"><![CDATA[ <?php $person = DB_DataObject::factory('person'); $person->name = 'fred' // use a human readable date // full format $person->birthday = new DB_DataObject_Cast::date('21/12/2003'); // use only a month/year - actually sets to 1 december 2003 $person->expires = DB_DataObject_Cast::date('12/2003'); // use only a year only - actually sets to 1 jan 2003 $person->expires = DB_DataObject_Cast::date(2003); // use a iso formated // full formated $person->birthday = DB_DataObject_Cast::date('2003-12-21'); // use only a year-month - actually sets to 1 december 2003 $person->expires = DB_DataObject_Cast::date('2003-12'); // using array syntax // full formated $person->birthday = DB_DataObject_Cast::date(2003,12,21); // use only a year-month - actually sets to 1 december 2003 $person->expires = DB_DataObject_Cast::date(2003,12); // the real values are stored in object variables echo $person->birthday->year; // prints 2003 echo $person->birthday->month; // prints 12 echo $person->birthday->day; // prints 21 // you can do simple date addition (similar to mktime) $d = DB_DataObject_Cast::date('01/12/2003'); $nextMonth = DB_DataObject_Cast::date($d->year,$d->month+1,1); ?> ]]> </programlisting> </example> </para> </refsect1> <refsect1> <title>The sql type</title> <para> Some types are sql specific, or may even be database specific, you can use the sql type to put raw strings as part of the sql statement. </para> <para> <example> <title> using raw sql</title> <programlisting role="php"><![CDATA[ <?php $person = DB_DataObject::factory('person'); $person->get(12); // set the birthday to null. $person->birthday = DB_DataObject_Cast::sql('NULL'); // do a sql cast statement (postgres specific) $data = DB_DataObject_Cast::sql('cast("123123",datetime)'); // now insert into the database. $person->insert(); ?> ]]> </programlisting> </example> </para> </refsect1> </refentry>