Newer Older
114 lines | 2.351kb
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

            
update document
yuki-kimoto authored on 2010-05-27
6
use base 'DBIx::Custom';
7

            
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
8
use Carp 'croak';
packaging one directory
yuki-kimoto authored on 2009-11-16
9

            
update document
yuki-kimoto authored on 2010-05-27
10
__PACKAGE__->attr([qw/database host port/]);
11

            
packaging one directory
yuki-kimoto authored on 2009-11-16
12
sub connect {
update document
yuki-kimoto authored on 2010-05-27
13
    my $proto = shift;
14
    
15
    # Create
16
    my $self = ref $proto ? $proto : $proto->new(@_);
packaging one directory
yuki-kimoto authored on 2009-11-16
17
    
update document
yuki-kimoto authored on 2010-01-30
18
    # Create data source
add port and host method
yuki-kimoto authored on 2009-11-16
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
        $data_source .= "database=$database;" if $database;
25
        $data_source .= "host=$host;"         if $host;
26
        $data_source .= "port=$port;"         if $port;
27
        $self->data_source($data_source);
packaging one directory
yuki-kimoto authored on 2009-11-16
28
    }
29
    
30
    return $self->SUPER::connect;
31
}
32

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
45
1;
46

            
packaging one directory
yuki-kimoto authored on 2009-11-16
47
=head1 NAME
48

            
update document
yuki-kimoto authored on 2010-05-27
49
DBIx::Custom::MySQL - a MySQL implementation of DBIx::Custom
packaging one directory
yuki-kimoto authored on 2009-11-16
50

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

            
update document
yuki-kimoto authored on 2010-05-27
53
    # Connect
54
    my $dbi = DBIx::Custom::MySQL->connect(user      => 'taro', 
55
                                           password => 'kliej&@K',
56
                                           database  => 'your_database');
57
    
58
    # Last insert id
59
    my $id = $dbi->last_insert_id;
packaging one directory
yuki-kimoto authored on 2009-11-16
60

            
update document
yuki-kimoto authored on 2010-05-27
61
=head1 ATTRIBUTES
packaging one directory
yuki-kimoto authored on 2009-11-16
62

            
update document
yuki-kimoto authored on 2010-05-27
63
This class is L<DBIx::Custom> subclass.
64
You can use all attributes of L<DBIx::Custom>
packaging one directory
yuki-kimoto authored on 2009-11-16
65

            
update document
yuki-kimoto authored on 2010-05-27
66
=head2 database
packaging one directory
yuki-kimoto authored on 2009-11-16
67

            
update document
yuki-kimoto authored on 2010-05-27
68
Database name
update document
yuki-kimoto authored on 2009-11-19
69

            
update document
yuki-kimoto authored on 2010-05-27
70
    $dbi      = $dbi->database('your_database');
71
    $database = $dbi->database;
update document
yuki-kimoto authored on 2009-11-19
72

            
update document
yuki-kimoto authored on 2010-05-27
73
=head2 host
packaging one directory
yuki-kimoto authored on 2009-11-16
74

            
update document
yuki-kimoto authored on 2010-05-27
75
Database host name.
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
76

            
update document
yuki-kimoto authored on 2010-05-27
77
    $dbi  = $dbi->host('somehost.com');
78
    $host = $dbi->host;
79

            
80
IP address can be set to host attribute.
81

            
82
    $dbi->host('127.03.45.12');
83

            
84
=head2 port
85

            
86
Database port.
87

            
88
    $dbi  = $dbi->port(1198);
89
    $port = $dbi->port;
90

            
91
=head1 METHODS
92

            
93
This class is L<DBIx::Custom> subclass.
94
You can use all methods of L<DBIx::Custom>.
95

            
96
=head2 connect - overridden
97

            
98
Connect to database.
99

            
100
    # Connect
101
    my $dbi = DBIx::Custom::MySQL->connect(user      => 'taro', 
102
                                           password => 'kliej&@K',
103
                                           database  => 'your_database');
104

            
105
=head2 last_insert_id
version 0.0901
yuki-kimoto authored on 2009-12-17
106

            
update document
yuki-kimoto authored on 2010-05-27
107
Last insert ID.
version 0.0901
yuki-kimoto authored on 2009-12-17
108

            
update document
yuki-kimoto authored on 2009-11-19
109
    $last_insert_id = $dbi->last_insert_id;
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
110

            
update document
yuki-kimoto authored on 2010-05-27
111
This is equal to MySQL last_insert_id() function.
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
112

            
113
    
update document
yuki-kimoto authored on 2010-01-30
114
=cut