packaging one directory
|
1 |
package DBIx::Custom::SQLite; |
2 |
use base 'DBIx::Custom::Basic'; |
|
3 | ||
4 |
use strict; |
|
update document
|
5 |
use warnings; |
packaging one directory
|
6 |
use Carp 'croak'; |
7 | ||
8 |
my $class = __PACKAGE__; |
|
9 | ||
10 |
$class->add_format( |
|
11 |
datetime => $class->formats->{SQL99_datetime}, |
|
12 |
date => $class->formats->{SQL99_date}, |
|
13 |
time => $class->formats->{SQL99_time}, |
|
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,
|
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
|
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
|
73 |
database => 'sample'); |
packaging one directory
|
74 |
|
version 0.0901
|
75 |
# Connect memory database |
76 |
my $dbi->connect_memory; |
|
packaging one directory
|
77 |
|
version 0.0901
|
78 |
=head1 See DBIx::Custom and DBIx::Custom::Basic documentation at first |
packaging one directory
|
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
|
86 |
=head1 Methods |
packaging one directory
|
87 | |
88 |
=head2 connect |
|
89 | ||
update document
|
90 |
Connect to database |
packaging one directory
|
91 | |
92 |
$dbi->connect; |
|
93 | ||
version 0.0901
|
94 |
If you set database, host, or port, data source is automatically created. |
packaging one directory
|
95 | |
96 |
=head2 connect_memory |
|
97 | ||
update document
|
98 |
Connect memory database |
99 | ||
100 |
$dbi->connect_memory; |
|
packaging one directory
|
101 | |
102 |
=head2 reconnect_memory |
|
103 | ||
update document
|
104 |
Reconnect to memory databsse |
105 | ||
version 0.0901
|
106 |
$dbi->reconnect_memory; |
packaging one directory
|
107 | |
add Oracle, DB2, Pg,
|
108 |
=head2 last_insert_id |
109 | ||
update document
|
110 |
Get last insert id |
111 | ||
version 0.0901
|
112 |
$last_insert_id = $dbi->last_insert_id; |
update document
|
113 |
|
version 0.0901
|
114 |
The folloing is last_insert_id sample. |
115 | ||
update document
|
116 |
$dbi->insert('books', {title => 'Perl', author => 'taro'}); |
117 |
$last_insert_id = $dbi->last_insert_id; |
|
add Oracle, DB2, Pg,
|
118 | |
119 |
This is equal to SQLite function |
|
120 | ||
121 |
last_insert_rowid() |
|
122 | ||
packaging one directory
|
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 |