... | ... |
@@ -85,7 +85,7 @@ sub connect { |
85 | 85 |
my $connect_info = $self->connect_info; |
86 | 86 |
|
87 | 87 |
foreach my $key (keys %{$self->connect_info}) { |
88 |
- croak("connect_info '$key' is invald") |
|
88 |
+ croak("connect_info '$key' is wrong name") |
|
89 | 89 |
unless $VALID_CONNECT_INFO{$key}; |
90 | 90 |
} |
91 | 91 |
|
... | ... |
@@ -319,6 +319,7 @@ sub create_sql { |
319 | 319 |
|
320 | 320 |
our $TAG_SYNTAX = <<'EOS'; |
321 | 321 |
[tag] [expand] |
322 |
+{? name} ? |
|
322 | 323 |
{= name} name = ? |
323 | 324 |
{<> name} name <> ? |
324 | 325 |
|
... | ... |
@@ -364,7 +365,7 @@ sub parse { |
364 | 365 |
my ($tag_name, @args) = split /\s+/, $tag; |
365 | 366 |
|
366 | 367 |
$tag ||= ''; |
367 |
- croak("Tag '$tag' in SQL template is invalid.\n\n" . |
|
368 |
+ croak("Tag '$tag' in SQL template is not exist.\n\n" . |
|
368 | 369 |
"SQL template tag syntax\n$TAG_SYNTAX\n\n" . |
369 | 370 |
"Your SQL template is \n$original_template\n\n") |
370 | 371 |
unless $VALID_TAG_NAMES{$tag_name}; |
... | ... |
@@ -486,6 +487,8 @@ Version 0.0101 |
486 | 487 |
|
487 | 488 |
=head2 add_filter |
488 | 489 |
|
490 |
+ |
|
491 |
+ |
|
489 | 492 |
=head2 bind_filter |
490 | 493 |
|
491 | 494 |
=head2 clone |
... | ... |
@@ -164,7 +164,7 @@ use Scalar::Util qw/blessed/; |
164 | 164 |
); |
165 | 165 |
eval{$dbi->connect}; |
166 | 166 |
|
167 |
- like($@, qr/connect_info 'no_exist' is invald/, 'no exist'); |
|
167 |
+ like($@, qr/connect_info 'no_exist' is wrong name/, 'no exist'); |
|
168 | 168 |
} |
169 | 169 |
|
170 | 170 |
{ |
... | ... |
@@ -1,6 +1,7 @@ |
1 | 1 |
use Test::More; |
2 | 2 |
use strict; |
3 | 3 |
use warnings; |
4 |
+use DBI; |
|
4 | 5 |
|
5 | 6 |
BEGIN { |
6 | 7 |
eval { require DBD::SQLite; 1 } |
... | ... |
@@ -12,14 +13,57 @@ BEGIN { |
12 | 13 |
use_ok('DBI::Custom'); |
13 | 14 |
} |
14 | 15 |
|
15 |
-my $dbi = DBI::Custom->new( |
|
16 |
- connect_info => {data_source => 'dbi:SQLite:dbname=:memory:'} |
|
17 |
-); |
|
16 |
+package Test::DBI::Custom; |
|
17 |
+use Object::Simple; |
|
18 | 18 |
|
19 |
-$dbi->query_raw_sql("create table t1 (k1 char(10), k2 char(10))"); |
|
19 |
+sub dbi : Attr {} |
|
20 | 20 |
|
21 |
-{ |
|
22 |
- $dbi->query("insert into t1 {insert_values}",{insert_values => {k1 => 1, k2 => 2}}); |
|
21 |
+sub new { |
|
22 |
+ my $self = shift->SUPER::new; |
|
23 |
+ my $dbi = DBI::Custom->new->connect_info(data_source => 'dbi:SQLite:dbname=:memory:'); |
|
24 |
+ |
|
25 |
+ $dbi->connect; |
|
26 |
+ $self->dbi($dbi); |
|
27 |
+ return $self; |
|
28 |
+} |
|
29 |
+ |
|
30 |
+sub create_table { |
|
31 |
+ my ($self, $create_table) = @_; |
|
32 |
+ $self->dbi->query_raw_sql($create_table); |
|
33 |
+ return $self; |
|
34 |
+} |
|
35 |
+ |
|
36 |
+sub create_table1 { |
|
37 |
+ my $self = shift; |
|
38 |
+ $self->create_table("create table t1 (k1 char(255), k2 char(255), k3 char(255), k4 char(255), k5 char(255));"); |
|
39 |
+ return $self; |
|
40 |
+} |
|
41 |
+ |
|
42 |
+sub insert { |
|
43 |
+ my ($self, @values_list) = @_; |
|
44 |
+ my $table = ref $values_list[0] ? '' : shift; |
|
45 |
+ $table ||= 't1'; |
|
46 |
+ |
|
47 |
+ foreach my $values (@values_list) { |
|
48 |
+ my $sql = $self->dbi->query( |
|
49 |
+ "insert into $table {insert_values}", {insert_values => $values} |
|
50 |
+ ); |
|
51 |
+ } |
|
52 |
+ return $self; |
|
53 |
+} |
|
54 |
+ |
|
55 |
+sub test { |
|
56 |
+ my ($self, $code) = @_; |
|
57 |
+ $code->($self->dbi); |
|
58 |
+} |
|
59 |
+ |
|
60 |
+Object::Simple->build_class; |
|
61 |
+ |
|
62 |
+package main; |
|
63 |
+my $t = Test::DBI::Custom->new; |
|
64 |
+ |
|
65 |
+$t->new->create_table1->insert({k1 => 1, k2 => 2}, {k1 => 3, k2 => 4})->test(sub { |
|
66 |
+ my $dbi = shift; |
|
23 | 67 |
|
24 | 68 |
$dbi->fetch_filter(sub { |
25 | 69 |
my ($key, $value) = @_; |
... | ... |
@@ -36,4 +80,5 @@ $dbi->query_raw_sql("create table t1 (k1 char(10), k2 char(10))"); |
36 | 80 |
$result->finish; |
37 | 81 |
|
38 | 82 |
is_deeply(\@values, [3, 2]); |
39 |
-} |
|
83 |
+}); |
|
84 |
+ |
... | ... |
@@ -1,38 +0,0 @@ |
1 |
-use Test::More; |
|
2 |
-use strict; |
|
3 |
-use warnings; |
|
4 |
- |
|
5 |
-# user password database |
|
6 |
-our ($U, $P, $D) = connect_info(); |
|
7 |
- |
|
8 |
-plan skip_all => 'private MySQL test' unless $U; |
|
9 |
- |
|
10 |
-plan 'no_plan'; |
|
11 |
- |
|
12 |
-use DBI::Custom; |
|
13 |
-use Scalar::Util 'blessed'; |
|
14 |
-{ |
|
15 |
- my $dbi = DBI::Custom->new( |
|
16 |
- connect_info => { |
|
17 |
- user => $U, |
|
18 |
- password => $P, |
|
19 |
- data_source => "dbi:mysql:$D" |
|
20 |
- } |
|
21 |
- ); |
|
22 |
- $dbi->connect; |
|
23 |
- |
|
24 |
- ok(blessed $dbi->dbh); |
|
25 |
- can_ok($dbi->dbh, qw/prepare/); |
|
26 |
-} |
|
27 |
- |
|
28 |
-sub connect_info { |
|
29 |
- my $file = 'password.tmp'; |
|
30 |
- open my $fh, '<', $file |
|
31 |
- or return; |
|
32 |
- |
|
33 |
- my ($user, $password, $database) = split(/\s/, (<$fh>)[0]); |
|
34 |
- |
|
35 |
- close $fh; |
|
36 |
- |
|
37 |
- return ($user, $password, $database); |
|
38 |
-} |