Showing 1 changed files with 72 additions and 50 deletions
+72 -50
lib/DBIx/Custom.pm
... ...
@@ -145,7 +145,7 @@ sub update {
145 145
     my @where_keys = keys %$where;
146 146
     
147 147
     # Not exists where keys
148
-    croak qq{"where" must contain column-value pair}
148
+    croak qq{"where" must contain the pairs of column name and value}
149 149
       if !@where_keys && !$allow_update_all;
150 150
     
151 151
     # Update clause
... ...
@@ -634,7 +634,7 @@ you connect database easily.
634 634
     use DBIx::Custom::SQLite;
635 635
     my $dbi = DBIx::Custom::SQLite->connect(database => 'dbname');
636 636
     
637
-If database is  MySQL, use L<DBIx::Costom::MySQL>.
637
+If database is  MySQL, use L<DBIx::Custom::MySQL>.
638 638
 
639 639
     use DBIx::Custom::MySQL;
640 640
     my $dbi = DBIx::Custom::MySQL->connect(
... ...
@@ -826,7 +826,7 @@ Fetch all rows into array of hash
826 826
 
827 827
     my $rows = $result->fetch_hash_all;
828 828
 
829
-If you want to access statement handle of L<DBI>, use C<sth()> attribute.
829
+If you want to access statement handle of L<DBI>, use C<sth> attribute.
830 830
 
831 831
     my $sth = $result->sth;
832 832
 
... ...
@@ -914,7 +914,7 @@ You can specify these filters to C<filter> argument of C<execute()> method.
914 914
     );
915 915
 
916 916
 C<filter> argument can be specified to suger methods, such as
917
-C<insert()>, C<update()>, C<update_all>,
917
+C<insert()>, C<update()>, C<update_all()>,
918 918
 C<delete()>, C<delete_all()>, C<select()>.
919 919
 
920 920
     # insert(), having filter argument
... ...
@@ -984,7 +984,7 @@ Note that in fetch filter, column names must be lower case
984 984
 even if the column name conatains upper case charactors.
985 985
 This is requirment not to depend database systems.
986 986
 
987
-=head2 7. Performance
987
+=head2 7. Get high performance
988 988
 
989 989
 =head3 Disable filter checking
990 990
 
... ...
@@ -1010,8 +1010,16 @@ In that case, you can prepare a query by C<create_query()> method.
1010 1010
     my $query = $dbi->create_query(
1011 1011
         "insert into books {insert_param title author};"
1012 1012
     );
1013
-    
1014
-Execute query repeatedly
1013
+
1014
+Return value of C<create_query()> is L<DBIx::Custom::Query> object.
1015
+This keep the information of SQL and column names.
1016
+
1017
+    {
1018
+        sql     => 'insert into books (title, author) values (?, ?);',
1019
+        columns => ['title', 'author']
1020
+    }
1021
+
1022
+Execute query repeatedly.
1015 1023
     
1016 1024
     my $inputs = [
1017 1025
         {title => 'Perl',      author => 'Ken'},
... ...
@@ -1022,26 +1030,26 @@ Execute query repeatedly
1022 1030
         $dbi->execute($query, $input);
1023 1031
     }
1024 1032
 
1025
-This is faster than C<insert()> and C<update()> method.
1033
+This is faster than C<insert()> method.
1026 1034
 
1027
-=head2 caching
1035
+=head3 caching
1028 1036
 
1029
-C<execute()> method cache the parsing result of SQL soruce.
1037
+C<execute()> method caches the parsed result of the source of SQL.
1030 1038
 Default to 1
1031 1039
 
1032 1040
     $dbi->cache(1);
1033 1041
 
1034 1042
 Caching is on memory, but you can change this by C<cache_method()>.
1035 1043
 First argument is L<DBIx::Custom> object.
1036
-Second argument is SQL source,
1037
-such as "select * from books where {=title} and {=author};";
1044
+Second argument is a source of SQL,
1045
+such as "select * from books where {= title} and {= author};";
1038 1046
 Third argument is parsed result, such as
1039 1047
 {sql => "select * from books where title = ? and author = ?",
1040 1048
  columns => ['title', 'author']}, this is hash reference.
1041
-If argument is more than two, this is called ti set cache.
1042
-otherwise, called to get cache.
1049
+If arguments is more than two, this method is called to set cache.
1050
+If not, this method is called to get cache.
1043 1051
 
1044
-    $dbi->cache_mehod(sub {
1052
+    $dbi->cache_method(sub {
1045 1053
         sub {
1046 1054
             my $self = shift;
1047 1055
             
... ...
@@ -1212,7 +1220,7 @@ B<Example:>
1212 1220
 Enable filter check. 
1213 1221
 Default to 1.
1214 1222
 This check maybe damege performance.
1215
-If you require performance, set C<filter_check> to 0.
1223
+If you require performance, set C<filter_check> attribute to 0.
1216 1224
 
1217 1225
 =head1 METHODS
1218 1226
 
... ...
@@ -1226,7 +1234,7 @@ and implements the following new ones.
1226 1234
 
1227 1235
 Create a new L<DBIx::Custom> object and connect to the database.
1228 1236
 L<DBIx::Custom> is a wrapper of L<DBI>.
1229
-C<AutoCommit> and C<RaiseError> option is true, 
1237
+C<AutoCommit> and C<RaiseError> options are true, 
1230 1238
 and C<PrintError> option is false by default. 
1231 1239
 
1232 1240
 =head2 C<insert>
... ...
@@ -1240,11 +1248,11 @@ Execute insert statement.
1240 1248
 C<insert> method have C<table>, C<param>, C<append>
1241 1249
 and C<filter> arguments.
1242 1250
 C<table> is a table name.
1243
-C<param> is column-value pairs. this must be hash reference.
1251
+C<param> is the pairs of column name value. this must be hash reference.
1244 1252
 C<append> is a string added at the end of the SQL statement.
1245 1253
 C<filter> is filters when parameter binding is executed.
1246 1254
 This is overwrites C<default_bind_filter>.
1247
-Return value of C<insert> is the count of affected rows.
1255
+Return value of C<insert()> is the count of affected rows.
1248 1256
 
1249 1257
 B<Example:>
1250 1258
 
... ...
@@ -1270,14 +1278,14 @@ C<where> is where clause. this must be hash reference.
1270 1278
 C<append> is a string added at the end of the SQL statement.
1271 1279
 C<filter> is filters when parameter binding is executed.
1272 1280
 This is overwrites C<default_bind_filter>.
1273
-Return value of C<update> is the count of affected rows.
1281
+Return value of C<update()> is the count of affected rows.
1274 1282
 
1275 1283
 B<Example:>
1276 1284
 
1277 1285
     $dbi->update(table  => 'books',
1278 1286
                  param  => {title => 'Perl', author => 'Taro'},
1279 1287
                  where  => {id => 5},
1280
-                 append => "for update",
1288
+                 append => "some statement",
1281 1289
                  filter => {title => 'encode_utf8'});
1282 1290
 
1283 1291
 =head2 C<update_all>
... ...
@@ -1290,7 +1298,7 @@ B<Example:>
1290 1298
 Execute update statement to update all rows.
1291 1299
 Arguments is same as C<update> method,
1292 1300
 except that C<update_all> don't have C<where> argument.
1293
-Return value of C<update_all> is the count of affected rows.
1301
+Return value of C<update_all()> is the count of affected rows.
1294 1302
 
1295 1303
 B<Example:>
1296 1304
 
... ...
@@ -1311,7 +1319,7 @@ C<table> is a table name.
1311 1319
 C<where> is where clause. this must be hash reference.
1312 1320
 C<append> is a string added at the end of the SQL statement.
1313 1321
 C<filter> is filters when parameter binding is executed.
1314
-Return value of C<delete> is the count of affected rows.
1322
+Return value of C<delete()> is the count of affected rows.
1315 1323
 
1316 1324
 B<Example:>
1317 1325
 
... ...
@@ -1327,7 +1335,7 @@ B<Example:>
1327 1335
 Execute delete statement to delete all rows.
1328 1336
 Arguments is same as C<delete> method,
1329 1337
 except that C<delete_all> don't have C<where> argument.
1330
-Return value of C<delete_all> is the count of affected rows.
1338
+Return value of C<delete_all()> is the count of affected rows.
1331 1339
 
1332 1340
 B<Example:>
1333 1341
     
... ...
@@ -1343,11 +1351,10 @@ B<Example:>
1343 1351
                               filter   => \%filter);
1344 1352
 
1345 1353
 Execute select statement.
1346
-C<select> method have C<table>, C<column>, C<where>, C<append>
1354
+C<select> method have C<table>, C<column>, C<where>, C<append>,
1347 1355
 C<relation> and C<filter> arguments.
1348 1356
 C<table> is a table name.
1349
-C<where> is where clause. this must be hash reference
1350
-or a string containing such tags as "{= title} or {= author}".
1357
+C<where> is where clause. this is normally hash reference.
1351 1358
 C<append> is a string added at the end of the SQL statement.
1352 1359
 C<filter> is filters when parameter binding is executed.
1353 1360
 
... ...
@@ -1375,30 +1382,53 @@ B<Example:>
1375 1382
         relation => {'books.id' => 'rental.book_id'}
1376 1383
     );
1377 1384
 
1385
+If you use more complex condition,
1386
+you can specify a array reference to C<where> argument.
1387
+
1388
+    my $result = $dbi->select(
1389
+        table  => 'books',
1390
+        column => ['title', 'author'],
1391
+        where  => ['{= title} or {like author}',
1392
+                   {title => '%Perl%', author => 'Ken'}]
1393
+    );
1394
+
1395
+First element is a string. it contains tags,
1396
+such as "{= title} or {like author}".
1397
+Second element is paramters.
1398
+
1378 1399
 =head2 C<create_query>
1379 1400
     
1380 1401
     my $query = $dbi->create_query(
1381
-        "select * from authors where {= name} and {= age};"
1402
+        "select * from books where {= author} and {like title};"
1382 1403
     );
1383 1404
 
1384
-Create the instance of L<DBIx::Custom::Query> from SQL source.
1405
+Create the instance of L<DBIx::Custom::Query> from the source of SQL.
1406
+If you want to get high performance,
1407
+use C<create_query()> method and execute it by C<execute()> method
1408
+instead of suger methods.
1409
+
1410
+    $dbi->execute($query, {author => 'Ken', title => '%Perl%'});
1385 1411
 
1386 1412
 =head2 C<execute>
1387 1413
 
1388 1414
     my $result = $dbi->execute($query,  param => $params, filter => \%filter);
1389 1415
     my $result = $dbi->execute($source, param => $params, filter => \%filter);
1390 1416
 
1391
-Execute query or SQL source. Query is L<DBIx::Csutom::Query> object.
1392
-Return value is L<DBIx::Custom::Result> in select statement,
1393
-or the count of affected rows in insert, update, delete statement.
1417
+Execute query or the source of SQL.
1418
+Query is L<DBIx::Custom::Query> object.
1419
+Return value is L<DBIx::Custom::Result> if select statement is executed,
1420
+or the count of affected rows if insert, update, delete statement is executed.
1394 1421
 
1395 1422
 B<Example:>
1396 1423
 
1397
-    my $result = $dbi->execute("select * from authors where {= name} and {= age}", 
1398
-                            param => {name => 'taro', age => 19});
1424
+    my $result = $dbi->execute(
1425
+        "select * from books where {= author} and {like title}", 
1426
+        param => {author => 'Ken', title => '%Perl%'}
1427
+    );
1399 1428
     
1400 1429
     while (my $row = $result->fetch) {
1401
-        # do something
1430
+        my $author = $row->[0];
1431
+        my $title  = $row->[1];
1402 1432
     }
1403 1433
 
1404 1434
 =head2 C<register_filter>
... ...
@@ -1406,40 +1436,32 @@ B<Example:>
1406 1436
     $dbi->register_filter(%filters);
1407 1437
     $dbi->register_filter(\%filters);
1408 1438
     
1409
-Register filter. Registered filters is available in the following methods
1439
+Register filter. Registered filters is available in the following attributes
1410 1440
 or arguments.
1411 1441
 
1412 1442
 =over 4
1413 1443
 
1414 1444
 =item *
1415 1445
 
1416
-C<default_bind_filter()>
1417
-
1418
-=item *
1419
-
1420
-C<default_fetch_filter()>
1446
+C<default_bind_filter>, C<default_fetch_filter>
1421 1447
 
1422 1448
 =item *
1423 1449
 
1424 1450
 C<filter> argument of C<insert()>, C<update()>,
1425
-C<update_all()>, C<delete()>, C<delete_all()>, C<select()>,
1426
-C<execute> method.
1427
-
1428
-=item *
1429
-
1430
-C<DBIx::Custom::Query::default_filter()>
1451
+C<update_all()>, C<delete()>, C<delete_all()>, C<select()>
1452
+methods
1431 1453
 
1432 1454
 =item *
1433 1455
 
1434
-C<DBIx::Csutom::Query::filter()>
1456
+C<execute()> method
1435 1457
 
1436 1458
 =item *
1437 1459
 
1438
-C<DBIx::Custom::Result::default_filter()>
1460
+C<default_filter> and C<filter> of C<DBIx::Custom::Query>
1439 1461
 
1440 1462
 =item *
1441 1463
 
1442
-C<DBIx::Custom::Result::filter()>
1464
+C<default_filter> and C<filter> of C<DBIx::Custom::Result>
1443 1465
 
1444 1466
 =back
1445 1467