| ... | ... |
@@ -1192,19 +1192,23 @@ If tranzation is died, rollback is execute. |
| 1192 | 1192 |
|
| 1193 | 1193 |
=head2 insert |
| 1194 | 1194 |
|
| 1195 |
-Insert |
|
| 1195 |
+Insert row |
|
| 1196 | 1196 |
|
| 1197 |
- $dbi->insert($table, $insert_values); |
|
| 1197 |
+ $ret_val = $self->insert($table, \%$insert_params); |
|
| 1198 |
+ |
|
| 1199 |
+$ret_val is maybe affected rows count |
|
| 1198 | 1200 |
|
| 1199 | 1201 |
# Sample |
| 1200 | 1202 |
$dbi->insert('books', {title => 'Perl', author => 'Taro'});
|
| 1201 | 1203 |
|
| 1202 | 1204 |
=head2 update |
| 1203 | 1205 |
|
| 1204 |
-Update |
|
| 1206 |
+Update rows |
|
| 1207 |
+ |
|
| 1208 |
+ $self = $self->update($table, \%update_params, \%where); |
|
| 1209 |
+ |
|
| 1210 |
+$ret_val is maybe affected rows count |
|
| 1205 | 1211 |
|
| 1206 |
- $dbi->update($table, $update_values, $where); |
|
| 1207 |
- |
|
| 1208 | 1212 |
# Sample |
| 1209 | 1213 |
$dbi->update('books', {title => 'Perl', author => 'Taro'}, {id => 5});
|
| 1210 | 1214 |
|
| ... | ... |
@@ -1212,69 +1216,99 @@ Update |
| 1212 | 1216 |
|
| 1213 | 1217 |
Update all rows |
| 1214 | 1218 |
|
| 1215 |
- $dbi->update($table, $updat_values); |
|
| 1219 |
+ $ret_val = $self->update_all($table, \%updat_params); |
|
| 1220 |
+ |
|
| 1221 |
+$ret_val is maybe affected rows count |
|
| 1222 |
+ |
|
| 1223 |
+ # Sample |
|
| 1224 |
+ $dbi->update_all('books', {author => 'taro'});
|
|
| 1216 | 1225 |
|
| 1217 | 1226 |
=head2 delete |
| 1218 | 1227 |
|
| 1219 |
-Delete |
|
| 1228 |
+Delete rows |
|
| 1229 |
+ |
|
| 1230 |
+ $ret_val = $self->delete($table, \%where); |
|
| 1220 | 1231 |
|
| 1221 |
- $dbi->delete($table, $where); |
|
| 1232 |
+$ret_val is maybe affected rows count |
|
| 1222 | 1233 |
|
| 1223 | 1234 |
# Sample |
| 1224 |
- $dbi->delete('Books', {id => 5});
|
|
| 1235 |
+ $dbi->delete('books', {id => 5});
|
|
| 1225 | 1236 |
|
| 1226 | 1237 |
=head2 delete_all |
| 1227 | 1238 |
|
| 1228 | 1239 |
Delete all rows |
| 1229 | 1240 |
|
| 1230 |
- $dbi->delete_all($table); |
|
| 1241 |
+ $ret_val = $self->delete_all($table); |
|
| 1231 | 1242 |
|
| 1232 |
-=head2 last_insert_id |
|
| 1233 |
- |
|
| 1234 |
-Get last insert id |
|
| 1243 |
+$ret_val is maybe affected rows count |
|
| 1235 | 1244 |
|
| 1236 |
- $last_insert_id = $dbi->last_insert_id; |
|
| 1237 |
- |
|
| 1238 |
-This method is implemented by subclass. |
|
| 1245 |
+ # Sample |
|
| 1246 |
+ $dib->delete_all('books');
|
|
| 1239 | 1247 |
|
| 1240 | 1248 |
=head2 select |
| 1241 | 1249 |
|
| 1242 |
-Select |
|
| 1250 |
+Select rows |
|
| 1243 | 1251 |
|
| 1244 |
- $dbi->select( |
|
| 1252 |
+ $resut = $self->select( |
|
| 1245 | 1253 |
$table, # must be string or array; |
| 1246 |
- [@$columns], # must be array reference. this is optional |
|
| 1247 |
- {%$where_params}, # must be hash reference. this is optional
|
|
| 1254 |
+ \@$columns, # must be array reference. this is optional |
|
| 1255 |
+ \%$where_params, # must be hash reference. this is optional |
|
| 1248 | 1256 |
$append_statement, # must be string. this is optional |
| 1249 | 1257 |
$query_edit_callback # must be code reference. this is optional |
| 1250 | 1258 |
); |
| 1259 |
+ |
|
| 1260 |
+$reslt is L<DBI::Custom::Result> object |
|
| 1261 |
+ |
|
| 1262 |
+The following is some select samples |
|
| 1263 |
+ |
|
| 1264 |
+ # select * from books; |
|
| 1265 |
+ $result = $dbi->select('books');
|
|
| 1251 | 1266 |
|
| 1252 |
- # Sample |
|
| 1267 |
+ # select * from books where title = 'Perl'; |
|
| 1268 |
+ $result = $dbi->select('books', {title => 1});
|
|
| 1269 |
+ |
|
| 1270 |
+ # select title, author from books where id = 1 for update; |
|
| 1271 |
+ $result = $dbi->select( |
|
| 1272 |
+ 'books', # table |
|
| 1273 |
+ ['title', 'author'], # columns |
|
| 1274 |
+ {id => 1}, # where clause
|
|
| 1275 |
+ 'for update', # append statement |
|
| 1276 |
+ ); |
|
| 1277 |
+ |
|
| 1278 |
+You can join multi tables |
|
| 1279 |
+ |
|
| 1280 |
+ $result = $dbi->select( |
|
| 1281 |
+ ['table1', 'table2'], # tables |
|
| 1282 |
+ ['table1.id as table1_id', 'title'], # columns (alias is ok) |
|
| 1283 |
+ {table1.id => 1}, # where clase
|
|
| 1284 |
+ "where table1.id = table2.id", # join clause (must start 'where') |
|
| 1285 |
+ ); |
|
| 1286 |
+ |
|
| 1287 |
+You can also edit query |
|
| 1288 |
+ |
|
| 1253 | 1289 |
$dbi->select( |
| 1254 |
- 'Books', |
|
| 1255 |
- ['title', 'author'], |
|
| 1256 |
- {id => 1},
|
|
| 1257 |
- "for update", |
|
| 1290 |
+ 'books', |
|
| 1291 |
+ # column, where clause, append statement, |
|
| 1258 | 1292 |
sub {
|
| 1259 | 1293 |
my $query = shift; |
| 1260 | 1294 |
$query->bind_filter(sub {
|
| 1261 | 1295 |
# ... |
| 1262 | 1296 |
}); |
| 1263 | 1297 |
} |
| 1264 |
- ); |
|
| 1265 |
- |
|
| 1266 |
- # The way to join multi tables |
|
| 1267 |
- $dbi->select( |
|
| 1268 |
- ['table1', 'table2'], |
|
| 1269 |
- ['table1.id as table1_id', 'title'], |
|
| 1270 |
- {table1.id => 1},
|
|
| 1271 |
- "where table1.id = table2.id", |
|
| 1272 |
- ); |
|
| 1298 |
+ } |
|
| 1299 |
+ |
|
| 1300 |
+ |
|
| 1301 |
+=head2 last_insert_id |
|
| 1302 |
+ |
|
| 1303 |
+Get last insert id |
|
| 1273 | 1304 |
|
| 1305 |
+ $last_insert_id = $dbi->last_insert_id; |
|
| 1274 | 1306 |
|
| 1275 |
-=head1 CAUTION |
|
| 1307 |
+This method is implemented by subclass. |
|
| 1308 |
+ |
|
| 1309 |
+=head1 Caution |
|
| 1276 | 1310 |
|
| 1277 |
-DBIx::Custom have DIB object internal. |
|
| 1311 |
+DBIx::Custom have DBI object. |
|
| 1278 | 1312 |
This module is work well in the following DBI condition. |
| 1279 | 1313 |
|
| 1280 | 1314 |
1. AutoCommit is true |