Newer Older
106 lines | 2.499kb
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

            
cleanup
yuki-kimoto authored on 2009-12-22
8
my $p = __PACKAGE__;
packaging one directory
yuki-kimoto authored on 2009-11-16
9

            
cleanup
yuki-kimoto authored on 2009-12-22
10
$p->add_format(
11
    datetime => $p->formats->{SQL99_datetime},
12
    date     => $p->formats->{SQL99_date},
13
    time     => $p->formats->{SQL99_time},
packaging one directory
yuki-kimoto authored on 2009-11-16
14
);
15

            
16

            
17
sub connect {
18
    my $self = shift;
19
    
add port and host method
yuki-kimoto authored on 2009-11-16
20
    if (!$self->data_source) {
21
        my $database = $self->database;
22
        my $host     = $self->host;
23
        my $port     = $self->port;
24
        
25
        my $data_source = "dbi:mysql:";
26
        my $data_source_original = $data_source;
27
        $data_source .= "database=$database;" if $database;
28
        $data_source .= "host=$host;"         if $host;
29
        $data_source .= "port=$port;"         if $port;
30
        
31
        $data_source =~ s/:$// if $data_source eq $data_source_original;
32
        $self->data_source($data_source);
packaging one directory
yuki-kimoto authored on 2009-11-16
33
    }
34
    
35
    return $self->SUPER::connect;
36
}
37

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

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

            
50
DBIx::Custom::MySQL - DBIx::Custom MySQL implementation
51

            
52
=head1 Synopsys
53

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

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

            
60
This class is L<DBIx::Custom::Basic> subclass,
61
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass.
62

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

            
66
=head1 Object methods
67

            
68
=head2 connect
69

            
update document
yuki-kimoto authored on 2009-11-19
70
Connect to database
71

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

            
74
This override L<DBIx::Custom> connect.
75

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

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

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

            
82
The folloing is last_insert_id sample.
83

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

            
87
This is equal to MySQL function
88

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

            
93
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
94

            
95
Github L<http://github.com/yuki-kimoto>
96

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

            
99
=head1 Copyright & license
100

            
101
Copyright 2009 Yuki Kimoto, all rights reserved.
102

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

            
106