packaging one directory
|
1 |
package DBIx::Custom::MySQL; |
2 |
use base 'DBIx::Custom::Basic'; |
|
3 | ||
4 |
use warnings; |
|
5 |
use strict; |
|
add Oracle, DB2, Pg,
|
6 |
use Carp 'croak'; |
packaging one directory
|
7 | |
8 |
my $class = __PACKAGE__; |
|
9 | ||
10 |
$class->add_format( |
|
11 |
datetime => $class->formats->{SQL99_datetime}, |
|
12 |
date => $class->formats->{SQL99_date}, |
|
13 |
time => $class->formats->{SQL99_time}, |
|
14 |
); |
|
15 | ||
16 | ||
17 |
sub connect { |
|
18 |
my $self = shift; |
|
19 |
|
|
20 |
if (!$self->data_source && (my $database = $self->database)) { |
|
21 |
$self->data_source("dbi:mysql:dbname=$database"); |
|
22 |
} |
|
23 |
|
|
24 |
return $self->SUPER::connect; |
|
25 |
} |
|
26 | ||
add Oracle, DB2, Pg,
|
27 |
sub last_insert_id { |
28 |
my $self = shift; |
|
29 |
|
|
30 |
croak "Not yet connected" unless $self->connected; |
|
31 |
|
|
32 |
my $last_insert_id = $self->dbh->{mysql_insertid}; |
|
33 |
|
|
34 |
return $last_insert_id; |
|
35 |
} |
|
36 | ||
packaging one directory
|
37 |
=head1 NAME |
38 | ||
39 |
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation |
|
40 | ||
41 |
=head1 Synopsys |
|
42 | ||
43 |
# New |
|
44 |
my $dbi = DBIx::Custom::MySQL->new(user => 'taro', $password => 'kliej&@K', |
|
45 |
database => 'sample_db'); |
|
46 |
# Insert |
|
47 |
$dbi->insert('books', {title => 'perl', author => 'taro'}); |
|
48 |
|
|
49 |
# Update |
|
50 |
# same as 'update books set (title = 'aaa', author = 'ken') where id = 5; |
|
51 |
$dbi->update('books', {title => 'aaa', author => 'ken'}, {id => 5}); |
|
52 |
|
|
53 |
# Delete |
|
54 |
$dbi->delete('books', {author => 'taro'}); |
|
55 |
|
|
56 |
# select * from books; |
|
57 |
$dbi->select('books'); |
|
58 |
|
|
59 |
# select * from books where ahthor = 'taro'; |
|
60 |
$dbi->select('books', {author => 'taro'}); |
|
61 | ||
62 |
=head1 See DBIx::Custom and DBI::Custom::Basic documentation |
|
63 | ||
64 |
This class is L<DBIx::Custom::Basic> subclass, |
|
65 |
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass. |
|
66 | ||
67 |
You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom> |
|
68 |
Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation. |
|
69 | ||
70 |
=head1 Object methods |
|
71 | ||
72 |
=head2 connect |
|
73 | ||
74 |
This method override DBIx::Custom::connect |
|
75 |
|
|
76 |
If database attribute is set, automatically data source is created and connect |
|
77 | ||
add Oracle, DB2, Pg,
|
78 |
=head2 last_insert_id |
79 | ||
80 |
# Get last insert id |
|
81 |
$last_insert_id = $self->last_insert_id; |
|
82 | ||
83 |
This is equal to MySQL function |
|
84 | ||
85 |
last_insert_id() |
|
86 |
|
|
packaging one directory
|
87 |
=head1 Author |
88 | ||
89 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
90 | ||
91 |
Github L<http://github.com/yuki-kimoto> |
|
92 | ||
93 |
I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
94 | ||
95 |
=head1 Copyright & license |
|
96 | ||
97 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
|
98 | ||
99 |
This program is free software; you can redistribute it and/or modify it |
|
100 |
under the same terms as Perl itself. |
|
101 | ||
102 |