Showing 10 changed files with 111 additions and 221 deletions
+9 -66
lib/DBIx/Custom.pm
... ...
@@ -128,44 +128,6 @@ sub reconnect {
128 128
     return $self;
129 129
 }
130 130
 
131
-sub prepare {
132
-    my ($self, $sql) = @_;
133
-    
134
-    # Connect if not
135
-    $self->connect unless $self->connected;
136
-    
137
-    # Prepare
138
-    my $sth = eval{$self->dbh->prepare($sql)};
139
-    
140
-    # Error
141
-    croak("$@<Your SQL>\n$sql") if $@;
142
-    
143
-    return $sth;
144
-}
145
-
146
-sub do{
147
-    my ($self, $sql, @bind_values) = @_;
148
-    
149
-    # Connect if not
150
-    $self->connect unless $self->connected;
151
-    
152
-    # Do
153
-    my $affected = eval{$self->dbh->do($sql, @bind_values)};
154
-    
155
-    # Error
156
-    if ($@) {
157
-        my $error = $@;
158
-        require Data::Dumper;
159
-        
160
-        my $bind_value_dump
161
-          = Data::Dumper->Dump([\@bind_values], ['*bind_valuds']);
162
-        
163
-        croak("$error<Your SQL>\n$sql\n<Your bind values>\n$bind_value_dump\n");
164
-    }
165
-    
166
-    return $affected;
167
-}
168
-
169 131
 sub create_query {
170 132
     my ($self, $template) = @_;
171 133
     
... ...
@@ -200,7 +162,7 @@ sub create_query {
200 162
     $self->connect unless $self->connected;
201 163
     
202 164
     # Prepare statement handle
203
-    my $sth = $self->prepare($query->{sql});
165
+    my $sth = $self->dbh->prepare($query->{sql});
204 166
     
205 167
     # Set statement handle
206 168
     $query->sth($sth);
... ...
@@ -363,8 +325,11 @@ sub create_table {
363 325
     # End
364 326
     $sql .= ");";
365 327
     
328
+    # Connect
329
+    $self->connect unless $self->connected;
330
+    
366 331
     # Do query
367
-    return $self->do($sql);
332
+    return $self->dbh->do($sql);
368 333
 }
369 334
 
370 335
 sub drop_table {
... ...
@@ -373,8 +338,11 @@ sub drop_table {
373 338
     # Drop table
374 339
     my $sql = "drop table $table;";
375 340
 
341
+    # Connect
342
+    $self->connect unless $self->connected;
343
+
376 344
     # Do query
377
-    return $self->do($sql);
345
+    return $self->dbh->do($sql);
378 346
 }
379 347
 
380 348
 our %VALID_INSERT_ARGS = map { $_ => 1 } qw/append filter/;
... ...
@@ -1122,33 +1090,8 @@ You can also edit query
1122 1090
         }
1123 1091
     }
1124 1092
 
1125
-=head2 prepare
1126
-
1127
-Prepare statement handle.
1128
-
1129
-    $sth = $dbi->prepare('select * from books;');
1130
-
1131
-This method is same as DBI prepare method.
1132
-
1133
-See also L<DBI>.
1134
-
1135
-=head2 do
1136
-
1137
-Execute SQL
1138
-
1139
-    $affected = $dbi->do('insert into books (title, author) values (?, ?)',
1140
-                        'Perl', 'taro');
1141
-
1142
-Retrun value is affected rows count.
1143
-
1144
-This method is same as DBI do method.
1145
-
1146
-See also L<DBI>
1147
-
1148 1093
 =head2 run_transaction
1149 1094
 
1150
-
1151
-
1152 1095
 =head1 DBIx::Custom default configuration
1153 1096
 
1154 1097
 DBIx::Custom have DBI object.
+1 -1
lib/DBIx/Custom/SQLTemplate.pm
... ...
@@ -18,7 +18,7 @@ __PACKAGE__->dual_attr('tag_end',   default => '}', inherit => 'scalar_copy');
18 18
 __PACKAGE__->dual_attr('tag_syntax', inherit => 'scalar_copy');
19 19
 
20 20
 __PACKAGE__->resist_tag_processor(
21
-    '?'      => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag,
21
+    '?'      => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_placeholder_tag,
22 22
     '='      => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag,
23 23
     '<>'     => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag,
24 24
     '>'      => \&DBIx::Custom::SQLTemplate::TagProcessors::expand_basic_tag,
+4 -4
lib/DBIx/Custom/SQLTemplate/TagProcessor.pm
... ...
@@ -38,13 +38,13 @@ sub expand_in_tag {
38 38
     my ($column, $count) = @$tag_args;
39 39
     
40 40
     # Key must be specified
41
-    croak("You must be pass key as first argument of tag '{$tag_name }'\n" . 
42
-          "Usage: {$tag_name \$key \$count}")
41
+    croak("You must be pass key as first argument of tag '{in }'\n" . 
42
+          "Usage: {in \$key \$count}")
43 43
       unless $column;
44 44
     
45 45
     # Place holder count must be specified
46
-    croak("You must be pass placeholder count as second argument of tag '{$tag_name }'\n" . 
47
-          "Usage: {$tag_name \$key \$count}")
46
+    croak("You must be pass value count as second argument of tag '{in }'\n" . 
47
+          "Usage: {in \$key \$count}")
48 48
       if !$count || $count =~ /\D/;
49 49
 
50 50
     # Expand tag
+1 -1
t/00-load.t 1000644 → 1000755
... ...
@@ -8,7 +8,7 @@ BEGIN {
8 8
 	use_ok( 'DBIx::Custom::MySQL' );
9 9
 	use_ok( 'DBIx::Custom::Query' );
10 10
 	use_ok( 'DBIx::Custom::Result' );
11
-	use_ok( 'DBIx::Custom::SQL::Template' );
11
+	use_ok( 'DBIx::Custom::SQLTemplate' );
12 12
 	use_ok( 'DBIx::Custom::SQLite' );
13 13
 }
14 14
 
+43 -68
t/dbix-custom-core-sqlite.t
... ...
@@ -72,22 +72,6 @@ $dbi->connect;
72 72
 ok($dbi->connected, "$test : connected");
73 73
 
74 74
 
75
-test 'preapare';
76
-$dbi = DBIx::Custom->new($NEW_ARGS->{0});
77
-$sth = $dbi->prepare($CREATE_TABLE->{0});
78
-ok($sth, "$test : auto connect");
79
-$sth->execute;
80
-$sth = $dbi->prepare($DROP_TABLE->{0});
81
-ok($sth, "$test : basic");
82
-
83
-
84
-test 'do';
85
-$dbi = DBIx::Custom->new($NEW_ARGS->{0});
86
-$ret_val = $dbi->do($CREATE_TABLE->{0});
87
-ok(defined $ret_val, "$test : auto connect");
88
-$ret_val = $dbi->do($DROP_TABLE->{0});
89
-ok(defined $ret_val, "$test : basic");
90
-
91 75
 test 'create_table';
92 76
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
93 77
 $ret_val = $dbi->create_table(
... ...
@@ -109,11 +93,9 @@ ok($@, "$test : table not exist");
109 93
 # Prepare table
110 94
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
111 95
 $dbi->connect;
112
-$dbi->do($CREATE_TABLE->{0});
113
-$sth = $dbi->prepare("insert into table1 (key1, key2) values (?, ?);");
114
-$sth->execute(1, 2);
115
-$sth->execute(3, 4);
116
-
96
+$dbi->query($CREATE_TABLE->{0});
97
+$dbi->insert('table1', {key1 => 1, key2 => 2});
98
+$dbi->insert('table1', {key1 => 3, key2 => 4});
117 99
 
118 100
 test 'DBIx::Custom::Result test';
119 101
 $tmpl = "select key1, key2 from table1";
... ...
@@ -165,8 +147,8 @@ is_deeply(\@rows, [[1, 2], [3, 4]], "$test : fetch_hash_all list context");
165 147
 
166 148
 
167 149
 test 'Insert query return value';
168
-$dbi->do($DROP_TABLE->{0});
169
-$dbi->do($CREATE_TABLE->{0});
150
+$dbi->query($DROP_TABLE->{0});
151
+$dbi->query($CREATE_TABLE->{0});
170 152
 $tmpl = "insert into table1 {insert key1 key2}";
171 153
 $query = $dbi->create_query($tmpl);
172 154
 $ret_val = $dbi->query($query, {key1 => 1, key2 => 2});
... ...
@@ -174,8 +156,8 @@ ok($ret_val, $test);
174 156
 
175 157
 
176 158
 test 'Direct query';
177
-$dbi->do($DROP_TABLE->{0});
178
-$dbi->do($CREATE_TABLE->{0});
159
+$dbi->query($DROP_TABLE->{0});
160
+$dbi->query($CREATE_TABLE->{0});
179 161
 $insert_tmpl = "insert into table1 {insert key1 key2}";
180 162
 $dbi->query($insert_tmpl, {key1 => 1, key2 => 2});
181 163
 $result = $dbi->query($SELECT_TMPLS->{0});
... ...
@@ -183,8 +165,8 @@ $rows = $result->fetch_hash_all;
183 165
 is_deeply($rows, [{key1 => 1, key2 => 2}], $test);
184 166
 
185 167
 test 'Filter basic';
186
-$dbi->do($DROP_TABLE->{0});
187
-$dbi->do($CREATE_TABLE->{0});
168
+$dbi->query($DROP_TABLE->{0});
169
+$dbi->query($CREATE_TABLE->{0});
188 170
 $dbi->resist_filter(twice       => sub { $_[0] * 2}, 
189 171
                     three_times => sub { $_[0] * 3});
190 172
 
... ...
@@ -195,10 +177,10 @@ $dbi->query($insert_query, {key1 => 1, key2 => 2});
195 177
 $result = $dbi->query($SELECT_TMPLS->{0});
196 178
 $rows = $result->filter({key2 => 'three_times'})->fetch_hash_all;
197 179
 is_deeply($rows, [{key1 => 2, key2 => 6}], "$test : filter fetch_filter");
198
-$dbi->do($DROP_TABLE->{0});
180
+$dbi->query($DROP_TABLE->{0});
199 181
 
200 182
 test 'Filter in';
201
-$dbi->do($CREATE_TABLE->{0});
183
+$dbi->query($CREATE_TABLE->{0});
202 184
 $insert_tmpl  = "insert into table1 {insert key1 key2};";
203 185
 $insert_query = $dbi->create_query($insert_tmpl);
204 186
 $dbi->query($insert_query, {key1 => 2, key2 => 4});
... ...
@@ -210,11 +192,10 @@ $rows = $result->fetch_hash_all;
210 192
 is_deeply($rows, [{key1 => 2, key2 => 4}], "$test : filter");
211 193
 
212 194
 test 'DBIx::Custom::SQLTemplate basic tag';
213
-$dbi->do($DROP_TABLE->{0});
214
-$dbi->do($CREATE_TABLE->{1});
215
-$sth = $dbi->prepare("insert into table1 (key1, key2, key3, key4, key5) values (?, ?, ?, ?, ?);");
216
-$sth->execute(1, 2, 3, 4, 5);
217
-$sth->execute(6, 7, 8, 9, 10);
195
+$dbi->query($DROP_TABLE->{0});
196
+$dbi->query($CREATE_TABLE->{1});
197
+$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
198
+$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
218 199
 
219 200
 $tmpl = "select * from table1 where {= key1} and {<> key2} and {< key3} and {> key4} and {>= key5};";
220 201
 $query = $dbi->create_query($tmpl);
... ...
@@ -229,11 +210,10 @@ $rows = $result->fetch_hash_all;
229 210
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic tag2");
230 211
 
231 212
 test 'DIB::Custom::SQLTemplate in tag';
232
-$dbi->do($DROP_TABLE->{0});
233
-$dbi->do($CREATE_TABLE->{1});
234
-$sth = $dbi->prepare("insert into table1 (key1, key2, key3, key4, key5) values (?, ?, ?, ?, ?);");
235
-$sth->execute(1, 2, 3, 4, 5);
236
-$sth->execute(6, 7, 8, 9, 10);
213
+$dbi->query($DROP_TABLE->{0});
214
+$dbi->query($CREATE_TABLE->{1});
215
+$dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
216
+$dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
237 217
 
238 218
 $tmpl = "select * from table1 where {in key1 2};";
239 219
 $query = $dbi->create_query($tmpl);
... ...
@@ -242,7 +222,7 @@ $rows = $result->fetch_hash_all;
242 222
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
243 223
 
244 224
 test 'DBIx::Custom::SQLTemplate insert tag';
245
-$dbi->do("delete from table1");
225
+$dbi->query("delete from table1");
246 226
 $insert_tmpl = 'insert into table1 {insert key1 key2 key3 key4 key5}';
247 227
 $dbi->query($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
248 228
 
... ...
@@ -251,7 +231,7 @@ $rows = $result->fetch_hash_all;
251 231
 is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "$test : basic");
252 232
 
253 233
 test 'DBIx::Custom::SQLTemplate update tag';
254
-$dbi->do("delete from table1");
234
+$dbi->query("delete from table1");
255 235
 $insert_tmpl = "insert into table1 {insert key1 key2 key3 key4 key5}";
256 236
 $dbi->query($insert_tmpl, {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
257 237
 $dbi->query($insert_tmpl, {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
... ...
@@ -265,8 +245,8 @@ is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
265 245
                   {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "$test : basic");
266 246
 
267 247
 test 'transaction';
268
-$dbi->do($DROP_TABLE->{0});
269
-$dbi->do($CREATE_TABLE->{0});
248
+$dbi->query($DROP_TABLE->{0});
249
+$dbi->query($CREATE_TABLE->{0});
270 250
 $dbi->run_transaction(sub {
271 251
     $insert_tmpl = 'insert into table1 {insert key1 key2}';
272 252
     $dbi->query($insert_tmpl, {key1 => 1, key2 => 2});
... ...
@@ -276,8 +256,8 @@ $result = $dbi->query($SELECT_TMPLS->{0});
276 256
 $rows   = $result->fetch_hash_all;
277 257
 is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : commit");
278 258
 
279
-$dbi->do($DROP_TABLE->{0});
280
-$dbi->do($CREATE_TABLE->{0});
259
+$dbi->query($DROP_TABLE->{0});
260
+$dbi->query($CREATE_TABLE->{0});
281 261
 $dbi->dbh->{RaiseError} = 0;
282 262
 eval{
283 263
     $dbi->run_transaction(sub {
... ...
@@ -313,13 +293,8 @@ like($@, qr/AutoCommit must be true before transaction start/,
313 293
 
314 294
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
315 295
 $sql = 'laksjdf';
316
-eval{$dbi->prepare($sql)};
317
-like($@, qr/$sql/, "$test : prepare fail");
318
-
319
-$dbi = DBIx::Custom->new($NEW_ARGS->{0});
320
-$sql = 'laksjdf';
321
-eval{$dbi->do($sql, qw/1 2 3/)};
322
-like($@, qr/$sql/, "$test : do fail");
296
+eval{$dbi->query($sql, qw/1 2 3/)};
297
+like($@, qr/$sql/, "$test : query fail");
323 298
 
324 299
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
325 300
 eval{$dbi->create_query("{p }")};
... ...
@@ -327,22 +302,22 @@ ok($@, "$test : create_query invalid SQL template");
327 302
 
328 303
 test 'insert';
329 304
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
330
-$dbi->do($CREATE_TABLE->{0});
305
+$dbi->query($CREATE_TABLE->{0});
331 306
 $dbi->insert('table1', {key1 => 1, key2 => 2});
332 307
 $dbi->insert('table1', {key1 => 3, key2 => 4});
333 308
 $result = $dbi->query($SELECT_TMPLS->{0});
334 309
 $rows   = $result->fetch_hash_all;
335 310
 is_deeply($rows, [{key1 => 1, key2 => 2}, {key1 => 3, key2 => 4}], "$test : basic");
336 311
 
337
-$dbi->do('delete from table1');
312
+$dbi->query('delete from table1');
338 313
 $dbi->resist_filter(three_times => sub { $_[0] * 3});
339 314
 $dbi->insert('table1', {key1 => 1, key2 => 2}, {filter => {key1 => 'three_times'}});
340 315
 $result = $dbi->query($SELECT_TMPLS->{0});
341 316
 $rows   = $result->fetch_hash_all;
342 317
 is_deeply($rows, [{key1 => 3, key2 => 2}], "$test : filter");
343 318
 
344
-$dbi->do($DROP_TABLE->{0});
345
-$dbi->do($CREATE_TABLE->{0});
319
+$dbi->query($DROP_TABLE->{0});
320
+$dbi->query($CREATE_TABLE->{0});
346 321
 $dbi->insert('table1', {key1 => 1, key2 => 2}, {append => '   '});
347 322
 $rows = $dbi->select('table1')->fetch_hash_all;
348 323
 is_deeply($rows, [{key1 => 1, key2 => 2}], 'insert append');
... ...
@@ -354,7 +329,7 @@ like($@, qr/Key-value pairs for insert must be specified to 'insert' second argu
354 329
 
355 330
 test 'update';
356 331
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
357
-$dbi->do($CREATE_TABLE->{1});
332
+$dbi->query($CREATE_TABLE->{1});
358 333
 $dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
359 334
 $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
360 335
 $dbi->update('table1', {key2 => 11}, {where => {key1 => 1}});
... ...
@@ -364,7 +339,7 @@ is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
364 339
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
365 340
                   "$test : basic");
366 341
                   
367
-$dbi->do("delete from table1");
342
+$dbi->query("delete from table1");
368 343
 $dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
369 344
 $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
370 345
 $dbi->update('table1', {key2 => 12}, {where => {key2 => 2, key3 => 3}});
... ...
@@ -374,7 +349,7 @@ is_deeply($rows, [{key1 => 1, key2 => 12, key3 => 3, key4 => 4, key5 => 5},
374 349
                   {key1 => 6, key2 => 7,  key3 => 8, key4 => 9, key5 => 10}],
375 350
                   "$test : update key same as search key");
376 351
 
377
-$dbi->do("delete from table1");
352
+$dbi->query("delete from table1");
378 353
 $dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
379 354
 $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
380 355
 $dbi->resist_filter(twice => sub { $_[0] * 2 });
... ...
@@ -391,7 +366,7 @@ $result = $dbi->update('table1', {key2 => 11}, {where => {key1 => 1}, append =>
391 366
 
392 367
 test 'update error';
393 368
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
394
-$dbi->do($CREATE_TABLE->{1});
369
+$dbi->query($CREATE_TABLE->{1});
395 370
 eval{$dbi->update('table1')};
396 371
 like($@, qr/Key-value pairs for update must be specified to 'update' second argument/,
397 372
          "$test : update key-value pairs not specified");
... ...
@@ -402,7 +377,7 @@ like($@, qr/Key-value pairs for where clause must be specified to 'update' third
402 377
 
403 378
 test 'update_all';
404 379
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
405
-$dbi->do($CREATE_TABLE->{1});
380
+$dbi->query($CREATE_TABLE->{1});
406 381
 $dbi->insert('table1', {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
407 382
 $dbi->insert('table1', {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
408 383
 $dbi->resist_filter(twice => sub { $_[0] * 2 });
... ...
@@ -416,7 +391,7 @@ is_deeply($rows, [{key1 => 1, key2 => 20, key3 => 3, key4 => 4, key5 => 5},
416 391
 
417 392
 test 'delete';
418 393
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
419
-$dbi->do($CREATE_TABLE->{0});
394
+$dbi->query($CREATE_TABLE->{0});
420 395
 $dbi->insert('table1', {key1 => 1, key2 => 2});
421 396
 $dbi->insert('table1', {key1 => 3, key2 => 4});
422 397
 $dbi->delete('table1', {where => {key1 => 1}});
... ...
@@ -424,7 +399,7 @@ $result = $dbi->query($SELECT_TMPLS->{0});
424 399
 $rows   = $result->fetch_hash_all;
425 400
 is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : basic");
426 401
 
427
-$dbi->do("delete from table1;");
402
+$dbi->query("delete from table1;");
428 403
 $dbi->insert('table1', {key1 => 1, key2 => 2});
429 404
 $dbi->insert('table1', {key1 => 3, key2 => 4});
430 405
 $dbi->resist_filter(twice => sub { $_[0] * 2 });
... ...
@@ -445,14 +420,14 @@ is_deeply($rows, [{key1 => 3, key2 => 4}], "$test : delete multi key");
445 420
 
446 421
 test 'delete error';
447 422
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
448
-$dbi->do($CREATE_TABLE->{0});
423
+$dbi->query($CREATE_TABLE->{0});
449 424
 eval{$dbi->delete('table1')};
450 425
 like($@, qr/Key-value pairs for where clause must be specified to 'delete' second argument/,
451 426
          "$test : where key-value pairs not specified");
452 427
 
453 428
 test 'delete_all';
454 429
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
455
-$dbi->do($CREATE_TABLE->{0});
430
+$dbi->query($CREATE_TABLE->{0});
456 431
 $dbi->insert('table1', {key1 => 1, key2 => 2});
457 432
 $dbi->insert('table1', {key1 => 3, key2 => 4});
458 433
 $dbi->delete_all('table1');
... ...
@@ -463,7 +438,7 @@ is_deeply($rows, [], "$test : basic");
463 438
 
464 439
 test 'select';
465 440
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
466
-$dbi->do($CREATE_TABLE->{0});
441
+$dbi->query($CREATE_TABLE->{0});
467 442
 $dbi->insert('table1', {key1 => 1, key2 => 2});
468 443
 $dbi->insert('table1', {key1 => 3, key2 => 4});
469 444
 $rows = $dbi->select('table1')->fetch_hash_all;
... ...
@@ -487,7 +462,7 @@ $rows = $dbi->select('table1', {where => {key1 => 2}, filter => {key1 => 'decrem
487 462
             ->fetch_hash_all;
488 463
 is_deeply($rows, [{key1 => 1, key2 => 2}], "$test : filter");
489 464
 
490
-$dbi->do($CREATE_TABLE->{2});
465
+$dbi->query($CREATE_TABLE->{2});
491 466
 $dbi->insert('table2', {key1 => 1, key3 => 5});
492 467
 $rows = $dbi->select([qw/table1 table2/],
493 468
                       {
... ...
@@ -501,7 +476,7 @@ is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}], "
501 476
 test 'Cache';
502 477
 $dbi = DBIx::Custom->new($NEW_ARGS->{0});
503 478
 DBIx::Custom->query_cache_max(2);
504
-$dbi->do($CREATE_TABLE->{0});
479
+$dbi->query($CREATE_TABLE->{0});
505 480
 delete $DBIx::Custom::CLASS_ATTRS->{_query_caches};
506 481
 delete $DBIx::Custom::CLASS_ATTRS->{_query_cache_keys};
507 482
 $tmpls[0] = "insert into table1 {insert key1 key2}";
+8 -8
t/dbix-custom-core.t
... ...
@@ -3,7 +3,7 @@ use strict;
3 3
 use warnings;
4 4
 
5 5
 use DBIx::Custom;
6
-use DBIx::Custom::SQL::Template;
6
+use DBIx::Custom::SQLTemplate;
7 7
 
8 8
 # Function for test name
9 9
 my $test;
... ...
@@ -13,9 +13,9 @@ sub test {
13 13
 
14 14
 # Variables for test
15 15
 our $SQL_TMPL = {
16
-    0 => DBIx::Custom::SQL::Template->new->tag_start(0),
17
-    1 => DBIx::Custom::SQL::Template->new->tag_start(1),
18
-    2 => DBIx::Custom::SQL::Template->new->tag_start(2)
16
+    0 => DBIx::Custom::SQLTemplate->new->tag_start(0),
17
+    1 => DBIx::Custom::SQLTemplate->new->tag_start(1),
18
+    2 => DBIx::Custom::SQLTemplate->new->tag_start(2)
19 19
 };
20 20
 my $dbi;
21 21
 
... ...
@@ -111,14 +111,14 @@ is_deeply($dbi->formats, {f => 3}, "$test : formats");
111 111
 isa_ok($dbi, 'DBIx::Custom');
112 112
 
113 113
 
114
-test 'add_filters';
114
+test 'resist_filters';
115 115
 $dbi = DBIx::Custom->new;
116
-$dbi->add_filter(a => sub {1});
116
+$dbi->resist_filter(a => sub {1});
117 117
 is($dbi->filters->{a}->(), 1, $test);
118 118
 
119
-test 'add_formats';
119
+test 'resist_formats';
120 120
 $dbi = DBIx::Custom->new;
121
-$dbi->add_format(a => sub {1});
121
+$dbi->resist_format(a => sub {1});
122 122
 is($dbi->formats->{a}->(), 1, $test);
123 123
 
124 124
 test 'Accessor';
+4 -4
t/dbix-custom-query.t
... ...
@@ -16,14 +16,14 @@ my $query;
16 16
 test 'Accessors';
17 17
 $query = DBIx::Custom::Query->new(
18 18
     sql              => 'a',
19
-    key_infos        => 'b',
20
-    query_filter      => 'c',
19
+    columns        => 'b',
20
+    filter      => 'c',
21 21
     sth              => 'e',
22 22
     fetch_filter     => 'f',
23 23
 );
24 24
 
25 25
 is($query->sql, 'a', "$test : sql");
26
-is($query->key_infos, 'b', "$test : key_infos ");
27
-is($query->query_filter, 'c', "$test : query_filter");
26
+is($query->columns, 'b', "$test : columns ");
27
+is($query->filter, 'c', "$test : filter");
28 28
 is($query->sth, 'e', "$test : sth");
29 29
 
+9 -16
t/dbix-custom-result-sqlite.t
... ...
@@ -33,7 +33,7 @@ my $row;
33 33
 my @rows;
34 34
 my $rows;
35 35
 my $result;
36
-my $fetch_filter;
36
+my $filter;
37 37
 my @error;
38 38
 my $error;
39 39
 
... ...
@@ -207,25 +207,18 @@ is_deeply(\@rows, [[1, 2], [3, 4]], $test);
207 207
 
208 208
 
209 209
 test 'fetch filter';
210
-$fetch_filter = sub {
211
-    my ($value, $key, $dbi, $infos) = @_;
212
-    my ($type, $sth, $i) = @{$infos}{qw/type sth index/};
213
-    
214
-    if ($key eq 'key1' && $value == 1 && $type =~ /char/i && $i == 0 && $sth->{TYPE}->[$i] eq $type) {
215
-        return $value * 3;
216
-    }
217
-    return $value;
218
-};
219
-
220
-$result = query($dbh, $sql);
221
-$result->fetch_filter($fetch_filter);
210
+$result = query($dbh, $sql);
211
+$result->filters({three_times => sub { $_[0] * 3}});
212
+$result->filter({key1 => 'three_times'});
213
+
222 214
 $rows = $result->fetch_all;
223
-is_deeply($rows, [[3, 2], [3, 4]], "$test array");
215
+is_deeply($rows, [[3, 2], [9, 4]], "$test array");
224 216
 
225 217
 $result = query($dbh, $sql);
226
-$result->fetch_filter($fetch_filter);
218
+$result->filters({three_times => sub { $_[0] * 3}});
219
+$result->filter({key1 => 'three_times'});
227 220
 $rows = $result->fetch_hash_all;
228
-is_deeply($rows, [{key1 => 3, key2 => 2}, {key1 => 3, key2 => 4}], "$test hash");
221
+is_deeply($rows, [{key1 => 3, key2 => 2}, {key1 => 9, key2 => 4}], "$test hash");
229 222
 
230 223
 test 'finish';
231 224
 $result = query($dbh, $sql);
+27 -48
t/dbix-custom-sql-template.t
... ...
@@ -3,7 +3,7 @@ use warnings;
3 3
 
4 4
 use Test::More 'no_plan';
5 5
 
6
-use DBIx::Custom::SQL::Template;
6
+use DBIx::Custom::SQLTemplate;
7 7
 
8 8
 # Function for test name
9 9
 my $test;
... ...
@@ -24,26 +24,13 @@ $datas = [
24 24
     {   name            => 'placeholder basic',
25 25
         tmpl            => "a {?  k1} b {=  k2} {<> k3} {>  k4} {<  k5} {>= k6} {<= k7} {like k8}", ,
26 26
         sql_expected    => "a ? b k2 = ? k3 <> ? k4 > ? k5 < ? k6 >= ? k7 <= ? k8 like ?;",
27
-        key_infos_expected   => [
28
-            {table => '', column => 'k1', id => ''},
29
-            {table => '', column => 'k2', id => ''},
30
-            {table => '', column => 'k3', id => ''},
31
-            {table => '', column => 'k4', id => ''},
32
-            {table => '', column => 'k5', id => ''},
33
-            {table => '', column => 'k6', id => ''},
34
-            {table => '', column => 'k7', id => ''},
35
-            {table => '', column => 'k8', id => ''},
36
-        ],
27
+        columns_expected   => [qw/k1 k2 k3 k4 k5 k6 k7 k8/]
37 28
     },
38 29
     {
39 30
         name            => 'placeholder in',
40 31
         tmpl            => "{in k1 3};",
41 32
         sql_expected    => "k1 in (?, ?, ?);",
42
-        key_infos_expected   => [
43
-            {table => '', column => 'k1', id => '', pos => 0},
44
-            {table => '', column => 'k1', id => '', pos => 1},
45
-            {table => '', column => 'k1', id => '', pos => 2},
46
-        ],
33
+        columns_expected   => [qw/k1 k1 k1/]
47 34
     },
48 35
     
49 36
     # Table name
... ...
@@ -51,87 +38,79 @@ $datas = [
51 38
         name            => 'placeholder with table name',
52 39
         tmpl            => "{= a.k1} {= a.k2}",
53 40
         sql_expected    => "a.k1 = ? a.k2 = ?;",
54
-        key_infos_expected  => [
55
-            {table => 'a', column => 'k1', id => ''},
56
-            {table => 'a', column => 'k2', id => ''},
57
-        ],
41
+        columns_expected  => [qw/a.k1 a.k2/]
58 42
     },
59 43
     {   
60 44
         name            => 'placeholder in with table name',
61 45
         tmpl            => "{in a.k1 2} {in b.k2 2}",
62 46
         sql_expected    => "a.k1 in (?, ?) b.k2 in (?, ?);",
63
-        key_infos_expected  => [
64
-            {table => 'a', column => 'k1', id => '', pos => 0},
65
-            {table => 'a', column => 'k1', id => '', pos => 1},
66
-            {table => 'b', column => 'k2', id => '', pos => 0},
67
-            {table => 'b', column => 'k2', id => '', pos => 1},
68
-        ],
47
+        columns_expected  => [qw/a.k1 a.k1 b.k2 b.k2/]
69 48
     },
70 49
     {
71 50
         name            => 'not contain tag',
72 51
         tmpl            => "aaa",
73 52
         sql_expected    => "aaa;",
74
-        key_infos_expected  => [],
53
+        columns_expected  => [],
75 54
     }
76 55
 ];
77 56
 
78 57
 for (my $i = 0; $i < @$datas; $i++) {
79 58
     my $data = $datas->[$i];
80
-    my $sql_tmpl = DBIx::Custom::SQL::Template->new;
59
+    my $sql_tmpl = DBIx::Custom::SQLTemplate->new;
81 60
     my $query = $sql_tmpl->create_query($data->{tmpl});
82 61
     is($query->{sql}, $data->{sql_expected}, "$test : $data->{name} : sql");
83
-    is_deeply($query->{key_infos}, $data->{key_infos_expected}, "$test : $data->{name} : key_infos");
62
+    is_deeply($query->{columns}, $data->{columns_expected}, "$test : $data->{name} : columns");
84 63
 }
85 64
 
86 65
 
87 66
 test 'Original tag processor';
88
-$sql_tmpl = DBIx::Custom::SQL::Template->new;
67
+$sql_tmpl = DBIx::Custom::SQLTemplate->new;
89 68
 
90
-$ret_val = $sql_tmpl->add_tag_processor(
69
+$ret_val = $sql_tmpl->resist_tag_processor(
91 70
     p => sub {
92 71
         my ($tag_name, $args) = @_;
93 72
         
94 73
         my $expand    = "$tag_name ? $args->[0] $args->[1]";
95
-        my $key_infos = [2];
96
-        return ($expand, $key_infos);
74
+        my $columns = [2];
75
+        return ($expand, $columns);
97 76
     }
98 77
 );
99 78
 
100 79
 $query = $sql_tmpl->create_query("{p a b}");
101
-is($query->{sql}, "p ? a b;", "$test : add_tag_processor sql");
102
-is_deeply($query->{key_infos}, [2], "$test : add_tag_processor key_infos");
103
-isa_ok($ret_val, 'DBIx::Custom::SQL::Template');
80
+is($query->{sql}, "p ? a b;", "$test : resist_tag_processor sql");
81
+is_deeply($query->{columns}, [2], "$test : resist_tag_processor columns");
82
+isa_ok($ret_val, 'DBIx::Custom::SQLTemplate');
104 83
 
105 84
 
106 85
 test "Tag processor error case";
107
-$sql_tmpl = DBIx::Custom::SQL::Template->new;
86
+$sql_tmpl = DBIx::Custom::SQLTemplate->new;
108 87
 
109 88
 
110 89
 eval{$sql_tmpl->create_query("{a }")};
111 90
 like($@, qr/Tag '{a }' in SQL template is not exist/, "$test : tag_processor not exist");
112 91
 
113
-$sql_tmpl->add_tag_processor({
92
+$sql_tmpl->resist_tag_processor({
114 93
     q => 'string'
115 94
 });
116 95
 
117 96
 eval{$sql_tmpl->create_query("{q}", {})};
118 97
 like($@, qr/Tag processor 'q' must be code reference/, "$test : tag_processor not code ref");
119 98
 
120
-$sql_tmpl->add_tag_processor({
99
+$sql_tmpl->resist_tag_processor({
121 100
    r => sub {} 
122 101
 });
123 102
 
124 103
 eval{$sql_tmpl->create_query("{r}")};
125
-like($@, qr/\QTag processor 'r' must return (\E\$expand\Q, \E\$key_infos\Q)/, "$test : tag processor return noting");
104
+like($@, qr/\QTag processor 'r' must return (\E\$expand\Q, \E\$columns\Q)/, "$test : tag processor return noting");
126 105
 
127
-$sql_tmpl->add_tag_processor({
106
+$sql_tmpl->resist_tag_processor({
128 107
    s => sub { return ("a", "")} 
129 108
 });
130 109
 
131 110
 eval{$sql_tmpl->create_query("{s}")};
132
-like($@, qr/\QTag processor 's' must return (\E\$expand\Q, \E\$key_infos\Q)/, "$test : tag processor return not array key_infos");
111
+like($@, qr/\QTag processor 's' must return (\E\$expand\Q, \E\$columns\Q)/, "$test : tag processor return not array columns");
133 112
 
134
-$sql_tmpl->add_tag_processor(
113
+$sql_tmpl->resist_tag_processor(
135 114
     t => sub {return ("a", [])}
136 115
 );
137 116
 
... ...
@@ -140,8 +119,8 @@ like($@, qr/Tag '{t }' arguments cannot contain '?'/, "$test : cannot contain '?
140 119
 
141 120
 
142 121
 test 'General error case';
143
-$sql_tmpl = DBIx::Custom::SQL::Template->new;
144
-$sql_tmpl->add_tag_processor(
122
+$sql_tmpl = DBIx::Custom::SQLTemplate->new;
123
+$sql_tmpl->resist_tag_processor(
145 124
     a => sub {
146 125
         return ("? ? ?", [[],[]]);
147 126
     }
... ...
@@ -158,16 +137,16 @@ eval{$sql_tmpl->create_query("{in }")};
158 137
 like($@, qr/You must be pass key as first argument of tag '{in }'/, "$test : in : key not exist");
159 138
 
160 139
 eval{$sql_tmpl->create_query("{in a}")};
161
-like($@, qr/\QYou must be pass placeholder count as second argument of tag '{in }'\E\n\QUsage: {in \E\$key\Q \E\$placeholder_count\Q}/,
140
+like($@, qr/\QYou must be pass value count as second argument of tag '{in }'\E\n\QUsage: {in \E\$key\Q \E\$count\Q}/,
162 141
      "$test : in : key not exist");
163 142
 
164 143
 eval{$sql_tmpl->create_query("{in a r}")};
165
-like($@, qr/\QYou must be pass placeholder count as second argument of tag '{in }'\E\n\QUsage: {in \E\$key\Q \E\$placeholder_count\Q}/,
144
+like($@, qr/\QYou must be pass value count as second argument of tag '{in }'\E\n\QUsage: {in \E\$key\Q \E\$count\Q}/,
166 145
      "$test : in : key not exist");
167 146
 
168 147
 
169 148
 test 'Clone';
170
-$sql_tmpl = DBIx::Custom::SQL::Template->new;
149
+$sql_tmpl = DBIx::Custom::SQLTemplate->new;
171 150
 $sql_tmpl
172 151
   ->tag_start('[')
173 152
   ->tag_end(']')
+5 -5
t/dbix-custom-sqlite.t
... ...
@@ -37,7 +37,7 @@ my $id;
37 37
 test 'connect_memory';
38 38
 $dbi = DBIx::Custom::SQLite->new;
39 39
 $dbi->connect_memory;
40
-$ret_val = $dbi->do($CREATE_TABLE->{0});
40
+$ret_val = $dbi->query($CREATE_TABLE->{0});
41 41
 ok(defined $ret_val, $test);
42 42
 $dbi->insert('table1', {key1 => 'a', key2 => 2});
43 43
 $rows = $dbi->select('table1', {where => {key1 => 'a'}})->fetch_hash_all;
... ...
@@ -50,10 +50,10 @@ like($@, qr/Already connected/, "$test : already connected");
50 50
 test 'reconnect_memory';
51 51
 $dbi = DBIx::Custom::SQLite->new;
52 52
 $dbi->reconnect_memory;
53
-$ret_val = $dbi->do($CREATE_TABLE->{0});
53
+$ret_val = $dbi->query($CREATE_TABLE->{0});
54 54
 ok(defined $ret_val, "$test : connect first");
55 55
 $dbi->reconnect_memory;
56
-$ret_val = $dbi->do($CREATE_TABLE->{2});
56
+$ret_val = $dbi->query($CREATE_TABLE->{2});
57 57
 ok(defined $ret_val, "$test : connect first");
58 58
 
59 59
 test 'connect';
... ...
@@ -62,7 +62,7 @@ unlink $db_file if -f $db_file;
62 62
 $dbi = DBIx::Custom::SQLite->new(database => $db_file);
63 63
 $dbi->connect;
64 64
 ok(-f $db_file, "$test : database file");
65
-$ret_val = $dbi->do($CREATE_TABLE->{0});
65
+$ret_val = $dbi->query($CREATE_TABLE->{0});
66 66
 ok(defined $ret_val, "$test : database");
67 67
 $dbi->disconnect;
68 68
 unlink $db_file if -f $db_file;
... ...
@@ -70,7 +70,7 @@ unlink $db_file if -f $db_file;
70 70
 test 'last_insert_rowid';
71 71
 $dbi = DBIx::Custom::SQLite->new;
72 72
 $dbi->connect_memory;
73
-$ret_val = $dbi->do($CREATE_TABLE->{0});
73
+$ret_val = $dbi->query($CREATE_TABLE->{0});
74 74
 $dbi->insert('table1', {key1 => 1, key2 => 2});
75 75
 is($dbi->last_insert_rowid, 1, "$test: first");
76 76
 $dbi->insert('table1', {key1 => 1, key2 => 2});