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 |
|
|
add port and host method
|
20 |
if (!$self->data_source) { |
21 |
my $database = $self->database; |
|
22 |
my $host = $self->host; |
|
23 |
my $port = $self->port; |
|
24 |
|
|
25 |
my $data_source = "dbi:mysql:"; |
|
26 |
my $data_source_original = $data_source; |
|
27 |
$data_source .= "database=$database;" if $database; |
|
28 |
$data_source .= "host=$host;" if $host; |
|
29 |
$data_source .= "port=$port;" if $port; |
|
30 |
|
|
31 |
$data_source =~ s/:$// if $data_source eq $data_source_original; |
|
32 |
$self->data_source($data_source); |
|
packaging one directory
|
33 |
} |
34 |
|
|
35 |
return $self->SUPER::connect; |
|
36 |
} |
|
37 | ||
add Oracle, DB2, Pg,
|
38 |
sub last_insert_id { |
39 |
my $self = shift; |
|
40 |
|
|
41 |
croak "Not yet connected" unless $self->connected; |
|
42 |
|
|
43 |
my $last_insert_id = $self->dbh->{mysql_insertid}; |
|
44 |
|
|
45 |
return $last_insert_id; |
|
46 |
} |
|
47 | ||
packaging one directory
|
48 |
=head1 NAME |
49 | ||
50 |
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation |
|
51 | ||
52 |
=head1 Synopsys |
|
53 | ||
54 |
# New |
|
55 |
my $dbi = DBIx::Custom::MySQL->new(user => 'taro', $password => 'kliej&@K', |
|
version 0.0901
|
56 |
database => 'sample_db'); |
packaging one directory
|
57 | |
version 0.0901
|
58 |
=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first |
packaging one directory
|
59 | |
60 |
This class is L<DBIx::Custom::Basic> subclass, |
|
61 |
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass. |
|
62 | ||
63 |
You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom> |
|
64 |
Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation. |
|
65 | ||
66 |
=head1 Object methods |
|
67 | ||
68 |
=head2 connect |
|
69 | ||
update document
|
70 |
Connect to database |
71 | ||
version 0.0901
|
72 |
$self->connect; |
update document
|
73 | |
74 |
This override L<DBIx::Custom> connect. |
|
75 | ||
version 0.0901
|
76 |
If you set database, host, or port, data source is automatically created. |
packaging one directory
|
77 | |
add Oracle, DB2, Pg,
|
78 |
=head2 last_insert_id |
79 | ||
version 0.0901
|
80 |
$last_insert_id = $dbi->last_insert_id; |
81 | ||
82 |
The folloing is last_insert_id sample. |
|
83 | ||
update document
|
84 |
$dbi->insert('books', {title => 'Perl', author => 'taro'}); |
85 |
$last_insert_id = $dbi->last_insert_id; |
|
add Oracle, DB2, Pg,
|
86 | |
87 |
This is equal to MySQL function |
|
88 | ||
89 |
last_insert_id() |
|
90 |
|
|
packaging one directory
|
91 |
=head1 Author |
92 | ||
93 |
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >> |
|
94 | ||
95 |
Github L<http://github.com/yuki-kimoto> |
|
96 | ||
97 |
I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom> |
|
98 | ||
99 |
=head1 Copyright & license |
|
100 | ||
101 |
Copyright 2009 Yuki Kimoto, all rights reserved. |
|
102 | ||
103 |
This program is free software; you can redistribute it and/or modify it |
|
104 |
under the same terms as Perl itself. |
|
105 | ||
106 |