Newer Older
134 lines | 2.576kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::SQLite;
2

            
3
use strict;
update document
yuki-kimoto authored on 2009-11-17
4
use warnings;
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
5

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

            
packaging one directory
yuki-kimoto authored on 2009-11-16
8
use Carp 'croak';
9

            
update document
yuki-kimoto authored on 2010-05-27
10
__PACKAGE__->attr('database');
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
    
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
18
    # Create data source
packaging one directory
yuki-kimoto authored on 2009-11-16
19
    if (!$self->data_source && (my $database = $self->database)) {
20
        $self->data_source("dbi:SQLite:dbname=$database");
21
    }
22
    
23
    return $self->SUPER::connect;
24
}
25

            
26
sub connect_memory {
27
    my $self = shift;
28
    
29
    # Data source for memory database
30
    $self->data_source('dbi:SQLite:dbname=:memory:');
31
    
32
    # Already connected
33
    croak("Already connected") if $self->connected;
34
    
35
    # Connect
36
    $self->connect;
37
    
38
    return $self;
39
}
40

            
41
sub reconnect_memory {
42
    my $self = shift;
43

            
44
    # Data source for memory database
45
    $self->data_source('dbi:SQLite:dbname=:memory:');
46
    
47
    # Reconnect
48
    $self->reconnect;
49
    
50
    return $self;
51
}
52

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
53
sub last_insert_rowid {
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
54
    my $self = shift;
55
    
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
56
    # Not connected
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
57
    croak "Not yet connected" unless $self->connected;
58
    
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
59
    # Get last insert row id
60
    my $last_insert_rowid = $self->dbh->func('last_insert_rowid');
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
61
    
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
62
    return $last_insert_rowid;
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
63
}
packaging one directory
yuki-kimoto authored on 2009-11-16
64

            
removed register_format()
yuki-kimoto authored on 2010-05-26
65
1;
66

            
packaging one directory
yuki-kimoto authored on 2009-11-16
67
=head1 NAME
68

            
update document
yuki-kimoto authored on 2010-05-27
69
DBIx::Custom::SQLite - a SQLite implementation of DBIx::Custom
packaging one directory
yuki-kimoto authored on 2009-11-16
70

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
71
=head1 SYNOPSYS
packaging one directory
yuki-kimoto authored on 2009-11-16
72

            
73
    use DBIx::Custom::SQLite;
74
    
update document
yuki-kimoto authored on 2010-05-27
75
    # Connect
76
    my $dbi = DBIx::Custom::SQLite->connect(user      => 'taro', 
77
                                            password => 'kl&@K',
78
                                            database  => 'your_database');
packaging one directory
yuki-kimoto authored on 2009-11-16
79
    
version 0.0901
yuki-kimoto authored on 2009-12-17
80
    # Connect memory database
update document
yuki-kimoto authored on 2010-05-27
81
    my $dbi = DBIx::Custom::SQLite->connect_memory;
82
    
83
    # Reconnect memory database
84
    $dbi->reconnect_memory;
85
    
86
    # Last insert row ID
87
    my $id = $dbi->last_insert_rowid;
packaging one directory
yuki-kimoto authored on 2009-11-16
88
    
update document
yuki-kimoto authored on 2010-05-27
89
=head1 ATTRIBUTES
90

            
91
This class is L<DBIx::Custom> subclass.
92
You can use all attributes of L<DBIx::Custom>.
93

            
94
=head2 database
95

            
96
Database name
97

            
98
    $dbi      = $dbi->database('your_database');
99
    $database = $dbi->database;
packaging one directory
yuki-kimoto authored on 2009-11-16
100

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
101
=head1 METHODS
packaging one directory
yuki-kimoto authored on 2009-11-16
102

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

            
update document
yuki-kimoto authored on 2010-05-27
106
=head2 connect - overridden
packaging one directory
yuki-kimoto authored on 2009-11-16
107

            
update document
yuki-kimoto authored on 2010-05-27
108
Connect to database.
packaging one directory
yuki-kimoto authored on 2009-11-16
109

            
110
    $dbi->connect;
111

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

            
114
=head2 connect_memory
115

            
update document
yuki-kimoto authored on 2010-05-27
116
Connect memory database.
update document
yuki-kimoto authored on 2009-11-19
117

            
118
    $dbi->connect_memory;
packaging one directory
yuki-kimoto authored on 2009-11-16
119

            
120
=head2 reconnect_memory
121

            
update document
yuki-kimoto authored on 2010-05-27
122
Reconnect to memory databsse.
update document
yuki-kimoto authored on 2009-11-19
123

            
version 0.0901
yuki-kimoto authored on 2009-12-17
124
    $dbi->reconnect_memory;
packaging one directory
yuki-kimoto authored on 2009-11-16
125

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
126
=head2 last_insert_rowid
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
127

            
update document
yuki-kimoto authored on 2010-05-27
128
Last insert row ID.
update document
yuki-kimoto authored on 2009-11-19
129

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
130
    $last_insert_rowid = $dbi->last_insert_rowid;
update document
yuki-kimoto authored on 2009-11-19
131
    
update document
yuki-kimoto authored on 2010-05-27
132
This is equal to SQLite last_insert_rowid() function.
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
133

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
134
=cut