Newer Older
1270 lines | 33.294kb
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

            
update pod
Yuki Kimoto authored on 2011-01-30
124
=item 4. Methods for insert, update, delete, select
update pod
Yuki Kimoto authored on 2011-01-28
125

            
update pod
Yuki Kimoto authored on 2011-01-30
126
L<DBIx::Custom> provides methods for insert, update, delete, select
127
There are C<insert()>, C<update()>, C<delete()>,C<select()>.
update pod
Yuki Kimoto authored on 2011-01-28
128

            
129
    my $param = {title => 'Perl', author => 'Ken'};
130
    $dbi->insert(table => 'book', param => $param);
131

            
update pod
Yuki Kimoto authored on 2011-01-30
132
=item 5. Register method for table.
deprecated DBIx::Custom::MyS...
root authored on 2010-11-26
133

            
update pod
Yuki Kimoto authored on 2011-01-30
134
You can register method for table.
update pod
Yuki Kimoto authored on 2011-01-28
135

            
update pod
Yuki Kimoto authored on 2011-01-30
136
    $dbi->table('book')->method(
update pod
Yuki Kimoto authored on 2011-01-28
137
        list => sub {
138
            ...
139
        },
update pod
Yuki Kimoto authored on 2011-01-30
140
        something => sub {
141
            ...
update pod
Yuki Kimoto authored on 2011-01-28
142
        }
143
    );
144

            
update pod
Yuki Kimoto authored on 2011-01-30
145
use the mehtod.
update pod
Yuki Kimoto authored on 2011-01-28
146

            
147
    $dbi->table('book')->list;
148

            
update pod
Yuki Kimoto authored on 2011-01-30
149
Many O/R mapper must create class for table,
150
but L<DBIx::Custom> make it easy.
update pod
Yuki Kimoto authored on 2011-01-28
151

            
152
=back
153

            
update pod
Yuki Kimoto authored on 2011-01-30
154
L<DBIx::Custom> is very useful.
155
See the following if you are interested in it.
update pod
Yuki Kimoto authored on 2011-01-28
156

            
update pod
Yuki Kimoto authored on 2011-01-30
157
=head2 1. Connect to database
update pod
Yuki Kimoto authored on 2011-01-28
158

            
update pod
Yuki Kimoto authored on 2011-01-30
159
Load L<DBIx::Custom>.
update pod
Yuki Kimoto authored on 2011-01-28
160

            
161
    use DBIx::Custom;
162

            
update pod
Yuki Kimoto authored on 2011-01-30
163
use C<connect()> to connect to database.
164
Return value is L<DBIx::Custom> object.
update pod
Yuki Kimoto authored on 2011-01-28
165

            
166
    my $dbi = DBIx::Custom->connect(
update pod
Yuki Kimoto authored on 2011-01-30
167
        data_source => "dbi:mysql:database=bookstore",
update pod
Yuki Kimoto authored on 2011-01-28
168
        user => 'ken',
169
        password => '!LFKD%$&',
170
        dbi_options => {mysql_enable_utf8 => 1}
171
    );
172

            
update pod
Yuki Kimoto authored on 2011-01-30
173
C<data_source> must be one corresponding to the database system.
174
The following ones are data source example.
update pod
Yuki Kimoto authored on 2011-01-28
175

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

            
178
    "dbi:mysql:database=$database"
179
    "dbi:mysql:database=$database;host=$hostname;port=$port"
180

            
update pod
Yuki Kimoto authored on 2011-01-28
181
B<SQLite>
182

            
183
    "dbi:SQLite:dbname=$database"
184
    "dbi:SQLite:dbname=:memory:"
185

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

            
188
    "dbi:Pg:dbname=$dbname"
189

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

            
192
    "dbi:Oracle:$dbname"
193
    "dbi:Oracle:host=$host;sid=$sid"
194

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

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

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

            
201
   "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
202

            
update pod
Yuki Kimoto authored on 2011-01-30
203
If authentication is needed, you can specify C<user> and C<password>
204

            
205
L<DBIx::Custom> is wrapper class of L<DBI>.
206
You can use all methods of L<DBI> from L<DBIx::Custom> object.
207

            
208
    $dbi->do(...);
209
    $dbi->begin_work;
update pod
Yuki Kimoto authored on 2011-01-28
210

            
update pod
Yuki Kimoto authored on 2011-01-30
211
use C<dhb()> to get database handle of L<DBI>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
212

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

            
update pod
Yuki Kimoto authored on 2011-01-30
215
By default, the following ones is set to database handle attributes.
216

            
217
    RaiseError  ->  1
218
    PrintError  ->  0
219
    AutoCommit  ->  1
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
220

            
update pod
Yuki Kimoto authored on 2011-01-30
221
If fatal error occuer, program terminate.
222
If SQL is executed, commit is executed automatically.
update pod
Yuki Kimoto authored on 2011-01-28
223

            
update pod
Yuki Kimoto authored on 2011-01-31
224
=head2 2. Methods for insert, update, delete, or insert
update pod
Yuki Kimoto authored on 2011-01-28
225

            
update pod
Yuki Kimoto authored on 2011-01-31
226
There are following methods.
update pod
Yuki Kimoto authored on 2011-01-28
227

            
update pod
Yuki Kimoto authored on 2011-01-31
228
=head3 C<insert()>
update pod
Yuki Kimoto authored on 2011-01-28
229

            
update pod
Yuki Kimoto authored on 2011-01-31
230
use C<insert()> to insert row into database
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
231

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

            
update pod
Yuki Kimoto authored on 2011-01-31
235
C<table> is table name, C<param> is insert data.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
236

            
update pod
Yuki Kimoto authored on 2011-01-31
237
Following SQL is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
238

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

            
update pod
Yuki Kimoto authored on 2011-01-31
241
=head3 C<update()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
242

            
update pod
Yuki Kimoto authored on 2011-01-31
243
use C<update()> to update row in database.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
244

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

            
update pod
Yuki Kimoto authored on 2011-01-31
249
C<table> is table name, C<param> is update data, C<where> is condition.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
250

            
update pod
Yuki Kimoto authored on 2011-01-31
251
Following SQL is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
252

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

            
update pod
Yuki Kimoto authored on 2011-01-31
255
You can't execute C<update()> without C<where> for safety.
256
use C<update_all()> if you want to update all rows.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
257

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

            
update pod
Yuki Kimoto authored on 2011-01-31
261
=head3 C<delete()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
262

            
update pod
Yuki Kimoto authored on 2011-01-31
263
use C<delete()> to delete rows from database.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
264

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

            
update pod
Yuki Kimoto authored on 2011-01-31
268
C<table> is table name, C<where> is condition.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
269

            
update pod
Yuki Kimoto authored on 2011-01-31
270
Following SQL is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
271

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

            
update pod
Yuki Kimoto authored on 2011-01-31
274
You can't execute C<delete()> without C<where> for safety.
275
use C<delete_all()> if you want to delete all rows.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
276

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

            
update pod
Yuki Kimoto authored on 2011-01-31
279
=head3 C<select()>
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
280

            
update pod
Yuki Kimoto authored on 2011-01-31
281
use C<select()> to select rows from database
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
282

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

            
update pod
Yuki Kimoto authored on 2011-01-31
285
Following SQL is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
286

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

            
update pod
Yuki Kimoto authored on 2011-01-31
289
Return value is L<DBIx::Custom::Result> object.
290
use C<fetch()> to fetch row.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
291

            
292
    while (my $row = $result->fetch) {
293
        my $title  = $row->[0];
294
        my $author = $row->[1];
295
    }
296

            
update pod
Yuki Kimoto authored on 2011-01-31
297
See L<3. Fetch row/"3. Fetch row"> about L<DBIx::Custom::Result>.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
298

            
update pod
Yuki Kimoto authored on 2011-01-31
299
Continue more examples.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
300

            
301
    my $result = $dbi->select(
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
302
        table  => 'book',
update pod
Yuki Kimoto authored on 2011-01-28
303
        column => ['author',  'title'],
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
304
        where  => {author => 'Ken'}
305
    );
306

            
update pod
Yuki Kimoto authored on 2011-01-31
307
C<column> is column names, C<where> is condition.
308

            
309
Following SQL is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
310

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

            
update pod
Yuki Kimoto authored on 2011-01-31
313
Next example.
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', 'rental'],
update pod
Yuki Kimoto authored on 2011-01-31
317
        where    => {'book.name' => 'Perl'},
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
318
        relation => {'book.id' => 'rental.book_id'}
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
319
    );
320

            
update pod
Yuki Kimoto authored on 2011-01-31
321
C<relation> is relation of tables. This is inner join.
322

            
323
Following SQL is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
324

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

            
update pod
Yuki Kimoto authored on 2011-01-31
327
Next example.
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',
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
331
        where  => {author => 'Ken'},
update pod
Yuki Kimoto authored on 2011-01-28
332
        append => 'for update',
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
333
    );
334

            
update pod
Yuki Kimoto authored on 2011-01-31
335
C<append> is string appending to end of SQL.
336

            
337
Following SQL is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
338

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

            
update pod
Yuki Kimoto authored on 2011-01-31
341
C<appned> is also used at C<insert()>, C<update()>, C<update_all()>
342
C<delete()>, C<delete_all()>, and C<select()>.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
343

            
update pod
Yuki Kimoto authored on 2011-01-31
344
=head3 C<execute()> SQL
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
345

            
update pod
Yuki Kimoto authored on 2011-01-31
346
use C<execute()> to execute SQL
update pod
Yuki Kimoto authored on 2011-01-28
347

            
348
    $dbi->execute("select * from book;");
349

            
update pod
Yuki Kimoto authored on 2011-01-31
350
Process tag and execute SQL.
update pod
Yuki Kimoto authored on 2011-01-28
351

            
352
    $dbi->execute(
353
        "select * from book {= title} and {= author};"
354
        param => {title => 'Perl', author => 'Ken'}
355
    );
356

            
update pod
Yuki Kimoto authored on 2011-01-31
357
Following SQL is executed.
update pod
Yuki Kimoto authored on 2011-01-28
358

            
359
    select * from book title = ? and author = ?;
360

            
update pod
Yuki Kimoto authored on 2011-01-31
361
Values of title and author is embbdeded into placeholder.
update pod
Yuki Kimoto authored on 2011-01-28
362

            
update pod
Yuki Kimoto authored on 2011-01-31
363
See L<5. Tag/"5. Tag"> about tag.
update pod
Yuki Kimoto authored on 2011-01-28
364

            
update pod
Yuki Kimoto authored on 2011-01-31
365
You don't have to wirte last semicolon in C<execute()>. 
update pod
Yuki Kimoto authored on 2011-01-28
366

            
367
    $dbi->execute('select * from book');
368

            
update pod
Yuki Kimoto authored on 2011-02-04
369
=head2 3. Fetch row
update pod
Yuki Kimoto authored on 2011-01-28
370

            
update pod
Yuki Kimoto authored on 2011-02-04
371
Return value of C<select()> is L<DBIx::Custom::Result> object.
372
There are many methods to fetch row.
update pod
Yuki Kimoto authored on 2011-01-28
373

            
update pod
Yuki Kimoto authored on 2011-02-04
374
=head3 Fetch a row (array) C<fetch()>
update pod
Yuki Kimoto authored on 2011-01-28
375

            
update pod
Yuki Kimoto authored on 2011-02-04
376
use C<fetch()> to fetch a row and assign it into array reference.
377

            
378
    my $row = $result->fetch;
379

            
380
You can get all rows.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
381

            
382
    while (my $row = $result->fetch) {
update pod
Yuki Kimoto authored on 2011-01-28
383
        my $title  = $row->[0];
384
        my $author = $row->[1];
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
385
    }
386

            
update pod
Yuki Kimoto authored on 2011-02-04
387
=head3 Fetch only first row (array) C<fetch_first()>
update pod
Yuki Kimoto authored on 2011-01-28
388

            
update pod
Yuki Kimoto authored on 2011-02-04
389
use C<fetch_first()> to fetch only first row.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
390

            
391
    my $row = $result->fetch_first;
392

            
update pod
Yuki Kimoto authored on 2011-02-04
393
You can't fetch rest rows
394
because statement handle C<finish()> is executed.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
395

            
update pod
Yuki Kimoto authored on 2011-02-04
396
=head3 Fetch rows (array) C<fetch_multi()>
update pod
Yuki Kimoto authored on 2011-01-28
397

            
update pod
Yuki Kimoto authored on 2011-02-04
398
use C<fetch_multi()> to fetch rows and assign it into
399
array reference which has array references as element.
update pod
Yuki Kimoto authored on 2011-01-28
400

            
401
    while (my $rows = $result->fetch_multi(2)) {
402
        my $title0   = $rows->[0][0];
403
        my $author0  = $rows->[0][1];
404
        
405
        my $title1   = $rows->[1][0];
406
        my $author1  = $rows->[1][1];
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
407
    }
update pod
Yuki Kimoto authored on 2011-01-28
408

            
update pod
Yuki Kimoto authored on 2011-02-04
409
Specify row count as argument.
update pod
Yuki Kimoto authored on 2011-01-28
410

            
update pod
Yuki Kimoto authored on 2011-02-04
411
You can get the following data.
update pod
Yuki Kimoto authored on 2011-01-28
412

            
413
    [
414
        ['Perl', 'Ken'],
415
        ['Ruby', 'Mark']
416
    ]
417

            
update pod
Yuki Kimoto authored on 2011-02-04
418
=head3 Fetch all rows (array) C<fetch_all>
update pod
Yuki Kimoto authored on 2011-01-28
419

            
update pod
Yuki Kimoto authored on 2011-02-04
420
use C<fetch_all()> to fetch all rows and assign it into
421
array reference which has array reference as element.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
422

            
423
    my $rows = $result->fetch_all;
424

            
update pod
Yuki Kimoto authored on 2011-02-04
425
You can get the following data.
update pod
Yuki Kimoto authored on 2011-01-28
426

            
427
    [
428
        ['Perl', 'Ken'],
429
        ['Ruby', 'Mark']
430
    ]
431

            
update pod
Yuki Kimoto authored on 2011-02-04
432
=head3 Fetch a row (hash) C<fetch_hash()>
update pod
Yuki Kimoto authored on 2011-01-28
433

            
update pod
Yuki Kimoto authored on 2011-02-04
434
use C<fetch_hash()> to fetch a row and assign it into hash reference.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
435

            
436
    while (my $row = $result->fetch_hash) {
437
        my $title  = $row->{title};
438
        my $author = $row->{author};
439
    }
440

            
update pod
Yuki Kimoto authored on 2011-02-04
441
=head3 Fetch only first row (hash) C<fetch_hash_first()>
update pod
Yuki Kimoto authored on 2011-01-28
442

            
update pod
Yuki Kimoto authored on 2011-02-04
443
use C<fetch_hash_first()> to fetch only first row
444
and assign it into hash reference.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
445

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

            
update pod
Yuki Kimoto authored on 2011-02-04
448
You can't fetch rest rows
449
because statement handle C<finish()> is executed.
update pod
Yuki Kimoto authored on 2011-01-28
450

            
update pod
Yuki Kimoto authored on 2011-02-04
451
=head3 Fetch rows (hash) C<fetch_hash_multi()>
update pod
Yuki Kimoto authored on 2011-01-28
452

            
update pod
Yuki Kimoto authored on 2011-02-04
453
use C<fetch_hash_multi()> to fetch rows and
454
assign it into array reference which has hash references as element.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
455

            
456
    while (my $rows = $result->fetch_hash_multi(5)) {
update pod
Yuki Kimoto authored on 2011-01-28
457
        my $title0   = $rows->[0]{title};
458
        my $author0  = $rows->[0]{author};
459
        my $title1  = $rows->[1]{title};
460
        my $author1 = $rows->[1]{author};
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
461
    }
update pod
Yuki Kimoto authored on 2011-01-28
462

            
update pod
Yuki Kimoto authored on 2011-02-04
463
Specify row count as argument.
update pod
Yuki Kimoto authored on 2011-01-28
464

            
update pod
Yuki Kimoto authored on 2011-02-04
465
You can get the following data.
update pod
Yuki Kimoto authored on 2011-01-28
466

            
467
    [
468
        {title => 'Perl', author => 'Ken'},
469
        {title => 'Ruby', author => 'Mark'}
470
    ]
471

            
update pod
Yuki Kimoto authored on 2011-02-04
472
=head3 Fetch all rows (hash) C<fetch_hash_all()>
update pod
Yuki Kimoto authored on 2011-01-28
473

            
update pod
Yuki Kimoto authored on 2011-02-04
474
use C<fetch_hash_all()> to fetch all rows and
475
assign it into array reference which has hash 
476
references as element.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
477

            
478
    my $rows = $result->fetch_hash_all;
479

            
update pod
Yuki Kimoto authored on 2011-02-04
480
You can get the following data.
update pod
Yuki Kimoto authored on 2011-01-28
481

            
482
    [
483
        {title => 'Perl', author => 'Ken'},
484
        {title => 'Ruby', author => 'Mark'}
485
    ]
486

            
update pod
Yuki Kimoto authored on 2011-02-04
487
=head3 Statement handle C<sth()>
update pod
Yuki Kimoto authored on 2011-01-28
488

            
update pod
Yuki Kimoto authored on 2011-02-04
489
use <sth()> to get statement handle.
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
490

            
491
    my $sth = $result->sth;
492

            
update pod
Yuki Kimoto authored on 2011-01-28
493
=head2 4. �t�B���^�����O
494

            
495
�f�[�^�x�[�X�Ƀf�[�^��o�^����Ƃ���f�[�^�x�[�X����f�[�^��擾����
496
�Ƃ��Ɏ����I�ɒl�̕ϊ���s�������ꍇ�������Ǝv���܂��B
497
���Ƃ��΁A��t��\�������̏ꍇ�́A
498
�f�[�^�x�[�X�ɓo�^����ꍇ��L<Time::Piece>�I�u�W�F�N�g����
499
�f�[�^�x�[�X�̓�t�̃t�H�[�}�b�g�ɁA
500
�f�[�^�x�[�X����f�[�^��擾����Ƃ��́A���̋t��s����ƕ֗��ł��B
501

            
502
=head3 �t�B���^�̓o�^ C<register_filter()>
503

            
504
�t�B���^��o�^����ɂ�C<register_filter()>��g�p���܂��B
505

            
506
    $dbi->register_filter(
507
        # Time::Piece object to DATE format
508
        tp_to_date => sub {
509
            my $date = shift;
510

            
511
            return '0000-00-00' unless $tp;
512
            return $tp->strftime('%Y-%m-%d');
513
        },
514
        
515
        # DATE to Time::Piece object
516
        date_to_tp => sub {
517
            my $date = shift;
518

            
519
            return if $date eq '0000-00-00';
520
            return Time::Piece->strptime($date, '%Y-%m-%d');
521
        },
522
    );
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
523

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

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

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

            
530
    $dbi->apply_filter('book',
531
        issue_date => {out => 'tp_to_date', in => 'date_to_tp'},
532
        first_issue_date => {out => 'tp_to_date', in => 'date_to_tp'}
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
533
    );
534

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

            
542
    issue_date => {out => sub { ... }, in => sub { ... }}
543

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

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

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

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

            
556
    my $row = $resutl->fetch_hash_first;
557
    my $tp = $row->{issue_date};
558

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

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

            
564
    $dbi->select(
565
        table => 'book',
566
        where => {'book.title' => 'Perl', 'book.author' => 'Ken'}
567
    );
568

            
569
�e�[�u�����ʂ���K�v������Ƃ��ɕ֗��ȋ@�\�ł��B
570

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

            
573
C<apply_filter()>��g��čŏ��ɂ��ׂẴe�[�u���̗�ɂ‚���
574
�t�B���^���`���邱�Ƃ�ł��܂����A
575
�•ʂɃt�B���^��K�p���邱�Ƃ�ł��܂��B
576
�•ʂ̃t�B���^��C<apply_filter()>�œK�p�����t�B���^��㏑���܂��B
577
�•ʂ̃t�B���^��SQL��as��g��āA��̕ʖ���쐬����K�v������ꍇ�Ɋ��􂵂܂��B
578

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

            
584
C<insert()>�̗����܂��B
585

            
586
    $dbi->insert(
587
        table => 'book',
588
        param => {issue_date => $tp, first_issue_date => $tp},
589
        filter => {issue_date => 'tp_to_date', first_issue_date => 'tp_to_date'}
590
    );
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
591

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

            
594
my $sql = <<"EOS";
595
select YEAR(issue_date) as issue_year
596
from book
597
where YEAR(issue_date) = {? issue_year}
598
EOS
599
   
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
600
    my $result = $dbi->execute(
update pod
Yuki Kimoto authored on 2011-01-28
601
        $sql,
602
        param => {issue_year => '2010'},
603
        filter => {issue_year => 'tp_to_year'}
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
604
    );
605

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

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

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

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

            
620
    $dbi->apply_filter('book',
621
        'issue_year' => {out => 'tp_to_year', in => 'year_to_tp'}
622
    );
623

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

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

            
631
    $result->end_filter(issue_date => sub {
632
        my $tp = shift;
633
        
634
        return '' unless $tp;
635
        return $tp->strftime('%Y/%m/%d %h:%m:%s (%a)');
636
    });
637

            
638
��t��₷���`�Ƀt�H�[�}�b�g���邱�Ƃ��ł��܂��B
639

            
640
�t�B���^�̓t�F�b�`��s���O�ɓo�^���Ă����K�v�����邱�Ƃ�
641
���ӂ��Ă��������B
642

            
643
    $result->filter(...);
644
    $result->end_filter(...);
645
    my $row = $result->fetch_hash_first;
646

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

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

            
653
    $dbi->each_column(
654
        sub {
655
            my ($self, $table, $column, $info) = @_;
656
            
657
            my $type = $info->{TYPE_NAME};
658
            
659
            my $filter = $type eq 'DATE'     ? {out => 'tp_to_date', in => 'date_to_tp'}
660
                       : $type eq 'DATETIME' ? {out => 'tp_to_datetime', in => 'datetime_to_tp'}
661
                                             : undef;
662
            
663
            $self->apply_filter($table, $column, $filter)
664
              if $filter;
665
        }
666
    );
667

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

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

            
677
=head2 5. �^�O
678

            
679
=head3 �^�O�̋@�\
680

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

            
683
    select * from book where {= title} and {like author};
684

            
685
{= title}��{like author}�̕������^�O�ł��B�^�O�͎��̂悤�Ȍ`��
686
����܂��B
687

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

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

            
696
    select from book \\{ ... \\}
697

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

            
701
��L�̃^�O��SQL����s�����O�Ɏ���SQL�ɓW�J����܂��B
702

            
703
    select * from book where title = ? and author like ?;
704

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

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

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

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

            
715
    $dbi->execute($sql, param => {title => 'Perl', author => '%Ken%'}
716
                  filter => {title => 'to_something');
717

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

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

            
update pod
Yuki Kimoto authored on 2011-01-31
726
=head3 �^�O�ꗗ
update pod
Yuki Kimoto authored on 2011-01-28
727

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

            
730
���̂悤�Ƀ^�O��g���SQL����\������̂�L<DBIx::Custom>��
731
����ł��B�ȉ��̃^�O�����p�”\�ł��B
732

            
update pod
Yuki Kimoto authored on 2011-01-31
733
=head4 C<?>
update pod
Yuki Kimoto authored on 2011-01-28
734

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

            
737
    {? NAME}    ->   ?
738

            
update pod
Yuki Kimoto authored on 2011-01-31
739
=head4 C<=>
update pod
Yuki Kimoto authored on 2011-01-28
740

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

            
743
    {= NAME}    ->   NAME = ?
744

            
update pod
Yuki Kimoto authored on 2011-01-31
745
=head4 C<E<lt>E<gt>>
update pod
Yuki Kimoto authored on 2011-01-28
746

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

            
749
    {<> NAME}   ->   NAME <> ?
750

            
update pod
Yuki Kimoto authored on 2011-01-31
751
=head4 C<E<lt>>
update pod
Yuki Kimoto authored on 2011-01-28
752

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

            
755
    {< NAME}    ->   NAME < ?
756

            
update pod
Yuki Kimoto authored on 2011-01-31
757
=head4 C<E<gt>>
update pod
Yuki Kimoto authored on 2011-01-28
758

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

            
761
    {> NAME}    ->   NAME > ?
762

            
update pod
Yuki Kimoto authored on 2011-01-31
763
=head4 C<E<gt>=>
update pod
Yuki Kimoto authored on 2011-01-28
764

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

            
767
    {>= NAME}   ->   NAME >= ?
768

            
update pod
Yuki Kimoto authored on 2011-01-31
769
=head4 C<E<lt>=>
update pod
Yuki Kimoto authored on 2011-01-28
770

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

            
773
    {<= NAME}   ->   NAME <= ?
774

            
update pod
Yuki Kimoto authored on 2011-01-31
775
=head4 C<like>
update pod
Yuki Kimoto authored on 2011-01-28
776

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

            
779
    {like NAME}   ->   NAME like ?
780

            
update pod
Yuki Kimoto authored on 2011-01-31
781
=head4 C<in>
update pod
Yuki Kimoto authored on 2011-01-28
782

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

            
786
    {in NAME COUNT}   ->   NAME in [?, ?, ..]
787

            
update pod
Yuki Kimoto authored on 2011-01-31
788
=head4 C<insert_param>
update pod
Yuki Kimoto authored on 2011-01-28
789

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

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

            
update pod
Yuki Kimoto authored on 2011-01-31
794
=head4 C<update_param>
update pod
Yuki Kimoto authored on 2011-01-28
795

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

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

            
update pod
Yuki Kimoto authored on 2011-01-31
800
=head3 �����̗�̈���
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
801

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-01-31
812
=head3 �^�O�̒lj� C<register_tag()>
update pod
Yuki Kimoto authored on 2011-01-28
813

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

            
817
    $dbi->register_tag(
818
        '=' => sub {
819
            my $column = shift;
820
            
821
            return ["$column = ?", [$column]];
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
822
        }
823
    );
824

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

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

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

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

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

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

            
838
    [
839
        �W�J��̕�����,
840
        [�v���[�X�z���_�ɖ��ߍ��݂ɗ��p�����1, ��2, ...]
841
    ]
842

            
843
��–ڂ̗v�f�͓W�J��̕�����ł��B���̗�ł�
844

            
845
    'title = ?'
846

            
847
��Ԃ��K�v������܂��B
848

            
849
��–ڂ̗v�f�̓v���[�X�z���_�ɖ��ߍ��݂ɗ��p����񖼂�܂ޔz���
850
���t�@�����X�ł��B����̗�ł�
851

            
852
    ['title']
853

            
854
��Ԃ��K�v������܂��B�����̃v���[�X�z���_��܂ޏꍇ�́A���̕�����
855
�����ɂȂ�܂��BC<insert_param>�^�O��C<update_param>�^�O��
856
���̕�������ە����ɂȂ�Ă��܂��B
857

            
858
��L��킹���
859

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

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

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

            
869
=head3 Where��̓��I�Ȑ��� where()
870

            
871
�����̌�����w�肵�āA�����s�������ꍇ������܂��B
872
����3�‚̃P�[�X��where���l���Ă݂܂��傤�B
873
���L�̂悤��where�傪�K�v�ɂȂ�܂��B
874

            
875
title�̒l�����Ō�������ꍇ
876

            
877
    where {= title}
878

            
879
author�̒l�����Ō�������ꍇ
880

            
881
    where {= author}
882

            
883
title��author�̗���̒l�Ō�������ꍇ
884

            
885
    where {= title} and {=author}
886

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

            
890
    my $where = $dbi->where;
891

            
892
����C<clause()>��g�p����where���L�q���܂��B
893

            
894
    $where->clause(
895
        ['and', '{= title'}, '{= author}']
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
896
    );
897

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

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

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

            
905
C<clause>�̎w��͓��q�ɂ��邱�Ƃ�ł��A����ɕ��G�ȏ�
906
��L�q���邱�Ƃ�ł��܂��B
907

            
908
    ['and', 
909
      '{= title}', 
910
      ['or', '{= author}', '{like date}']
911
    ]
912

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

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

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

            
923
    my $where_clause = $where->to_string;
924

            
925
�p�����[�^��title�����ł��̂ŁA���̂悤��where�傪��������܂��B
926

            
927
    where {= title}
928

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

            
933
    my $where_clause = "$where";
934

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

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

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

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

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

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

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

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

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

            
956
    $where->clause(
957
        ['and', '{> date}', '{< date}']
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
958
    );
update pod
Yuki Kimoto authored on 2011-01-28
959
    $where->param($p);
960

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

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

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

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

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

            
972
�ǂ�����݂��Ȃ��ꍇ�͎��̂悤�ȃf�[�^��쐬���܂��B
973

            
974
    my $p = {date => []};
975

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

            
978
    my @date;
979
    push @date, exists $param->{start_date} ? $param->{start_date}
980
                                            : $dbi->not_exists;
981
    push @date, $param->{end_date} if exists $param->{end_date};
982
    my $p = {date => \@date};
983

            
984
=head3 C<select()>�Ƃ̘A�g
985

            
986
L<DBIx::Custom::Where>�I�u�W�F�N�g��
987
C<select()>��C<where>�ɒ��ړn�����Ƃ�
988
�ł��܂��B
989
    
990
    my $where = $dbi->where;
991
    $where->clause(...);
992
    $where->param($param);
993
    my $result = $dbi->select(table => 'book', where => $where);
994

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

            
997
=head3 C<execute()>�Ƃ̘A�g
998

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

            
1001

            
update pod
Yuki Kimoto authored on 2011-01-28
1002
    my $where = $dbi->where;
1003
    $where->clause(...);
1004
    $where->param($param);
1005

            
1006
    my $sql = <<"EOS"
1007
    select * from book;
1008
    $where
1009
    EOS
1010

            
1011
    $dbi->execute($sql, param => $param);
1012

            
1013
=head2 7. �e�[�u�����f��
1014

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

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

            
1020
�A�v���P�[�V�����̃��W�b�N��L�q����Ƃ��ɁA���̃��W�b�N��
1021
�f�[�^�x�[�X�̃e�[�u���ɂ����邱�Ƃ́ARDBMS�𗘗p����
1022
���f���ł���΁A�R�[�h�̏d�����Ȃ�
1023
�킩��₷����̂ɂȂ�܂��B
1024

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

            
1027
    my $table = $dbi->table('book');
1028

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

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

            
1038
    $table->insert(param => $param);
1039

            
1040
C<table���̒l�͎����I��book�ɐݒ肳��܂��B
1041

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

            
1044
    $table->method(
1045
        register => sub {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1046
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-01-28
1047
            my $table_name = $self->name;
1048
            # something
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1049
        },
update pod
Yuki Kimoto authored on 2011-01-28
1050
        list => sub {
1051
            my $self = shift;
1052
            my $table_name = $self->name;
1053
            # something
1054
        }
1055
    );
1056

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

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

            
1062
    $table->register(...);
1063
    $table->list(...);
1064

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

            
1067
    $table->method(
1068
        insert => sub {
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1069
            my $self = shift;
1070
            
update pod
Yuki Kimoto authored on 2011-01-28
1071
            $self->base_insert(...);
1072
            
1073
            # something
added experimental DBIx::Cus...
Yuki Kimoto authored on 2011-01-17
1074
        }
1075
    );
1076

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

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

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

            
update pod
Yuki Kimoto authored on 2011-01-28
1085
    $dbi->base_table->method(
1086
        count => sub {
1087
            my $self = shift;
1088
            return $self->select(column => ['count(*)']);
1089
        }
1090
    );
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1091

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

            
update pod
Yuki Kimoto authored on 2011-01-28
1094
    # DBIx::Custom method
1095
    $table->execute($sql);
1096
    
1097
    # DBI method
1098
    $table->begin_work;
1099
    $table->commit;
1100

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

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

            
update pod
Yuki Kimoto authored on 2011-01-28
1106
    package MyDBI;
1107
    
1108
    use base 'DBIx::Custom';
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1109
    
update pod
Yuki Kimoto authored on 2011-01-28
1110
    sub connect {
1111
        my $self = shift->SUPER::connect(@_);
1112
        
1113
        $self->base_table->method(
1114
            ... => sub { ... }
1115
        );
1116
        
1117
        $self->table('book')->method(
1118
            insert_multi => sub { ... },
1119
            ... => sub { ... }
1120
        );
1121
        
1122
        $self->table('company')->method(
1123
            ... => sub { ... },
1124
        );
1125
    }
1126

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

            
1129
    my $dbi = MyDBI->connect(...);
1130
    $dbi->table('book')->insert_multi(...);
1131

            
1132
=head2 8. �p�t�H�[�}���X�̉�P
1133

            
1134
=head3 �N�G���̍쐬
1135

            
1136
��C<insert()>���\�b�h��g�p���ăC���T�[�g���s�����ꍇ�A
1137
�K�v�ȃp�t�H�[�}���X�𓾂��Ȃ��ꍇ�����邩����܂���B
1138
C<insert()>���\�b�h�́ASQL���ƃX�e�[�g�����g�n���h����
1139
����쐬���邽�߂ł��B
1140

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

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

            
1146
�܂�C<create_query()>���\�b�h��g��ĔC�ӂ�SQL�̃N�G����쐬
1147
���邱�Ƃ�ł��܂��B
1148

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

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

            
1157
    {
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1158
        sql     => 'insert into book (title, author) values (?, ?);',
update pod
Yuki Kimoto authored on 2011-01-28
1159
        columns => ['title', 'author'],
1160
        sth     => $sth
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1161
    }
1162

            
update pod
Yuki Kimoto authored on 2011-01-28
1163
�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
1164
    
remove DBIx::Custom::Model
Yuki Kimoto authored on 2011-01-12
1165
    my $params = [
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1166
        {title => 'Perl',      author => 'Ken'},
1167
        {title => 'Good days', author => 'Mike'}
1168
    ];
1169
    
update pod
Yuki Kimoto authored on 2011-01-28
1170
    foreach my $param (@$paramss) {
1171
        $dbi->execute($query, table => 'book', param => $input);
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1172
    }
1173

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

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

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

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

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

            
update pod
Yuki Kimoto authored on 2011-01-28
1191
    $dbi->method(
1192
        update_or_insert => sub {
1193
            my $self = shift;
1194
            # something
1195
        },
1196
        find_or_create   => sub {
1197
            my $self = shift;
1198
            # something
1199
        }
1200
    );
1201

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

            
1205
    $dbi->update_or_insert;
1206
    $dbi->find_or_create;
1207

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

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

            
update pod
Yuki Kimoto authored on 2011-01-28
1212
    package MyResult;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1213
    use base 'DBIx::Custom::Result';
1214
    
1215
    sub some_method { ... }
1216

            
1217
    1;
1218
    
1219
    package main;
1220
    
update pod
Yuki Kimoto authored on 2011-01-28
1221
    use MyResult;
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1222
    
1223
    my $dbi = DBIx::Custom->connect(...);
update pod
Yuki Kimoto authored on 2011-01-28
1224
    $dbi->result_class('MyResult');
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1225

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

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

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

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

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

            
1239
    $dbi->cache_method(sub {
1240
        sub {
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1241
            my $self = shift;
update pod
Yuki Kimoto authored on 2011-01-28
1242
            
1243
            $self->{_cached} ||= {};
1244
            
1245
            if (@_ > 1) {
1246
                # Set
1247
                $self->{_cached}{$_[0]} = $_[1] 
1248
            }
1249
            else {
1250
                # Get
1251
                return $self->{_cached}{$_[0]}
1252
            }
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1253
        }
update pod
Yuki Kimoto authored on 2011-01-28
1254
    });
1255
    
1256
����L<DBIx::Custom>�I�u�W�F�N�g�ł��B
1257
����̓^�O�̓W�J�����O��SQL�ł��B
1258
��O��̓^�O�̓W�J���SQL�ł��B
added DBIx::Custom::Guides
yuki-kimoto authored on 2010-10-17
1259

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

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

            
pod fix
Yuki Kimoto authored on 2011-01-21
1266
=head1 EXAMPLES
1267

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

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