Newer Older
104 lines | 2.513kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::MySQL;
2
use base 'DBIx::Custom::Basic';
3

            
4
use warnings;
5
use strict;
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
6
use Carp 'croak';
packaging one directory
yuki-kimoto authored on 2009-11-16
7

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
8
__PACKAGE__->add_format(
9
    datetime => __PACKAGE__->formats->{SQL99_datetime},
10
    date     => __PACKAGE__->formats->{SQL99_date},
11
    time     => __PACKAGE__->formats->{SQL99_time},
packaging one directory
yuki-kimoto authored on 2009-11-16
12
);
13

            
14

            
15
sub connect {
16
    my $self = shift;
17
    
add port and host method
yuki-kimoto authored on 2009-11-16
18
    if (!$self->data_source) {
19
        my $database = $self->database;
20
        my $host     = $self->host;
21
        my $port     = $self->port;
22
        
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
        
29
        $data_source =~ s/:$// if $data_source eq $data_source_original;
30
        $self->data_source($data_source);
packaging one directory
yuki-kimoto authored on 2009-11-16
31
    }
32
    
33
    return $self->SUPER::connect;
34
}
35

            
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
36
sub last_insert_id {
37
    my $self = shift;
38
    
39
    croak "Not yet connected" unless $self->connected;
40
    
41
    my $last_insert_id = $self->dbh->{mysql_insertid};
42
    
43
    return $last_insert_id;
44
}
45

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

            
48
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation
49

            
50
=head1 Synopsys
51

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

            
version 0.0901
yuki-kimoto authored on 2009-12-17
56
=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first
packaging one directory
yuki-kimoto authored on 2009-11-16
57

            
58
This class is L<DBIx::Custom::Basic> subclass,
59
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass.
60

            
61
You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom>
62
Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation.
63

            
64
=head1 Object methods
65

            
66
=head2 connect
67

            
update document
yuki-kimoto authored on 2009-11-19
68
Connect to database
69

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

            
72
This override L<DBIx::Custom> connect.
73

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

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

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

            
80
The folloing is last_insert_id sample.
81

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

            
85
This is equal to MySQL function
86

            
87
    last_insert_id()
88
    
packaging one directory
yuki-kimoto authored on 2009-11-16
89
=head1 Author
90

            
91
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
92

            
93
Github L<http://github.com/yuki-kimoto>
94

            
95
I develope this module L<http://github.com/yuki-kimoto/DBIx-Custom>
96

            
97
=head1 Copyright & license
98

            
99
Copyright 2009 Yuki Kimoto, all rights reserved.
100

            
101
This program is free software; you can redistribute it and/or modify it
102
under the same terms as Perl itself.
103

            
104