Newer Older
117 lines | 2.185kb
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

            
6
use base 'DBIx::Custom::Basic';
packaging one directory
yuki-kimoto authored on 2009-11-16
7
use Carp 'croak';
8

            
9
sub connect {
10
    my $self = shift;
11
    
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
12
    # Create data source
packaging one directory
yuki-kimoto authored on 2009-11-16
13
    if (!$self->data_source && (my $database = $self->database)) {
14
        $self->data_source("dbi:SQLite:dbname=$database");
15
    }
16
    
17
    return $self->SUPER::connect;
18
}
19

            
20
sub connect_memory {
21
    my $self = shift;
22
    
23
    # Data source for memory database
24
    $self->data_source('dbi:SQLite:dbname=:memory:');
25
    
26
    # Already connected
27
    croak("Already connected") if $self->connected;
28
    
29
    # Connect
30
    $self->connect;
31
    
32
    return $self;
33
}
34

            
35
sub reconnect_memory {
36
    my $self = shift;
37

            
38
    # Data source for memory database
39
    $self->data_source('dbi:SQLite:dbname=:memory:');
40
    
41
    # Reconnect
42
    $self->reconnect;
43
    
44
    return $self;
45
}
46

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

            
removed register_format()
yuki-kimoto authored on 2010-05-26
59
1;
60

            
packaging one directory
yuki-kimoto authored on 2009-11-16
61
=head1 NAME
62

            
63
DBIx::Custom::SQLite - DBIx::Custom SQLite implementation
64

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

            
67
    use DBIx::Custom::SQLite;
68
    
69
    # New
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
70
    my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kl&@K',
update document
yuki-kimoto authored on 2009-11-19
71
                                        database => 'sample');
packaging one directory
yuki-kimoto authored on 2009-11-16
72
    
version 0.0901
yuki-kimoto authored on 2009-12-17
73
    # Connect memory database
74
    my $dbi->connect_memory;
packaging one directory
yuki-kimoto authored on 2009-11-16
75
    
76

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

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
79
This class is L<DBIx::Custom::Basic> subclass.
80
You can use all methods of L<DBIx::Custom::Basic>
packaging one directory
yuki-kimoto authored on 2009-11-16
81

            
82
=head2 connect
83

            
update document
yuki-kimoto authored on 2009-11-19
84
Connect to database
packaging one directory
yuki-kimoto authored on 2009-11-16
85

            
86
    $dbi->connect;
87

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

            
90
=head2 connect_memory
91

            
update document
yuki-kimoto authored on 2009-11-19
92
Connect memory database
93

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

            
96
=head2 reconnect_memory
97

            
update document
yuki-kimoto authored on 2009-11-19
98
Reconnect to memory databsse
99

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

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

            
update document
yuki-kimoto authored on 2009-11-19
104
Get last insert id
105

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
106
    $last_insert_rowid = $dbi->last_insert_rowid;
update document
yuki-kimoto authored on 2009-11-19
107
    
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
108
The folloing is last_insert_rowid sample.
version 0.0901
yuki-kimoto authored on 2009-12-17
109

            
update document
yuki-kimoto authored on 2009-11-19
110
    $dbi->insert('books', {title => 'Perl', author => 'taro'});
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
111
    $last_insert_rowid = $dbi->last_insert_rowid;
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
112

            
113
This is equal to SQLite function
114

            
115
    last_insert_rowid()
116

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