packaging one directory
|
1 |
package DBIx::Custom::SQLite; |
2 | ||
3 |
use strict; |
|
update document
|
4 |
use warnings; |
rename DBIx::Custom::SQLite ...
|
5 | |
update document
|
6 |
use base 'DBIx::Custom'; |
7 | ||
packaging one directory
|
8 |
use Carp 'croak'; |
9 | ||
update document
|
10 |
__PACKAGE__->attr('database'); |
11 | ||
packaging one directory
|
12 |
sub connect { |
update document
|
13 |
my $proto = shift; |
14 |
|
|
15 |
# Create |
|
16 |
my $self = ref $proto ? $proto : $proto->new(@_); |
|
packaging one directory
|
17 |
|
rename DBIx::Custom::SQLite ...
|
18 |
# Create data source |
packaging one directory
|
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 | ||
rename DBIx::Custom::SQLite ...
|
53 |
sub last_insert_rowid { |
add Oracle, DB2, Pg,
|
54 |
my $self = shift; |
55 |
|
|
rename DBIx::Custom::SQLite ...
|
56 |
# Not connected |
add Oracle, DB2, Pg,
|
57 |
croak "Not yet connected" unless $self->connected; |
58 |
|
|
rename DBIx::Custom::SQLite ...
|
59 |
# Get last insert row id |
60 |
my $last_insert_rowid = $self->dbh->func('last_insert_rowid'); |
|
add Oracle, DB2, Pg,
|
61 |
|
rename DBIx::Custom::SQLite ...
|
62 |
return $last_insert_rowid; |
add Oracle, DB2, Pg,
|
63 |
} |
packaging one directory
|
64 | |
removed register_format()
|
65 |
1; |
66 | ||
packaging one directory
|
67 |
=head1 NAME |
68 | ||
update document
|
69 |
DBIx::Custom::SQLite - a SQLite implementation of DBIx::Custom |
packaging one directory
|
70 | |
rename DBIx::Custom::SQLite ...
|
71 |
=head1 SYNOPSYS |
packaging one directory
|
72 | |
73 |
use DBIx::Custom::SQLite; |
|
74 |
|
|
update document
|
75 |
# Connect |
76 |
my $dbi = DBIx::Custom::SQLite->connect(user => 'taro', |
|
77 |
password => 'kl&@K', |
|
78 |
database => 'your_database'); |
|
packaging one directory
|
79 |
|
version 0.0901
|
80 |
# Connect memory database |
update document
|
81 |
my $dbi = DBIx::Custom::SQLite->connect_memory; |
82 |
|
|
83 |
# Reconnect memory database |
|
84 |
$dbi->reconnect_memory; |
|
85 |
|
|
86 |
# Last insert row ID |
|
87 |
my $id = $dbi->last_insert_rowid; |
|
packaging one directory
|
88 |
|
update document
|
89 |
=head1 ATTRIBUTES |
90 | ||
91 |
This class is L<DBIx::Custom> subclass. |
|
92 |
You can use all attributes of L<DBIx::Custom>. |
|
93 | ||
94 |
=head2 database |
|
95 | ||
96 |
Database name |
|
97 | ||
98 |
$dbi = $dbi->database('your_database'); |
|
99 |
$database = $dbi->database; |
|
packaging one directory
|
100 | |
rename DBIx::Custom::SQLite ...
|
101 |
=head1 METHODS |
packaging one directory
|
102 | |
update document
|
103 |
This class is L<DBIx::Custom> subclass. |
104 |
You can use all methods of L<DBIx::Custom>. |
|
packaging one directory
|
105 | |
update document
|
106 |
=head2 connect - overridden |
packaging one directory
|
107 | |
update document
|
108 |
Connect to database. |
packaging one directory
|
109 | |
110 |
$dbi->connect; |
|
111 | ||
version 0.0901
|
112 |
If you set database, host, or port, data source is automatically created. |
packaging one directory
|
113 | |
114 |
=head2 connect_memory |
|
115 | ||
update document
|
116 |
Connect memory database. |
update document
|
117 | |
118 |
$dbi->connect_memory; |
|
packaging one directory
|
119 | |
120 |
=head2 reconnect_memory |
|
121 | ||
update document
|
122 |
Reconnect to memory databsse. |
update document
|
123 | |
version 0.0901
|
124 |
$dbi->reconnect_memory; |
packaging one directory
|
125 | |
rename DBIx::Custom::SQLite ...
|
126 |
=head2 last_insert_rowid |
add Oracle, DB2, Pg,
|
127 | |
update document
|
128 |
Last insert row ID. |
update document
|
129 | |
rename DBIx::Custom::SQLite ...
|
130 |
$last_insert_rowid = $dbi->last_insert_rowid; |
update document
|
131 |
|
update document
|
132 |
This is equal to SQLite last_insert_rowid() function. |
add Oracle, DB2, Pg,
|
133 | |
rename DBIx::Custom::SQLite ...
|
134 |
=cut |