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