Newer Older
137 lines | 2.826kb
packaging one directory
yuki-kimoto authored on 2009-11-16
1
package DBIx::Custom::SQLite;
2
use base 'DBIx::Custom::Basic';
3

            
4
use strict;
update document
yuki-kimoto authored on 2009-11-17
5
use warnings;
packaging one directory
yuki-kimoto authored on 2009-11-16
6
use Carp 'croak';
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
sub connect {
17
    my $self = shift;
18
    
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

            
add Oracle, DB2, Pg,
yuki-kimoto authored on 2009-11-16
53
sub last_insert_id {
54
    my $self = shift;
55
    
56
    croak "Not yet connected" unless $self->connected;
57
    
58
    my $last_insert_id = $self->dbh->func('last_insert_rowid');
59
    
60
    return $last_insert_id;
61
}
packaging one directory
yuki-kimoto authored on 2009-11-16
62

            
63
=head1 NAME
64

            
65
DBIx::Custom::SQLite - DBIx::Custom SQLite implementation
66

            
67
=head1 Synopsys
68

            
69
    use DBIx::Custom::SQLite;
70
    
71
    # New
72
    my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kliej&@K',
update document
yuki-kimoto authored on 2009-11-19
73
                                        database => 'sample');
packaging one directory
yuki-kimoto authored on 2009-11-16
74
    
version 0.0901
yuki-kimoto authored on 2009-12-17
75
    # Connect memory database
76
    my $dbi->connect_memory;
packaging one directory
yuki-kimoto authored on 2009-11-16
77
    
version 0.0901
yuki-kimoto authored on 2009-12-17
78
=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first
packaging one directory
yuki-kimoto authored on 2009-11-16
79

            
80
This class is L<DBIx::Custom::Basic> subclass.
81
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass
82

            
83
You can use all methods of L<DBIx::Custom::Basic> and <DBIx::Custom>
84
Please see L<DBIx::Custom::Basic> and <DBIx::Custom> documentation
85

            
version 0.0901
yuki-kimoto authored on 2009-12-17
86
=head1 Methods
packaging one directory
yuki-kimoto authored on 2009-11-16
87

            
88
=head2 connect
89

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

            
92
    $dbi->connect;
93

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

            
96
=head2 connect_memory
97

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

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

            
102
=head2 reconnect_memory
103

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

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

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

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

            
version 0.0901
yuki-kimoto authored on 2009-12-17
112
    $last_insert_id = $dbi->last_insert_id;
update document
yuki-kimoto authored on 2009-11-19
113
    
version 0.0901
yuki-kimoto authored on 2009-12-17
114
The folloing is last_insert_id sample.
115

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

            
119
This is equal to SQLite function
120

            
121
    last_insert_rowid()
122

            
packaging one directory
yuki-kimoto authored on 2009-11-16
123
=head1 Author
124

            
125
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
126

            
127
Github L<http://github.com/yuki-kimoto>
128

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

            
131
=head1 Copyright & lisence
132

            
133
Copyright 2009 Yuki Kimoto, all rights reserved.
134

            
135
This program is free software; you can redistribute it and/or modify it
136
under the same terms as Perl itself.
137