| ... | ... |
@@ -197,275 +197,6 @@ my $binary; |
| 197 | 197 |
$dbi = DBIx::Custom->connect; |
| 198 | 198 |
|
| 199 | 199 |
|
| 200 |
-test 'delete_at'; |
|
| 201 |
-$dbi = DBIx::Custom->connect; |
|
| 202 |
-eval { $dbi->execute('drop table table1') };
|
|
| 203 |
-$dbi->execute($create_table1_2); |
|
| 204 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 205 |
-$dbi->delete_at( |
|
| 206 |
- table => 'table1', |
|
| 207 |
- primary_key => ['key1', 'key2'], |
|
| 208 |
- where => [1, 2], |
|
| 209 |
-); |
|
| 210 |
-is_deeply($dbi->select(table => 'table1')->all, []); |
|
| 211 |
- |
|
| 212 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 213 |
-$dbi->delete_at( |
|
| 214 |
- table => 'table1', |
|
| 215 |
- primary_key => 'key1', |
|
| 216 |
- where => 1, |
|
| 217 |
-); |
|
| 218 |
-is_deeply($dbi->select(table => 'table1')->all, []); |
|
| 219 |
- |
|
| 220 |
-test 'insert_at'; |
|
| 221 |
-$dbi = DBIx::Custom->connect; |
|
| 222 |
-eval { $dbi->execute('drop table table1') };
|
|
| 223 |
-$dbi->execute($create_table1_2); |
|
| 224 |
-$dbi->insert_at( |
|
| 225 |
- primary_key => ['key1', 'key2'], |
|
| 226 |
- table => 'table1', |
|
| 227 |
- where => [1, 2], |
|
| 228 |
- param => {key3 => 3}
|
|
| 229 |
-); |
|
| 230 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 231 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 232 |
-is($dbi->select(table => 'table1')->one->{key3}, 3);
|
|
| 233 |
- |
|
| 234 |
-$dbi->delete_all(table => 'table1'); |
|
| 235 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 236 |
-$dbi->insert_at( |
|
| 237 |
- primary_key => 'key1', |
|
| 238 |
- table => 'table1', |
|
| 239 |
- where => 1, |
|
| 240 |
- param => {key2 => 2, key3 => 3}
|
|
| 241 |
-); |
|
| 242 |
- |
|
| 243 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 244 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 245 |
-is($dbi->select(table => 'table1')->one->{key3}, 3);
|
|
| 246 |
- |
|
| 247 |
-eval {
|
|
| 248 |
- $dbi->insert_at( |
|
| 249 |
- table => 'table1', |
|
| 250 |
- primary_key => ['key1', 'key2'], |
|
| 251 |
- where => {},
|
|
| 252 |
- param => {key1 => 1, key2 => 2, key3 => 3},
|
|
| 253 |
- ); |
|
| 254 |
-}; |
|
| 255 |
-like($@, qr/must be/); |
|
| 256 |
- |
|
| 257 |
-$dbi = DBIx::Custom->connect; |
|
| 258 |
-eval { $dbi->execute('drop table table1') };
|
|
| 259 |
-$dbi->execute($create_table1_2); |
|
| 260 |
-$dbi->insert_at( |
|
| 261 |
- {key3 => 3},
|
|
| 262 |
- primary_key => ['key1', 'key2'], |
|
| 263 |
- table => 'table1', |
|
| 264 |
- where => [1, 2], |
|
| 265 |
-); |
|
| 266 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 267 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 268 |
-is($dbi->select(table => 'table1')->one->{key3}, 3);
|
|
| 269 |
- |
|
| 270 |
-test 'update_at'; |
|
| 271 |
-$dbi = DBIx::Custom->connect; |
|
| 272 |
-eval { $dbi->execute('drop table table1') };
|
|
| 273 |
-$dbi->execute($create_table1_2); |
|
| 274 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 275 |
-$dbi->update_at( |
|
| 276 |
- table => 'table1', |
|
| 277 |
- primary_key => ['key1', 'key2'], |
|
| 278 |
- where => [1, 2], |
|
| 279 |
- param => {key3 => 4}
|
|
| 280 |
-); |
|
| 281 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 282 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 283 |
-is($dbi->select(table => 'table1')->one->{key3}, 4);
|
|
| 284 |
- |
|
| 285 |
-$dbi->delete_all(table => 'table1'); |
|
| 286 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 287 |
-$dbi->update_at( |
|
| 288 |
- table => 'table1', |
|
| 289 |
- primary_key => 'key1', |
|
| 290 |
- where => 1, |
|
| 291 |
- param => {key3 => 4}
|
|
| 292 |
-); |
|
| 293 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 294 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 295 |
-is($dbi->select(table => 'table1')->one->{key3}, 4);
|
|
| 296 |
- |
|
| 297 |
-$dbi = DBIx::Custom->connect; |
|
| 298 |
-eval { $dbi->execute('drop table table1') };
|
|
| 299 |
-$dbi->execute($create_table1_2); |
|
| 300 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 301 |
-$dbi->update_at( |
|
| 302 |
- {key3 => 4},
|
|
| 303 |
- table => 'table1', |
|
| 304 |
- primary_key => ['key1', 'key2'], |
|
| 305 |
- where => [1, 2] |
|
| 306 |
-); |
|
| 307 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 308 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 309 |
-is($dbi->select(table => 'table1')->one->{key3}, 4);
|
|
| 310 |
- |
|
| 311 |
-test 'select_at'; |
|
| 312 |
-$dbi = DBIx::Custom->connect; |
|
| 313 |
-eval { $dbi->execute('drop table table1') };
|
|
| 314 |
-$dbi->execute($create_table1_2); |
|
| 315 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 316 |
-$result = $dbi->select_at( |
|
| 317 |
- table => 'table1', |
|
| 318 |
- primary_key => ['key1', 'key2'], |
|
| 319 |
- where => [1, 2] |
|
| 320 |
-); |
|
| 321 |
-$row = $result->one; |
|
| 322 |
-is($row->{key1}, 1);
|
|
| 323 |
-is($row->{key2}, 2);
|
|
| 324 |
-is($row->{key3}, 3);
|
|
| 325 |
- |
|
| 326 |
-$dbi->delete_all(table => 'table1'); |
|
| 327 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 328 |
-$result = $dbi->select_at( |
|
| 329 |
- table => 'table1', |
|
| 330 |
- primary_key => 'key1', |
|
| 331 |
- where => 1, |
|
| 332 |
-); |
|
| 333 |
-$row = $result->one; |
|
| 334 |
-is($row->{key1}, 1);
|
|
| 335 |
-is($row->{key2}, 2);
|
|
| 336 |
-is($row->{key3}, 3);
|
|
| 337 |
- |
|
| 338 |
-$dbi->delete_all(table => 'table1'); |
|
| 339 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 340 |
-$result = $dbi->select_at( |
|
| 341 |
- table => 'table1', |
|
| 342 |
- primary_key => ['key1', 'key2'], |
|
| 343 |
- where => [1, 2] |
|
| 344 |
-); |
|
| 345 |
-$row = $result->one; |
|
| 346 |
-is($row->{key1}, 1);
|
|
| 347 |
-is($row->{key2}, 2);
|
|
| 348 |
-is($row->{key3}, 3);
|
|
| 349 |
- |
|
| 350 |
-eval {
|
|
| 351 |
- $result = $dbi->select_at( |
|
| 352 |
- table => 'table1', |
|
| 353 |
- primary_key => ['key1', 'key2'], |
|
| 354 |
- where => {},
|
|
| 355 |
- ); |
|
| 356 |
-}; |
|
| 357 |
-like($@, qr/must be/); |
|
| 358 |
- |
|
| 359 |
-eval {
|
|
| 360 |
- $result = $dbi->select_at( |
|
| 361 |
- table => 'table1', |
|
| 362 |
- primary_key => ['key1', 'key2'], |
|
| 363 |
- where => [1], |
|
| 364 |
- ); |
|
| 365 |
-}; |
|
| 366 |
-like($@, qr/same/); |
|
| 367 |
- |
|
| 368 |
-eval {
|
|
| 369 |
- $result = $dbi->update_at( |
|
| 370 |
- table => 'table1', |
|
| 371 |
- primary_key => ['key1', 'key2'], |
|
| 372 |
- where => {},
|
|
| 373 |
- param => {key1 => 1, key2 => 2},
|
|
| 374 |
- ); |
|
| 375 |
-}; |
|
| 376 |
-like($@, qr/must be/); |
|
| 377 |
- |
|
| 378 |
-eval {
|
|
| 379 |
- $result = $dbi->delete_at( |
|
| 380 |
- table => 'table1', |
|
| 381 |
- primary_key => ['key1', 'key2'], |
|
| 382 |
- where => {},
|
|
| 383 |
- ); |
|
| 384 |
-}; |
|
| 385 |
-like($@, qr/must be/); |
|
| 386 |
- |
|
| 387 |
-test 'columns'; |
|
| 388 |
-use MyDBI1; |
|
| 389 |
-$dbi = MyDBI1->connect; |
|
| 390 |
-$model = $dbi->model('book');
|
|
| 391 |
- |
|
| 392 |
- |
|
| 393 |
-test 'model delete_at'; |
|
| 394 |
-$dbi = MyDBI6->connect; |
|
| 395 |
-eval { $dbi->execute('drop table table1') };
|
|
| 396 |
-eval { $dbi->execute('drop table table2') };
|
|
| 397 |
-eval { $dbi->execute('drop table table3') };
|
|
| 398 |
-$dbi->execute($create_table1_2); |
|
| 399 |
-$dbi->execute($create_table2_2); |
|
| 400 |
-$dbi->execute($create_table3); |
|
| 401 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 402 |
-$dbi->model('table1')->delete_at(where => [1, 2]);
|
|
| 403 |
-is_deeply($dbi->select(table => 'table1')->all, []); |
|
| 404 |
-$dbi->insert(table => 'table2', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 405 |
-$dbi->model('table1_1')->delete_at(where => [1, 2]);
|
|
| 406 |
-is_deeply($dbi->select(table => 'table1')->all, []); |
|
| 407 |
-$dbi->insert(table => 'table3', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 408 |
-$dbi->model('table1_3')->delete_at(where => [1, 2]);
|
|
| 409 |
-is_deeply($dbi->select(table => 'table1')->all, []); |
|
| 410 |
- |
|
| 411 |
-test 'model insert_at'; |
|
| 412 |
-$dbi = MyDBI6->connect; |
|
| 413 |
-eval { $dbi->execute('drop table table1') };
|
|
| 414 |
-$dbi->execute($create_table1_2); |
|
| 415 |
-$dbi->model('table1')->insert_at(
|
|
| 416 |
- where => [1, 2], |
|
| 417 |
- param => {key3 => 3}
|
|
| 418 |
-); |
|
| 419 |
-$result = $dbi->model('table1')->select;
|
|
| 420 |
-$row = $result->one; |
|
| 421 |
-is($row->{key1}, 1);
|
|
| 422 |
-is($row->{key2}, 2);
|
|
| 423 |
-is($row->{key3}, 3);
|
|
| 424 |
- |
|
| 425 |
-test 'model update_at'; |
|
| 426 |
-$dbi = MyDBI6->connect; |
|
| 427 |
-eval { $dbi->execute('drop table table1') };
|
|
| 428 |
-$dbi->execute($create_table1_2); |
|
| 429 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 430 |
-$dbi->model('table1')->update_at(
|
|
| 431 |
- where => [1, 2], |
|
| 432 |
- param => {key3 => 4}
|
|
| 433 |
-); |
|
| 434 |
-$result = $dbi->model('table1')->select;
|
|
| 435 |
-$row = $result->one; |
|
| 436 |
-is($row->{key1}, 1);
|
|
| 437 |
-is($row->{key2}, 2);
|
|
| 438 |
-is($row->{key3}, 4);
|
|
| 439 |
- |
|
| 440 |
-test 'model select_at'; |
|
| 441 |
-$dbi = MyDBI6->connect; |
|
| 442 |
-eval { $dbi->execute('drop table table1') };
|
|
| 443 |
-$dbi->execute($create_table1_2); |
|
| 444 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3});
|
|
| 445 |
-$result = $dbi->model('table1')->select_at(where => [1, 2]);
|
|
| 446 |
-$row = $result->one; |
|
| 447 |
-is($row->{key1}, 1);
|
|
| 448 |
-is($row->{key2}, 2);
|
|
| 449 |
-is($row->{key3}, 3);
|
|
| 450 |
- |
|
| 451 |
- |
|
| 452 |
-test 'mycolumn and column'; |
|
| 453 |
-$dbi = MyDBI7->connect; |
|
| 454 |
-eval { $dbi->execute('drop table table1') };
|
|
| 455 |
-eval { $dbi->execute('drop table table2') };
|
|
| 456 |
-$dbi->execute($create_table1); |
|
| 457 |
-$dbi->execute($create_table2); |
|
| 458 |
-$dbi->separator('__');
|
|
| 459 |
-$dbi->setup_model; |
|
| 460 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
|
|
| 461 |
-$dbi->insert(table => 'table2', param => {key1 => 1, key3 => 3});
|
|
| 462 |
-$model = $dbi->model('table1');
|
|
| 463 |
-$result = $model->select( |
|
| 464 |
- column => [$model->mycolumn, $model->column('table2')],
|
|
| 465 |
- where => {'table1.key1' => 1}
|
|
| 466 |
-); |
|
| 467 |
-is_deeply($result->one, |
|
| 468 |
- {key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
|
|
| 469 | 200 |
|
| 470 | 201 |
test 'update_param'; |
| 471 | 202 |
$dbi = DBIx::Custom->connect; |