packaging one directory
|
1 |
package DBIx::Custom::MySQL; |
2 | ||
3 |
use warnings; |
|
4 |
use strict; |
|
update document
|
5 | |
6 |
use base 'DBIx::Custom::Basic'; |
|
add Oracle, DB2, Pg,
|
7 |
use Carp 'croak'; |
packaging one directory
|
8 | |
some changed
|
9 |
__PACKAGE__->register_format( |
catch up with Object::Simple...
|
10 |
datetime => __PACKAGE__->formats->{SQL99_datetime}, |
11 |
date => __PACKAGE__->formats->{SQL99_date}, |
|
12 |
time => __PACKAGE__->formats->{SQL99_time}, |
|
packaging one directory
|
13 |
); |
14 | ||
15 |
sub connect { |
|
16 |
my $self = shift; |
|
17 |
|
|
update document
|
18 |
# Create data source |
add port and host method
|
19 |
if (!$self->data_source) { |
20 |
my $database = $self->database; |
|
21 |
my $host = $self->host; |
|
22 |
my $port = $self->port; |
|
23 |
my $data_source = "dbi:mysql:"; |
|
24 |
my $data_source_original = $data_source; |
|
25 |
$data_source .= "database=$database;" if $database; |
|
26 |
$data_source .= "host=$host;" if $host; |
|
27 |
$data_source .= "port=$port;" if $port; |
|
28 |
$data_source =~ s/:$// if $data_source eq $data_source_original; |
|
29 |
$self->data_source($data_source); |
|
packaging one directory
|
30 |
} |
31 |
|
|
32 |
return $self->SUPER::connect; |
|
33 |
} |
|
34 | ||
add Oracle, DB2, Pg,
|
35 |
sub last_insert_id { |
36 |
my $self = shift; |
|
37 |
|
|
update document
|
38 |
# Not connected |
add Oracle, DB2, Pg,
|
39 |
croak "Not yet connected" unless $self->connected; |
40 |
|
|
update document
|
41 |
# Get last insert id |
add Oracle, DB2, Pg,
|
42 |
my $last_insert_id = $self->dbh->{mysql_insertid}; |
43 |
|
|
44 |
return $last_insert_id; |
|
45 |
} |
|
46 | ||
packaging one directory
|
47 |
=head1 NAME |
48 | ||
49 |
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation |
|
50 | ||
update document
|
51 |
=head1 SYNOPSYS |
packaging one directory
|
52 | |
53 |
# New |
|
54 |
my $dbi = DBIx::Custom::MySQL->new(user => 'taro', $password => 'kliej&@K', |
|
version 0.0901
|
55 |
database => 'sample_db'); |
packaging one directory
|
56 | |
update document
|
57 |
=head1 METHODS |
packaging one directory
|
58 | |
update document
|
59 |
This class is L<DBIx::Custom::Basic> subclass. |
60 |
You can use all methods of L<DBIx::Custom::Basic> |
|
packaging one directory
|
61 | |
62 |
=head2 connect |
|
63 | ||
update document
|
64 |
Connect to database |
65 | ||
version 0.0901
|
66 |
$self->connect; |
update document
|
67 | |
version 0.0901
|
68 |
If you set database, host, or port, data source is automatically created. |
packaging one directory
|
69 | |
add Oracle, DB2, Pg,
|
70 |
=head2 last_insert_id |
71 | ||
version 0.0901
|
72 |
$last_insert_id = $dbi->last_insert_id; |
73 | ||
74 |
The folloing is last_insert_id sample. |
|
75 | ||
update document
|
76 |
$dbi->insert('books', {title => 'Perl', author => 'taro'}); |
77 |
$last_insert_id = $dbi->last_insert_id; |
|
add Oracle, DB2, Pg,
|
78 | |
79 |
This is equal to MySQL function |
|
80 | ||
81 |
last_insert_id() |
|
82 |
|
|
update document
|
83 |
=cut |