|
594 | 594 | end
|
595 | 595 | end
|
596 | 596 | end
|
| 597 | + |
| 598 | + context 'last_id' do |
| 599 | + before(:each) do |
| 600 | + @client.query "USE test" |
| 601 | + @client.query "CREATE TABLE IF NOT EXISTS lastIdTest (`id` BIGINT NOT NULL AUTO_INCREMENT, blah INT(11), PRIMARY KEY (`id`))" |
| 602 | + end |
| 603 | + |
| 604 | + after(:each) do |
| 605 | + @client.query "DROP TABLE lastIdTest" |
| 606 | + end |
| 607 | + |
| 608 | + it 'should return last insert id' do |
| 609 | + stmt = @client.prepare 'INSERT INTO lastIdTest (blah) VALUES (?)' |
| 610 | + expect(stmt.last_id).to eq 0 |
| 611 | + stmt.execute 1 |
| 612 | + expect(stmt.last_id).to eq 1 |
| 613 | + end |
| 614 | + |
| 615 | + it 'should handle bigint ids' do |
| 616 | + stmt = @client.prepare 'INSERT INTO lastIdTest (id, blah) VALUES (?, ?)' |
| 617 | + stmt.execute 5000000000, 5000 |
| 618 | + expect(stmt.last_id).to eql(5000000000) |
| 619 | + |
| 620 | + stmt = @client.prepare 'INSERT INTO lastIdTest (blah) VALUES (?)' |
| 621 | + stmt.execute 5001 |
| 622 | + expect(stmt.last_id).to eql(5000000001) |
| 623 | + end |
| 624 | + end |
| 625 | + |
| 626 | + context 'affected_rows' do |
| 627 | + before :each do |
| 628 | + @client.query 'DELETE FROM mysql2_test' |
| 629 | + @client.query 'INSERT INTO mysql2_test (bool_cast_test) VALUES (1)' |
| 630 | + end |
| 631 | + |
| 632 | + after :each do |
| 633 | + @client.query 'DELETE FROM mysql2_test' |
| 634 | + end |
| 635 | + |
| 636 | + it 'should return number of rows affected by an insert' do |
| 637 | + stmt = @client.prepare 'INSERT INTO mysql2_test (bool_cast_test) VALUES (?)' |
| 638 | + expect(stmt.affected_rows).to eq 0 |
| 639 | + stmt.execute 1 |
| 640 | + expect(stmt.affected_rows).to eq 1 |
| 641 | + end |
| 642 | + |
| 643 | + it 'should return number of rows affected by an update' do |
| 644 | + stmt = @client.prepare 'UPDATE mysql2_test SET bool_cast_test=? WHERE bool_cast_test=?' |
| 645 | + stmt.execute 0, 1 |
| 646 | + expect(stmt.affected_rows).to eq 1 |
| 647 | + end |
| 648 | + |
| 649 | + it 'should return number of rows affected by a delete' do |
| 650 | + stmt = @client.prepare 'DELETE FROM mysql2_test WHERE bool_cast_test=?' |
| 651 | + stmt.execute 1 |
| 652 | + expect(stmt.affected_rows).to eq 1 |
| 653 | + end |
| 654 | + end |
597 | 655 | end
|
0 commit comments