packaging one directory
|
1 |
package DBIx::Custom::SQLite; |
2 | ||
3 |
use strict; |
|
update document
|
4 |
use warnings; |
rename DBIx::Custom::SQLite ...
|
5 | |
6 |
use base 'DBIx::Custom::Basic'; |
|
packaging one directory
|
7 |
use Carp 'croak'; |
8 | ||
rename DBIx::Custom::SQLite ...
|
9 |
# Add format |
some changed
|
10 |
__PACKAGE__->register_format( |
catch up with Object::Simple...
|
11 |
datetime => __PACKAGE__->formats->{SQL99_datetime}, |
12 |
date => __PACKAGE__->formats->{SQL99_date}, |
|
13 |
time => __PACKAGE__->formats->{SQL99_time}, |
|
packaging one directory
|
14 |
); |
15 | ||
16 |
sub connect { |
|
17 |
my $self = shift; |
|
18 |
|
|
rename DBIx::Custom::SQLite ...
|
19 |
# Create data source |
packaging one directory
|
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 ...
|
54 |
sub last_insert_rowid { |
add Oracle, DB2, Pg,
|
55 |
my $self = shift; |
56 |
|
|
rename DBIx::Custom::SQLite ...
|
57 |
# Not connected |
add Oracle, DB2, Pg,
|
58 |
croak "Not yet connected" unless $self->connected; |
59 |
|
|
rename DBIx::Custom::SQLite ...
|
60 |
# Get last insert row id |
61 |
my $last_insert_rowid = $self->dbh->func('last_insert_rowid'); |
|
add Oracle, DB2, Pg,
|
62 |
|
rename DBIx::Custom::SQLite ...
|
63 |
return $last_insert_rowid; |
add Oracle, DB2, Pg,
|
64 |
} |
packaging one directory
|
65 | |
66 |
=head1 NAME |
|
67 | ||
68 |
DBIx::Custom::SQLite - DBIx::Custom SQLite implementation |
|
69 | ||
rename DBIx::Custom::SQLite ...
|
70 |
=head1 SYNOPSYS |
packaging one directory
|
71 | |
72 |
use DBIx::Custom::SQLite; |
|
73 |
|
|
74 |
# New |
|
rename DBIx::Custom::SQLite ...
|
75 |
my $dbi = DBIx::Custom::SQLite->new(user => 'taro', $password => 'kl&@K', |
update document
|
76 |
database => 'sample'); |
packaging one directory
|
77 |
|
version 0.0901
|
78 |
# Connect memory database |
79 |
my $dbi->connect_memory; |
|
packaging one directory
|
80 |
|
81 | ||
rename DBIx::Custom::SQLite ...
|
82 |
=head1 METHODS |
packaging one directory
|
83 | |
rename DBIx::Custom::SQLite ...
|
84 |
This class is L<DBIx::Custom::Basic> subclass. |
85 |
You can use all methods of L<DBIx::Custom::Basic> |
|
packaging one directory
|
86 | |
87 |
=head2 connect |
|
88 | ||
update document
|
89 |
Connect to database |
packaging one directory
|
90 | |
91 |
$dbi->connect; |
|
92 | ||
version 0.0901
|
93 |
If you set database, host, or port, data source is automatically created. |
packaging one directory
|
94 | |
95 |
=head2 connect_memory |
|
96 | ||
update document
|
97 |
Connect memory database |
98 | ||
99 |
$dbi->connect_memory; |
|
packaging one directory
|
100 | |
101 |
=head2 reconnect_memory |
|
102 | ||
update document
|
103 |
Reconnect to memory databsse |
104 | ||
version 0.0901
|
105 |
$dbi->reconnect_memory; |
packaging one directory
|
106 | |
rename DBIx::Custom::SQLite ...
|
107 |
=head2 last_insert_rowid |
add Oracle, DB2, Pg,
|
108 | |
update document
|
109 |
Get last insert id |
110 | ||
rename DBIx::Custom::SQLite ...
|
111 |
$last_insert_rowid = $dbi->last_insert_rowid; |
update document
|
112 |
|
rename DBIx::Custom::SQLite ...
|
113 |
The folloing is last_insert_rowid sample. |
version 0.0901
|
114 | |
update document
|
115 |
$dbi->insert('books', {title => 'Perl', author => 'taro'}); |
rename DBIx::Custom::SQLite ...
|
116 |
$last_insert_rowid = $dbi->last_insert_rowid; |
add Oracle, DB2, Pg,
|
117 | |
118 |
This is equal to SQLite function |
|
119 | ||
120 |
last_insert_rowid() |
|
121 | ||
rename DBIx::Custom::SQLite ...
|
122 |
=cut |