Newer Older
135 lines | 2.84kb
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

            
catch up with Object::Simple...
yuki-kimoto authored on 2010-01-18
8
__PACKAGE__->add_format(
9
    datetime => __PACKAGE__->formats->{SQL99_datetime},
10
    date     => __PACKAGE__->formats->{SQL99_date},
11
    time     => __PACKAGE__->formats->{SQL99_time},
packaging one directory
yuki-kimoto authored on 2009-11-16
12
);
13

            
14
sub connect {
15
    my $self = shift;
16
    
17
    if (!$self->data_source && (my $database = $self->database)) {
18
        $self->data_source("dbi:SQLite:dbname=$database");
19
    }
20
    
21
    return $self->SUPER::connect;
22
}
23

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

            
39
sub reconnect_memory {
40
    my $self = shift;
41

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

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

            
61
=head1 NAME
62

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

            
65
=head1 Synopsys
66

            
67
    use DBIx::Custom::SQLite;
68
    
69
    # New
70
    my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kliej&@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
    
version 0.0901
yuki-kimoto authored on 2009-12-17
76
=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first
packaging one directory
yuki-kimoto authored on 2009-11-16
77

            
78
This class is L<DBIx::Custom::Basic> subclass.
79
and L<DBIx::Custom::Basic> is L<DBIx::Custom> subclass
80

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

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

            
86
=head2 connect
87

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

            
90
    $dbi->connect;
91

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

            
94
=head2 connect_memory
95

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

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

            
100
=head2 reconnect_memory
101

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

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

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

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

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

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

            
117
This is equal to SQLite function
118

            
119
    last_insert_rowid()
120

            
packaging one directory
yuki-kimoto authored on 2009-11-16
121
=head1 Author
122

            
123
Yuki Kimoto, C<< <kimoto.yuki at gmail.com> >>
124

            
125
Github L<http://github.com/yuki-kimoto>
126

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

            
129
=head1 Copyright & lisence
130

            
131
Copyright 2009 Yuki Kimoto, all rights reserved.
132

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