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

            
3
use strict;
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
4
use warnings;
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

            
8
__PACKAGE__->attr([qw/database host port/]);
9

            
packaging one directory
yuki-kimoto authored on 2009-11-16
10
sub connect {
update document
yuki-kimoto authored on 2010-05-27
11
    my $proto = shift;
12
    
13
    # Create
14
    my $self = ref $proto ? $proto : $proto->new(@_);
packaging one directory
yuki-kimoto authored on 2009-11-16
15
    
update document
yuki-kimoto authored on 2010-01-30
16
    # Create data source
add port and host method
yuki-kimoto authored on 2009-11-16
17
    if (!$self->data_source) {
18
        my $database = $self->database;
19
        my $host     = $self->host;
20
        my $port     = $self->port;
21
        my $data_source = "dbi:mysql:";
22
        $data_source .= "database=$database;" if $database;
23
        $data_source .= "host=$host;"         if $host;
24
        $data_source .= "port=$port;"         if $port;
25
        $self->data_source($data_source);
packaging one directory
yuki-kimoto authored on 2009-11-16
26
    }
27
    
28
    return $self->SUPER::connect;
29
}
30

            
removed reconnect method
yuki-kimoto authored on 2010-05-28
31
sub last_insert_id { shift->dbh->{mysql_insertid} }
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
32

            
removed register_format()
yuki-kimoto authored on 2010-05-26
33
1;
34

            
packaging one directory
yuki-kimoto authored on 2009-11-16
35
=head1 NAME
36

            
cleanup
yuki-kimoto authored on 2010-08-03
37
DBIx::Custom::MySQL - MySQL implementation
packaging one directory
yuki-kimoto authored on 2009-11-16
38

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

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
41
    # Connect to database
42
    my $dbi = DBIx::Custom::MySQL->connect(user     => 'taro', 
update document
yuki-kimoto authored on 2010-05-27
43
                                           password => 'kliej&@K',
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
44
                                           database => 'your_database');
update document
yuki-kimoto authored on 2010-05-27
45
    
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
46
    # Get last insert id
update document
yuki-kimoto authored on 2010-05-27
47
    my $id = $dbi->last_insert_id;
packaging one directory
yuki-kimoto authored on 2009-11-16
48

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

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

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
54
=head2 C<database>
packaging one directory
yuki-kimoto authored on 2009-11-16
55

            
cleanup
yuki-kimoto authored on 2010-08-03
56
    my $database = $dbi->database;
57
    $dbi         = $dbi->database('your_database');
update document
yuki-kimoto authored on 2009-11-19
58

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
59
Database name.
60
This is used for connect().
packaging one directory
yuki-kimoto authored on 2009-11-16
61

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
62
=head2 C<host>
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
63

            
cleanup
yuki-kimoto authored on 2010-08-03
64
    my $host = $dbi->host;
65
    $dbi     = $dbi->host('somehost.com');
update document
yuki-kimoto authored on 2010-05-27
66

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
67
Database host name.
68
You can also set IP address, instead of host name.
69
This is used for connect().
update document
yuki-kimoto authored on 2010-05-27
70

            
71
    $dbi->host('127.03.45.12');
72

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
73
=head2 C<port>
update document
yuki-kimoto authored on 2010-05-27
74

            
cleanup
yuki-kimoto authored on 2010-08-03
75
    my $port = $dbi->port;
76
    $dbi     = $dbi->port(1198);
update document
yuki-kimoto authored on 2010-05-27
77

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
78
Database port. This is used for connect().
79

            
update document
yuki-kimoto authored on 2010-05-27
80
=head1 METHODS
81

            
82
This class is L<DBIx::Custom> subclass.
83
You can use all methods of L<DBIx::Custom>.
84

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
85
=head2 C<connect (overridden)>
update document
yuki-kimoto authored on 2010-05-27
86

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
87
    $dbi = DBIx::Custom::MySQL->connect(
88
        data_source => "dbi:mysql:database=books;host=somehost;port=2000"
89
    );
90
    
91
    $dbi = DBIx::Custom::MySQL->connect(user     => 'taro', 
92
                                        password => 'kliej&@K',
93
                                        database => 'your_database',
94
                                        host     => 'somehost',
95
                                        port     => 2000);
update document
yuki-kimoto authored on 2010-05-27
96

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
97
Connect to database. You can also specify database, host, and port
98
(instead of data soruce).
update document
yuki-kimoto authored on 2010-05-27
99

            
removed DBIx::Custom commit ...
yuki-kimoto authored on 2010-07-14
100
=head2 C<last_insert_id>
version 0.0901
yuki-kimoto authored on 2009-12-17
101

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

            
removed DESTROY method(not b...
yuki-kimoto authored on 2010-07-18
104
Get last insert id.
update document
yuki-kimoto authored on 2010-05-27
105
This is equal to MySQL last_insert_id() function.
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
106

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