Newer Older
1298 lines | 35.542kb
update pod
Yuki Kimoto authored on 2011-01-28
1
=encoding utf8
2

            
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
3
=head1 NAME
4

            
update pod
Yuki Kimoto authored on 2011-01-28
5
DBIx::Custom::Guide - DBIx::Custom Guide
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
6

            
pod fix
Yuki Kimoto authored on 2011-01-21
7
=head1 GUIDE
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
8

            
update pod
Yuki Kimoto authored on 2011-01-28
9
B<This guide is now writing.>
update pod
Yuki Kimoto authored on 2011-01-26
10

            
update pod
Yuki Kimoto authored on 2011-01-28
11
L<DBIx::Custom> is the class to make easy to execute SQL.
12
This is L<DBI> wrapper class like L<DBIx::Class> or L<DBIx::Simple>.
13
You can do thing more easy than L<DBIx::Class>, more flexible
14
than L<DBIx::Simple>.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
15

            
update pod
Yuki Kimoto authored on 2011-01-28
16
L<DBIx::Custom> is B<not< O/R mapper, O/R mapper is usefule, but
17
you must learn many things. Created SQL is sometimes inefficient,
18
and in many cases you create raw SQL because
19
O/R mapper can't make complex SQL
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
20

            
update pod
Yuki Kimoto authored on 2011-01-28
21
L<DBIx::Custom> is opposit of O/R mapper.
22
The main purpose is that we respect SQL
23
and make easy difficult works if you use only L<DBI>.
24
If you already learn SQL, it is easy to use L<DBIx::Custom>.
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
25

            
update pod
Yuki Kimoto authored on 2011-01-28
26
I explain L<DBIx::Custom> a little in this section.
27
In L<DBIx::Custom>, you embbed tag in SQL.
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
28

            
update pod
Yuki Kimoto authored on 2011-01-28
29
    select * from book where {= title} and {=author};
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
30

            
update pod
Yuki Kimoto authored on 2011-01-28
31
The part arround {} is tag.
32
This SQL is converted to the one which contains place holder.
33

            
34
    select * from book where title = ? and author = ?;
35

            
36
Maybe you ask me that this conversion is meaningful.
37
On the top of this, usuful features is implemented.
38
See the following descriptions.
39

            
40
=over 4
41

            
42
=item 1. Specify place holder binding value as hash refernce
43

            
44
If you use L<DBI>, you must specify place holder binding value
45
as array.
46

            
47
    $sth->execute(@bind);
48

            
49
If you use L<DBIx::Custom>, you specify it as hash reference.
50
    
51
    my $param = {title => 'Perl', author => 'Ken'};
52
    $dbi->execute($sql, $param);
53

            
54
=item 2. Filtering
55

            
56
L<DBIx::Custom> provides filtering system.
57
For example, You think that about date value you want to 
58
manipulate it as date object like L<Time::Piece> in Perl,
59
and want to convert it to database DATE format.
60
and want to do reverse.
61

            
62
You can use filtering system.
63

            
64
At first, register filter.
65

            
66
    $dbi->register_filter(
67
        tp_to_date => sub {
68
            ...
69
        },
70
        date_to_tp => sub {
71
            ...
72
        }
73
    );
74

            
75
next, apply this filter to each column.
76

            
77
    $dbi->apply_filter('book',
78
        'issue_date' => {out => 'tp_to_date', in => 'date_to_tp'}
79
    );
80

            
81
C<out> is perl-to-database way. C<in> is perl-from-database way.
82

            
83
This filter is automatically enabled in many method.
84

            
85
    $dbi->insert(table => 'book', param => {issue_date => $tp});
86

            
87

            
88
=item 3. Selective search condition
89

            
90
It is difficult to create selective where clause in L<DBI>.
91
For example, If C<title> and C<author> is specified, we create 
92
the following SQL.
93

            
94
    select * from book where title = ? and author = ?;
95

            
96
If only C<title> is specified, the following one
97

            
98
    select * from book where title = ?;
99

            
100
If only C<author> is specified, the following one,
101

            
102
    select * from book where author = ?;
103

            
104
This is hard work. Generally we use modules like L<SQL::Abstract>.
105
L<DBIx::Custom> prepare the way to make it easy.
106

            
107
    # Where object
108
    my $where = $dbi->where;
109
    
110
    # Search condition
111
    $where->clause(
112
        ['and', '{= title}', {'= author'}]
113
    );
114
    
115
    # Setting to automatically select needed column
116
    $where->param({title => 'Perl'});
117

            
118
    # Embbed where clause to SQL
119
    my $sql = "select * from book $where";
120

            
121
You can create where clause which has selected search condition.
122
You can write nesting of where clause and C<or> condition
123

            
124
=item 4. Method of insert, update, delete, select
125

            
126
L<DBIx::Custom>�ł�SQL���ɊȒP�Ɏ�s���邽�߂�
127
���\�b�h��񋟂��Ă��܂��B
128
C<insert()>, C<update()>, C<delete()>,C<select()>�Ȃǂ�
129
�V���K�[���\�b�h��g��āA�}��A�X�V�A�폜�A�I��Ƃ��������s�����Ƃ�
130
�ł��܂��B
131

            
132
    my $param = {title => 'Perl', author => 'Ken'};
133
    $dbi->insert(table => 'book', param => $param);
134

            
135
=item 5. �e�[�u���P�ʂ̑���̓o�^
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
136

            
update pod
Yuki Kimoto authored on 2011-01-28
137
�e�[�u���ɑ΂��đ����o�^���邱�Ƃ��ł��܂��B����ɂ���
138
�e�[�u������J��Ԃ��w�肷��K�v���Ȃ��Ȃ�A�\�[�X�R�[�h��
139
���ʂ����ǂ��Ȃ�܂��B
140

            
141
    $dbi->talbe('book',
142
        list => sub {
143
            ...
144
        },
145
        list_somethin => sub {
146
            
147
        }
148
    );
149

            
150
�o�^�������\�b�h�͂��̂܂ܗ��p���邱�Ƃ��ł��܂��B
151

            
152
    $dbi->table('book')->list;
153

            
154
�ʏ�O/R�}�b�p�̓e�[�u���ɑΉ�����N���X��쐬���Ȃ����
155
�Ȃ�Ȃ����Ƃ������ł����AL<DBIx::Custom>�ł͂��̍�Ƃ�ȕւ�
156
���Ă���A��L�̂悤�ɓo�^���邱�Ƃ��ł��܂��B
157

            
158
=back
159

            
160
L<DBIx::Custom>��L<DBI>��₤�ƂĂ�֗��ȃ��W���[���ł��B
161
��������ꂽ��́A���̌�ŏڂ�������s���܂��̂ŁA
162
�����ɂȂ�Ă݂Ă��������B
163

            
164
=head2 1. �f�[�^�x�[�X�ւ̐ڑ�
165

            
166
�܂�L<DBIx::Custom>��ǂݍ��݂܂��B
167

            
168
    use DBIx::Custom;
169

            
170
L<DBIx::Custom>�I�u�W�F�N�g�𐶐����A�f�[�^�x�[�X�ɐڑ�����ɂ�
171
C<connect()>���\�b�h��g�p���܂��B
172

            
173
    my $dbi = DBIx::Custom->connect(
174
        data_source => "dbi:mysql:database=dbname",
175
        user => 'ken',
176
        password => '!LFKD%$&',
177
        dbi_options => {mysql_enable_utf8 => 1}
178
    );
179

            
180
C<data_source>�̓f�[�^�x�[�X�V�X�e���ɉ������t�H�[�}�b�g��
181
�w�肷��K�v������܂��B�ȉ��Ƀf�[�^�x�[�X���Ƃ̃t�H�[�}�b�g
182
��@�̃T���v����f�ڂ��Ă����܂��B
183

            
184
B<MySQL>
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
185

            
186
    "dbi:mysql:database=$database"
187
    "dbi:mysql:database=$database;host=$hostname;port=$port"
188

            
update pod
Yuki Kimoto authored on 2011-01-28
189
B<SQLite>
190

            
191
    "dbi:SQLite:dbname=$database"
192
    "dbi:SQLite:dbname=:memory:"
193

            
194
B<PostgreSQL>
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
195

            
196
    "dbi:Pg:dbname=$dbname"
197

            
update pod
Yuki Kimoto authored on 2011-01-28
198
B<Oracle>
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
199

            
200
    "dbi:Oracle:$dbname"
201
    "dbi:Oracle:host=$host;sid=$sid"
202

            
update pod
Yuki Kimoto authored on 2011-01-28
203
B<ODBC(Microsoft Access)>
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
204

            
205
    "dbi:ODBC:driver=Microsoft Access Driver (*.mdb);dbq=hoge.mdb"
206

            
update pod
Yuki Kimoto authored on 2011-01-28
207
B<ODBC(SQL Server)>
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
208

            
209
   "dbi:ODBC:driver={SQL Server};Server=(local);database=test;Trusted_Connection=yes;AutoTranslate=No;"
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
210

            
update pod
Yuki Kimoto authored on 2011-01-28
211
�܂��F�؂����߂���ꍇ�́AC<user>��C<password>���[�U����
212
�p�X���[�h��w�肷��K�v������܂��B
213

            
214
L<DBIx::Custom>��L<DBI>�̃��b�p�ł��B
215
L<DBI>�̃f�[�^�x�[�X�n���h����C<dbh>�Ŏ擾���邱�Ƃ��ł��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
216

            
update pod
Yuki Kimoto authored on 2011-01-28
217
    my $dbh = $dbi->dbh;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
218

            
update pod
Yuki Kimoto authored on 2011-01-28
219
L<DBIx::Custom>�ł̓f�[�^�x�[�X�n���h�������ɂ̓f�t�H���g�Ŏ��̂�̂��ݒ肳��܂��B
220
    
221
    $dbi->dbh->{RaiseError} = 1;
222
    $dbi->dbh->{PrintError} = 0;
223
    $dbi->dbh->{AutoCommit} = 1;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
224

            
update pod
Yuki Kimoto authored on 2011-01-28
225
���̐ݒ��s��Ă���̂ŁA�v���I�ȃG���[���N����ƁA
226
��O���������v���O�����͏I�����܂��B
227
�܂��N�G�������s�����Ǝ����I�ɃR�~�b�g����܂��B
228

            
229
=head2 2. �}��A�X�V�A�폜�A�I��̂��߂̃��\�b�h
230

            
231
L<DBIx::Custom>�́A
232
C<insert()>�AC<update()>�AC<delete()>�AC<select()>
233
�̂悤�ȑ}��A�X�V�A�폜�A�I���s�����߂̃��\�b�h���Ă��܂��B
234
�ȒP�Ȃ��Ƃ��s���̂ł���΁ASQL����ŋL�q����K�v������܂���B
235

            
236
=head3 �f�[�^�̑}�� C<insert()>
237

            
238
�f�[�^�x�[�X�Ƀf�[�^��}���ɂ�C<insert()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
239

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
240
    $dbi->insert(table  => 'book',
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
241
                 param  => {title => 'Perl', author => 'Ken'});
242

            
update pod
Yuki Kimoto authored on 2011-01-28
243
C<table>�ɂ̓e�[�u�����AC<param>�ɂ͑}����f�[�^��w�肵�܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
244

            
update pod
Yuki Kimoto authored on 2011-01-28
245
����SQL�����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
246

            
update pod
Yuki Kimoto authored on 2011-01-28
247
    insert into (title, author) values (?, ?);
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
248

            
update pod
Yuki Kimoto authored on 2011-01-28
249
=head3 �f�[�^�̍X�V C<update()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
250

            
update pod
Yuki Kimoto authored on 2011-01-28
251
�f�[�^�x�[�X�̃f�[�^��X�V����ɂ́AC<update()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
252

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
253
    $dbi->update(table  => 'book', 
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
254
                 param  => {title => 'Perl', author => 'Ken'}, 
255
                 where  => {id => 5});
256

            
update pod
Yuki Kimoto authored on 2011-01-28
257
C<table>�ɂ̓e�[�u�����AC<param>�ɂ͑}����f�[�^�AC<where>�ɂ�
258
���w�肵�܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
259

            
update pod
Yuki Kimoto authored on 2011-01-28
260
����SQL�����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
261

            
update pod
Yuki Kimoto authored on 2011-01-28
262
    update book set title = ?, author = ?;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
263

            
update pod
Yuki Kimoto authored on 2011-01-28
264
C<update>���\�b�h�͈�S�̂���
265
where��̂Ȃ�SQL�𔭍s���邱�Ƃ�‚��Ă��܂���B
266
�����ׂĂ̍s��X�V�������ꍇ��
267
C<update_all()>��g�p�����������B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
268

            
update pod
Yuki Kimoto authored on 2011-01-28
269
    $dbi->update_all(table  => 'book', 
270
                     param  => {title => 'Perl', author => 'Ken'});
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
271

            
update pod
Yuki Kimoto authored on 2011-01-28
272
=head3 �f�[�^�̍폜 C<delete()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
273

            
update pod
Yuki Kimoto authored on 2011-01-28
274
�f�[�^�x�[�X�̃f�[�^��1���폜����ɂ́AC<delete()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
275

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
276
    $dbi->delete(table  => 'book',
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
277
                 where  => {author => 'Ken'});
278

            
update pod
Yuki Kimoto authored on 2011-01-28
279
C<table>�ɂ̓e�[�u�����AC<where>�ɂ͏��w�肵�܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
280

            
update pod
Yuki Kimoto authored on 2011-01-28
281
����SQL�����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
282

            
update pod
Yuki Kimoto authored on 2011-01-28
283
    delete from book where id = ?;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
284

            
update pod
Yuki Kimoto authored on 2011-01-28
285
C<delete>���\�b�h�͈�S�̂���
286
where��̂Ȃ�SQL�𔭍s���邱�Ƃ�‚��Ă��܂���B
287
�����ׂĂ̍s��폜�������ꍇ��
288
C<delete_all()>��g�p�����������B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
289

            
update pod
Yuki Kimoto authored on 2011-01-28
290
    $dbi->delete_all(table  => 'book');
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
291

            
update pod
Yuki Kimoto authored on 2011-01-28
292
=head3 �f�[�^�̑I�� C<select()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
293

            
update pod
Yuki Kimoto authored on 2011-01-28
294
�s��I���ɂ�C<select()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
295

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
296
    my $result = $dbi->select(table => 'book');
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
297

            
update pod
Yuki Kimoto authored on 2011-01-28
298
C<table>������w�肵�āA���̏��w�肵�Ȃ��ꍇ�͎���SQL�����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
299

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
300
    select * from book;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
301

            
update pod
Yuki Kimoto authored on 2011-01-28
302
C<select()>���\�b�h�̖߂�l��L<DBIx::Custom::Result>
303
�I�u�W�F�N�g�ł��B�s��t�F�b�`����ɂ�C<fetch()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
304

            
305
    while (my $row = $result->fetch) {
306
        my $title  = $row->[0];
307
        my $author = $row->[1];
308
    }
309

            
update pod
Yuki Kimoto authored on 2011-01-28
310
L<DBIx::Custom::Result>�ɂ‚��Ă͂��̌�L<3. �s�̃t�F�b�`/"3. �s�̃t�F�b�`">�ŏڂ��������܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
311

            
update pod
Yuki Kimoto authored on 2011-01-28
312
���܂��܂�C<select()>�̎g�����Ă����܂��傤�B
313
����C<select>�͍s�̖��O��where���w�肵����̂ł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
314

            
315
    my $result = $dbi->select(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
316
        table  => 'book',
update pod
Yuki Kimoto authored on 2011-01-28
317
        column => ['author',  'title'],
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
318
        where  => {author => 'Ken'}
319
    );
320

            
update pod
Yuki Kimoto authored on 2011-01-28
321
C<column>�ɂ͗񖼂�AC<where>�ɂ͏��w�肷�邱�Ƃ��ł��܂��B
322
����SQL�����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
323

            
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
324
    select author, title from book where author = ?;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
325

            
update pod
Yuki Kimoto authored on 2011-01-28
326
�e�[�u������������ꍇ�͂�C<relation>�Ƀe�[�u����
327
�֌W��L�q���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
328

            
329
    my $result = $dbi->select(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
330
        table    => ['book', 'rental'],
update pod
Yuki Kimoto authored on 2011-01-28
331
        where    => {book.name => 'Perl'},
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
332
        relation => {'book.id' => 'rental.book_id'}
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
333
    );
334

            
update pod
Yuki Kimoto authored on 2011-01-28
335
book�e�[�u����id���rental�e�[�u����book_id���֘A�t�����܂��B
336
����SQL�����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
337

            
update pod
Yuki Kimoto authored on 2011-01-28
338
    select * from book, rental where book.name = ? and book.id = rental.book_id;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
339

            
update pod
Yuki Kimoto authored on 2011-01-28
340
SQL���̖���ɕ������lj�������ꍇ��<append>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
341

            
342
    my $result = $dbi->select(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
343
        table  => 'book',
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
344
        where  => {author => 'Ken'},
update pod
Yuki Kimoto authored on 2011-01-28
345
        append => 'for update',
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
346
    );
347

            
update pod
Yuki Kimoto authored on 2011-01-28
348
����SQL�����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
349

            
update pod
Yuki Kimoto authored on 2011-01-28
350
    select * book where author = ? for update;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
351

            
update pod
Yuki Kimoto authored on 2011-01-28
352
�܂�C<append>�́AC<select>�����łȂ�C<insert()>�AC<update()>�AC<update_all()>
353
C<delete()>�AC<delete_all()>�AC<select()>�Ŏg�p���邱�Ƃ�ł��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
354

            
update pod
Yuki Kimoto authored on 2011-01-28
355
=head3 SQL�̎�s C<execute()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
356

            
update pod
Yuki Kimoto authored on 2011-01-28
357
�C�ӂ�SQL���s����ɂ�execute���\�b�h��g�p���܂��B
358

            
359
    $dbi->execute("select * from book;");
360

            
361
C<execute()>��L<DBIx::Custom>�̍����̃��\�b�h�ł���^�O��W�J���܂��B
362

            
363
    $dbi->execute(
364
        "select * from book {= title} and {= author};"
365
        param => {title => 'Perl', author => 'Ken'}
366
    );
367

            
368
��L�̃^�O��܂�SQL�͎��̂悤�ɓW�J����܂��B
369

            
370
    select * from book title = ? and author = ?;
371

            
372
SQL����s�����Ƃ��Ƀv���[�X�z���_(?)�ɑΉ�����ʒu��title��author
373
�̒l���������I�ɖ��ߍ��܂�܂��B
374

            
375
�^�O�ɂ‚��Ă�L<5. �^�O/"5. �^�O">�ŏڂ�������܂����A
376
�ЂƂ‚̒��ӓ_������܂��B
377
�^�O��W�J���邽�߂�C<{>��C<}>�͗\���ɂȂ�Ă��܂��B
378
�����p�������ꍇ�͒��O��\����ăG�X�P�[�v��s���K�v������܂��B
379

            
380
    $dbi->execute("... \\{ ... \\} ...");
381

            
382
\���̂�Perl�̃G�X�P�[�v�����ł��̂ŁA��•K�v�ɂȂ�Ƃ����_�ɒ��ӂ��Ă��������B
383

            
384
�܂�execute�̃L���[�g�ȋ@�\�Ƃ��āASQL�̍Ō�ɃZ�~�R��������Ȃ��Ă�
385
���܂��܂���B
386

            
387
    $dbi->execute('select * from book');
388

            
389
=head2 3. �s�̃t�F�b�`
390

            
391
C<select()>���\�b�h�̖߂�l��L<DBIx::Custom::Result>�I�u�W�F�N�g�ł��B
392
L<DBIx::Custom::Result>�ɂ͍s��t�F�b�`���邽�߂̂��܂��܂ȃ��\�b�h��
393
�p�ӂ���Ă��܂��B
394

            
395
=head3 1�s�ƒt�F�b�`(�z��) C<fetch()>
396

            
397
��s�t�F�b�`���Ĕz��̃��t�@�����X�Ɋi�[����ɂ�C<fetch()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
398

            
399
    while (my $row = $result->fetch) {
update pod
Yuki Kimoto authored on 2011-01-28
400
        my $title  = $row->[0];
401
        my $author = $row->[1];
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
402
    }
403

            
update pod
Yuki Kimoto authored on 2011-01-28
404
while���[�v��g��āA���ׂĂ̍s��擾���邱�Ƃ��ł��܂��B
405

            
406
=head3 �ŏ��̍s�����t�F�b�`(�z��) C<fetch_first()>
407

            
408
��s�����t�F�b�`���Ĕz��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_first()>
409
��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
410

            
411
    my $row = $result->fetch_first;
412

            
update pod
Yuki Kimoto authored on 2011-01-28
413
��s�̃t�F�b�`���I������͂���ȏ�t�F�b�`�ł��Ȃ��Ȃ�܂��B
414
���I�ɂ�1�s�̃t�F�b�`���I�������
415
�X�e�[�g�����g�n���h����C<finish()>����s����܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
416

            
update pod
Yuki Kimoto authored on 2011-01-28
417
=head3 �����s��Ƀt�F�b�`(�z��) C<fetch_multi()>
418

            
419
�����s��t�F�b�`���Ĕz��̃��t�@�����X��v�f�Ɏ���
420
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_multi()>��g�p���܂��B
421

            
422
    while (my $rows = $result->fetch_multi(2)) {
423
        my $title0   = $rows->[0][0];
424
        my $author0  = $rows->[0][1];
425
        
426
        my $title1   = $rows->[1][0];
427
        my $author1  = $rows->[1][1];
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
428
    }
update pod
Yuki Kimoto authored on 2011-01-28
429

            
430
��ɂ͎��o�������s����w�肵�܂��B
431

            
432
�w�肵���s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B
433

            
434
    [
435
        ['Perl', 'Ken'],
436
        ['Ruby', 'Mark']
437
    ]
438

            
439
=head3 ���ׂĂ̍s��t�F�b�`(�z��) C<fetch_all>
440

            
441
���ׂĂ̍s��t�F�b�`���Ĕz��̃��t�@�����X��v�f�Ɏ���
442
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_all()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
443

            
444
    my $rows = $result->fetch_all;
445

            
update pod
Yuki Kimoto authored on 2011-01-28
446
���ׂĂ̍s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B
447

            
448
    [
449
        ['Perl', 'Ken'],
450
        ['Ruby', 'Mark']
451
    ]
452

            
453
=head3 1�s�ƒt�F�b�`(�n�b�V��) C<fetch_hash()>
454

            
455
��s�t�F�b�`���ăn�b�V���̃��t�@�����X�Ɋi�[����ɂ�C<fetch_hash()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
456

            
457
    while (my $row = $result->fetch_hash) {
458
        my $title  = $row->{title};
459
        my $author = $row->{author};
460
    }
461

            
update pod
Yuki Kimoto authored on 2011-01-28
462
=head3 �ŏ��̍s�����t�F�b�`(�n�b�V��) C<fetch_hash_first()>
463

            
464
��s�����t�F�b�`���ăn�b�V���̃��t�@�����X�Ɋi�[����ɂ�
465
C<fetch_hash_first()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
466

            
467
    my $row = $result->fetch_hash_first;
update pod
Yuki Kimoto authored on 2011-01-28
468

            
469
��s�̃t�F�b�`���I������͂���ȏ�t�F�b�`�ł��Ȃ��Ȃ�܂��B
470
���I�ɂ�1�s�̃t�F�b�`���I�������
471
�X�e�[�g�����g�n���h����C<finish()>����s����܂��B
472

            
473
=head3 �����s��Ƀt�F�b�`(�n�b�V��) C<fetch_hash_multi()>
474

            
475
�����s��t�F�b�`���ăn�b�V���̃��t�@�����X��v�f�Ɏ���
476
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_hash_multi()>
477
��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
478

            
479
    while (my $rows = $result->fetch_hash_multi(5)) {
update pod
Yuki Kimoto authored on 2011-01-28
480
        my $title0   = $rows->[0]{title};
481
        my $author0  = $rows->[0]{author};
482
        my $title1  = $rows->[1]{title};
483
        my $author1 = $rows->[1]{author};
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
484
    }
update pod
Yuki Kimoto authored on 2011-01-28
485

            
486
��ɂ͎��o�������s����w�肵�܂��B
487

            
488
�w�肵���s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B
489

            
490
    [
491
        {title => 'Perl', author => 'Ken'},
492
        {title => 'Ruby', author => 'Mark'}
493
    ]
494

            
495
=head3 ���ׂĂ̍s��t�F�b�`(�n�b�V��) C<fetch_hash_all()>
496

            
497
���ׂĂ̍s��t�F�b�`���ăn�b�V���̃��t�@�����X��v�f�Ɏ���
498
�z��̃��t�@�����X�Ɋi�[����ɂ�C<fetch_hash_all()>
499
��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
500

            
501
    my $rows = $result->fetch_hash_all;
502

            
update pod
Yuki Kimoto authored on 2011-01-28
503
���ׂĂ̍s��i�[�������̂悤�ȃf�[�^��擾�ł��܂��B
504

            
505
    [
506
        {title => 'Perl', author => 'Ken'},
507
        {title => 'Ruby', author => 'Mark'}
508
    ]
509

            
510
=head3 �X�e�[�g�����g�n���h�� C<sth()>
511

            
512
�X�e�[�g�����g�n���h���ɒ��ڃA�N�Z�X�������ꍇ��
513
<sth>�Ŏ擾���邱�Ƃ��ł��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
514

            
515
    my $sth = $result->sth;
516

            
update pod
Yuki Kimoto authored on 2011-01-28
517
�t�F�b�`�̃p�t�H�[�}���X���p���𖞂����Ȃ��Ƃ��ɂ́A
518
�X�e�[�g�����g�n���h������
519
���p�ł��鑬�x�̑������\�b�h�𗘗p���邱�Ƃ��ł��܂��B
520

            
521
=head2 4. �t�B���^�����O
522

            
523
�f�[�^�x�[�X�Ƀf�[�^��o�^����Ƃ���f�[�^�x�[�X����f�[�^��擾����
524
�Ƃ��Ɏ����I�ɒl�̕ϊ���s�������ꍇ�������Ǝv���܂��B
525
���Ƃ��΁A��t��\�������̏ꍇ�́A
526
�f�[�^�x�[�X�ɓo�^����ꍇ��L<Time::Piece>�I�u�W�F�N�g����
527
�f�[�^�x�[�X�̓�t�̃t�H�[�}�b�g�ɁA
528
�f�[�^�x�[�X����f�[�^��擾����Ƃ��́A���̋t��s����ƕ֗��ł��B
529

            
530
=head3 �t�B���^�̓o�^ C<register_filter()>
531

            
532
�t�B���^��o�^����ɂ�C<register_filter()>��g�p���܂��B
533

            
534
    $dbi->register_filter(
535
        # Time::Piece object to DATE format
536
        tp_to_date => sub {
537
            my $date = shift;
538

            
539
            return '0000-00-00' unless $tp;
540
            return $tp->strftime('%Y-%m-%d');
541
        },
542
        
543
        # DATE to Time::Piece object
544
        date_to_tp => sub {
545
            my $date = shift;
546

            
547
            return if $date eq '0000-00-00';
548
            return Time::Piece->strptime($date, '%Y-%m-%d');
549
        },
550
    );
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
551

            
update pod
Yuki Kimoto authored on 2011-01-28
552
�o�^�����t�B���^��C<apply_filter()>�Ȃǂŗ��p���邱�Ƃ��ł��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
553

            
update pod
Yuki Kimoto authored on 2011-01-28
554
=head3 �t�B���^�̓K�p C<apply_filter()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
555

            
update pod
Yuki Kimoto authored on 2011-01-28
556
�쐬�����t�B���^��K�p����ɂ́AC<apply_filter()>��g�p���܂��B
557

            
558
    $dbi->apply_filter('book',
559
        issue_date => {out => 'tp_to_date', in => 'date_to_tp'},
560
        first_issue_date => {out => 'tp_to_date', in => 'date_to_tp'}
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
561
    );
562

            
update pod
Yuki Kimoto authored on 2011-01-28
563
����̓e�[�u�����ł��B����ȍ~�́A�񖼂ƃt�B���^���[���̃y�A��L�q���܂��B
564
�t�B���^���[����out�ɂ́A�f�[�^�x�[�X�Ƀf�[�^�𑗐M����Ƃ��ɓK�p����t�B���^��A
565
�t�B���^���[����in�ɂ́A�f�[�^�x�[�X����f�[�^��擾����Ƃ��ɓK�p����t�B���^��
566
�L�q���܂��Bout���f�[�^�x�[�X�ɑ��M������Ain���f�[�^�x�[�X������o�����ł��B
567
�t�B���^�ɂ́AC<register_filter>�œo�^�����t�B���^���̑��ɁA�R�[�h���t�@�����X��
568
�w�肷�邱�Ƃ�ł��܂��B
569

            
570
    issue_date => {out => sub { ... }, in => sub { ... }}
571

            
572
�K�p���ꂽ�t�B���^��C<insert()>�AC<update()>�AC<update_all()>�AC<delete()>�A
573
C<delete_all()>�AC<select()>�ŗL��ɂȂ�܂��B
574

            
575
    my $tp = Time::Piece->strptime('2010/10/14', '%Y/%m/%d');
576
    my $result = $dbi->select(table => 'book', where => {issu_date => $tp});
577

            
578
�f�[�^�x�[�X�Ƀf�[�^�����M�����Ƃ��ɁAL<Time::Piece>�I�u�W�F�N�g��
579
�f�[�^�x�[�X�̓�t�̃t�H�[�}�b�g�u2010-10-14�v�ɕϊ�����܂��B
580

            
581
�܂��t�Ƀf�[�^��t�F�b�`����Ƃ��ɂ́A�f�[�^�x�[�X�̓�t�̃t�H�[�}�b�g��
582
�^�C���s�[�X�I�u�W�F�N�g�ɕϊ�����܂��B
583

            
584
    my $row = $resutl->fetch_hash_first;
585
    my $tp = $row->{issue_date};
586

            
587
���̂悤�Ȏ����I�Ɏ�s�����t�B���^��o�^�ł��邱�Ƃ�L<DBIx::Custom>��
588
����̂ЂƂ‚ł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
589

            
update pod
Yuki Kimoto authored on 2011-01-28
590
C<apply_filter()>�œK�p���ꂽ�t�B���^�̓e�[�u�������܂ޗ񖼂ɑ΂��Ă�L��ł��B
591

            
592
    $dbi->select(
593
        table => 'book',
594
        where => {'book.title' => 'Perl', 'book.author' => 'Ken'}
595
    );
596

            
597
�e�[�u�����ʂ���K�v������Ƃ��ɕ֗��ȋ@�\�ł��B
598

            
599
=head3 �•ʂ̃t�B���^�̓K�p C<filter>
600

            
601
C<apply_filter()>��g��čŏ��ɂ��ׂẴe�[�u���̗�ɂ‚���
602
�t�B���^���`���邱�Ƃ�ł��܂����A
603
�•ʂɃt�B���^��K�p���邱�Ƃ�ł��܂��B
604
�•ʂ̃t�B���^��C<apply_filter()>�œK�p�����t�B���^��㏑���܂��B
605
�•ʂ̃t�B���^��SQL��as��g��āA��̕ʖ���쐬����K�v������ꍇ�Ɋ��􂵂܂��B
606

            
607
�f�[�^�x�[�X�ɑ��M����ꍇ�ɁA�•ʂ̃t�B���^��K�p����ɂ́A�e���\�b�h��
608
C<filter>�I�v�V������g�p���܂��B�•ʂ̃t�B���^�́AC<insert()>�AC<update()>�A
609
C<update_all()>�AC<delete()>�AC<delete_all()>�AC<select()>�AC<execute()>
610
�Ŏg�p���邱�Ƃ��ł��܂��B
611

            
612
C<insert()>�̗����܂��B
613

            
614
    $dbi->insert(
615
        table => 'book',
616
        param => {issue_date => $tp, first_issue_date => $tp},
617
        filter => {issue_date => 'tp_to_date', first_issue_date => 'tp_to_date'}
618
    );
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
619

            
update pod
Yuki Kimoto authored on 2011-01-28
620
C<execute()>�̗����܂��B
621

            
622
my $sql = <<"EOS";
623
select YEAR(issue_date) as issue_year
624
from book
625
where YEAR(issue_date) = {? issue_year}
626
EOS
627
   
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
628
    my $result = $dbi->execute(
update pod
Yuki Kimoto authored on 2011-01-28
629
        $sql,
630
        param => {issue_year => '2010'},
631
        filter => {issue_year => 'tp_to_year'}
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
632
    );
633

            
update pod
Yuki Kimoto authored on 2011-01-28
634
�����C<filter>��g���ǂ������ł��Bissue_date�̕ϊ��ɂ‚��Ă�C<apply_filter()>
635
�œo�^���Ă���̂ł����A�V�����쐬������ł���issue_year�ɂ‚��ẮA
636
���̕ϊ���o�^����Ă��܂���B�ł��̂ŁA�•ʂɃt�B���^��ݒ肵�Ă��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
637

            
update pod
Yuki Kimoto authored on 2011-01-28
638
�܂����΂ɍs��t�F�b�`����Ƃ��ɂ�•ʂ̃t�B���^��K�p���邱�Ƃ��ł��܂��B
639
�t�B���^��K�p����ɂ́A
640
C<DBIx::Custom::Result>�N���X��C<filter>���\�b�h��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
641

            
update pod
Yuki Kimoto authored on 2011-01-28
642
    $result->filter(issue_year => 'year_to_tp');
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
643

            
update pod
Yuki Kimoto authored on 2011-01-28
644
�p�ɂɗ��p����̂ł���΁A�•ʂɓo�^�������C<apply_filter()>�œo�^
645
���Ă������ق����֗��ł��傤�BC<apply_filter()>�͑��݂��Ȃ���ɑ΂��Ă�
646
�t�B���^��K�p�ł��邩��ł��B
647

            
648
    $dbi->apply_filter('book',
649
        'issue_year' => {out => 'tp_to_year', in => 'year_to_tp'}
650
    );
651

            
652
=head3 �ŏI�o�͂̂��߂̃t�B���^�����O C<end_filter()>
653

            
654
C<DBIx::Custom::Result>�ł͂���ɍŌ�ɂ���x�A�t�B���^��lj��
655
�o�^���邱�Ƃ��ł��܂��B���Ƃ���HTML�ɏo�͂������ꍇ�ɁATime::Piece
656
�I�u�W�F�N�g����ǂ݂₷���L�q�ɕϊ����邱�Ƃ��ł��܂��B
657
�Ō�̃t�B���^��o�^����ɂ́AC<end_filter()>��g�p���܂��B
658

            
659
    $result->end_filter(issue_date => sub {
660
        my $tp = shift;
661
        
662
        return '' unless $tp;
663
        return $tp->strftime('%Y/%m/%d %h:%m:%s (%a)');
664
    });
665

            
666
��t��₷���`�Ƀt�H�[�}�b�g���邱�Ƃ��ł��܂��B
667

            
668
�t�B���^�̓t�F�b�`��s���O�ɓo�^���Ă����K�v�����邱�Ƃ�
669
���ӂ��Ă��������B
670

            
671
    $result->filter(...);
672
    $result->end_filter(...);
673
    my $row = $result->fetch_hash_first;
674

            
675
=head3 ��̏���Ƀt�B���^��K�p���� C<each_column()>
676

            
677
��t�^�̗�͎蓮�Őݒ肵�Ȃ��Ă�A�����I�ɐݒ�ł���ƕ֗��ł��B
678
���̂��߂Ƀf�[�^�x�[�X�̃e�[�u���̗�̂��ׂĂ̏���
679
���Ԃɏ������邽�߂�C<each_column()>������܂��B
680

            
681
    $dbi->each_column(
682
        sub {
683
            my ($self, $table, $column, $info) = @_;
684
            
685
            my $type = $info->{TYPE_NAME};
686
            
687
            my $filter = $type eq 'DATE'     ? {out => 'tp_to_date', in => 'date_to_tp'}
688
                       : $type eq 'DATETIME' ? {out => 'tp_to_datetime', in => 'datetime_to_tp'}
689
                                             : undef;
690
            
691
            $self->apply_filter($table, $column, $filter)
692
              if $filter;
693
        }
694
    );
695

            
696
each_column�̓R�[���o�b�N��󂯎��܂��B�R�[���o�b�N�̈��
697
���Ԃ�L<DBIx::Custom>�I�u�W�F�N�g�A�e�[�u�����A�񖼁A��̏��ł��B
698
��̌^���̏����ƂɎ����I�ɁA�t�B���^��K�p���Ă��܂��B
699

            
700
�ЂƂ‚̒��ӓ_�Ƃ��ăR�[���o�b�N�̒�����A�R�[���o�b�N�̊O��
701
�̕ϐ���Q�Ƃ��Ȃ��悤�ɒ��ӂ��Ă��������Beach_column��
702
���X1�񂾂���s����邾���Ȃ̂ŁA�قƂ�ǂ̏ꍇ��肠��܂��񂪁A
703
�z�ŽQ�Ƃɂ�郁�������[�N���������Ă��܂��”\�����Ă��邩��ł��B
704

            
705
=head2 5. �^�O
706

            
707
=head3 �^�O�̋@�\
708

            
709
L<DBIx::Custom>��SQL�̒��Ƀ^�O�𖄂ߍ��ދ@�\���Ă��܂��B
710

            
711
    select * from book where {= title} and {like author};
712

            
713
{= title}��{like author}�̕������^�O�ł��B�^�O�͎��̂悤�Ȍ`��
714
����܂��B
715

            
716
    {�^�O�� ��1 ��2 ...}
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
717
    
update pod
Yuki Kimoto authored on 2011-01-28
718
�^�O��C<{>�Ŏn�܂�AC<}>�ŏI���܂��B�ŏ���C<{>�ƃ^�O���̊�
719
�ɂ͋󔒂�}��Ȃ��悤���ӂ��Ă��������B
720

            
721
�^�O�̋@�\�̂��߂�C<{>��C<}>�͗\���ɂȂ�Ă��܂��B
722
�����p�������ꍇ�͒��O��\����ăG�X�P�[�v��s���K�v������܂��B
723

            
724
    select from book \\{ ... \\}
725

            
726
C<\>���̂�Perl�̃G�X�P�[�v�����ł��̂ŁA
727
�G�X�P�[�v����ꍇ��C<\>����•K�v�ɂȂ�Ƃ����_�ɒ��ӂ��Ă��������B
728

            
729
��L�̃^�O��SQL����s�����O�Ɏ���SQL�ɓW�J����܂��B
730

            
731
    select * from book where title = ? and author like ?;
732

            
733
�^�O��܂�SQL���s����ɂ�C<execute()>��g�p���܂��B
734

            
735
    my $sql = "select * from book where {= author} and {like title};"
736
    $dbi->execute($sql, param => {title => 'Perl', author => '%Ken%'});
737

            
738
C<param>�I�v�V������g��āA�v���[�X�z���_�ɖ��ߍ��݂����l��
739
�n�b�V�����t�@�����X�Ŏw�肷�邱�Ƃ��ł��܂��B
740

            
741
���̃��\�b�h�Ɠ��l��C<execute()>�ɂ����Ă�C<filter>��w�肷�邱�Ƃ��ł��܂��B
742

            
743
    $dbi->execute($sql, param => {title => 'Perl', author => '%Ken%'}
744
                  filter => {title => 'to_something');
745

            
746
C<execute>�̂ЂƂ‚̒��ӓ_�Ƃ��Ă�C<apply_filter()>�œK�p���ꂽ�t�B���^
747
�̓f�t�H���g�ł͗L��ł͂Ȃ��Ƃ������Ƃɒ��ӂ��Ă��������B
748
C<apply_filter()>�œK�p���ꂽ�t�B���^��L��ɂ���ɂ́A
749
C<table>��w�肷��K�v������܂��B
750

            
751
    $dbi->execute($sql, param => {title => 'Perl', author => '%Ken%'}
752
                  table => ['book']);
753

            
754
=head2 �^�O�ꗗ
755

            
756
L<DBIx::Custom>�ł͎��̃^�O���g�p�”\�ł��B
757

            
758
���̂悤�Ƀ^�O��g���SQL����\������̂�L<DBIx::Custom>��
759
����ł��B�ȉ��̃^�O�����p�”\�ł��B
760

            
761
=head3 C<?>
762

            
763
C<?>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
764

            
765
    {? NAME}    ->   ?
766

            
767
=head3 C<=>
768

            
769
C<=>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
770

            
771
    {= NAME}    ->   NAME = ?
772

            
773
=head3 C<E<lt>E<gt>>
774

            
775
C<E<lt>E<gt>>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
776

            
777
    {<> NAME}   ->   NAME <> ?
778

            
779
=head3 C<E<lt>>
780

            
781
C<E<lt>>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
782

            
783
    {< NAME}    ->   NAME < ?
784

            
785
=head3 C<E<gt>>
786

            
787
C<E<gt>>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
788

            
789
    {> NAME}    ->   NAME > ?
790

            
791
=head3 C<E<gt>=>
792

            
793
C<E<gt>=>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
794

            
795
    {>= NAME}   ->   NAME >= ?
796

            
797
=head3 C<E<lt>=>
798

            
799
C<E<lt>=>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
800

            
801
    {<= NAME}   ->   NAME <= ?
802

            
803
=head3 C<like>
804

            
805
C<like>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
806

            
807
    {like NAME}   ->   NAME like ?
808

            
809
=head3 C<in>
810

            
811
C<in>�^�O�͈ȉ��̂悤�ɓW�J����܂��B�v���[�X�z���_��
812
�����Ŏw�肷��K�v�����邱�Ƃɒ��ӂ��Ă��������B
813

            
814
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
815

            
816
=head3 C<insert_param>
817

            
818
C<insert_param>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
819

            
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
820
    {insert_param NAME1 NAME2}   ->   (NAME1, NAME2) values (?, ?)
update pod
Yuki Kimoto authored on 2011-01-28
821

            
822
=head3 C<update_param>
823

            
824
C<update_param>�^�O�͈ȉ��̂悤�ɓW�J����܂��B
825

            
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
826
    {update_param NAME1 NAME2}   ->   set NAME1 = ?, NAME2 = ?
827

            
update pod
Yuki Kimoto authored on 2011-01-28
828
=head2 �����̗�̈���
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
829

            
update pod
Yuki Kimoto authored on 2011-01-28
830
�����̗��܂ރ^�O������ꍇ�ɂ�ASQL���s���邱�Ƃ��ł��܂��B
831
���Ƃ��΁A��‚̓�t�Ŕ�r���Ȃ���΂Ȃ�Ȃ��ꍇ��
832
�l���Č��܂��傤�B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
833

            
update pod
Yuki Kimoto authored on 2011-01-28
834
    my $sql = "select * from table where {> date} and {< date};";
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
835

            
update pod
Yuki Kimoto authored on 2011-01-28
836
���̂悤�ȏꍇ�͑Ή�����p�����[�^�̒l��z��̃��t�@�����X�ɂ��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
837

            
update pod
Yuki Kimoto authored on 2011-01-28
838
    my $dbi->execute($sql, param => {date => ['2010-10-01', '2012-02-10']});
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
839

            
update pod
Yuki Kimoto authored on 2011-01-28
840
=head2 �^�O�̒lj� C<register_tag()>
841

            
842
L<DBIx::Custom>�ł̓^�O��Ǝ��ɒlj���邱�Ƃ��ł��܂��B
843
�^�O��lj����ɂ�C<register_tag()>��g�p���܂��B
844

            
845
    $dbi->register_tag(
846
        '=' => sub {
847
            my $column = shift;
848
            
849
            return ["$column = ?", [$column]];
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
850
        }
851
    );
852

            
update pod
Yuki Kimoto authored on 2011-01-28
853
�����ł̓f�t�H���g��C<=>�^�O���ǂ̂悤�Ɏ������Ă��邩����Ă��܂��B
854
�^�O��o�^����֐��̈�̓^�O�̒��ɏ����ꂽ��ɂȂ�܂��B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
855

            
update pod
Yuki Kimoto authored on 2011-01-28
856
    {�^�O�� ��1 ��2}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
857

            
update pod
Yuki Kimoto authored on 2011-01-28
858
C<=>�^�O�̏ꍇ��
cleanup
Yuki Kimoto authored on 2011-01-12
859

            
update pod
Yuki Kimoto authored on 2011-01-28
860
    {= title}
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
861

            
update pod
Yuki Kimoto authored on 2011-01-28
862
�Ƃ����`���ł�����A�T�u���[�`���ɂ�title�Ƃ����ЂƂ‚̗񖼂��킽��Ă��܂��B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
863

            
update pod
Yuki Kimoto authored on 2011-01-28
864
�T�u���[�`���̖߂�l�ɂ͎��̌`���̔z��̃��t�@�����X��Ԃ��K�v������܂��B
865

            
866
    [
867
        �W�J��̕�����,
868
        [�v���[�X�z���_�ɖ��ߍ��݂ɗ��p�����1, ��2, ...]
869
    ]
870

            
871
��–ڂ̗v�f�͓W�J��̕�����ł��B���̗�ł�
872

            
873
    'title = ?'
874

            
875
��Ԃ��K�v������܂��B
876

            
877
��–ڂ̗v�f�̓v���[�X�z���_�ɖ��ߍ��݂ɗ��p����񖼂�܂ޔz���
878
���t�@�����X�ł��B����̗�ł�
879

            
880
    ['title']
881

            
882
��Ԃ��K�v������܂��B�����̃v���[�X�z���_��܂ޏꍇ�́A���̕�����
883
�����ɂȂ�܂��BC<insert_param>�^�O��C<update_param>�^�O��
884
���̕�������ە����ɂȂ�Ă��܂��B
885

            
886
��L��킹���
887

            
888
    ['title = ?', ['title']]
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
889
    
update pod
Yuki Kimoto authored on 2011-01-28
890
��Ԃ��K�v������Ƃ������Ƃł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
891

            
update pod
Yuki Kimoto authored on 2011-01-28
892
�^�O�̎���̑��̃T���v����L<DBIx::Custom::Tag>�̃\�[�X�R�[�h
893
����ɂȂ�Ă݂Ă��������B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
894

            
update pod
Yuki Kimoto authored on 2011-01-28
895
=head2 6. Where��̓��I�Ȑ���
896

            
897
=head3 Where��̓��I�Ȑ��� where()
898

            
899
�����̌�����w�肵�āA�����s�������ꍇ������܂��B
900
����3�‚̃P�[�X��where���l���Ă݂܂��傤�B
901
���L�̂悤��where�傪�K�v�ɂȂ�܂��B
902

            
903
title�̒l�����Ō�������ꍇ
904

            
905
    where {= title}
906

            
907
author�̒l�����Ō�������ꍇ
908

            
909
    where {= author}
910

            
911
title��author�̗���̒l�Ō�������ꍇ
912

            
913
    where {= title} and {=author}
914

            
915
L<DBIx::Custom>�ł͓��I��Where��̐�����T�|�[�g���Ă��܂��B
916
�܂�C<where()>��L<DBIx::Custom::Where>�I�u�W�F�N�g�𐶐����܂��B
917

            
918
    my $where = $dbi->where;
919

            
920
����C<clause()>��g�p����where���L�q���܂��B
921

            
922
    $where->clause(
923
        ['and', '{= title'}, '{= author}']
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
924
    );
925

            
update pod
Yuki Kimoto authored on 2011-01-28
926
clause�̎w���@�͎��̂悤�ɂȂ�܂��B
927

            
928
    ['or' ���邢�� 'and', �^�O1, �^�O2, �^�O3]
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
929

            
update pod
Yuki Kimoto authored on 2011-01-28
930
����ɂ�or���邢��and��w�肵�܂��B����ȍ~�ɂ�
931
������^�O��g��ċL�q���܂��B
932

            
933
C<clause>�̎w��͓��q�ɂ��邱�Ƃ�ł��A����ɕ��G�ȏ�
934
��L�q���邱�Ƃ�ł��܂��B
935

            
936
    ['and', 
937
      '{= title}', 
938
      ['or', '{= author}', '{like date}']
939
    ]
940

            
941
���̂悤��C<clause>��ݒ肵�����C<param>�Ƀp�����[�^��w�肵�܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
942
    
update pod
Yuki Kimoto authored on 2011-01-28
943
    my $param => {title => 'Perl'};
944
    $where->param($param);
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
945

            
update pod
Yuki Kimoto authored on 2011-01-28
946
���̗�ł�title�������p�����[�^�Ɋ܂܂�Ă��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
947

            
update pod
Yuki Kimoto authored on 2011-01-28
948
���̌�C<to_string()>���s�����$param�Ɋ܂܂��p�����[�^�𖞂���
949
where��𐶐����邱�Ƃ��ł��܂��B
950

            
951
    my $where_clause = $where->to_string;
952

            
953
�p�����[�^��title�����ł��̂ŁA���̂悤��where�傪��������܂��B
954

            
955
    where {= title}
956

            
957
�܂�L<DBIx::Custom>�͕�����̕]����I�[�o�[���[�h���āAC<to_string()>
958
��Ăяo���悤�ɂ��Ă��܂��̂ŁA���̂悤�ɂ���where��𐶐����邱�Ƃ�
959
�ł��܂��B
960

            
961
    my $where_clause = "$where";
962

            
963
�����SQL�̒���where��𖄂ߍ��ނƂ��ɂƂĂ�𗧂‹@�\�ł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
964

            
update pod
Yuki Kimoto authored on 2011-01-28
965
=head3 ����̗񖼂�܂ޏꍇ
check arguments of connect m...
Yuki Kimoto authored on 2010-12-20
966

            
update pod
Yuki Kimoto authored on 2011-01-28
967
�^�O�̒��ɓ���̖��O��‚�̂����݂����ꍇ�ł��I��
968
where���쐬���邱�Ƃ��ł��܂��B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
969

            
update pod
Yuki Kimoto authored on 2011-01-28
970
���Ƃ��΁A�p�����[�^�Ƃ��ĊJ�n��t�ƏI����t��󂯎������Ƃ�
971
�l���Ă݂Ă��������B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
972

            
update pod
Yuki Kimoto authored on 2011-01-28
973
    my $param = {start_date => '2010-11-15', end_date => '2011-11-21'};
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
974

            
update pod
Yuki Kimoto authored on 2011-01-28
975
�܂��J�n��t�ƏI����t�̕Е���A�ǂ����󂯎��Ȃ��ꍇ���邩����܂���B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
976

            
update pod
Yuki Kimoto authored on 2011-01-28
977
���̏ꍇ�͎��̂悤�ȃp�����[�^�ɕϊ����邱�ƂőΉ����邱�Ƃ��ł��܂��B
978

            
979
    my $p = {date => ['2010-11-15', '2011-11-21']};
980

            
981
�l���z��̃��t�@�����X�ɂȂ�Ă��邱�Ƃɒ��ڂ��Ă��������B���̂悤�ɂ����
982
�����̗��܂ރ^�O�ɏ��Ԃɖ��ߍ��ނ��Ƃ��ł��܂��B
983

            
984
    $where->clause(
985
        ['and', '{> date}', '{< date}']
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
986
    );
update pod
Yuki Kimoto authored on 2011-01-28
987
    $where->param($p);
988

            
989
�܂��J�n��t�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B
990

            
991
    my $p = {date => [$dbi->not_exists, '2011-11-21']};
992

            
993
L<DBIx::Custom>��C<not_exists>��DBIx::Custom::NotExists�I�u�W�F�N�g��
994
�擾�ł��܂��B����͑Ή�����l�����݂��Ȃ����Ƃ�����߂̂�̂ł��B
995

            
996
�܂��I����t�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B
997

            
998
    my $p = {date => ['2010-11-15']};
999

            
1000
�ǂ�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B
1001

            
1002
    my $p = {date => []};
1003

            
1004
��������̂ň�ԊȒP�ɍ쐬�ł��郍�W�b�N����Ă����܂��B
1005

            
1006
    my @date;
1007
    push @date, exists $param->{start_date} ? $param->{start_date}
1008
                                            : $dbi->not_exists;
1009
    push @date, $param->{end_date} if exists $param->{end_date};
1010
    my $p = {date => \@date};
1011

            
1012
=head3 C<select()>�Ƃ̘A�g
1013

            
1014
L<DBIx::Custom::Where>�I�u�W�F�N�g��
1015
C<select()>��C<where>�ɒ��ړn�����Ƃ�
1016
�ł��܂��B
1017
    
1018
    my $where = $dbi->where;
1019
    $where->clause(...);
1020
    $where->param($param);
1021
    my $result = $dbi->select(table => 'book', where => $where);
1022

            
1023
���邢��C<update()>�AC<delete()>��where�Ɏw�肷�邱�Ƃ�”\�ł��B
1024

            
1025
=head3 C<execute()>�Ƃ̘A�g
1026

            
1027
C<execute()>�Ƃ̘A�g�ł��BSQL��쐬����Ƃ��ɖ��ߍ��ނ��Ƃ��ł��܂��B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1028

            
1029

            
update pod
Yuki Kimoto authored on 2011-01-28
1030
    my $where = $dbi->where;
1031
    $where->clause(...);
1032
    $where->param($param);
1033

            
1034
    my $sql = <<"EOS"
1035
    select * from book;
1036
    $where
1037
    EOS
1038

            
1039
    $dbi->execute($sql, param => $param);
1040

            
1041
=head2 7. �e�[�u�����f��
1042

            
1043
=head3 �e�[�u���I�u�W�F�N�g�̍쐬 C<table()>
1044

            
1045
L<DBIx::Custom>�̓��W�b�N�Ƃ��ăe�[�u���𒆐S�ɂ�����
1046
���f���̍쐬��x�����܂��B
1047

            
1048
�A�v���P�[�V�����̃��W�b�N��L�q����Ƃ��ɁA���̃��W�b�N��
1049
�f�[�^�x�[�X�̃e�[�u���ɂ����邱�Ƃ́ARDBMS�𗘗p����
1050
���f���ł���΁A�R�[�h�̏d�����Ȃ�
1051
�킩��₷����̂ɂȂ�܂��B
1052

            
1053
�e�[�u���I�u�W�F�N�g�𐶐�����ɂ�C<table()>��g�p���܂��B
1054

            
1055
    my $table = $dbi->table('book');
1056

            
1057
��ۂɃf�[�^�x�[�X�Ƀe�[�u���͑��݂��Ă���K�v�͂���܂���B
1058
����͉��z�I�ȃe�[�u���I�u�W�F�N�g�ł��B�����
1059
L<DBIx::Customm::Table>�I�u�W�F�N�g�ɂȂ�܂��B
1060

            
1061
�e�[�u���I�u�W�F�N�g�����C<insert()>�AC<update()>�AC<update_all()>�A
1062
C<delete()>�AC<delete_all()>�AC<select()>�Ȃǂ̃��\�b�h�Ăяo�����Ƃ��ł��܂��B
1063
L<DBIx::Custom>�ƈقȂ�Ƃ���́AC<table>��K������w�肷��K�v��
1064
�Ȃ��Ƃ������Ƃł��B
1065

            
1066
    $table->insert(param => $param);
1067

            
1068
C<table���̒l�͎����I��book�ɐݒ肳��܂��B
1069

            
1070
�܂��e�[�u���I�u�W�F�N�g�ɂ͓Ǝ��̃��\�b�h��lj���邱�Ƃ��ł��܂��B
1071

            
1072
    $table->method(
1073
        register => sub {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1074
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-01-28
1075
            my $table_name = $self->name;
1076
            # something
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1077
        },
update pod
Yuki Kimoto authored on 2011-01-28
1078
        list => sub {
1079
            my $self = shift;
1080
            my $table_name = $self->name;
1081
            # something
1082
        }
1083
    );
1084

            
1085
���\�b�h�ɓn���������L<DBIx::Custom::Table>�I�u�W�F�N�g�ł��B
1086
C<name()>��g�p���āA�e�[�u������擾���邱�Ƃ��ł��܂��B
1087

            
1088
���̂悤�ɂ��ēo�^�������\�b�h�͒��ڌĂяo�����Ƃ��ł��܂��B
1089

            
1090
    $table->register(...);
1091
    $table->list(...);
1092

            
1093
�܂��e�[�u����p�̃��\�b�h��I�[�o�[���C�h���č쐬���邱�Ƃ�ł��܂��B
1094

            
1095
    $table->method(
1096
        insert => sub {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1097
            my $self = shift;
1098
            
update pod
Yuki Kimoto authored on 2011-01-28
1099
            $self->base_insert(...);
1100
            
1101
            # something
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1102
        }
1103
    );
1104

            
update pod
Yuki Kimoto authored on 2011-01-28
1105
��Ƃ�Ƒ��݂��Ă���C<insert()>��ĂԂɂ�C<base_$method>�Ƃ��܂��BL<DBIx::Custom::Table>
1106
�̃I�[�o�[���C�h�̋@�\�͊ȈՓI�Ȃ�̂ł����A�ƂĂ�֗��ł��B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1107

            
update pod
Yuki Kimoto authored on 2011-01-28
1108
=head2 �e�[�u���ŋ��L�̃��\�b�h�̓o�^
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1109

            
update pod
Yuki Kimoto authored on 2011-01-28
1110
���ׂẴe�[�u���Ń��\�b�h��L����ɂ�C<table>���\�b�h�Ńe�[�u����쐬����O�ɁA
1111
C<base_table>�Ƀ��\�b�h��o�^���Ă����܂��B
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1112

            
update pod
Yuki Kimoto authored on 2011-01-28
1113
    $dbi->base_table->method(
1114
        count => sub {
1115
            my $self = shift;
1116
            return $self->select(column => ['count(*)']);
1117
        }
1118
    );
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1119

            
update pod
Yuki Kimoto authored on 2011-01-28
1120
�܂��e�[�u�������L<DBIx::Custom>��L<DBI>�̂��ׂẴ��\�b�h��Ăяo�����Ƃ��ł��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1121

            
update pod
Yuki Kimoto authored on 2011-01-28
1122
    # DBIx::Custom method
1123
    $table->execute($sql);
1124
    
1125
    # DBI method
1126
    $table->begin_work;
1127
    $table->commit;
1128

            
1129
=head2 ��ʓI�ȃ��f���̍\��
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1130

            
update pod
Yuki Kimoto authored on 2011-01-28
1131
��ʓI�ɂ́AL<DBIx::Custom>��p�����ăR���X�g���N�^�̒��ɁA���f����쐬
1132
����̂��悢�ł��傤�B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1133

            
update pod
Yuki Kimoto authored on 2011-01-28
1134
    package MyDBI;
1135
    
1136
    use base 'DBIx::Custom';
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1137
    
update pod
Yuki Kimoto authored on 2011-01-28
1138
    sub connect {
1139
        my $self = shift->SUPER::connect(@_);
1140
        
1141
        $self->base_table->method(
1142
            ... => sub { ... }
1143
        );
1144
        
1145
        $self->table('book')->method(
1146
            insert_multi => sub { ... },
1147
            ... => sub { ... }
1148
        );
1149
        
1150
        $self->table('company')->method(
1151
            ... => sub { ... },
1152
        );
1153
    }
1154

            
1155
���̂悤�ɂ��Ē�`���Ă����΁A���̂悤�ɗ��p���邱�Ƃ��ł��܂��B
1156

            
1157
    my $dbi = MyDBI->connect(...);
1158
    $dbi->table('book')->insert_multi(...);
1159

            
1160
=head2 8. �p�t�H�[�}���X�̉�P
1161

            
1162
=head3 �N�G���̍쐬
1163

            
1164
��C<insert()>���\�b�h��g�p���ăC���T�[�g���s�����ꍇ�A
1165
�K�v�ȃp�t�H�[�}���X�𓾂��Ȃ��ꍇ�����邩����܂���B
1166
C<insert()>���\�b�h�́ASQL���ƃX�e�[�g�����g�n���h����
1167
����쐬���邽�߂ł��B
1168

            
1169
���̂悤�ȏꍇ�́AC<query>�I�v�V������w�肷�邱�ƂŁA
1170
�N�G����擾���邱�Ƃ��ł��܂��B
1171

            
1172
    my $query = $dbi->insert(table => 'book', param => $param, query => 1);
1173

            
1174
�܂�C<create_query()>���\�b�h��g��ĔC�ӂ�SQL�̃N�G����쐬
1175
���邱�Ƃ�ł��܂��B
1176

            
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1177
    my $query = $dbi->create_query(
update pod
Yuki Kimoto authored on 2011-01-28
1178
        "insert into book {insert_param title author};";
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1179
    );
1180

            
update pod
Yuki Kimoto authored on 2011-01-28
1181
�߂�l��L<DBIx::Custom::Query>�I�u�W�F�N�g�ł��B
1182
���̃I�u�W�F�N�g��SQL���ƃp�����[�^�o�C���h���̗񖼂�
1183
�ێ����Ă��܂��B�܂��X�e�[�g�����g�n���h����ێ����Ă��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1184

            
1185
    {
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1186
        sql     => 'insert into book (title, author) values (?, ?);',
update pod
Yuki Kimoto authored on 2011-01-28
1187
        columns => ['title', 'author'],
1188
        sth     => $sth
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1189
    }
1190

            
update pod
Yuki Kimoto authored on 2011-01-28
1191
�N�G���I�u�W�F�N�g��g��ČJ��Ԃ���s����ɂ�C<execute()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1192
    
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1193
    my $params = [
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1194
        {title => 'Perl',      author => 'Ken'},
1195
        {title => 'Good days', author => 'Mike'}
1196
    ];
1197
    
update pod
Yuki Kimoto authored on 2011-01-28
1198
    foreach my $param (@$paramss) {
1199
        $dbi->execute($query, table => 'book', param => $input);
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1200
    }
1201

            
update pod
Yuki Kimoto authored on 2011-01-28
1202
C<execute>���\�b�h�̑���ɃN�G���I�u�W�F�g��n�����Ƃ��ł��܂��B
1203
C<insert()>���\�b�h�������ł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1204

            
update pod
Yuki Kimoto authored on 2011-01-28
1205
���ӓ_�������‚�����܂��B����̓p�����[�^�̐��͕K�������łȂ��Ă͂Ȃ�Ȃ�
1206
�Ƃ������Ƃł��B�ŏ���3�‚̃p�����[�^������n�����̂ɁA���̎�s�ł�
1207
��‚̃p�����[�^��n���Ɨ\��Ȃ����ʂɂȂ�܂��B�����
1208
���I�ɐ������ꂽSQL�Ɋ܂܂��v���[�X�z���_�̐����قȂ邩��ł��B
1209
�܂�C<execute()>�ɂ��Ă͎����I�ɂ̓t�B���^���L��ɂȂ�Ȃ��̂ŁA
1210
C<table>��w�肷��K�v�̂��邱�Ƃɒ��ӂ��Ă��������B
1211
�{���ɕK�v�ȏꍇ�������p���Ă��������B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1212

            
update pod
Yuki Kimoto authored on 2011-01-28
1213
=head2 9. ���̑��̋@�\
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1214

            
update pod
Yuki Kimoto authored on 2011-01-28
1215
=head3 ���\�b�h�̓o�^
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1216

            
update pod
Yuki Kimoto authored on 2011-01-28
1217
���\�b�h��o�^����ɂ�C<method()>��g�p���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1218

            
update pod
Yuki Kimoto authored on 2011-01-28
1219
    $dbi->method(
1220
        update_or_insert => sub {
1221
            my $self = shift;
1222
            # something
1223
        },
1224
        find_or_create   => sub {
1225
            my $self = shift;
1226
            # something
1227
        }
1228
    );
1229

            
1230
<method()>�œo�^�������\�b�h��
1231
L<DBIx::Custom>�I�u�W�F�N�g���璼�ڌĂяo�����Ƃ��ł��܂��B
1232

            
1233
    $dbi->update_or_insert;
1234
    $dbi->find_or_create;
1235

            
1236
=head3 ���ʃN���X�̕ύX
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1237

            
update pod
Yuki Kimoto authored on 2011-01-28
1238
�K�v�Ȃ�Ό��ʃN���X��ύX���邱�Ƃ��ł��܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1239

            
update pod
Yuki Kimoto authored on 2011-01-28
1240
    package MyResult;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1241
    use base 'DBIx::Custom::Result';
1242
    
1243
    sub some_method { ... }
1244

            
1245
    1;
1246
    
1247
    package main;
1248
    
update pod
Yuki Kimoto authored on 2011-01-28
1249
    use MyResult;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1250
    
1251
    my $dbi = DBIx::Custom->connect(...);
update pod
Yuki Kimoto authored on 2011-01-28
1252
    $dbi->result_class('MyResult');
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1253

            
update pod
Yuki Kimoto authored on 2011-01-28
1254
=head3 �L���b�V���O
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1255

            
update pod
Yuki Kimoto authored on 2011-01-28
1256
�^�O�̓W�J���SQL�̓p�t�H�[�}���X�̗��R�̂��߂ɃL���b�V������܂��B
1257
�����C<chace>�Őݒ�ł��A�f�t�H���g�ł̓L���b�V����s���ݒ�ł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1258

            
update pod
Yuki Kimoto authored on 2011-01-28
1259
    $dbi->cache(1);
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1260

            
update pod
Yuki Kimoto authored on 2011-01-28
1261
�L���b�V����@��C<cache_method>�Ƀ��\�b�h��w�肷�邱�Ƃ�
1262
�ύX���邱�Ƃ��ł��܂��B
1263
�f�[�^�̕ۑ��Ǝ擾�̂��߂̃��\�b�h���`���܂��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1264

            
update pod
Yuki Kimoto authored on 2011-01-28
1265
�f�t�H���g�ł͎��̂悤�Ƀ�������ɃL���b�V����s����̂ɂȂ�Ă��܂��B
1266

            
1267
    $dbi->cache_method(sub {
1268
        sub {
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1269
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-01-28
1270
            
1271
            $self->{_cached} ||= {};
1272
            
1273
            if (@_ > 1) {
1274
                # Set
1275
                $self->{_cached}{$_[0]} = $_[1] 
1276
            }
1277
            else {
1278
                # Get
1279
                return $self->{_cached}{$_[0]}
1280
            }
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1281
        }
update pod
Yuki Kimoto authored on 2011-01-28
1282
    });
1283
    
1284
����L<DBIx::Custom>�I�u�W�F�N�g�ł��B
1285
����̓^�O�̓W�J�����O��SQL�ł��B
1286
��O��̓^�O�̓W�J���SQL�ł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1287

            
update pod
Yuki Kimoto authored on 2011-01-28
1288
�����ō쐬����ꍇ�͑�O�����݂����ꍇ�̓L���b�V����ݒ肵�A
1289
���݂��Ȃ�����ꍇ�̓L���b�V����擾��������
1290
�����������B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1291

            
update pod
Yuki Kimoto authored on 2011-01-28
1292
=cut
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1293

            
pod fix
Yuki Kimoto authored on 2011-01-21
1294
=head1 EXAMPLES
1295

            
1296
L<DBIx::Custom Wiki|https://github.com/yuki-kimoto/DBIx-Custom/wiki> - Many useful examples
add examples
Yuki Kimoto authored on 2011-01-07
1297

            
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1298
=cut