Added data type docs
This commit is contained in:
parent
d8c48da227
commit
9257eefee5
@ -0,0 +1,59 @@
|
|||||||
|
<?php ?>
|
||||||
|
The WHERE clause, if given, indicates the condition or conditions that the records must satisfy to be selected.
|
||||||
|
|
||||||
|
Doctrine_Query provides easy to use WHERE -part management methods where and addWhere. The where methods always overrides
|
||||||
|
the query WHERE -part whereas addWhere adds new condition to the WHERE -part stack.
|
||||||
|
<br \>
|
||||||
|
<?php
|
||||||
|
renderCode("<?php
|
||||||
|
// find all groups where the group primary key is bigger than 10
|
||||||
|
|
||||||
|
\$coll = \$q->from('Group')->where('Group.id > 10');
|
||||||
|
|
||||||
|
// the same query using Doctrine_Expression component
|
||||||
|
\$e = \$q->expr;
|
||||||
|
\$coll = \$q->from('Group')->where(\$e->gt('Group.id', 10));
|
||||||
|
?>");
|
||||||
|
?>
|
||||||
|
<br \><br \>
|
||||||
|
Using regular expression operator: <br \><br \>
|
||||||
|
<?php
|
||||||
|
renderCode("<?php
|
||||||
|
// find all users where users where user name matches
|
||||||
|
// a regular expression, regular expressions must be
|
||||||
|
// supported by the underlying database
|
||||||
|
|
||||||
|
\$coll = \$conn->query(\"FROM User WHERE User.name REGEXP '[ad]'\");
|
||||||
|
?>");
|
||||||
|
?>
|
||||||
|
<br \><br \>
|
||||||
|
DQL has support for portable LIKE operator: <br \><br \>
|
||||||
|
<?php
|
||||||
|
renderCode("<?php
|
||||||
|
// find all users and their associated emails
|
||||||
|
// where SOME of the users phonenumbers
|
||||||
|
// (the association between user and phonenumber
|
||||||
|
// tables is One-To-Many) starts with 123
|
||||||
|
|
||||||
|
\$coll = \$q->select('u.*, e.*')
|
||||||
|
->from('User u LEFT JOIN u.Email e LEFT JOIN u.Phonenumber p')
|
||||||
|
->where(\"p.phonenumber LIKE '123%'\");
|
||||||
|
?>");
|
||||||
|
?>
|
||||||
|
<br \><br \>
|
||||||
|
Using multiple conditions and condition nesting are also possible: <br \><br \>
|
||||||
|
<?php
|
||||||
|
renderCode("<?php
|
||||||
|
// multiple conditions
|
||||||
|
|
||||||
|
\$coll = \$q->select('u.*')
|
||||||
|
->from('User u LEFT JOIN u.Email e')
|
||||||
|
->where(\"u.name LIKE '%Jack%' AND e.address LIKE '%@drinkmore.info'\");
|
||||||
|
|
||||||
|
// nesting conditions
|
||||||
|
|
||||||
|
\$coll = \$q->select('u.*')
|
||||||
|
->from('User u LEFT JOIN u.Email e')
|
||||||
|
->where(\"u.name LIKE '%Jack%' OR u.name LIKE '%John%') AND e.address LIKE '%@drinkmore.info'\");
|
||||||
|
?>");
|
||||||
|
?>
|
@ -57,6 +57,39 @@ Following attributes are availible for columns
|
|||||||
Sets <i>default</i> as an application level default value for a column. When default value has been set for a column every time a record is created the specified column has the <i>default</i> as its value.
|
Sets <i>default</i> as an application level default value for a column. When default value has been set for a column every time a record is created the specified column has the <i>default</i> as its value.
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
<b>zerofill</b>
|
||||||
|
</td>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
boolean zerofill
|
||||||
|
</td>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
Defines column as zerofilled column. Only supported by some drivers.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
<b>unsigned</b>
|
||||||
|
</td>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
boolean true
|
||||||
|
</td>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
Defines column with integer type as unsigned. Only supported by some drivers.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
<b>fixed</b>
|
||||||
|
</td>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
boolean true
|
||||||
|
</td>
|
||||||
|
<td class='title' valign='top'>
|
||||||
|
Defines string typed column as fixed length.
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td class='title' valign='top'>
|
<td class='title' valign='top'>
|
||||||
<b>enum</b>
|
<b>enum</b>
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
<?php ?>
|
||||||
|
Doctrine supports default values for all data types. When default value is attached to a record column this means two of things.
|
||||||
|
First this value is attached to every newly created Record.
|
||||||
|
<br \><br \>
|
||||||
|
<?php
|
||||||
|
renderCode("<?php
|
||||||
|
class User {
|
||||||
|
public function setTableDefinition() {
|
||||||
|
\$this->hasColumn('name', 'string', 50, 'default name');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
\$user = new User();
|
||||||
|
print \$user->name; // default name
|
||||||
|
?>");
|
||||||
|
?>
|
||||||
|
<br \>
|
||||||
|
Also when exporting record class to database DEFAULT <i>value</i> is attached to column definition statement. <br \>
|
1
manual/docs/Schema reference - Data types - Array.php
Normal file
1
manual/docs/Schema reference - Data types - Array.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
This is the same as 'array' type in PHP.
|
3
manual/docs/Schema reference - Data types - Blob.php
Normal file
3
manual/docs/Schema reference - Data types - Blob.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Blob (Binary Large OBject) data type is meant to store data of undefined length that may be too large to store in text fields, like data that is usually stored in files.
|
||||||
|
<br \><br \>
|
||||||
|
Blob fields are usually not meant to be used as parameters of query search clause (WHERE) unless the underlying DBMS supports a feature usually known as "full text search"
|
5
manual/docs/Schema reference - Data types - Boolean.php
Normal file
5
manual/docs/Schema reference - Data types - Boolean.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
The boolean data type represents only two values that can be either 1 or 0.
|
||||||
|
Do not assume that these data types are stored as integers because some DBMS drivers may implement this
|
||||||
|
type with single character text fields for a matter of efficiency.
|
||||||
|
Ternary logic is possible by using null as the third possible value that may be assigned to fields of this type.
|
||||||
|
|
5
manual/docs/Schema reference - Data types - Clob.php
Normal file
5
manual/docs/Schema reference - Data types - Clob.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
Clob (Character Large OBject) data type is meant to store data of undefined length that may be too large to store in text fields, like data that is usually stored in files.
|
||||||
|
<br \><br \>
|
||||||
|
Clob fields are meant to store only data made of printable ASCII characters whereas blob fields are meant to store all types of data.
|
||||||
|
<br \><br \>
|
||||||
|
Clob fields are usually not meant to be used as parameters of query search clause (WHERE) unless the underlying DBMS supports a feature usually known as "full text search"
|
6
manual/docs/Schema reference - Data types - Date.php
Normal file
6
manual/docs/Schema reference - Data types - Date.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
The date data type may represent dates with year, month and day. DBMS independent representation of dates is accomplished by using text strings formatted according to the IS0-8601 standard.
|
||||||
|
<br \><br \>
|
||||||
|
The format defined by the ISO-8601 standard for dates is YYYY-MM-DD where YYYY is the number of the year (Gregorian calendar), MM is the number of the month from 01 to 12 and DD is the number of the day from 01 to 31. Months or days numbered below 10 should be padded on the left with 0.
|
||||||
|
<br \><br \>
|
||||||
|
Some DBMS have native support for date formats, but for others the DBMS driver may have to represent them as integers or text values. In any case, it is always possible to make comparisons between date values as well sort query results by fields of this type.
|
||||||
|
<br \><br \>
|
2
manual/docs/Schema reference - Data types - Enum.php
Normal file
2
manual/docs/Schema reference - Data types - Enum.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Doctrine has a unified enum type. Enum typed columns automatically convert the string values into index numbers and vice versa. The possible values for the column
|
||||||
|
can be specified with Doctrine_Record::setEnumValues(columnName, array values).
|
1
manual/docs/Schema reference - Data types - Float.php
Normal file
1
manual/docs/Schema reference - Data types - Float.php
Normal file
@ -0,0 +1 @@
|
|||||||
|
The float data type may store floating point decimal numbers. This data type is suitable for representing numbers within a large scale range that do not require high accuracy. The scale and the precision limits of the values that may be stored in a database depends on the DBMS that it is used.
|
2
manual/docs/Schema reference - Data types - Gzip.php
Normal file
2
manual/docs/Schema reference - Data types - Gzip.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Gzip datatype is the same as string except that its automatically compressed when persisted and uncompressed when fetched. This datatype can be useful
|
||||||
|
when for example storing images / mp3s to database.
|
6
manual/docs/Schema reference - Data types - Integer.php
Normal file
6
manual/docs/Schema reference - Data types - Integer.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
The integer type is the same as integer type in PHP. It may store integer values as large as each DBMS may handle.
|
||||||
|
<br \><br \>
|
||||||
|
Fields of this type may be created optionally as unsigned integers but not all DBMS support it.
|
||||||
|
Therefore, such option may be ignored. Truly portable applications should not rely on the availability of this option.
|
||||||
|
<br \><br \>
|
||||||
|
The integer type maps to different database type depending on the column length.
|
24
manual/docs/Schema reference - Data types - Introduction.php
Normal file
24
manual/docs/Schema reference - Data types - Introduction.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
All DBMS provide multiple choice of data types for the information that can be stored in their database table fields.
|
||||||
|
However, the set of data types made available varies from DBMS to DBMS.
|
||||||
|
<br \> <br \>
|
||||||
|
To simplify the interface with the DBMS supported by Doctrine, it was defined a base set of data types
|
||||||
|
that applications may access independently of the underlying DBMS.
|
||||||
|
<br \><br \>
|
||||||
|
The Doctrine applications programming interface takes care of mapping data types
|
||||||
|
when managing database options. It is also able to convert that is sent to and received from the underlying DBMS using the respective driver.
|
||||||
|
<br \><br \>
|
||||||
|
The following data type examples should be used with Doctrine's createTable() method.
|
||||||
|
The example array at the end of the data types section may be used with createTable()
|
||||||
|
to create a portable table on the DBMS of choice (please refer to the main Doctrine
|
||||||
|
documentation to find out what DBMS back ends are properly supported).
|
||||||
|
It should also be noted that the following examples do not cover the creation
|
||||||
|
and maintenance of indices, this chapter is only concerned with data types and the proper usage thereof.
|
||||||
|
<br \><br \>
|
||||||
|
It should be noted that the length of the column affects in database level type as well as application level validated length (the length that is validated with Doctrine validators).
|
||||||
|
<br \><br \>
|
||||||
|
Example 1. Column named 'content' with type 'string' and length 3000 results in database type 'TEXT' of which has database level length of 4000. However when the record is validated it is only allowed to have 'content' -column with maximum length of 3000.
|
||||||
|
<br \><br \>
|
||||||
|
Example 2. Column with type 'integer' and length 1 results in 'TINYINT' on many databases.
|
||||||
|
<br \><br \>
|
||||||
|
In general Doctrine is smart enough to know which integer/string type to use depending on the specified length.
|
||||||
|
|
2
manual/docs/Schema reference - Data types - Object.php
Normal file
2
manual/docs/Schema reference - Data types - Object.php
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Doctrine supports objects as column types. Basically you can set an object to a field and Doctrine handles automatically the serialization / unserialization
|
||||||
|
of that object.
|
7
manual/docs/Schema reference - Data types - String.php
Normal file
7
manual/docs/Schema reference - Data types - String.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
The text data type is available with two options for the length: one that is explicitly length limited and another of undefined length that should be as large as the database allows.
|
||||||
|
<br \><br \>
|
||||||
|
The length limited option is the most recommended for efficiency reasons. The undefined length option allows very large fields but may prevent the use of indexes, nullability and may not allow sorting on fields of its type.
|
||||||
|
<br \><br \>
|
||||||
|
The fields of this type should be able to handle 8 bit characters. Drivers take care of DBMS specific escaping of characters of special meaning with the values of the strings to be converted to this type.
|
||||||
|
<br \><br \>
|
||||||
|
By default Doctrine will use variable length character types. If fixed length types should be used can be controlled via the fixed modifier.
|
6
manual/docs/Schema reference - Data types - Time.php
Normal file
6
manual/docs/Schema reference - Data types - Time.php
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
The time data type may represent the time of a given moment of the day. DBMS independent representation of the time of the day is also accomplished by using text strings formatted according to the ISO-8601 standard.
|
||||||
|
<br \><br \>
|
||||||
|
The format defined by the ISO-8601 standard for the time of the day is HH:MI:SS where HH is the number of hour the day from 00 to 23 and MI and SS are respectively the number of the minute and of the second from 00 to 59. Hours, minutes and seconds numbered below 10 should be padded on the left with 0.
|
||||||
|
<br \><br \>
|
||||||
|
Some DBMS have native support for time of the day formats, but for others the DBMS driver may have to represent them as integers or text values. In any case, it is always possible to make comparisons between time values as well sort query results by fields of this type.
|
||||||
|
|
@ -0,0 +1,4 @@
|
|||||||
|
The timestamp data type is a mere combination of the date and the time of the day data types.
|
||||||
|
The representation of values of the time stamp type is accomplished by joining the date and time
|
||||||
|
string values in a single string joined by a space. Therefore, the format template is YYYY-MM-DD HH:MI:SS.
|
||||||
|
The represented values obey the same rules and ranges described for the date and time data types
|
@ -0,0 +1,48 @@
|
|||||||
|
Within the Doctrine API there are a few modifiers that have been designed to aid in optimal table design. These are:
|
||||||
|
<br \>
|
||||||
|
<ul>
|
||||||
|
<li \>The notnull modifiers
|
||||||
|
|
||||||
|
<li \>The length modifiers
|
||||||
|
|
||||||
|
<li \>The default modifiers
|
||||||
|
|
||||||
|
<li \>unsigned modifiers for some field definitions, although not all DBMS's support this modifier for integer field types.
|
||||||
|
|
||||||
|
<li \>zerofill modifiers (not supported by all drivers)
|
||||||
|
|
||||||
|
<li \>collation modifiers (not supported by all drivers)
|
||||||
|
|
||||||
|
<li \>fixed length modifiers for some field definitions.
|
||||||
|
</ul>
|
||||||
|
Building upon the above, we can say that the modifiers alter the field definition to create more specific field types for specific usage scenarios. The notnull modifier will be used in the following way to set the default DBMS NOT NULL Flag on the field to true or false, depending on the DBMS's definition of the field value: In PostgreSQL the "NOT NULL" definition will be set to "NOT NULL", whilst in MySQL (for example) the "NULL" option will be set to "NO". In order to define a "NOT NULL" field type, we simply add an extra parameter to our definition array (See the examples in the following section)
|
||||||
|
<br \><br \>
|
||||||
|
<?php
|
||||||
|
'sometime' = array(
|
||||||
|
'type' = 'time',
|
||||||
|
'default' = '12:34:05',
|
||||||
|
'notnull' = true,
|
||||||
|
),
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
<br \><br \>
|
||||||
|
Using the above example, we can also explore the default field operator. Default is set in the same way as the notnull operator to set a default value for the field. This value may be set in any character set that the DBMS supports for text fields, and any other valid data for the field's data type. In the above example, we have specified a valid time for the "Time" data type, '12:34:05'. Remember that when setting default dates and times, as well as datetimes, you should research and stay within the epoch of your chosen DBMS, otherwise you will encounter difficult to diagnose errors!
|
||||||
|
<br \><br \>
|
||||||
|
Example 33-1. Example of the length modifier
|
||||||
|
|
||||||
|
|
||||||
|
<?php
|
||||||
|
'sometext' = array(
|
||||||
|
'type' = 'text',
|
||||||
|
'length' = 12,
|
||||||
|
),
|
||||||
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<br \><br \>
|
||||||
|
The above example will create a character varying field of length 12 characters in the database table. If the length definition is left out, MDB2 will create a length of the maximum allowable length for the data type specified, which may create a problem with some field types and indexing. Best practice is to define lengths for all or most of your fields.
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user