| ... | ... |
@@ -1,4 +1,5 @@ |
| 1 | 1 |
0.1659 |
| 2 |
+ - removed EXPERIMENTAL selection |
|
| 2 | 3 |
- added select() all_column option |
| 3 | 4 |
0.1658 |
| 4 | 5 |
- added EXPERIMENTAL DBIx::Custom::Model column() prefix option. |
| ... | ... |
@@ -1797,13 +1797,6 @@ C<default_filter> and C<filter> of C<DBIx::Custom::Result> |
| 1797 | 1797 |
|
| 1798 | 1798 |
Register tag. |
| 1799 | 1799 |
|
| 1800 |
-=head2 C<rollback> |
|
| 1801 |
- |
|
| 1802 |
- $dbi->rollback; |
|
| 1803 |
- |
|
| 1804 |
-Rollback transaction. |
|
| 1805 |
-This is same as L<DBI>'s C<rollback>. |
|
| 1806 |
- |
|
| 1807 | 1800 |
=head2 C<select> |
| 1808 | 1801 |
|
| 1809 | 1802 |
my $result = $dbi->select( |
| ... | ... |
@@ -1812,7 +1805,7 @@ This is same as L<DBI>'s C<rollback>. |
| 1812 | 1805 |
where => {author => 'Ken'},
|
| 1813 | 1806 |
); |
| 1814 | 1807 |
|
| 1815 |
-Execute select statement. |
|
| 1808 |
+Select statement. |
|
| 1816 | 1809 |
|
| 1817 | 1810 |
The following opitons are currently available. |
| 1818 | 1811 |
|
| ... | ... |
@@ -1822,7 +1815,7 @@ The following opitons are currently available. |
| 1822 | 1815 |
|
| 1823 | 1816 |
Table name. |
| 1824 | 1817 |
|
| 1825 |
- $dbi->select(table => 'book', ...); |
|
| 1818 |
+ $dbi->select(table => 'book'); |
|
| 1826 | 1819 |
|
| 1827 | 1820 |
=item C<column> |
| 1828 | 1821 |
|
| ... | ... |
@@ -1841,9 +1834,9 @@ Default is '*' unless C<column> is specified. |
| 1841 | 1834 |
|
| 1842 | 1835 |
=item C<all_column EXPERIMENTAL> |
| 1843 | 1836 |
|
| 1844 |
-Colum clause, contains all columns. This is true or false value |
|
| 1837 |
+Colum clause, contains all columns of joined table. This is true or false value |
|
| 1845 | 1838 |
|
| 1846 |
- $dbi->select(all_column => 1, ...); |
|
| 1839 |
+ $dbi->select(all_column => 1); |
|
| 1847 | 1840 |
|
| 1848 | 1841 |
If main table is C<book> and joined table is C<company>, |
| 1849 | 1842 |
This create the following column clause. |
| ... | ... |
@@ -1856,48 +1849,147 @@ This create the following column clause. |
| 1856 | 1849 |
Columns of main table is consist of only column name, |
| 1857 | 1850 |
Columns of joined table is consist of table and column name joined C<__>. |
| 1858 | 1851 |
|
| 1852 |
+Note that this option is failed unless L<DBIx::Custom::Model> object is set to |
|
| 1853 |
+C<model> and C<columns> of the object is set. |
|
| 1854 |
+ |
|
| 1855 |
+ # Generally do the following way before using all_column option |
|
| 1856 |
+ $dbi->include_model('MyModel')->setup_model;
|
|
| 1857 |
+ |
|
| 1859 | 1858 |
=item C<where> |
| 1860 | 1859 |
|
| 1861 | 1860 |
Where clause. This is hash reference or L<DBIx::Custom::Where> object. |
| 1862 | 1861 |
|
| 1863 | 1862 |
# Hash reference |
| 1864 |
- $dbi->select(where => {author => 'Ken', 'title' => 'Perl'}, ...);
|
|
| 1863 |
+ $dbi->select(where => {author => 'Ken', 'title' => 'Perl'});
|
|
| 1865 | 1864 |
|
| 1866 |
- # Where clause |
|
| 1865 |
+ # DBIx::Custom::Where object |
|
| 1867 | 1866 |
my $where = $dbi->where( |
| 1868 | 1867 |
clause => ['and', '{= author}', '{like title}'],
|
| 1869 | 1868 |
param => {author => 'Ken', title => '%Perl%'}
|
| 1870 | 1869 |
); |
| 1871 |
- $dbi->select(where => $where, ...); |
|
| 1870 |
+ $dbi->select(where => $where); |
|
| 1872 | 1871 |
|
| 1873 |
-=back |
|
| 1872 |
+=item C<join EXPERIMENTAL> |
|
| 1874 | 1873 |
|
| 1875 |
-C<filter> arguments. |
|
| 1876 |
-C<where> is where clause. this is normally hash reference. |
|
| 1877 |
-C<append> is a string added at the end of the SQL statement. |
|
| 1878 |
-C<filter> is filters when parameter binding is executed. |
|
| 1879 |
-C<query> is if you don't execute sql and get L<DBIx::Custom::Query> object as return value. |
|
| 1880 |
-default to 0. This is EXPERIMENTAL. |
|
| 1881 |
-C<selection> is string of column name and tables. This is EXPERIMENTAL |
|
| 1874 |
+Join clause used in need. This is array reference. |
|
| 1875 |
+ |
|
| 1876 |
+ $dbi->select(join => |
|
| 1877 |
+ [ |
|
| 1878 |
+ 'left outer join company on book.company_id = company_id', |
|
| 1879 |
+ 'left outer join location on company.location_id = location.id' |
|
| 1880 |
+ ] |
|
| 1881 |
+ ); |
|
| 1882 |
+ |
|
| 1883 |
+If column cluase or where clause contain table name like "company.name", |
|
| 1884 |
+needed join clause is used automatically. |
|
| 1885 |
+ |
|
| 1886 |
+ $dbi->select( |
|
| 1887 |
+ table => 'book', |
|
| 1888 |
+ column => ['company.location_id as company__location_id'], |
|
| 1889 |
+ where => {'company.name' => 'Orange'},
|
|
| 1890 |
+ join => [ |
|
| 1891 |
+ 'left outer join company on book.company_id = company.id', |
|
| 1892 |
+ 'left outer join location on company.location_id = location.id' |
|
| 1893 |
+ ] |
|
| 1894 |
+ ); |
|
| 1895 |
+ |
|
| 1896 |
+In above select, the following SQL is created. |
|
| 1897 |
+ |
|
| 1898 |
+ select company.location_id as company__location_id |
|
| 1899 |
+ from book |
|
| 1900 |
+ left outer join company on book.company_id = company.id |
|
| 1901 |
+ where company.name = Orange |
|
| 1902 |
+ |
|
| 1903 |
+=item C<append> |
|
| 1904 |
+ |
|
| 1905 |
+Appended statement to last of SQL. This is string. |
|
| 1906 |
+ |
|
| 1907 |
+ $dbi->select(append => 'order by title'); |
|
| 1908 |
+ |
|
| 1909 |
+=item C<filter> |
|
| 1910 |
+ |
|
| 1911 |
+Filter, executed before data is send to database. This is array reference |
|
| 1912 |
+and filter value is code reference or |
|
| 1913 |
+filter name registerd by C<register_filter()>. |
|
| 1914 |
+ |
|
| 1915 |
+ # Basic |
|
| 1916 |
+ $dbi->select( |
|
| 1917 |
+ filter => [ |
|
| 1918 |
+ title => sub { uc $_[0] }
|
|
| 1919 |
+ author => sub { uc $_[0] }
|
|
| 1920 |
+ ] |
|
| 1921 |
+ ); |
|
| 1922 |
+ |
|
| 1923 |
+ # At once |
|
| 1924 |
+ $dbi->select( |
|
| 1925 |
+ filter => [ |
|
| 1926 |
+ [qw/title author/] => sub { uc $_[0] }
|
|
| 1927 |
+ ] |
|
| 1928 |
+ ); |
|
| 1929 |
+ |
|
| 1930 |
+ # Filter name |
|
| 1931 |
+ $dbi->select( |
|
| 1932 |
+ filter => [ |
|
| 1933 |
+ title => 'upper_case', |
|
| 1934 |
+ author => 'upper_case' |
|
| 1935 |
+ ] |
|
| 1936 |
+ ); |
|
| 1882 | 1937 |
|
| 1883 |
- selection => 'name, location.name as location_name ' . |
|
| 1884 |
- 'from company inner join location' |
|
| 1938 |
+These filters are added to the C<out> filters set by C<apply_filter()>. |
|
| 1885 | 1939 |
|
| 1886 |
-First element is a string. it contains tags, |
|
| 1887 |
-such as "{= title} or {like author}".
|
|
| 1888 |
-Second element is paramters. |
|
| 1940 |
+=item C<query EXPERIMENTAL> |
|
| 1889 | 1941 |
|
| 1890 |
-C<join> is join clause after from clause. |
|
| 1891 |
-This is EXPERIMENTAL. |
|
| 1942 |
+Get L<DBIx::Custom::Query> object instead of executing SQL. |
|
| 1943 |
+This is true or false value. |
|
| 1944 |
+ |
|
| 1945 |
+ my $query = $dbi->select(query => 1, ...); |
|
| 1946 |
+ |
|
| 1947 |
+You can check executing SQL by this object. |
|
| 1948 |
+ |
|
| 1949 |
+ my $sql = $query->sql; |
|
| 1950 |
+ |
|
| 1951 |
+=back |
|
| 1892 | 1952 |
|
| 1893 | 1953 |
=head3 C<select_at() EXPERIMENTAL> |
| 1894 | 1954 |
|
| 1895 |
-To select row by using primary key, use C<select_at()>. |
|
| 1955 |
+Select statement, using primary key. |
|
| 1956 |
+ |
|
| 1957 |
+ $dbi->select_at( |
|
| 1958 |
+ table => 'book', |
|
| 1959 |
+ primary_key => 'id', |
|
| 1960 |
+ where => '5' |
|
| 1961 |
+ ); |
|
| 1962 |
+ |
|
| 1963 |
+This method is same as select method exept that |
|
| 1964 |
+primary_key is specified and C<where> is array reference. |
|
| 1965 |
+all option of C<select()> is available. |
|
| 1896 | 1966 |
|
| 1897 |
- $dbi->select_at(table => 'book', primary_key => ['id'], where => ['123']); |
|
| 1967 |
+=head2 C<primary_key> |
|
| 1898 | 1968 |
|
| 1899 |
-In this example, row which id colunm is 123 is selected. |
|
| 1900 |
-NOTE that you must pass array reference as C<where>. |
|
| 1969 |
+Primary key. This is constant value or array reference. |
|
| 1970 |
+ |
|
| 1971 |
+ # Constant value |
|
| 1972 |
+ $dbi->select(primary_key => 'id'); |
|
| 1973 |
+ |
|
| 1974 |
+ # Array reference |
|
| 1975 |
+ $dbi->select(primary_key => ['id1', 'id2' ]); |
|
| 1976 |
+ |
|
| 1977 |
+=head2 C<where> |
|
| 1978 |
+ |
|
| 1979 |
+Where clause, created by primary key infromation. |
|
| 1980 |
+This is constant value or array reference. |
|
| 1981 |
+ |
|
| 1982 |
+ # Constant value |
|
| 1983 |
+ $dbi->select(where => 5); |
|
| 1984 |
+ |
|
| 1985 |
+ # Array reference |
|
| 1986 |
+ $dbi->select(where => [3, 5]); |
|
| 1987 |
+ |
|
| 1988 |
+In first examle, the following SQL is created. |
|
| 1989 |
+ |
|
| 1990 |
+ select * from book where id = ? |
|
| 1991 |
+ |
|
| 1992 |
+Place holder is set to 5. |
|
| 1901 | 1993 |
|
| 1902 | 1994 |
=head2 C<update> |
| 1903 | 1995 |
|
| ... | ... |
@@ -363,20 +363,6 @@ Following SQL is executed. |
| 363 | 363 |
C<appned> is also used at C<insert()>, C<update()>, C<update_all()> |
| 364 | 364 |
C<delete()>, C<delete_all()>, and C<select()>. |
| 365 | 365 |
|
| 366 |
-Instead of C<column> and C<table>, |
|
| 367 |
-you can use C<selection>. |
|
| 368 |
-This is used to specify column names and table names at once |
|
| 369 |
- |
|
| 370 |
- my $selection = <<"EOS"; |
|
| 371 |
- title, author, company_name |
|
| 372 |
- from book inner join company on book.company_id = company.id |
|
| 373 |
- EOS |
|
| 374 |
- |
|
| 375 |
- $dbi->select(selection => $selection); |
|
| 376 |
- |
|
| 377 |
-Note that you can't use where clause in C<selection>. |
|
| 378 |
-use clause like "inner join". |
|
| 379 |
- |
|
| 380 | 366 |
=head3 C<execute()> |
| 381 | 367 |
|
| 382 | 368 |
use C<execute()> to execute SQL |
| ... | ... |
@@ -369,19 +369,6 @@ C<append>はSQLの末尾に追加される文字列です。 |
| 369 | 369 |
またC<append>は、C<select>だけでなくC<insert()>、C<update()>、C<update_all()> |
| 370 | 370 |
C<delete()>、C<delete_all()>、C<select()>で使用することもできます。 |
| 371 | 371 |
|
| 372 |
-C<column>とC<table>を使用する代わりに、C<selection>を使用することも |
|
| 373 |
-できます。列名とテーブル名をまとめて指定する場合に利用します。 |
|
| 374 |
- |
|
| 375 |
- my $selection = <<"EOS"; |
|
| 376 |
- title, author, company_name |
|
| 377 |
- from book inner join company on book.company_id = company.id |
|
| 378 |
- EOS |
|
| 379 |
- |
|
| 380 |
- $dbi->select(selection => $selection); |
|
| 381 |
- |
|
| 382 |
-C<selection>においてはwhere句を利用できないということに注意してください。 |
|
| 383 |
-"inner join"などの句を利用してください。 |
|
| 384 |
- |
|
| 385 | 372 |
=head3 SQLの実行 C<execute()> |
| 386 | 373 |
|
| 387 | 374 |
SQLを実行するにはC<execute()>を使用します。 |