Newer Older
122 lines | 2.388kb
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

            
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
9
# Add format
some changed
yuki-kimoto authored on 2010-05-02
10
__PACKAGE__->register_format(
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
11
    datetime => __PACKAGE__->formats->{SQL99_datetime},
12
    date     => __PACKAGE__->formats->{SQL99_date},
13
    time     => __PACKAGE__->formats->{SQL99_time},
packaging one directory
yuki-kimoto authored on 2009-11-16
14
);
15

            
16
sub connect {
17
    my $self = shift;
18
    
rename DBIx::Custom::SQLite ...
yuki-kimoto authored on 2010-01-30
19
    # Create data source
packaging one directory
yuki-kimoto authored on 2009-11-16
20
    if (!$self->data_source && (my $database = $self->database)) {
21
        $self->data_source("dbi:SQLite:dbname=$database");
22
    }
23
    
24
    return $self->SUPER::connect;
25
}
26

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

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

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

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

            
66
=head1 NAME
67

            
68
DBIx::Custom::SQLite - DBIx::Custom SQLite implementation
69

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

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

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

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

            
87
=head2 connect
88

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

            
91
    $dbi->connect;
92

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

            
95
=head2 connect_memory
96

            
update document
yuki-kimoto authored on 2009-11-19
97
Connect memory database
98

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

            
101
=head2 reconnect_memory
102

            
update document
yuki-kimoto authored on 2009-11-19
103
Reconnect to memory databsse
104

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

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

            
update document
yuki-kimoto authored on 2009-11-19
109
Get last insert id
110

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

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

            
118
This is equal to SQLite function
119

            
120
    last_insert_rowid()
121

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