Newer Older
79 lines | 1.76kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::MySQL;
2

            
3
use warnings;
4
use strict;
update document
yuki-kimoto authored on 2010-01-30
5

            
6
use base 'DBIx::Custom::Basic';
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
packaging one directory
yuki-kimoto authored on 2009-11-16
8

            
9
sub connect {
10
    my $self = shift;
11
    
update document
yuki-kimoto authored on 2010-01-30
12
    # Create data source
add port and host method
yuki-kimoto authored on 2009-11-16
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
yuki-kimoto authored on 2009-11-16
24
    }
25
    
26
    return $self->SUPER::connect;
27
}
28

            
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
29
sub last_insert_id {
30
    my $self = shift;
31
    
update document
yuki-kimoto authored on 2010-01-30
32
    # Not connected
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
33
    croak "Not yet connected" unless $self->connected;
34
    
update document
yuki-kimoto authored on 2010-01-30
35
    # Get last insert id
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
36
    my $last_insert_id = $self->dbh->{mysql_insertid};
37
    
38
    return $last_insert_id;
39
}
40

            
removed register_format()
yuki-kimoto authored on 2010-05-26
41
1;
42

            
packaging one directory
yuki-kimoto authored on 2009-11-16
43
=head1 NAME
44

            
45
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation
46

            
update document
yuki-kimoto authored on 2010-01-30
47
=head1 SYNOPSYS
packaging one directory
yuki-kimoto authored on 2009-11-16
48

            
49
    # New
50
    my $dbi = DBIx::Custom::MySQL->new(user => 'taro', $password => 'kliej&@K',
version 0.0901
yuki-kimoto authored on 2009-12-17
51
                                       database => 'sample_db');
packaging one directory
yuki-kimoto authored on 2009-11-16
52

            
update document
yuki-kimoto authored on 2010-01-30
53
=head1 METHODS
packaging one directory
yuki-kimoto authored on 2009-11-16
54

            
update document
yuki-kimoto authored on 2010-01-30
55
This class is L<DBIx::Custom::Basic> subclass.
56
You can use all methods of L<DBIx::Custom::Basic>
packaging one directory
yuki-kimoto authored on 2009-11-16
57

            
58
=head2 connect
59

            
update document
yuki-kimoto authored on 2009-11-19
60
Connect to database
61

            
version 0.0901
yuki-kimoto authored on 2009-12-17
62
    $self->connect;
update document
yuki-kimoto authored on 2009-11-19
63

            
version 0.0901
yuki-kimoto authored on 2009-12-17
64
If you set database, host, or port, data source is automatically created.
packaging one directory
yuki-kimoto authored on 2009-11-16
65

            
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
66
=head2 last_insert_id
67

            
version 0.0901
yuki-kimoto authored on 2009-12-17
68
    $last_insert_id = $dbi->last_insert_id;
69

            
70
The folloing is last_insert_id sample.
71

            
update document
yuki-kimoto authored on 2009-11-19
72
    $dbi->insert('books', {title => 'Perl', author => 'taro'});
73
    $last_insert_id = $dbi->last_insert_id;
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
74

            
75
This is equal to MySQL function
76

            
77
    last_insert_id()
78
    
update document
yuki-kimoto authored on 2010-01-30
79
=cut